Skip to content

Commit

Permalink
FE BE bug fix
Browse files Browse the repository at this point in the history
Co-authored-by: JYeonKim <JYeonKim@users.noreply.github.com>
  • Loading branch information
hyeon9698 and JYeonKim committed Nov 30, 2021
1 parent 1c03800 commit b959643
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 145 deletions.
2 changes: 1 addition & 1 deletion OJ-BE/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ RUN apk add --update --no-cache build-base nginx openssl curl unzip supervisor j
pip install --no-cache-dir -r /app/deploy/requirements.txt && \
apk del build-base --purge

RUN curl -L $(curl -s https://api.github.com/repos/QingdaoU/OnlineJudgeFE/releases/latest | grep /dist.zip | cut -d '"' -f 4) -o dist.zip && \
RUN curl -L $(curl -s https://api.github.com/repos/Sejong-Creative-Semester2021/Sejong.creative.semester.2021/releases/latest | grep /dist.zip | cut -d '"' -f 4) -o dist.zip && \
unzip dist.zip && \
rm dist.zip

Expand Down
181 changes: 91 additions & 90 deletions OJ-BE/aicontest/views/oj.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import json
import csv
# import pandas as pd
# import numpy as np
import numpy as np
# import sklearn

import logging
Expand Down Expand Up @@ -88,7 +88,8 @@ def get(self, request):
logger.info('problem_data={}'.format(problem_data))
return self.success(problem_data)
except AIProblem.DoesNotExist:
return self.error("Problem does not exist")
# return self.error("Problem does not exist-aicontest-views-oj.py2")
return None
logger.info('problem get continue')
# limit = request.GET.get("limit")
# if not limit:
Expand Down Expand Up @@ -219,98 +220,98 @@ def post(self, request):
2,13
3,346
"""
# y_true = np.array(np.loadtxt(os.path.join(settings.SOLUTION_DIR, csv.solution_id, "solution.csv"), delimiter=",", dtype=np.float32, skiprows=1, usecols = (1,)))
# y_pred = np.array(np.loadtxt(os.path.join(settings.PREDICT_DIR, predict_id, "predict.csv"), delimiter=",", dtype=np.float32, skiprows=1, usecols = (1,)))
# logger.info("y_true={}".format(str(y_true)))
# logger.info("y_pred={}".format(str(y_pred)))
y_true = np.array(np.loadtxt(os.path.join(settings.SOLUTION_DIR, csv.solution_id, "solution.csv"), delimiter=",", dtype=np.float32, skiprows=1, usecols = (1,)))
y_pred = np.array(np.loadtxt(os.path.join(settings.PREDICT_DIR, predict_id, "predict.csv"), delimiter=",", dtype=np.float32, skiprows=1, usecols = (1,)))
logger.info("y_true={}".format(str(y_true)))
logger.info("y_pred={}".format(str(y_pred)))

# eval_type = csv.eval_type
# logger.info("eval_type={}".format(eval_type))

# if eval_type == 'mse':
# logger.info("if mse in")
# y_score = np.square(np.subtract(y_true, y_pred)).mean()
# logger.info("y_score={}".format(str(y_score)))

# if eval_type == 'acc':
# logger.info("if acc in")
# y_score = (y_true == y_pred).mean()
# logger.info("y_score={}".format(str(y_score)))

# if eval_type == 'rmse':
# logger.info("if rmse in")
# y_score = np.sqrt(np.mean(np.subtract(y_true, y_pred)**2))
eval_type = csv.eval_type
logger.info("eval_type={}".format(eval_type))

if eval_type == 'mse':
logger.info("if mse in")
y_score = np.square(np.subtract(y_true, y_pred)).mean()
logger.info("y_score={}".format(str(y_score)))

if eval_type == 'acc':
logger.info("if acc in")
y_score = (y_true == y_pred).mean()
logger.info("y_score={}".format(str(y_score)))

if eval_type == 'rmse':
logger.info("if rmse in")
y_score = np.sqrt(np.mean(np.subtract(y_true, y_pred)**2))

# if eval_type == 'auc':
# logger.info("if auc in")

# if eval_type == 'mean_f_score':
# logger.info("if mean_f_score in")
# # accuracy = np.mean(np.equal(y_true, y_pred))
# right = np.sum(y_true * y_pred == 1)
# precision = right / np.sum(y_pred)
# recall = right / np.sum(y_true)
# f1 = 2 * precision*recall/(precision+recall)
# y_score = f1
# logger.info("if mean_f_score out")

# if eval_type == 'mae':
# logger.info("if mae in")
# y_score = np.mean(np.abs(np.subtract(y_true, y_pred)))

# if eval_type == 'f_beta':
# logger.info("if f_beta in")

# if eval_type == 'logloss':
# logger.info("if logloss in")
# def my_logloss(answer_array, proba_array):
# # 출처 https://velog.io/@skyepodium/logloss-%EC%95%8C%EC%95%84%EB%B3%B4%EA%B8%B0
# # 0이면 무한대 값이 나오기 때문에 0에 가까운 값으로 치환해줍니다.
# MIN_VALUE = 1e-15
# # array의 크기를 가져옵니다.
# size = answer_array.shape[0]
# # 반복문을 사용해서 logloss의 합을 계산합니다.
# logloss_sum = 0
# # zip함수로 묶으면 함께 순회할 수 있습니다.
# for answer, arr in zip(answer_array, proba_array):
# proba = arr[answer - 1]
# # 0이면 무한대 값이 나오기 때문에 0에 가까운 값으로 치환해줍니다.
# if proba <= MIN_VALUE:
# proba = MIN_VALUE
# # 음의 로그함수에 넣어서 logloss 계산
# logloss_sum += -np.log(proba)
# # logloss의 평균 계산
# result = logloss_sum / size
# # 반환
# return result
# y_score = my_logloss(y_true, y_pred)

# if eval_type == 'rmsle':
# logger.info("if rmsle in")
# def rmsle(predicted_values, actual_values):
# # 예측값과 실제 값에 1을 더하고 로그를 씌워준다.
# log_predict = np.log(predicted_values + 1)
# log_actual = np.log(actual_values + 1)
# # 위에서 계산한 예측값에서 실제값을 빼주고 제곱을 해준다.
# difference = log_predict - log_actual
# # difference = (log_predict - log_actual) ** 2
# difference = np.square(difference)
# # 평균을 낸다.
# mean_difference = difference.mean()
# # 다시 루트를 씌운다.
# score = np.sqrt(mean_difference)
# return score
# y_score = rmsle(y_true, y_pred)

# if eval_type == 'map@k':
# logger.info("if map@k in")
if eval_type == 'auc':
logger.info("if auc in")

if eval_type == 'mean_f_score':
logger.info("if mean_f_score in")
# accuracy = np.mean(np.equal(y_true, y_pred))
right = np.sum(y_true * y_pred == 1)
precision = right / np.sum(y_pred)
recall = right / np.sum(y_true)
f1 = 2 * precision*recall/(precision+recall)
y_score = f1
logger.info("if mean_f_score out")

if eval_type == 'mae':
logger.info("if mae in")
y_score = np.mean(np.abs(np.subtract(y_true, y_pred)))

if eval_type == 'f_beta':
logger.info("if f_beta in")

if eval_type == 'logloss':
logger.info("if logloss in")
def my_logloss(answer_array, proba_array):
# 출처 https://velog.io/@skyepodium/logloss-%EC%95%8C%EC%95%84%EB%B3%B4%EA%B8%B0
# 0이면 무한대 값이 나오기 때문에 0에 가까운 값으로 치환해줍니다.
MIN_VALUE = 1e-15
# array의 크기를 가져옵니다.
size = answer_array.shape[0]
# 반복문을 사용해서 logloss의 합을 계산합니다.
logloss_sum = 0
# zip함수로 묶으면 함께 순회할 수 있습니다.
for answer, arr in zip(answer_array, proba_array):
proba = arr[answer - 1]
# 0이면 무한대 값이 나오기 때문에 0에 가까운 값으로 치환해줍니다.
if proba <= MIN_VALUE:
proba = MIN_VALUE
# 음의 로그함수에 넣어서 logloss 계산
logloss_sum += -np.log(proba)
# logloss의 평균 계산
result = logloss_sum / size
# 반환
return result
y_score = my_logloss(y_true, y_pred)

if eval_type == 'rmsle':
logger.info("if rmsle in")
def rmsle(predicted_values, actual_values):
# 예측값과 실제 값에 1을 더하고 로그를 씌워준다.
log_predict = np.log(predicted_values + 1)
log_actual = np.log(actual_values + 1)
# 위에서 계산한 예측값에서 실제값을 빼주고 제곱을 해준다.
difference = log_predict - log_actual
# difference = (log_predict - log_actual) ** 2
difference = np.square(difference)
# 평균을 낸다.
mean_difference = difference.mean()
# 다시 루트를 씌운다.
score = np.sqrt(mean_difference)
return score
y_score = rmsle(y_true, y_pred)

if eval_type == 'map@k':
logger.info("if map@k in")

# os.remove(tmp_file)
os.remove(tmp_file)

# y_score = float(y_score)
y_score = float(y_score)

# logger.info("float change - y_score={}".format(y_score))
y_score = 55
logger.info("float change - y_score={}".format(y_score))
# y_score = 55
return self.success({"predictId": predict_id, "solutionId": csv.solution_id, "info": info, "y_score": y_score})


Expand Down Expand Up @@ -458,7 +459,7 @@ def put(self, request):
logger.info('problem={}'.format(problem))
# ensure_created_by(problem, request.user)
except AIProblem.DoesNotExist:
return self.error("Problem does not exist")
return self.error("Problem does not exist-aicontest-views-oj.py")

# _id = data["_id"] # Display ID
# if not _id:
Expand Down
2 changes: 1 addition & 1 deletion OJ-BE/deploy/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ XlsxWriter==1.1.5
django-dramatiq==0.5.0
dramatiq==1.3.0
django-dbconn-retry==0.1.5
# numpy
numpy
4 changes: 2 additions & 2 deletions OJ-BE/problem/views/oj.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def get(self, request):
self._add_problem_status(request, problem_data)
return self.success(problem_data)
except Problem.DoesNotExist:
return self.error("Problem does not exist")
return self.error("Problem does not exist-problem-views-oj.py-2")

limit = request.GET.get("limit")
if not limit:
Expand Down Expand Up @@ -103,7 +103,7 @@ def get(self, request):
contest=self.contest,
visible=True)
except Problem.DoesNotExist:
return self.error("Problem does not exist.")
return self.error("Problem does not exist-problem-views-oj.py-1")
if self.contest.problem_details_permission(request.user):
problem_data = ProblemSerializer(problem).data
self._add_problem_status(request, [problem_data, ])
Expand Down
3 changes: 2 additions & 1 deletion OJ-FE/src/pages/oj/views/aicontest/AIContest.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div class="problem-title" slot="title" style="display: inline-block; font-size: 50px; color: white;">{{problem.title}}</div>
</div>
<div style="position: absolute; display:inline-block; float: right; margin-top: 19%; margin-right: -50%;">
<b-button variant="primary" @click="join" :disabled="alreadyJoined == true || breforeStart === true" style="width: 180px; height: 60px; font-weight: bold; font-size: 25px; border-radius: 40px; margin-top: -220px;">{{joinText}}</b-button>
<b-button variant="primary" @click="join" :disabled="alreadyJoined == true || beforeStart === true" style="width: 180px; height: 60px; font-weight: bold; font-size: 25px; border-radius: 40px; margin-top: -220px;">{{joinText}}</b-button>
</div>
<Col id="problem-main" :span=17>
<!--problem main-->
Expand Down Expand Up @@ -479,6 +479,7 @@
console.log('gap2', gap)
if (gap < 0) {
this.beforeStart = true
this.joinText = '참여 불가'
}
},
submit () {
Expand Down
65 changes: 15 additions & 50 deletions OJ-FE/src/pages/oj/views/aicontest/AIContestList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</div>
<!-- 추가 부분 -->
<b-tabs content-class="block mt-3 tabs" pills card fill >
<b-tab title="일반용" id="contest-content" href="/">
<b-tab title="일반용" id="contest-content">
<div id="problem-group">
<b-card v-for="problem in problemList"
:key="problem.title"
Expand All @@ -27,21 +27,13 @@
shadow
class="mb-3 problem-card">
<b-card-body class="problem-content">
<b-card-title class="problem-title" @click="goProblem(problem._id)">{{problem.title}}</b-card-title>
<b-card-title class="problem-title">{{problem.title}}</b-card-title>
<b-card-sub-title class="problem-subtitle">{{problem.created_by.username}}</b-card-sub-title>
<b-card-text class="problem-text">
<p class="content" style="font-size: 16px; float: right; margin-top: -40px;">{{problem.start_time | localtime('YYYY-M-D')}} - {{problem.end_time | localtime('YYYY-M-D')}}</p>
<span v-for="tag in problem.tags" :key="tag.name">
<Button @click="filterByTag(tag)"
type="ghost"
size="small"
shape="circle"
class="tag-btn"
style="margin-top: 3px;">{{tag}}
</Button>
</span>
<span style="font-size: 23px; float: right; margin-top:-8px; font-weight:bold;">D-{{getDuration(problem.start_time, problem.end_time)}}</span>
</b-card-text>
<b-button pill variant="outline-primary" @click="goProblem(problem._id)" size="sm" style="float: right; margin-top: -30px; font-size: 1.1rem;"><b>입장하기</b></b-button>
<!--<span style="font-size: 23px; float: right; margin-top:-8px; font-weight:bold;">D-{{getDuration(problem.start_time, problem.end_time)}}</span>-->
<!--<b-button pill variant="outline-primary" @click="goProblem(problem._id)" size="sm" style="float: right; margin-top: -60px;"><b>더보기</b></b-button>-->
</b-card-body>
</b-card>
Expand Down Expand Up @@ -208,43 +200,11 @@
this.getProblemList()
this.getClassProblemList()
},
// 추가 부분
getDuration (startTime, endTime) {
// console.log(time.duration(startTime, endTime))
// this.currentTime = new Date()
var year = endTime.slice(0, 4)
var month = endTime.slice(5, 7)
var day = endTime.slice(8, 10)
// console.log('endTime', endTime)
// console.log(year, month, day)
var Dday = new Date(year, month - 1, day)
var nowTime = Date.now()
var gap = nowTime - Dday.getTime()
// console.log('gap1', gap)
// console.log('nowTime', nowTime)
// console.log('Dday', Dday)
var result = Math.floor(gap / (1000 * 60 * 60 * 24)) * -1
// console.log('result', result)
if (result === 0) {
result = 'D-day'
}
if (result > 0) { // 평상시 상황
result = 'D-' + result
}
if (result < 0) { // dday 지난 경우
result = '종료'
}
// 지금 시간이 대회 시작 날짜보다 이전이면...
var startDay = new Date(startTime.slice(0, 4), startTime.slice(5, 7) - 1, startTime.slice(8, 10))
console.log('nowTime', nowTime)
console.log('startDay.getTime()', startDay.getTime())
gap = nowTime - startDay.getTime()
var result2 = Math.floor(gap / (1000 * 60 * 60 * 24)) * -1
console.log('gap2', gap)
if (gap < 0) {
result = 'OPEN D-' + result2
}
return result
modalButtonClick (problemID, problemPwd) {
console.log('modal button')
this.isModalViewed = true
this.modalProblemID = problemID
this.modalProblemPwd = problemPwd
},
goProblem (problemID) {
this.$router.push({name: 'aiproblem-general-details', params: {problemID: problemID}})
Expand Down Expand Up @@ -405,10 +365,15 @@
margin-top: -20px;
margin-left: 10px;
}
// .problem-title{
// font-size: 23px;
// font-weight: 800;
// color: #3399ff;
// }
.problem-title{
font-size: 23px;
font-weight: 800;
color: #3399ff;
color: #2d2762;
}
.problem-subtitle{
font-size: 16px;
Expand Down

0 comments on commit b959643

Please sign in to comment.