@@ -99,6 +99,37 @@ export default class Problems extends React.PureComponent {
99
99
}
100
100
}
101
101
102
+ submitsolution ( ) {
103
+ console . log ( "Submitting solution" ) ;
104
+ const path = require ( 'path' ) ;
105
+ var prob = this . state . probs [ this . state . curr ]
106
+ var langcode = atom . config . get ( "codeblue.programmingLanguage" )
107
+ var ext = ""
108
+ if ( langcode == 43 ) ext = ".c"
109
+ else if ( langcode == 54 ) ext = ".cpp"
110
+ else ext = ".py"
111
+ var wd = atom . config . get ( "codeblue.workingDirectory" )
112
+ var towhere = path . join ( wd , prob . index )
113
+ var tosub = path . join ( towhere , prob . index + ext )
114
+ var proburl = "https://codeforces.com/contest/" + this . props . contest . id + "/problem/" + prob . index
115
+
116
+ cmd = "oj s " + proburl + " " + tosub + " --wait=0 --yes --no-open"
117
+ if ( langcode == 41 ) {
118
+ cmd += " --guess-python-interpreter pypy"
119
+ }
120
+
121
+ const { exec } = require ( 'child_process' ) ;
122
+ exec ( cmd , ( error , stdout , stderr ) => {
123
+ if ( error !== null ) {
124
+ console . log ( error ) ;
125
+ atom . notifications . addError ( "Error occured while submitting" )
126
+ } else {
127
+ this . loadsubmissions ( )
128
+ }
129
+
130
+ } )
131
+ }
132
+
102
133
fetch ( url ) {
103
134
return new Promise ( ( resolve , reject ) => {
104
135
request ( url , ( error , response , body ) => {
@@ -178,7 +209,7 @@ export default class Problems extends React.PureComponent {
178
209
this . setState ( { alloutputs : alloutputs } )
179
210
this . setState ( { allverdicts : allverdicts } )
180
211
// console.log(this.state.allverdicts);
181
- // this.createnv()
212
+ this . createnv ( )
182
213
}
183
214
184
215
loadsamplecases ( i ) {
@@ -217,7 +248,7 @@ export default class Problems extends React.PureComponent {
217
248
}
218
249
219
250
loadmystanding ( ) {
220
- console . log ( "Loading my standing" ) ;
251
+ // console.log("Loading my standing");
221
252
var url = "https://codeforces.com/api/contest.standings?contestId=" + this . props . contest . id + "&from=1&handles=" + atom . config . get ( "codeblue.codeforcesHandle" )
222
253
fetch ( url )
223
254
. then ( res => res . json ( ) )
@@ -226,7 +257,8 @@ export default class Problems extends React.PureComponent {
226
257
}
227
258
228
259
loadsubmissions ( ) {
229
- console . log ( "Loading new submissions" ) ;
260
+ console . log ( "Refreshing" ) ;
261
+ // console.log("Loading new submissions");
230
262
var url = "https://codeforces.com/contest/" + this . props . contest . id
231
263
this . fetch ( url ) . then ( ( html ) => {
232
264
this . scrape ( html ) ;
@@ -238,12 +270,13 @@ export default class Problems extends React.PureComponent {
238
270
}
239
271
240
272
fetchproblems ( problems ) {
273
+ // console.log("Fetching problems", problems);
241
274
var probs = [ ]
242
275
var noftests = [ ]
243
276
var allinputs = { }
244
277
var alloutputs = { }
245
278
var allverdicts = { }
246
- for ( var problem of problems ) {
279
+ for ( var problem of this . state . probs ) {
247
280
probs . push ( {
248
281
index : problem . index ,
249
282
name : problem . name ,
@@ -271,12 +304,20 @@ export default class Problems extends React.PureComponent {
271
304
var i = 0
272
305
for ( var prob of this . state . probs ) {
273
306
probs . push ( prob )
307
+ if ( prob . verdict == "OK" ) continue
308
+
274
309
for ( var action of this . state . actions ) {
275
310
if ( action . index == prob . index ) {
276
- probs [ i ] . verdict = action . verdict
277
- probs [ i ] . testset = action . testset
278
- probs [ i ] . errtest = action . errtest
279
- break
311
+ if ( action . verdict == "OK" ) {
312
+ probs [ i ] . verdict = "OK"
313
+ probs [ i ] . testset = action . testset
314
+ probs [ i ] . errtest = action . errtest
315
+ break
316
+ } else if ( prob . verdict == "NONE" ) {
317
+ probs [ i ] . verdict = action . verdict
318
+ probs [ i ] . testset = action . testset
319
+ probs [ i ] . errtest = action . errtest
320
+ }
280
321
}
281
322
}
282
323
i ++ ;
@@ -293,8 +334,9 @@ export default class Problems extends React.PureComponent {
293
334
else if ( action . verdict == "TIME_LIMIT_EXCEEDED" ) icon = "clock"
294
335
else if ( action . verdict == "RUNTIME_ERROR" ) icon = "stop"
295
336
else if ( action . verdict == "COMPILATION_ERROR" ) icon = "alert"
296
- else if ( action . verdict == "TESTING" ) icon = "kebab-horizontal"
297
337
else if ( action . verdict == "MEMORY_LIMIT_EXCEEDED" ) icon = "database"
338
+ else if ( action . verdict == "CHALLENGED" ) icon = "flame"
339
+ else icon = "hourglass"
298
340
299
341
actions . push ( {
300
342
index : action . problem . index ,
@@ -311,27 +353,58 @@ export default class Problems extends React.PureComponent {
311
353
}
312
354
313
355
fetchactions ( ) {
314
- console . log ( "Loading my actions" ) ;
356
+ // console.log("Loading my actions");
315
357
var url = "https://codeforces.com/api/contest.status?contestId=" + this . props . contest . id + "&handle=" + atom . config . get ( "codeblue.codeforcesHandle" )
316
358
fetch ( url )
317
359
. then ( res => res . json ( ) )
318
360
. then ( res => this . reloadactions ( res . result ) )
319
361
. catch ( err => console . log ( err ) )
320
362
}
321
363
364
+ scrapeproblems ( html ) {
365
+ $ = cheerio . load ( html )
366
+ var i = 2
367
+ var probs = [ ]
368
+ while ( true ) {
369
+ var idx = $ ( `#pageContent > div.datatable > div:nth-child(6) > table > tbody > tr:nth-child(${ i } ) > td.id > a` ) . text ( ) . trim ( )
370
+ var nm = $ ( `#pageContent > div.datatable > div:nth-child(6) > table > tbody > tr:nth-child(${ i } ) > td:nth-child(2) > div > div:nth-child(1) > a` ) . text ( ) . trim ( )
371
+ if ( idx . length == 0 ) {
372
+ break ;
373
+ } else {
374
+ probs . push ( { index : idx , name : nm } )
375
+ }
376
+ i ++ ;
377
+ }
378
+
379
+ this . setState ( { probs : probs } )
380
+ }
381
+
322
382
componentWillMount ( ) {
323
- var url = "https://codeforces.com/api/contest.standings?contestId=" + this . props . contest . id + "&from=1&count=1"
324
- fetch ( url )
325
- . then ( res => res . json ( ) )
326
- . then ( res => this . fetchproblems ( res . result . problems ) )
327
- . catch ( err => console . log ( err ) )
383
+ var url = "https://codeforces.com/contest/" + this . props . contest . id
384
+ this . fetch ( url ) . then ( html => {
385
+ this . scrapeproblems ( html ) ;
386
+ } ) . then ( res => {
387
+ this . fetchproblems ( )
388
+ } ) . catch ( ( error ) => {
389
+ atom . notifications . addWarning ( error . reason )
390
+ } )
328
391
329
- // setInterval(()=>{this.loadsubmissions()},10000)
392
+ var intervaltime = atom . config . get ( "codeblue.refreshinterval" )
393
+
394
+ if ( this . props . contest . finished == 0 ) {
395
+ setInterval ( ( ) => { this . loadsubmissions ( ) } , intervaltime * 1000 )
396
+ }
330
397
}
331
398
332
399
hide ( ele ) {
333
400
if ( ele == null ) return
334
- var val = ele . target . parentElement . nextElementSibling . style . display
401
+ var parent = ele . target . parentElement
402
+ if ( parent == null ) return
403
+ var tohide = parent . nextElementSibling
404
+ if ( tohide == null ) return
405
+ if ( tohide . classList . length < 1 ) return
406
+ if ( tohide . classList [ 0 ] != "problems" ) return
407
+ var val = tohide . style . display
335
408
if ( val == "flex" ) {
336
409
ele . target . parentElement . nextElementSibling . style . display = "none" ;
337
410
} else {
@@ -361,6 +434,7 @@ export default class Problems extends React.PureComponent {
361
434
outputs = { this . state . alloutputs [ this . state . probs [ this . state . curr ] . index ] }
362
435
tests = { this . state . allverdicts [ this . state . probs [ this . state . curr ] . index ] }
363
436
runexamples = { this . runexamples . bind ( this ) }
437
+ submitsolution = { this . submitsolution . bind ( this ) }
364
438
/> : null }
365
439
{ this . state . probs . length ? < RecentSubmissions actions = { this . state . actions } /> : null }
366
440
</ div >
0 commit comments