Skip to content

Commit e705836

Browse files
codeblue
1 parent b9738b4 commit e705836

File tree

14 files changed

+470
-60
lines changed

14 files changed

+470
-60
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.DS_Store
22
npm-debug.log
33
node_modules
4+
todo.txt

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# codeblue package
22

3-
A short description of your package.
3+
This is a wild game
44

55
![A screenshot of your package](https://f.cloud.github.com/assets/69169/2290250/c35d867a-a017-11e3-86be-cd7c5bf3ff9b.gif)

lib/codeblue.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import {
55
CompositeDisposable,
66
Disposable
77
} from 'atom';
8+
import config from './config'
89

910
export default {
1011

1112
subscriptions: null,
13+
config,
1214

1315
activate(state) {
1416
this.subscriptions = new CompositeDisposable(

lib/config.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
'use babel';
2+
3+
export default {
4+
codeforcesHandle: {
5+
title: 'Codeforces Handle',
6+
order: 1,
7+
type: 'string',
8+
default: 'blueedgetechno'
9+
},
10+
11+
programmingLanguage: {
12+
title: 'Programming Language',
13+
order: 2,
14+
description: 'The chosen language will only be used for submitting a source file.',
15+
type: 'integer',
16+
default: 31,
17+
enum: [
18+
{ value: 43, description: 'GNU GCC C11 5.1.0' },
19+
{ value: 61, description: 'GNU G++17 9.2.0 (64 bit, msys 2)' },
20+
{ value: 54, description: 'GNU G++17 7.3.0' },
21+
{ value: 31, description: 'Python 3.7.2' },
22+
{ value: 41, description: 'PyPy 3.6 (7.2.0)' },
23+
{ value: 34, description: 'JavaScript V8 4.8.0' },
24+
{ value: 55, description: 'Node.js 9.4.0' }
25+
]
26+
},
27+
28+
compilationCommand: {
29+
title: 'Compilation Command',
30+
order: 3,
31+
description: 'Remember to also adjust the executable file name in the file structure settings if necessary.',
32+
type: 'string',
33+
default: 'python'
34+
},
35+
36+
workingDirectory: {
37+
title: 'Working directory',
38+
order: 4,
39+
description: 'Where your source files will be stored during contest',
40+
type: 'string',
41+
default: 'C:/Users/'
42+
}
43+
}

lib/view/actions.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
'use babel';
2+
3+
import React from 'react';
4+
5+
const Actions = ({prob})=>{
6+
7+
const change = (ele)=>{
8+
ele.target.classList.toggle("icon-chevron-right")
9+
ele.target.classList.toggle("icon-chevron-down")
10+
var val = ele.target.parentElement.nextElementSibling.style.display
11+
if(val=="flex"){
12+
ele.target.parentElement.nextElementSibling.style.display = "none";
13+
}else{
14+
ele.target.parentElement.nextElementSibling.style.display = "flex";
15+
}
16+
// console.log(ele.target.nextElementSibling);
17+
}
18+
19+
return (
20+
<div className="actions">
21+
<h2 className="title">{prob.alpha} - {prob.name}</h2>
22+
<div className="tasks">
23+
<div className="task">
24+
<div className="up">
25+
<span onClick={change} className="icon icon-chevron-right">Examples</span>
26+
<button className="actionbutton">Run all</button>
27+
</div>
28+
<div className="down">
29+
<div className="verdict"> <span>example 1</span> <i className="icon icon-check"></i> </div>
30+
<div className="verdict"> <span>example 2</span> <i className="icon icon-x"></i> </div>
31+
<div className="verdict"> <span>example 3</span> <i className="icon icon-clock"></i> </div>
32+
<div className="verdict"> <span>example 3</span> <i className="icon icon-alert"></i> </div>
33+
</div>
34+
</div>
35+
<div className="task">
36+
<div className="up">
37+
<span onClick={change} className="icon icon-chevron-right">Submissions</span>
38+
<button className="actionbutton">Submit</button>
39+
</div>
40+
<div className="down">
41+
<div className="verdict"> <span>example 1</span> <i className="icon icon-check"></i> </div>
42+
<div className="verdict"> <span>example 2</span> <i className="icon icon-x"></i> </div>
43+
<div className="verdict"> <span>example 3</span> <i className="icon icon-clock"></i> </div>
44+
<div className="verdict"> <span>example 3</span> <i className="icon icon-alert"></i> </div>
45+
</div>
46+
</div>
47+
</div>
48+
</div>
49+
)
50+
}
51+
52+
export default Actions;

lib/view/index.js

Lines changed: 131 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,155 @@
22

33
import React from 'react';
44
import Problems from './problems';
5+
import config from '../config'
6+
import request from 'request'
7+
import cheerio from 'cheerio'
8+
9+
function exec(cmd, handler = function(error, stdout, stderr){
10+
console.log(stdout);
11+
if(error !== null){
12+
console.log(stderr)}
13+
}){
14+
const childfork = require('child_process');
15+
return childfork.exec(cmd, handler);
16+
}
17+
18+
function couple(x) {
19+
if(x<10){
20+
return "0"+x
21+
}else{
22+
return x;
23+
}
24+
}
525

626
export default class Root extends React.PureComponent {
727
constructor(props){
828
super(props);
9-
this.state = { num: 663, div: 2, id: 0 };
29+
// this.state = { desc: "", id: "", changed: 0, timeremaining: 0};
30+
this.state = { desc: "Codeforces Round #663 (Div. 2)", id: 1176, changed: 2, timeremaining: 0}
1031
}
1132

12-
display(){
13-
var editor = atom.workspace.getActiveTextEditor();
14-
if(editor){
15-
console.log(editor);
33+
fetch(url){
34+
return new Promise((resolve, reject) => {
35+
request(url, (error, response, body) => {
36+
if (!error && response.statusCode == 200) {
37+
resolve(body)
38+
} else {
39+
reject({
40+
reason: 'Unable to download page'
41+
})
42+
}
43+
})
44+
})
45+
}
46+
47+
timesolver(s){
48+
var t = 0
49+
s = s.split(":")
50+
t+=3600*parseInt(s[0])
51+
t+=60*parseInt(s[1])
52+
t+=parseInt(s[2])
53+
return t
54+
}
55+
56+
scrape(html){
57+
$ = cheerio.load(html)
58+
var tmp = $('#pageContent > div:nth-child(2) > span').text().trim()
59+
60+
if(this.state.desc.length==0){
61+
var desc = $("#pageContent > div:nth-child(1) > div").text().trim()
62+
this.setState({desc: desc})
63+
}
64+
65+
if(tmp.length){
66+
this.setState({timeremaining: this.timesolver(tmp)})
67+
}else{
68+
this.setState({changed: 2})
69+
this.setState({timeremaining: 0})
1670
}
1771
}
1872

19-
fetch(){
73+
fetchtimeremaining(){
74+
var url = "https://codeforces.com/contest/"+this.state.id+"/countdown"
75+
this.fetch(url).then((html) => {
76+
this.scrape(html)
77+
}).catch((error) => {
78+
atom.notifications.addWarning(error.reason)
79+
})
80+
}
2081

82+
display(){
83+
this.setState({changed: 1})
84+
this.fetchtimeremaining()
85+
var repeat = setInterval(()=>{
86+
this.setState({timeremaining: this.state.timeremaining-1})
87+
if(this.state.timeremaining==0){
88+
this.setState({changed: 2})
89+
clearInterval(repeat)
90+
}
91+
92+
this.setState({timeremaining: Math.max(this.state.timeremaining, 0)})
93+
},1000)
94+
}
95+
96+
pathfinder(){
97+
98+
// var editor = atom.workspace.getActiveTextEditor();
99+
// if(editor){
100+
// var file = editor.buffer.file
101+
// if(file){
102+
// var filepath = file.path
103+
// exec("python "+filepath);
104+
// }
105+
// }
106+
}
107+
108+
Timer({sec}){
109+
return(
110+
<div className="timer">
111+
<span>Before contest</span>
112+
<span>{couple(Math.floor(sec/3600))} : {couple(Math.floor((sec%3600)/60))} : {couple(Math.floor((sec%3600)%60))}</span>
113+
</div>
114+
)
115+
}
116+
117+
fetchinput(event){
118+
if(event.target){
119+
this.setState({id: event.target.value});
120+
}
121+
// console.log(this.state);
21122
}
22123

23124
render() {
24125
return (
25126
<div>
26-
<h2>Codeforces Round #{this.state.num} (Div. {this.state.div})</h2>
27-
{this.state.id ? <input type="text"/> : <Problems contest={this.state}/> }
28-
<button onClick={()=> this.fetch()}>Submit</button>
127+
{this.state.changed ? <h2>{this.state.desc}</h2> : null}
128+
129+
{this.state.changed==0 ? (
130+
<div className="fillup">
131+
<span>ContestId</span>
132+
<input type="text" value={this.state.id} onChange={this.fetchinput.bind(this)}/>
133+
<br/><button onClick={()=> this.display()}>Submit</button>
134+
</div>
135+
) : null}
136+
137+
{this.state.changed==1 ? (
138+
<div className="waiting">
139+
<this.Timer sec={this.state.timeremaining} />
140+
<button onClick={()=>this.fetchtimeremaining()} >Refresh</button>
141+
</div>
142+
):null}
143+
144+
{this.state.changed==2 ? (
145+
<Problems contest={this.state}/>
146+
):null}
147+
29148
</div>
30149
);
31150
}
32151
}
152+
// <button onClick={()=> this.pathfinder()}>Check</button>
33153

34154
// <button onClick={()=> this.toggler()}>Click me</button>
155+
156+
// <Problems contest={this.state} />

lib/view/problem.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import React from 'react';
44

5-
const Problem = ({prob})=>{
5+
const Problem = ({prob,changer})=>{
66
if(prob.con==0){
77
currentstate = <div className="accepted">Accepted</div>
88
}else if (prob.con==1) {
@@ -11,13 +11,15 @@ const Problem = ({prob})=>{
1111
currentstate = <div className="tle">TLE on {prob.test}</div>
1212
}else if(prob.con==3){
1313
currentstate = <div className="queue"></div>
14+
}else if(prob.con==4){
15+
currentstate = <div className="runtime">RE on {prob.test}</div>
1416
}else{
1517
currentstate = <div></div>
1618
}
1719
return (
18-
<div className="prob">
20+
<div onClick={changer} className="prob">
1921
<span>{prob.alpha} - {prob.name}</span>
20-
<span className="totsub">{prob.sub}</span>
22+
<span className="totsub"> <i className="icon icon-person"></i> {prob.sub}</span>
2123
{currentstate}
2224
</div>
2325
)

lib/view/problems.js

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,34 @@
22

33
import React from 'react'
44
import Problem from './problem'
5+
import Actions from './actions'
56
import request from 'request'
67
import cheerio from 'cheerio'
78

89
export default class Problems extends React.PureComponent {
910
constructor(props){
1011
super(props);
1112
this.state = {
12-
count: 0,
13+
curr: 1,
1314
probs: []
1415
};
1516
}
1617

18+
changecurr(ele){
19+
var hd = ele.target.innerText
20+
hd = hd.split(" ")
21+
var id = hd[0];
22+
var i=0
23+
24+
while(this.state.probs[i]!=null){
25+
if(this.state.probs[i].alpha == id){
26+
this.setState({curr: i})
27+
break;
28+
}
29+
i++;
30+
}
31+
}
32+
1733
fetch(url){
1834
return new Promise((resolve, reject) => {
1935
request(url, (error, response, body) => {
@@ -39,7 +55,7 @@ export default class Problems extends React.PureComponent {
3955
}else{
4056
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()
4157
var sub = $(`#pageContent > div.datatable > div:nth-child(6) > table > tbody > tr:nth-child(${i}) > td > a`).text().trim().substring(2)
42-
probs.push({alpha: al, name: nm, con: -1, test: 1, sub: sub});
58+
probs.push({alpha: al, name: nm, con: i%6-1, test: 1, sub: sub});
4359
}
4460
i++;
4561
}
@@ -57,19 +73,16 @@ export default class Problems extends React.PureComponent {
5773

5874
render(){
5975
return (
60-
<div className="problems">
61-
{this.state.probs && this.state.probs.map(prob=>{
62-
return (<Problem prob={prob}/>)
63-
})
64-
}
76+
<div className="display">
77+
<div className="problems">
78+
{this.state.probs.length ? this.state.probs.map(prob=>{
79+
return <Problem prob={prob} changer={this.changecurr.bind(this)}/>
80+
}) : (
81+
<div className="loader"></div>
82+
)
83+
}
84+
</div>
85+
{this.state.probs.length ? <Actions prob={this.state.probs[this.state.curr]}/> : null }
6586
</div>
6687
)}
6788
}
68-
69-
// [
70-
// {alpha: "A", name: "Suborrays"},
71-
// {alpha: "B", name: "Fix you"},
72-
// {alpha: "C", name: "Cyclic Permutations"},
73-
// {alpha: "D", name: "505"},
74-
// {alpha: "E", name: "Pairs of Pairs"}
75-
// ]

lib/view/rough.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const setup = require('./setup');
2+
3+
setup("C:/Users/Rohan/OneDrive/Atom/codeforces",[{alpha: "A"}])

0 commit comments

Comments
 (0)