Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions .idea/scoss_tagger.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

105 changes: 69 additions & 36 deletions webapp/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,58 @@

import datetime
import uuid
import os
from subprocess import call

# Config mongodb
myclient = pymongo.MongoClient("mongodb://scoss_tagger_mongo:27017/",
username='root',
password='example')
username='root',
password='example')
# myclient = pymongo.MongoClient("mongodb://localhost:27017/")

mydb = myclient["scoss"]
mycol = mydb["code"]
mycol_label = mydb["code_label"]
col_student = mydb["student"]
col_student_week = mydb["student_week"]


def save_code_mongodb(codes: list):
for code in codes:
mycol.insert(code)
return {
"errCode": 200,
"errMess": 'Save Successful'
}
"errCode": 200,
"errMess": 'Save Successful'
}


def save_student_info(student_id, student_name, class_id):
st = col_student.find_one({"student_id": student_id, "class_id": class_id})
if st == None:
id = str(uuid.uuid4())
col_student.insert({'_id': id, 'student_id': student_id, 'student_name':student_name, 'class_id': class_id})
return {'id': id}

if st is None:
id_student = str(uuid.uuid4())
col_student.insert(
{'_id': id_student, 'student_id': student_id, 'student_name': student_name, 'class_id': class_id})
col_student_week.insert(
{'_id': id_student, 'student_id': student_id, 'student_name': student_name, 'class_id': class_id})
return {'id': id_student}

st_week = col_student_week.find_one({"_id": st["_id"]})
if st_week is None:
col_student_week.insert(st)
return {'id': st["_id"]}


def get_code() -> dict:
code = None
count = 0
list_code = list(mycol.aggregate([{"$match": {"count": count}}, {"$sample": { "size": 1 }}]))
list_code = list(mycol.aggregate([{"$match": {"count": count}}, {"$sample": {"size": 1}}]))
if len(list_code) > 0:
code = list_code[0]
while (code == None and count < 20):
while code is None and count < 20:
count = count + 1
list_code = list(mycol.aggregate([{"$match": {"count": count}}, {"$sample": { "size": 1 }}]))
list_code = list(mycol.aggregate([{"$match": {"count": count}}, {"$sample": {"size": 1}}]))
if len(list_code) > 0:
code = list_code[0]

if code == None:
if code is None:
return {
"errCode": 500,
"errMess": 'Not found code'
Expand All @@ -64,26 +73,32 @@ def get_code() -> dict:
"output": code["output"]
}


def LCS(strA, strB):
n = len(strA)
m = len(strB)
dp = [[0] * m for i in range(n)]
for i in range(n):
for j in range(m):
if strA[i] == strB[j]:
if i == 0 or j == 0: dp[i][j] = 1
else: dp[i][j] = dp[i - 1][j - 1] + 1
if strA[i] == strB[j]:
if i == 0 or j == 0:
dp[i][j] = 1
else:
dp[i][j] = dp[i - 1][j - 1] + 1
else:
if i != 0: dp[i][j] = max(dp[i][j], dp[i - 1][j])
if j != 0: dp[i][j] = max(dp[i][j], dp[i][j - 1])
return dp[n - 1][m - 1]


def similarity(strA, strB):
return 2 * LCS(strA, strB) / (len(strA) + len(strB))


THRESH_HOLD = 0.9

def run_code(id: str, label: str, student_id: str, hints, submit= False) -> dict:

def run_code(id: str, label: str, student_id: str, hints, submit=False) -> dict:
check_id = True
code_doc = None
try:
Expand Down Expand Up @@ -120,15 +135,16 @@ def run_code(id: str, label: str, student_id: str, hints, submit= False) -> dict
if len(token_code) == len(token_label):
same_code = True
for i in range(len(token_label)):
if (token_label[i].token_type != token_code[i].token_type) or (str(token_label[i].token_value) != str(token_code[i].token_value)):
if (token_label[i].token_type != token_code[i].token_type) or (
str(token_label[i].token_value) != str(token_code[i].token_value)):
same_code = False
break
if same_code:
return {
'errCode': 400,
'errMess': 'Không được submit source code mẫu!'
}

strLabel = ""
for e in token_label:
strLabel += str(e.token_value)
Expand All @@ -140,31 +156,48 @@ def run_code(id: str, label: str, student_id: str, hints, submit= False) -> dict
'errCode': 400,
'errMess': 'Bạn chưa chỉnh sửa đủ cho source code'
}

# save label
doc_save = {
'src': code_doc['src'],
'label': label,
'hints': hints
'hints': hints,
'date': datetime.datetime.now(),
'student_id': student_id
}
mycol.update_one({'_id': ObjectId(id)}, {"$set": {'label' + str(count): doc_save, 'count': count}}, upsert=True)
mycol_label.insert(doc_save)

# update data student
student_doc = col_student.find_one({"_id": student_id})
if student_doc == None:
student_doc_week = col_student_week.find_one({"_id": student_id})

if student_doc is None:
return {
'errCode': 500,
'errMess': 'Vui lòng nhập thông tin sinh viên'
}
number = 1
if "number" in student_doc:
number = student_doc["number"] + 1
col_student.update_one({'_id': student_id}, {"$set": {'date' + str(number): datetime.datetime.now(), 'number': number}}, upsert=True)

list_date = []
if "date" in student_doc:
list_date = student_doc["date"]
list_date.append(datetime.datetime.now())
col_student.update_one({'_id': student_id},
{"$set": {'date': list_date}},
upsert=True)
list_date_week = []
if "date" in student_doc_week:
list_date_week = student_doc_week["date"]
list_date_week.append(datetime.datetime.now())
col_student_week.update_one({'_id': student_id},
{"$set": {'date': list_date_week}},
upsert=True)

return {'errCode': 200,
'save_label': save_label,
'rescompil' :rescompil,
'rescompil': rescompil,
'output': result_run
}
}


def compile_code(id: str, label: str) -> dict:
check_id = True
Expand All @@ -186,9 +219,9 @@ def compile_code(id: str, label: str) -> dict:

if res == 0:
return {'errCode': 200,
'rescompil' : "Biên dịch thành công!"
}
'rescompil': "Biên dịch thành công!"
}

return {'errCode': 500,
'rescompil' :rescompil
}
'rescompil': rescompil
}
2 changes: 1 addition & 1 deletion webapp/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ def save_label(codes: list):

@app.post("/api/save_student_info")
def save_label(st: Student):
return save_student_info(st.student_id, st.student_name, st.class_id)
return save_student_info(st.student_id.strip(), st.student_name.strip(), st.class_id.strip())
1 change: 1 addition & 0 deletions webapp/templates/main/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
var split = allText.split('\n');
var randomTextArr = getRandomSubarray(split, getRandomNumber(3, 3));
var randomText = "";
hints = [];
for (var i = 0; i < randomTextArr.length; ++i) {
split = randomTextArr[i].split(',');
hints.push(split[0])
Expand Down