feat: add hash log

This commit is contained in:
2024-10-16 12:59:46 +08:00
parent d45a289bbd
commit 93bcd0aedc
3 changed files with 68 additions and 13 deletions
+25 -11
View File
@@ -54,21 +54,35 @@ def write_to_csv(data, project):
""" """
csv_file_path = get_csv_file_path(project) csv_file_path = get_csv_file_path(project)
file_exists = os.path.isfile(csv_file_path) file_exists = os.path.isfile(csv_file_path)
with open(csv_file_path, mode="a", newline="", encoding="utf-8") as csvfile:
fieldnames = [ fieldnames = ["time", "id", "name", "score", "running_time", "details", "project"]
"time",
"id", existing_data = []
"name",
"score", # 文件存在,先保存
"running_time", if file_exists:
"details", with open(csv_file_path, mode="r", newline="", encoding="utf-8") as csvfile:
"project", reader = csv.DictReader(csvfile)
] fieldnames = reader.fieldnames # 获取原表头
existing_data = list(reader) # 读数据
# 扩展表头
for field in data.keys():
if field not in fieldnames:
fieldnames.append(field)
# 重写
with open(csv_file_path, mode="w", newline="", encoding="utf-8") as csvfile:
writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
if not file_exists: # 写表头
writer.writeheader() writer.writeheader()
# 写回数据
if existing_data:
writer.writerows(existing_data)
# 写新数据
writer.writerow(data) writer.writerow(data)
+21
View File
@@ -1,6 +1,8 @@
import importlib.util import importlib.util
import numpy as np import numpy as np
import os
import requests import requests
import subprocess
import time import time
import traceback import traceback
@@ -19,6 +21,24 @@ def load_user_function(file_path, function_name):
return getattr(user_code, function_name) return getattr(user_code, function_name)
def get_commit_hash_url():
"""
获取最新的提交哈希值
"""
try:
commit_hash = (
subprocess.check_output(["git", "rev-parse", "HEAD"])
.strip()
.decode("utf-8")
)
path = os.getcwd().replace("/workspace/", "")
url = f"https://git.intcplab.cn/{path}/commit/{commit_hash}"
return url
except subprocess.CalledProcessError as e:
print(f"Error: {e}")
return None
def evaluate_knn( def evaluate_knn(
user_func, train_data, train_labels, test_data, test_labels, log_details user_func, train_data, train_labels, test_data, test_labels, log_details
): ):
@@ -101,6 +121,7 @@ def upload_score(name, id, score_data):
), ),
"details": score_data["details"], "details": score_data["details"],
"project": PROJECT_NAME, "project": PROJECT_NAME,
"hash": get_commit_hash_url(),
}, },
) )
if response.status_code == 200: if response.status_code == 200:
+21 -1
View File
@@ -1,6 +1,7 @@
import importlib.util import importlib.util
import numpy as np import os
import requests import requests
import subprocess
import time import time
import traceback import traceback
@@ -19,6 +20,24 @@ def load_user_function(file_path, function_name):
return getattr(user_code, function_name) return getattr(user_code, function_name)
def get_commit_hash_url():
"""
获取最新的提交哈希值
"""
try:
commit_hash = (
subprocess.check_output(["git", "rev-parse", "HEAD"])
.strip()
.decode("utf-8")
)
path = os.getcwd().replace("/workspace/", "")
url = f"https://git.intcplab.cn/{path}/commit/{commit_hash}"
return url
except subprocess.CalledProcessError as e:
print(f"Error: {e}")
return None
def evaluate_knn( def evaluate_knn(
user_func, train_data, train_labels, test_data, test_labels, log_details user_func, train_data, train_labels, test_data, test_labels, log_details
): ):
@@ -101,6 +120,7 @@ def upload_score(name, id, score_data):
), ),
"details": score_data["details"], "details": score_data["details"],
"project": PROJECT_NAME, "project": PROJECT_NAME,
"hash": get_commit_hash_url(),
}, },
) )
if response.status_code == 200: if response.status_code == 200: