Skip to content

Commit 9ab2c3d

Browse files
Hail open source
1 parent a1300c8 commit 9ab2c3d

File tree

9 files changed

+192
-69
lines changed

9 files changed

+192
-69
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ main.py
66
rough.js
77
rough2.js
88
rough3.js
9+
backup.js

lib/view/actions.js

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,25 @@
22

33
import React from 'react';
44

5-
const Actions = ({prob,tests, runexamples})=>{
5+
export default class Actions extends React.PureComponent {
6+
constructor(props){
7+
super(props);
8+
this.state = {
9+
prob: props.prob,
10+
tests: props.tests,
11+
runexamples: props.runexamples
12+
}
13+
}
614

7-
state = {
8-
prob: prob,
9-
tests: tests,
10-
runexamples: runexamples
15+
componentWillReceiveProps(nextProps) {
16+
this.setState({
17+
prob: nextProps.prob,
18+
tests: nextProps.tests,
19+
runexamples: nextProps.runexamples
20+
});
1121
}
1222

13-
const change = (ele)=>{
23+
change(ele){
1424
ele.target.classList.toggle("icon-chevron-right")
1525
ele.target.classList.toggle("icon-chevron-down")
1626
var val = ele.target.parentElement.nextElementSibling.style.display
@@ -19,10 +29,9 @@ const Actions = ({prob,tests, runexamples})=>{
1929
}else{
2030
ele.target.parentElement.nextElementSibling.style.display = "flex";
2131
}
22-
// console.log(ele.target.nextElementSibling);
2332
}
2433

25-
const togglesubmit = (ele)=>{
34+
togglesubmit(ele){
2635
var parent = ele.target.parentElement
2736
for (var i = 1; i < parent.children.length; i++) {
2837
var child = parent.children[i]
@@ -35,38 +44,35 @@ const Actions = ({prob,tests, runexamples})=>{
3544
}
3645
}
3746

38-
return (
39-
<div className="actions">
40-
<h2 className="title titlename">{state.prob.index} - {state.prob.name}</h2>
41-
<div className="tasks">
42-
<div className="task">
43-
<div className="up">
44-
<span onClick={change} className="icon icon-chevron-right">Examples</span>
45-
<button className="actionbutton" onClick={state.runexamples}>Run all</button>
47+
render(){
48+
return (
49+
<div className="actions">
50+
<h2 className="title titlename">{this.state.prob.index} - {this.state.prob.name}</h2>
51+
<div className="tasks">
52+
<div className="task">
53+
<div className="up">
54+
<span onClick={this.change.bind(this)} className="icon icon-chevron-right">Examples</span>
55+
<button className="actionbutton" onClick={this.state.runexamples}>Run all</button>
56+
</div>
57+
<div className="down" style={{display: "none"}}>
58+
{this.state.tests && this.state.tests.map(test=>{
59+
return(<div className="verdict">
60+
<div className="show-verdict"><span>example {test.n+1}</span> <i className={"icon-"+test.icon}></i></div>
61+
<div className="errordetails"> <pre>{test.stderr}</pre> </div>
62+
</div>)
63+
})}
64+
</div>
4665
</div>
47-
<div className="down">
48-
{state.tests && state.tests.map(test=>{
49-
return <div className="verdict"> <span>example {test.n+1}</span> <i className={"icon-"+test.icon}></i> </div>
50-
})}
51-
</div>
52-
</div>
53-
<div className="task">
54-
<div className="up">
55-
<span className="icon icon-light-bulb">Submissions</span>
56-
<button onClick={togglesubmit} className="actionbutton" style={{display: "block"}}>Submit</button>
57-
<button onClick={togglesubmit} className="actionbutton realsubmit" style={{display: "none"}}>Submit</button>
58-
<button onClick={togglesubmit} className="actionbutton cancel" style={{display: "none"}}>Cancel</button>
66+
<div className="task">
67+
<div className="up">
68+
<span className="icon icon-light-bulb">Submissions</span>
69+
<button onClick={this.togglesubmit} className="actionbutton" style={{display: "block"}}>Submit</button>
70+
<button onClick={this.togglesubmit} className="actionbutton realsubmit" style={{display: "none"}}>Submit</button>
71+
<button onClick={this.togglesubmit} className="actionbutton cancel" style={{display: "none"}}>Cancel</button>
72+
</div>
5973
</div>
6074
</div>
6175
</div>
62-
</div>
63-
)
76+
)
77+
}
6478
}
65-
66-
export default Actions;
67-
68-
// var langcode = atom.config.get("codeblue.programmingLanguage")
69-
// var ext = ""
70-
// if(langcode==43) ext=".c"
71-
// else if(langcode==54) ext=".cpp"
72-
// else ext=".py"

lib/view/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ export default class Root extends React.PureComponent {
2525
// };
2626

2727
this.state = {
28-
desc: "Codeforces Round #664 (Div. 2)",
29-
id: 1395,
28+
desc: "Educational round 93",
29+
id: 1398,
3030
changed: 2,
3131
timeremaining: 0,
3232
profimg: "//templates.joomla-monster.com/joomla30/jm-news-portal/components/com_djclassifieds/assets/images/default_profile.png"

lib/view/judge.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
'use babel';
2+
3+
class Judge {
4+
constructor(){
5+
this.ignorewhitespace = true;
6+
}
7+
8+
clearstring(s){
9+
s = s.trim()
10+
s = s.split("\n")
11+
for (var i = 0; i < s.length; i++) {
12+
s[i] = s[i].trim()
13+
}
14+
return s.join("\n")
15+
}
16+
17+
verify(exp, out){
18+
exp = this.clearstring(exp)
19+
out = this.clearstring(out)
20+
return exp == out
21+
}
22+
23+
beautify(err){
24+
err = err.trim()
25+
err = err.split("\n")
26+
var tmp = []
27+
for (var i = 1; i < err.length; i++) {
28+
if(err[i].length){
29+
if(err[i].includes("File")){
30+
err[i] = err[i].split(",")[1]
31+
}
32+
tmp.push(err[i].trim())
33+
}
34+
}
35+
36+
var sol = []
37+
for (var i = 0; i < tmp.length; i++) {
38+
if(i&1^1){
39+
sol.push(tmp[i])
40+
}else{
41+
sol[sol.length-1]+=" : " + tmp[i]
42+
}
43+
}
44+
45+
var toreturn = []
46+
47+
for (var i = sol.length-1; i >=0 ; i--) {
48+
toreturn.push(sol[i])
49+
}
50+
51+
return toreturn.join("\n");
52+
}
53+
54+
}
55+
56+
export default new Judge();

lib/view/problems.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import Actions from './actions'
66
import request from 'request'
77
import cheerio from 'cheerio'
88
import RecentSubmissions from './recentsubmissions'
9+
import Judge from './judge'
910

1011
export default class Problems extends React.PureComponent {
1112
constructor(props){
1213
super(props);
1314
this.state = {
15+
temp: 0,
1416
curr: 0,
1517
mystanding: -1,
1618
probs: [],
@@ -58,11 +60,12 @@ export default class Problems extends React.PureComponent {
5860
exec(cmd,{
5961
timeout: 2500,
6062
maxBuffer: 1024*32,
61-
} ,(error, stdout, stderr)=>{
62-
var res = {n: i-1, error: false, verdict: "none", icon: "check"}
63-
res.stdout = stdout
63+
},(error, stdout, stderr)=>{
64+
var res = {n: i-1, error: false, verdict: "none", icon: "none"}
65+
res.stdout = stdout.trim("\n")
6466
if(error !== null){
6567
res.error = true
68+
stderr = Judge.beautify(stderr)
6669
if(error.killed){
6770
res.verdict = "TIME_LIMIT_EXCEEDED"
6871
res.icon = "clock"
@@ -73,15 +76,27 @@ export default class Problems extends React.PureComponent {
7376
res.verdict = "RUNTIME_ERROR"
7477
res.icon = "alert"
7578
}
76-
res.stderr = stderr
79+
}else{
80+
if(Judge.verify(res.stdout,this.state.alloutputs[prob.index][i-1])){
81+
res.verdict="OK"
82+
res.icon="check"
83+
}else{
84+
res.verdict=="WRONG_ANSWER"
85+
res.icon="x"
86+
}
7787
}
88+
res.stderr = stderr
7889
allverdicts[prob.index][i-1] = res
7990
this.setState({allverdicts: allverdicts})
91+
this.setState({temp: this.state.temp^1})
8092
})
8193
}
8294

8395
runexamples(){
84-
this.runtest(1)
96+
console.log("Running tests");
97+
for (var i = 0; i < this.state.noftests[this.state.curr]; i++) {
98+
this.runtest(i+1)
99+
}
85100
}
86101

87102
fetch(url){
@@ -292,7 +307,6 @@ export default class Problems extends React.PureComponent {
292307
})
293308
}
294309
this.setState({actions: actions})
295-
// console.log(this.state.actions);
296310
this.updateactions()
297311
}
298312

@@ -311,6 +325,8 @@ export default class Problems extends React.PureComponent {
311325
.then(res=>res.json())
312326
.then(res=> this.fetchproblems(res.result.problems))
313327
.catch(err=>console.log(err))
328+
329+
// setInterval(()=>{this.loadsubmissions()},10000)
314330
}
315331

316332
hide(ele){

lib/view/rough.js

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,6 @@
1-
var timer = 1
2-
var d1 = new Date()
3-
4-
function exec(cmd, handler = function(error, stdout, stderr){
5-
console.log(stdout);
6-
var d2 = new Date()
7-
console.log(d2.getTime() - d1.getTime());
8-
if(error !== null){
9-
console.log(stderr)}
10-
}){
11-
const childfork = require('child_process');
12-
return childfork.exec(cmd, handler);
13-
}
14-
15-
const path = require('path');
16-
17-
var dir = "C:/Users/Rohan/OneDrive/Atom/codeforces/A"//A.py"
18-
var pyfile = path.join(dir,"A.py")
19-
var outfile = path.join(dir,"examples/run1.out")
20-
var inputfile = path.join(dir,"examples/input1.in")
21-
22-
exec("python "+pyfile+ " < " + inputfile +" > "+outfile)
1+
var PrettyError = require('pretty-error');
2+
var pe = new PrettyError();
3+
pe.skipNodeFiles();
4+
pe.skipPath('C:/Users/Rohan/OneDrive/Atom/codeforces/A/A.py');
5+
var renderedError = pe.render(new Error('Traceback (most recent call last):\nFile "C:/Users/Rohan/OneDrive/Atom/codeforces/A/A.py", line 8, in <module>\nprint(1/0)\nZeroDivisionError: division by zero'));
6+
console.log(renderedError);

package-lock.json

Lines changed: 47 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"child_process": "^1.0.2",
1919
"fs": "0.0.1-security",
2020
"path": "^0.12.7",
21+
"pretty-error": "^2.1.1",
2122
"react": "^16.13.1",
2223
"react-dom": "^16.13.1",
2324
"request": "^2.88.2",

0 commit comments

Comments
 (0)