Spaces:
Running
Running
ChenyuRabbitLove
commited on
Commit
•
647ff2a
1
Parent(s):
62a652e
feat: add send player login info workflow
Browse files- app.py +13 -1
- utils/mes_player_acitivity_model.py +2 -2
- utils/utils.py +19 -4
app.py
CHANGED
@@ -6,10 +6,12 @@ import gradio as gr
|
|
6 |
from theme import Seafoam
|
7 |
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()
|
@@ -41,10 +43,13 @@ def get_player_info(player_backend_user_id):
|
|
41 |
|
42 |
return new_player.to_dict()
|
43 |
|
|
|
|
|
44 |
|
45 |
# start of gradio interface
|
46 |
with gr.Blocks(theme=seafoam, css=get_content("css/style.css")) as demo:
|
47 |
player_info = gr.State()
|
|
|
48 |
|
49 |
with gr.Row():
|
50 |
with gr.Column(
|
@@ -120,11 +125,18 @@ with gr.Blocks(theme=seafoam, css=get_content("css/style.css")) as demo:
|
|
120 |
update_status = gr.Textbox("", visible=False)
|
121 |
|
122 |
# actions when player login
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
player_info_query_btn.click(get_player_info, player_backend_id, player_info).then(
|
124 |
render_player_data,
|
125 |
player_info,
|
126 |
[avatar, pet_gallery, badge_gallery, adventure_log, achievements, adventure],
|
127 |
-
)
|
128 |
|
129 |
pull_newest_player_data.submit(
|
130 |
save_latest_player_data,
|
|
|
6 |
from theme import Seafoam
|
7 |
from utils.mes_player_model import Player
|
8 |
from utils.mes_achievements import Achievement
|
9 |
+
from utils.mes_player_activity_model import PlayerActivity
|
10 |
from utils.utils import (
|
11 |
get_content,
|
12 |
render_player_data,
|
13 |
save_latest_player_data,
|
14 |
+
render_finished,
|
15 |
)
|
16 |
|
17 |
seafoam = Seafoam()
|
|
|
43 |
|
44 |
return new_player.to_dict()
|
45 |
|
46 |
+
def create_new_player_activity():
|
47 |
+
return PlayerActivity()
|
48 |
|
49 |
# start of gradio interface
|
50 |
with gr.Blocks(theme=seafoam, css=get_content("css/style.css")) as demo:
|
51 |
player_info = gr.State()
|
52 |
+
player_activity_tracker = gr.State(create_new_player_activity)
|
53 |
|
54 |
with gr.Row():
|
55 |
with gr.Column(
|
|
|
125 |
update_status = gr.Textbox("", visible=False)
|
126 |
|
127 |
# actions when player login
|
128 |
+
# define args
|
129 |
+
send_player_login_info = dict(
|
130 |
+
fn=render_finished,
|
131 |
+
inputs=player_info,
|
132 |
+
outputs=None,
|
133 |
+
)
|
134 |
+
|
135 |
player_info_query_btn.click(get_player_info, player_backend_id, player_info).then(
|
136 |
render_player_data,
|
137 |
player_info,
|
138 |
[avatar, pet_gallery, badge_gallery, adventure_log, achievements, adventure],
|
139 |
+
).then(send_player_login_info)
|
140 |
|
141 |
pull_newest_player_data.submit(
|
142 |
save_latest_player_data,
|
utils/mes_player_acitivity_model.py
CHANGED
@@ -6,8 +6,8 @@ class PlayerActivity():
|
|
6 |
self.login_timestamp_tw = datetime.now()
|
7 |
self.rendered_timestamp_tw = None
|
8 |
|
9 |
-
def render_finished(self,
|
10 |
-
self.player_backend_user_id = player_backend_user_id
|
11 |
self.rendered_timestamp_tw = datetime.now()
|
12 |
|
13 |
def to_dict(self):
|
|
|
6 |
self.login_timestamp_tw = datetime.now()
|
7 |
self.rendered_timestamp_tw = None
|
8 |
|
9 |
+
def render_finished(self, player_info):
|
10 |
+
self.player_backend_user_id = player_info['player_backend_user_id']
|
11 |
self.rendered_timestamp_tw = datetime.now()
|
12 |
|
13 |
def to_dict(self):
|
utils/utils.py
CHANGED
@@ -212,8 +212,23 @@ def render_player_data(player_info: gr.State):
|
|
212 |
current_story,
|
213 |
)
|
214 |
|
215 |
-
def
|
216 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
217 |
|
218 |
-
def
|
219 |
-
|
|
|
|
|
|
212 |
current_story,
|
213 |
)
|
214 |
|
215 |
+
def insert_data_into_bigquery(client, dataset_id, table_id, rows_to_insert):
|
216 |
+
# Specify the destination table
|
217 |
+
table_ref = client.dataset(dataset_id).table(table_id)
|
218 |
+
table = client.get_table(table_ref)
|
219 |
+
|
220 |
+
# Insert data into the table
|
221 |
+
errors = client.insert_rows(table, rows_to_insert)
|
222 |
+
|
223 |
+
# Check if any errors occurred during insertion
|
224 |
+
if errors:
|
225 |
+
logging("Errors occurred while inserting rows:")
|
226 |
+
for error in errors:
|
227 |
+
print(error)
|
228 |
+
else:
|
229 |
+
logging(f"Inserted {len(rows_to_insert)} rows successfully.")
|
230 |
|
231 |
+
def render_finished(player_activity, *args):
|
232 |
+
player_activity.render_finished(*args)
|
233 |
+
insert_row = player_activity.to_dict()
|
234 |
+
insert_data_into_bigquery(bigquery_client, 'streaming_log', 'log_mes_player_login_activity', [insert_row])
|