-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot.py
74 lines (62 loc) · 2.53 KB
/
plot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import streamlit as st
import plotly
import ujson
import pandas as pd
import plotly.express as px
import glob
import time
from datetime import datetime as dt
import itertools
import collections
import os
st.set_page_config(layout="wide")
@st.cache
def load_jsons(ids):
point_dfs = []
club_data = []
for id in ids:
with open(id, "r") as f:
json_loaded = ujson.load(f)
point_dfs.append(json_loaded["point"])
club_data.append(list(json_loaded["stay"].values()))
point_dataframe = pd.DataFrame(data=dict(id=[i[27:].replace(".json","") for i in ids], point=point_dfs))
club_data = collections.Counter(itertools.chain.from_iterable(club_data))
club_data = pd.DataFrame(data=dict(name=list(club_data.keys()), counts=list(club_data.values())))
club_data.drop(0,inplace=True)
return point_dataframe, club_data
@st.cache
def load_data(id_selected):
with open(id_selected, "r") as f:
df = ujson.load(f)
df_history = pd.DataFrame(df)
df_history["point"] = df_history["log"].cumsum()
df_history["time"] = df_history["time"].apply(lambda x: dt.strptime("2021/"+x, r"%Y/%m/%d %H:%M:%S"))
return df_history
id_list = glob.glob(r"/app/gpoint-2021-site/2021/*.json")
id_list_names = [i[27:].replace(".json","") for i in id_list]
st.sidebar.write("### ID")
id_selected = st.sidebar.selectbox(' ', id_list_names)
st.sidebar.write("### point ranking")
point_dataframe, club_data = load_jsons(id_list)
st.sidebar.dataframe(point_dataframe.sort_values("point", ascending=False).reset_index(drop=True))
st.header("G-Point 履歴 2021\n")
tab1, tab2 = st.tabs(["user", "club"])
with tab1:
df_history = load_data("/app/gpoint-2021-site/2021/"+id_selected+".json")
st.subheader("ポイントの推移")
fig = px.line(df_history, x='time', y='point', hover_name='stay', markers=True)
st.write(fig)
left_column, right_column = st.columns([2,1])
left_column.subheader('ログ')
right_column.subheader('景品引き換え')
with left_column:
st.dataframe(df_history,height=150)
with right_column:
st.dataframe(pd.DataFrame(data=dict(prize=["item1","item2"],bool=["交換済み","交換済み"])))
#st.write("item1: "+"True")
#st.write("item2: "+"True")
with tab2:
st.subheader("サークルに訪れた人数")
fig = px.bar(club_data, x="name", y="counts")
st.write(fig)
st.subheader("合計ポイント: "+str(sum(point_dataframe["point"])))