ChenyuRabbitLove commited on
Commit
7b96f10
1 Parent(s): dd9fc50

refactor: formatting

Browse files
app.py CHANGED
@@ -8,12 +8,13 @@ from utils.mes_player_model import Player
8
  from utils.mes_achievements import Achievement
9
  from utils.utils import (
10
  get_content,
11
- render_player_data,
12
  save_latest_player_data,
13
  )
14
 
15
  seafoam = Seafoam()
16
 
 
17
  def get_player_info(player_backend_user_id):
18
  with open("latest_player_data.json", "r", encoding="utf-8") as file:
19
  player_info = json.load(file)
@@ -21,9 +22,15 @@ def get_player_info(player_backend_user_id):
21
  if player_backend_user_id in player_info:
22
  return player_info[player_backend_user_id]
23
  else:
24
- logging.info(f"No data found for player ID {player_backend_user_id}. Initializing new player data.")
 
 
25
 
26
- new_player = Player(player_backend_user_id=player_backend_user_id, init=True, available_achievements=Achievement.get_available_achievements())
 
 
 
 
27
  return new_player.to_dict()
28
 
29
 
@@ -106,7 +113,9 @@ with gr.Blocks(theme=seafoam, css=get_content("css/style.css")) as demo:
106
 
107
  # actions when player login
108
  player_info_query_btn.click(get_player_info, player_backend_id, player_info).then(
109
- render_player_data, player_info, [avatar, pet_gallery, badge_gallery, adventure_log, achievements, adventure]
 
 
110
  )
111
 
112
  pull_newest_player_data.submit(
 
8
  from utils.mes_achievements import Achievement
9
  from utils.utils import (
10
  get_content,
11
+ render_player_data,
12
  save_latest_player_data,
13
  )
14
 
15
  seafoam = Seafoam()
16
 
17
+
18
  def get_player_info(player_backend_user_id):
19
  with open("latest_player_data.json", "r", encoding="utf-8") as file:
20
  player_info = json.load(file)
 
22
  if player_backend_user_id in player_info:
23
  return player_info[player_backend_user_id]
24
  else:
25
+ logging.info(
26
+ f"No data found for player ID {player_backend_user_id}. Initializing new player data."
27
+ )
28
 
29
+ new_player = Player(
30
+ player_backend_user_id=player_backend_user_id,
31
+ init=True,
32
+ available_achievements=Achievement.get_available_achievements(),
33
+ )
34
  return new_player.to_dict()
35
 
36
 
 
113
 
114
  # actions when player login
115
  player_info_query_btn.click(get_player_info, player_backend_id, player_info).then(
116
+ render_player_data,
117
+ player_info,
118
+ [avatar, pet_gallery, badge_gallery, adventure_log, achievements, adventure],
119
  )
120
 
121
  pull_newest_player_data.submit(
utils/mes_achievements.py CHANGED
@@ -1,5 +1,6 @@
1
  from typing import List
2
 
 
3
  class Achievement:
4
  achievements_list = [
5
  "participation_star",
@@ -39,4 +40,4 @@ class Achievement:
39
 
40
  @classmethod
41
  def get_available_achievements(cls) -> List[str]:
42
- return cls.achievements_list
 
1
  from typing import List
2
 
3
+
4
  class Achievement:
5
  achievements_list = [
6
  "participation_star",
 
40
 
41
  @classmethod
42
  def get_available_achievements(cls) -> List[str]:
43
+ return cls.achievements_list
utils/mes_player_model.py CHANGED
@@ -198,8 +198,8 @@ class Player:
198
  """
199
  data = asdict(self)
200
  # Convert datetime.date objects to string
201
- for date_field in ['created_at_date', 'updated_at_date']:
202
  if data.get(date_field):
203
  data[date_field] = data[date_field].strftime("%Y-%m-%d")
204
 
205
- return data
 
198
  """
199
  data = asdict(self)
200
  # Convert datetime.date objects to string
201
+ for date_field in ["created_at_date", "updated_at_date"]:
202
  if data.get(date_field):
203
  data[date_field] = data[date_field].strftime("%Y-%m-%d")
204
 
205
+ return data
utils/utils.py CHANGED
@@ -41,6 +41,7 @@ def get_player_partners(player_info: gr.State) -> List[str]:
41
  def get_player_badges(player_info: gr.State) -> List[str]:
42
  return [f"{MEDIA_PATH}{badge}{MEDIA_FILE_TYPE}" for badge in player_info["badges"]]
43
 
 
44
  def get_player_avatar(player_info: gr.State) -> str:
45
  return f"{AVATAR_PATH}avatar_{player_info['player_group'] + 1}{AVATAR_FILE_TYPE}"
46
 
@@ -191,6 +192,7 @@ def save_latest_player_data():
191
  print("Saving latest player data...")
192
  json.dump(latest_player_data_as_dict, fp, default=date_serializer)
193
 
 
194
  def render_player_data(player_info: gr.State):
195
  player_avatar = get_player_avatar(player_info)
196
  player_partners = get_player_partners(player_info)
@@ -205,5 +207,5 @@ def render_player_data(player_info: gr.State):
205
  player_badges,
206
  player_adventure_logs,
207
  player_achievements,
208
- current_story
209
- )
 
41
  def get_player_badges(player_info: gr.State) -> List[str]:
42
  return [f"{MEDIA_PATH}{badge}{MEDIA_FILE_TYPE}" for badge in player_info["badges"]]
43
 
44
+
45
  def get_player_avatar(player_info: gr.State) -> str:
46
  return f"{AVATAR_PATH}avatar_{player_info['player_group'] + 1}{AVATAR_FILE_TYPE}"
47
 
 
192
  print("Saving latest player data...")
193
  json.dump(latest_player_data_as_dict, fp, default=date_serializer)
194
 
195
+
196
  def render_player_data(player_info: gr.State):
197
  player_avatar = get_player_avatar(player_info)
198
  player_partners = get_player_partners(player_info)
 
207
  player_badges,
208
  player_adventure_logs,
209
  player_achievements,
210
+ current_story,
211
+ )