Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

v1.0.17 #43

Merged
merged 1 commit into from
Aug 7, 2024
Merged
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
63 changes: 63 additions & 0 deletions api/src/route/api/TA/class/Assign/Edit_POST.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from function.GetGID import GetGID
from function.loadconfig import UPLOAD_FOLDER
from function.isCET import isCET
import function.grader as grader

gmt_timezone = pytz.timezone('Asia/Bangkok')

Expand Down Expand Up @@ -40,11 +41,14 @@ def update_database(conn, cursor, questions, qnum, source_files, release_files,
release_path = os.path.join(base_path, release_filename)

if i < existing_qnum:
isSourceUpdate = False

# Update existing question
current_qid, current_source_path, current_release_path = existing_questions[i]

# Check if source path has changed and remove old file if needed
if source_path:
isSourceUpdate = True
if os.path.exists(current_source_path):
os.remove(current_source_path)
source_files[str(i)].save(source_path)
Expand All @@ -64,6 +68,65 @@ def update_database(conn, cursor, questions, qnum, source_files, release_files,
SET MaxScore = %s, SourcePath = %s, ReleasePath = %s
WHERE QID = %s AND LID = %s
''', (max_score, source_path, release_path, current_qid, lid))

if isSourceUpdate:
select_query = "SELECT Path FROM addfile WHERE LID = %s"
cursor.execute(select_query, (lid,))
result = cursor.fetchall()

addfiles = [row[0] for row in result]

select_query = """
SELECT
`SID`,
`SummitedFile`
FROM
`submitted`
WHERE
QID = %s AND LID = %s
"""
cursor.execute(select_query, (current_qid, lid))
result = cursor.fetchall()

for SID, filepath in result:
err, data = grader.grade(source_path, filepath, addfile=addfiles, validate=False, check_keyword="ok")
if err:
return jsonify({
'success': False,
'msg': f'There is a problem while grading.\n{data}',
'data': {}
}), 200

s, m = 0, 0

if len(data) == 1:
s += float(data[0][0]) # Ensure data is converted to float
m += float(data[0][1]) # Ensure data is converted to float
else:
for j in range(len(data)):
s += float(data[j][0]) # Ensure data is converted to float
m += float(data[j][1]) # Ensure data is converted to float

# Check if m is zero to avoid division by zero
if m == 0:
Score = 0
else:
Score = float("{:.2f}".format((s / m) * float(max_score))) # Ensure MaxScore is converted to float

# Define the insert or update query
upsert_query = """
UPDATE
`submitted`
SET
`Score` = %s
WHERE
`SID` = %s
"""

# Execute the query with the provided values
cursor.execute(upsert_query, (Score, SID))
conn.commit()

else:
# Ensure source_path and release_path are not None before inserting
if source_path is None or release_path is None:
Expand Down
11 changes: 0 additions & 11 deletions auth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ func main() {
r.Run(":5050")
}

// func handleMain(c *gin.Context) {
// var html = `<html><body><a href="/auth/login">Google Log In</a></body></html>`
// c.Writer.Write([]byte(html))
// }

func handleGoogleLogin(c *gin.Context) {
state := uuid.New().String()
session := sessions.Default(c)
Expand Down Expand Up @@ -141,10 +136,4 @@ func handleGoogleCallback(c *gin.Context) {
encodedCiphertext := base64.URLEncoding.EncodeToString(ciphertext)

c.Redirect(http.StatusTemporaryRedirect, fmt.Sprintf("/callback?credential=%s", encodedCiphertext))

// c.JSON(http.StatusOK, gin.H{
// "user_info": userInfo,
// "hashed": ciphertext,
// "time": time.Now().In(location).Format("2006-01-02 15:04:05"),
// })
}
Loading