Skip to content
This repository was archived by the owner on Sep 16, 2023. It is now read-only.

Commit f14b293

Browse files
committed
feat: add options to select which dataset to be processed
1 parent d993d56 commit f14b293

File tree

3 files changed

+55
-42
lines changed

3 files changed

+55
-42
lines changed

docs/res/web.png

165 KB
Loading

src/twitchanal/cli.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,16 @@ def collect(dir: str, timestamp: bool, num: int, stream: int, extra: bool,
6969
is_flag=True,
7070
default=False,
7171
help='Run in debug mode.')
72-
def process(debug: bool):
72+
@click.option('--dir', '-d',
73+
default='dataset',
74+
help='Data directory.')
75+
@click.option('--timestamp', '-t',
76+
default=None,
77+
help='Data timestamp.')
78+
def process(debug: bool, dir: str, timestamp: str):
7379
""" Process data and do visualization.
7480
"""
75-
show(debug)
81+
show(debug, dir, timestamp)
7682

7783

7884
cli.add_command(save_user)

src/twitchanal/process/show.py

+47-40
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111

1212
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
1313

14-
game = Game()
15-
df = game.get_data()
16-
tags = game.get_tags()
17-
labels = game.get_labels()
14+
game = None
15+
df = None
16+
tags = None
17+
labels = None
1818

1919

2020
def draw_num_of_game_per_tag():
21+
print (game.get_data_pth())
2122
data = {'tag': [], 'num': []}
2223
for key in labels.keys():
2324
data['tag'].append(key)
@@ -93,40 +94,46 @@ def draw_viewer_channel():
9394
return fig
9495

9596

96-
## HTML layout for the web page
97-
app.layout = html.Div(children=[
98-
html.H1(children='Twitch Analysis', style={'textAlign': 'center'}),
99-
100-
# draw 2 plots in one row
101-
dbc.Row([
102-
dbc.Col(
103-
html.Div([
104-
dcc.Graph(id='num_of_game_per_tag_graph', figure=draw_num_of_game_per_tag()),
105-
])
106-
),
107-
dbc.Col(
108-
html.Div([
109-
dcc.Graph(id='total_viewers_graph', figure=draw_total_viewers()),
110-
])
111-
)
112-
]),
113-
114-
dbc.Row([
115-
dbc.Col(
116-
html.Div([
117-
dcc.Graph(id='aver_viewers_graph', figure=draw_average_viewers()),
118-
])
119-
),
120-
dbc.Col(
121-
html.Div([
122-
dcc.Graph(id='peak_viewers_graph', figure=draw_peak_viewers()),
123-
])
124-
),
125-
]),
126-
127-
dcc.Graph(id='viewer_channel_graph', figure=draw_viewer_channel())
128-
])
129-
130-
131-
def show(debug: bool):
97+
def show(debug: bool, dir, timestamp):
98+
# update global variables with input parameters
99+
global game, df, tags, labels
100+
game = Game(dir, timestamp)
101+
df = game.get_data()
102+
tags = game.get_tags()
103+
labels = game.get_labels()
104+
105+
## HTML layout for the web page
106+
app.layout = html.Div(children=[
107+
html.H1(children='Twitch Analysis', style={'textAlign': 'center'}),
108+
109+
# draw 2 plots in one row
110+
dbc.Row([
111+
dbc.Col(
112+
html.Div([
113+
dcc.Graph(id='num_of_game_per_tag_graph', figure=draw_num_of_game_per_tag()),
114+
])
115+
),
116+
dbc.Col(
117+
html.Div([
118+
dcc.Graph(id='total_viewers_graph', figure=draw_total_viewers()),
119+
])
120+
)
121+
]),
122+
123+
dbc.Row([
124+
dbc.Col(
125+
html.Div([
126+
dcc.Graph(id='aver_viewers_graph', figure=draw_average_viewers()),
127+
])
128+
),
129+
dbc.Col(
130+
html.Div([
131+
dcc.Graph(id='peak_viewers_graph', figure=draw_peak_viewers()),
132+
])
133+
),
134+
]),
135+
136+
dcc.Graph(id='viewer_channel_graph', figure=draw_viewer_channel())
137+
])
138+
132139
app.run_server(debug=debug)

0 commit comments

Comments
 (0)