@@ -99,6 +99,37 @@ export default class Problems extends React.PureComponent {
9999 }
100100 }
101101
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+
102133 fetch ( url ) {
103134 return new Promise ( ( resolve , reject ) => {
104135 request ( url , ( error , response , body ) => {
@@ -178,7 +209,7 @@ export default class Problems extends React.PureComponent {
178209 this . setState ( { alloutputs : alloutputs } )
179210 this . setState ( { allverdicts : allverdicts } )
180211 // console.log(this.state.allverdicts);
181- // this.createnv()
212+ this . createnv ( )
182213 }
183214
184215 loadsamplecases ( i ) {
@@ -217,7 +248,7 @@ export default class Problems extends React.PureComponent {
217248 }
218249
219250 loadmystanding ( ) {
220- console . log ( "Loading my standing" ) ;
251+ // console.log("Loading my standing");
221252 var url = "https://codeforces.com/api/contest.standings?contestId=" + this . props . contest . id + "&from=1&handles=" + atom . config . get ( "codeblue.codeforcesHandle" )
222253 fetch ( url )
223254 . then ( res => res . json ( ) )
@@ -226,7 +257,8 @@ export default class Problems extends React.PureComponent {
226257 }
227258
228259 loadsubmissions ( ) {
229- console . log ( "Loading new submissions" ) ;
260+ console . log ( "Refreshing" ) ;
261+ // console.log("Loading new submissions");
230262 var url = "https://codeforces.com/contest/" + this . props . contest . id
231263 this . fetch ( url ) . then ( ( html ) => {
232264 this . scrape ( html ) ;
@@ -238,12 +270,13 @@ export default class Problems extends React.PureComponent {
238270 }
239271
240272 fetchproblems ( problems ) {
273+ // console.log("Fetching problems", problems);
241274 var probs = [ ]
242275 var noftests = [ ]
243276 var allinputs = { }
244277 var alloutputs = { }
245278 var allverdicts = { }
246- for ( var problem of problems ) {
279+ for ( var problem of this . state . probs ) {
247280 probs . push ( {
248281 index : problem . index ,
249282 name : problem . name ,
@@ -271,12 +304,20 @@ export default class Problems extends React.PureComponent {
271304 var i = 0
272305 for ( var prob of this . state . probs ) {
273306 probs . push ( prob )
307+ if ( prob . verdict == "OK" ) continue
308+
274309 for ( var action of this . state . actions ) {
275310 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+ }
280321 }
281322 }
282323 i ++ ;
@@ -293,8 +334,9 @@ export default class Problems extends React.PureComponent {
293334 else if ( action . verdict == "TIME_LIMIT_EXCEEDED" ) icon = "clock"
294335 else if ( action . verdict == "RUNTIME_ERROR" ) icon = "stop"
295336 else if ( action . verdict == "COMPILATION_ERROR" ) icon = "alert"
296- else if ( action . verdict == "TESTING" ) icon = "kebab-horizontal"
297337 else if ( action . verdict == "MEMORY_LIMIT_EXCEEDED" ) icon = "database"
338+ else if ( action . verdict == "CHALLENGED" ) icon = "flame"
339+ else icon = "hourglass"
298340
299341 actions . push ( {
300342 index : action . problem . index ,
@@ -311,27 +353,58 @@ export default class Problems extends React.PureComponent {
311353 }
312354
313355 fetchactions ( ) {
314- console . log ( "Loading my actions" ) ;
356+ // console.log("Loading my actions");
315357 var url = "https://codeforces.com/api/contest.status?contestId=" + this . props . contest . id + "&handle=" + atom . config . get ( "codeblue.codeforcesHandle" )
316358 fetch ( url )
317359 . then ( res => res . json ( ) )
318360 . then ( res => this . reloadactions ( res . result ) )
319361 . catch ( err => console . log ( err ) )
320362 }
321363
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+
322382 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+ } )
328391
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+ }
330397 }
331398
332399 hide ( ele ) {
333400 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
335408 if ( val == "flex" ) {
336409 ele . target . parentElement . nextElementSibling . style . display = "none" ;
337410 } else {
@@ -361,6 +434,7 @@ export default class Problems extends React.PureComponent {
361434 outputs = { this . state . alloutputs [ this . state . probs [ this . state . curr ] . index ] }
362435 tests = { this . state . allverdicts [ this . state . probs [ this . state . curr ] . index ] }
363436 runexamples = { this . runexamples . bind ( this ) }
437+ submitsolution = { this . submitsolution . bind ( this ) }
364438 /> : null }
365439 { this . state . probs . length ? < RecentSubmissions actions = { this . state . actions } /> : null }
366440 </ div >
0 commit comments