Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sfcode
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ayush
sfcode
Commits
8ae277a8
Commit
8ae277a8
authored
Dec 08, 2020
by
Ayush
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add compilation execution to arena
parent
c339c587
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
61 additions
and
39 deletions
+61
-39
backend/execute.php
backend/execute.php
+1
-1
backend/questions/check_output.php
backend/questions/check_output.php
+6
-4
src/app/arena/arena.component.html
src/app/arena/arena.component.html
+1
-1
src/app/arena/arena.component.ts
src/app/arena/arena.component.ts
+36
-23
src/app/run-code.service.ts
src/app/run-code.service.ts
+3
-4
src/app/submit-try-code/submit-try-code.component.ts
src/app/submit-try-code/submit-try-code.component.ts
+14
-6
No files found.
backend/execute.php
View file @
8ae277a8
backend/questions/check_output.php
View file @
8ae277a8
...
...
@@ -18,7 +18,7 @@ if(isset($postData) && !empty($postData)){
$sql
=
"SELECT out1 FROM questions WHERE title='
$title
'"
;
if
(
$result
=
mysqli_query
(
$mysqli
,
$sql
)
->
fetch_all
(
MYSQLI_ASSOC
)){
$bool
=
0
;
if
(
result
[
'out1'
]
===
$out
){
if
(
$result
[
0
][
'out1'
]
===
$out
){
$bool
=
1
;
}
echo
json_encode
(
$bool
);
...
...
@@ -30,8 +30,10 @@ if(isset($postData) && !empty($postData)){
else
{
$sql
=
"SELECT out2 FROM questions WHERE title='
$title
'"
;
if
(
$result
=
mysqli_query
(
$mysqli
,
$sql
)
->
fetch_all
(
MYSQLI_ASSOC
)){
// echo json_encode($result);
// exit(0);
$bool
=
0
;
if
(
result
[
'out2'
]
===
$out
){
if
(
$result
[
0
]
[
'out2'
]
===
$out
){
$bool
=
1
;
}
...
...
src/app/arena/arena.component.html
View file @
8ae277a8
...
...
@@ -13,4 +13,4 @@
<textarea
id=
"editor"
name=
"editor"
></textarea>
</div>
<app-input
(valueEmit)=
"customInput = $event"
></app-input>
<app-submit-try-code
[
problem
]=
"question"
></app-submit-try-code>
<app-submit-try-code
[
question
]=
"question"
></app-submit-try-code>
src/app/arena/arena.component.ts
View file @
8ae277a8
...
...
@@ -3,13 +3,14 @@ import {Router} from '@angular/router';
// import {Problem} from '../problem';
// import {ProblemService} from '../problem.service';
import
{
ApiService
}
from
'
../api.service
'
;
import
{
InputComponent
}
from
'
../input/input.component
'
;
import
{
SubmitTryCodeComponent
}
from
'
../submit-try-code/submit-try-code.component
'
;
import
{
RunCodeService
}
from
'
../run-code.service
'
;
import
{
Question
}
from
'
../question
'
;
import
{
QuestionService
}
from
'
../question.service
'
;
import
{
Question
}
from
'
../question
'
;
import
{
QuestionService
}
from
'
../question.service
'
;
import
{
FileService
}
from
'
../file.service
'
;
import
{
File
}
from
'
../file
'
;
declare
const
CodeMirror
:
any
;
...
...
@@ -22,6 +23,7 @@ export class ArenaComponent implements OnInit {
title
:
string
;
question
:
Question
;
language
:
string
;
code
:
string
[]
=
[
`#include <iostream>
using namespace std;
...
...
@@ -43,7 +45,8 @@ export class ArenaComponent implements OnInit {
constructor
(
public
router
:
Router
,
private
apiService
:
ApiService
,
private
runCodeService
:
RunCodeService
,
private
questionService
:
QuestionService
)
{
private
questionService
:
QuestionService
,
private
fileService
:
FileService
)
{
}
ngOnInit
():
void
{
...
...
@@ -73,23 +76,14 @@ export class ArenaComponent implements OnInit {
const
extensions
=
[
'
.cpp
'
,
'
.py
'
,
'
.java
'
];
const
langsMime
=
[
'
text/x-c++src
'
,
'
text/x-python
'
,
'
text/x-java
'
];
const
code
:
string
[]
=
[
`#include <iostream>
using namespace std;
int main() {
cout << "Hello World!\\n";
return 0;
}`
,
`print("Hello World!")`
,
`class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}`
];
this
.
language
=
extensions
[
activeLang
];
document
.
getElementById
(
'
toggle-lang
'
).
onclick
=
function
():
void
{
const
th
=
this
as
HTMLDivElement
;
const
th
=
document
.
getElementById
(
'
toggle-lang
'
)
as
HTMLDivElement
;
th
.
onclick
=
()
=>
{
activeLang
=
(
activeLang
+
1
)
%
3
;
this
.
language
=
extensions
[
activeLang
];
th
.
innerHTML
=
langs
[
activeLang
];
editor
.
setValue
(
code
[
activeLang
]);
editor
.
setValue
(
this
.
code
[
activeLang
]);
editor
.
setOption
(
'
mode
'
,
langsMime
[
activeLang
]);
};
...
...
@@ -107,12 +101,24 @@ export class ArenaComponent implements OnInit {
// }
tryCode
(
c
):
void
{
if
(
document
.
getElementById
(
'
try
'
).
classList
.
contains
(
'
disabled
'
))
{
return
;
}
if
(
document
.
getElementById
(
'
try
'
).
classList
.
contains
(
'
disabled
'
))
{
return
;
}
this
.
isCompiling
=
true
;
this
.
runCodeService
.
compileQuestionFile
(
this
.
question
,
this
.
code
)
.
subscribe
(
data
=>
{
const
file
:
File
=
{
username
:
JSON
.
parse
(
this
.
apiService
.
getToken
()).
username
,
filename
:
this
.
question
.
title
,
language
:
this
.
language
,
text
:
this
.
code
[([
'
.cpp
'
,
'
.py
'
,
'
.java
'
]).
indexOf
(
this
.
language
)],
path
:
'
attempts/
'
};
console
.
log
(
file
);
this
.
fileService
.
upload
(
file
).
subscribe
(
data1
=>
{
console
.
log
(
data1
);
this
.
runCodeService
.
compileFile
(
file
).
subscribe
(
data2
=>
{
console
.
log
(
data2
);
this
.
submitField
.
submitting
=
c
;
this
.
submitField
.
reset
();
this
.
submitField
.
reset
(
file
,
[
this
.
question
.
tc1
,
this
.
question
.
tc2
]
);
this
.
submitField
.
isActive
=
true
;
this
.
isCompiling
=
false
;
},
error
=>
{
...
...
@@ -122,13 +128,20 @@ export class ArenaComponent implements OnInit {
this
.
compilationError
=
false
;
},
3000
);
});
},
error
=>
{
this
.
isCompiling
=
false
;
this
.
compilationError
=
true
;
setTimeout
(()
=>
{
this
.
compilationError
=
false
;
},
3000
);
});
}
getQuestion
():
void
{
this
.
questionService
.
getQues
()
.
subscribe
(
questions
=>
{
this
.
question
=
questions
.
find
(
i
=>
i
.
title
===
this
.
title
);
document
.
getElementById
(
"
p_s
"
).
innerHTML
=
this
.
question
.
statement
;
document
.
getElementById
(
'
p_s
'
).
innerHTML
=
this
.
question
.
statement
;
});
}
...
...
src/app/run-code.service.ts
View file @
8ae277a8
import
{
Injectable
}
from
'
@angular/core
'
;
import
{
Problem
}
from
'
./problem
'
;
//
import {Problem} from './problem';
import
{
Question
}
from
'
./question
'
;
import
{
File
}
from
'
./file
'
;
import
{
Observable
,
of
,
throwError
}
from
'
rxjs
'
;
...
...
@@ -33,9 +33,8 @@ export class RunCodeService {
// else {return throwError('error'); }
// }
tryTestcase
(
prob
:
Question
,
index
:
number
):
Observable
<
boolean
>
{
// return of(Math.floor(Math.random() * 2) === 1);
verifyTestcase
(
title
:
string
,
out
:
string
,
ind
:
number
):
Observable
<
any
>
{
return
this
.
httpClient
.
post
(
this
.
baseUrl
+
'
questions/check_output.php
'
,
{
title
,
out
,
ind
});
}
compileQuestionFile
(
ques
:
Question
,
code
:
string
[]):
Observable
<
any
>
{
...
...
src/app/submit-try-code/submit-try-code.component.ts
View file @
8ae277a8
...
...
@@ -2,6 +2,9 @@ import {Component, Input, OnInit} from '@angular/core';
// import {Problem} from '../problem';
import
{
RunCodeService
}
from
'
../run-code.service
'
;
import
{
Question
}
from
'
../question
'
;
import
{
FileService
}
from
'
../file.service
'
;
import
{
ApiService
}
from
'
../api.service
'
;
import
{
File
}
from
'
../file
'
;
@
Component
({
selector
:
'
app-submit-try-code
'
,
...
...
@@ -13,21 +16,26 @@ export class SubmitTryCodeComponent implements OnInit {
isActive
=
false
;
nts
:
number
[];
status
:
number
[];
@
Input
()
problem
:
Question
;
@
Input
()
question
:
Question
;
submitting
=
0
;
constructor
(
public
runCodeService
:
RunCodeService
)
{
}
constructor
(
public
runCodeService
:
RunCodeService
,
private
fileService
:
FileService
,
private
apiService
:
ApiService
)
{
}
ngOnInit
():
void
{
}
reset
():
void
{
this
.
nts
=
[
0
,
1
];
//Array(this.problem.n_testcases[this.submitting]).fill(1).map((x, i) => i);
reset
(
file
:
File
,
testcases
:
string
[]):
void
{
console
.
log
(
file
,
testcases
);
this
.
nts
=
[
0
,
1
];
// Array(this.problem.n_testcases[this.submitting]).fill(1).map((x, i) => i);
this
.
status
=
[
0
,
0
];
// Array(this.problem.n_testcases[this.submitting]).fill(0);
for
(
const
i
of
this
.
nts
)
{
this
.
runCodeService
.
tryTestcase
(
this
.
problem
,
i
)
this
.
runCodeService
.
executeFile
(
file
,
testcases
[
i
]
)
.
subscribe
(
ret
=>
{
this
.
status
[
i
]
=
ret
?
1
:
-
1
;
console
.
log
(
ret
);
this
.
runCodeService
.
verifyTestcase
(
file
.
filename
,
ret
,
i
)
.
subscribe
(
data
=>
{
this
.
status
[
i
]
=
data
===
1
?
1
:
-
1
;
});
});
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment