Yoon-gu Hwang commited on
Commit
efe5a1a
1 Parent(s): d928b01

시간도 기록

Browse files
Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -4,6 +4,7 @@ import gradio as gr
4
  import pandas as pd
5
  import random
6
  import json
 
7
 
8
  with open('pokemon.json', 'r') as f:
9
  pokemons = json.load(f)
@@ -35,7 +36,7 @@ def get_question_answer(pokemons_set):
35
  a = QUESTION_TEMPLATE['answer'].format(name=name)
36
  return q, a
37
 
38
- info = {u: {"done" : True, "score": 0, "count": 0} for u in USERS}
39
 
40
  MD = """# 포켓몬 퀴즈
41
  ## 사용방법
@@ -85,6 +86,7 @@ with gr.Blocks() as demo:
85
  answer.value = a
86
  info[user]['done'] = False
87
  info[user]['count'] = 0
 
88
  else:
89
  bot_message = "퀴즈를 시작하고 싶으시면, **퀴즈 시작**이라고 말씀해주세요."
90
  else:
@@ -97,16 +99,16 @@ with gr.Blocks() as demo:
97
  if quiz_count == info[user]['count']:
98
  bot_message = f"모든 퀴즈를 다 풀었습니다. 점수는 {info[user]['score']:3.1f}점 입니다."
99
  info[user]['done'] = True
 
100
  elif "퀴즈종료" == message.replace(" ", ""):
101
  bot_message = f"퀴즈를 강제 종료합니다."
102
  info[user]['done'] = True
103
- info[user]['score'] = 0
104
  else:
105
  bot_message = f"***{message}***!? 🧐 다시 한번 생각해보세요."
106
  info[user]['score'] -= 0.1
107
 
108
  chat_history.append((message, bot_message))
109
- return "", chat_history, MD.format(content='\n'.join([f"- {u}({v['score']:3.1f})" for u, v in info.items()]))
110
 
111
  demo.load(lambda : MD.format(content='\n'.join([f"- {u}({v['score']:3.1f}점)" for u, v in info.items()])),
112
  inputs=None,
 
4
  import pandas as pd
5
  import random
6
  import json
7
+ import time
8
 
9
  with open('pokemon.json', 'r') as f:
10
  pokemons = json.load(f)
 
36
  a = QUESTION_TEMPLATE['answer'].format(name=name)
37
  return q, a
38
 
39
+ info = {u: {"done" : True, "score": 0, "count": 0, "best": 0, "time": 0.0} for u in USERS}
40
 
41
  MD = """# 포켓몬 퀴즈
42
  ## 사용방법
 
86
  answer.value = a
87
  info[user]['done'] = False
88
  info[user]['count'] = 0
89
+ info[user]['time'] = time.time()
90
  else:
91
  bot_message = "퀴즈를 시작하고 싶으시면, **퀴즈 시작**이라고 말씀해주세요."
92
  else:
 
99
  if quiz_count == info[user]['count']:
100
  bot_message = f"모든 퀴즈를 다 풀었습니다. 점수는 {info[user]['score']:3.1f}점 입니다."
101
  info[user]['done'] = True
102
+ info[user]['time'] = time.time() - info[user]['time']
103
  elif "퀴즈종료" == message.replace(" ", ""):
104
  bot_message = f"퀴즈를 강제 종료합니다."
105
  info[user]['done'] = True
 
106
  else:
107
  bot_message = f"***{message}***!? 🧐 다시 한번 생각해보세요."
108
  info[user]['score'] -= 0.1
109
 
110
  chat_history.append((message, bot_message))
111
+ return "", chat_history, MD.format(content='\n'.join([f"- {u}({v['score']:3.1f}점, {v['time']:3.1f}초)" for u, v in info.items()]))
112
 
113
  demo.load(lambda : MD.format(content='\n'.join([f"- {u}({v['score']:3.1f}점)" for u, v in info.items()])),
114
  inputs=None,