chg: [app:scores] Added support of first_completion

This commit is contained in:
Sami Mokaddem 2024-07-03 12:37:23 +02:00
parent 6814294e77
commit fb32b59abe
2 changed files with 16 additions and 3 deletions

View file

@ -273,8 +273,18 @@ def mark_task_completed(user_id: int, exercise_uuid: str , task_uuid: str):
if not is_completed: if not is_completed:
db.EXERCISES_STATUS[exercise_uuid]['tasks'][task_uuid]['completed_by_user'].append({ db.EXERCISES_STATUS[exercise_uuid]['tasks'][task_uuid]['completed_by_user'].append({
'user_id': user_id, 'user_id': user_id,
'time': time.time(), 'timestamp': time.time(),
'first_completion': False,
}) })
# Update who was the first to complete the task
first_completion_index = None
first_completion_time = time.time()
for i, entry in enumerate(db.EXERCISES_STATUS[exercise_uuid]['tasks'][task_uuid]['completed_by_user']):
db.EXERCISES_STATUS[exercise_uuid]['tasks'][task_uuid]['completed_by_user'][i]['first_completion'] = False
if entry['timestamp'] < first_completion_time:
first_completion_time = entry['timestamp']
first_completion_index = i
db.EXERCISES_STATUS[exercise_uuid]['tasks'][task_uuid]['completed_by_user'][first_completion_index]['first_completion'] = True
def mark_task_incomplete(user_id: int, exercise_uuid: str , task_uuid: str): def mark_task_incomplete(user_id: int, exercise_uuid: str , task_uuid: str):

View file

@ -108,8 +108,11 @@
<small :class="progress.exercises[exercise.uuid].tasks_completion[task.uuid] ? 'dark:text-green-400 text-green-600' : 'dark:text-slate-500 text-slate-400'"> (+{{ task.score }})</small> <small :class="progress.exercises[exercise.uuid].tasks_completion[task.uuid] ? 'dark:text-green-400 text-green-600' : 'dark:text-slate-500 text-slate-400'"> (+{{ task.score }})</small>
</span> </span>
<span class="text-sm leading-3"> <span class="text-sm leading-3">
<span v-if="progress.exercises[exercise.uuid].tasks_completion[task.uuid].time"> <span
{{ (new Date(progress.exercises[exercise.uuid].tasks_completion[task.uuid].time * 1000)).toTimeString().split(' ', 1)[0] }} v-if="progress.exercises[exercise.uuid].tasks_completion[task.uuid].timestamp"
:class="progress.exercises[exercise.uuid].tasks_completion[task.uuid].first_completion ? 'font-bold' : 'font-extralight'"
>
{{ (new Date(progress.exercises[exercise.uuid].tasks_completion[task.uuid].timestamp * 1000)).toTimeString().split(' ', 1)[0] }}
</span> </span>
<span v-else></span> <span v-else></span>
</span> </span>