thak123 commited on
Commit
480c4d5
1 Parent(s): 542285e

Update index.py

Browse files
Files changed (1) hide show
  1. index.py +53 -7
index.py CHANGED
@@ -21,13 +21,29 @@ url='https://drive.google.com/uc?id=' + url.split('/')[-2]
21
 
22
  # reading of file
23
  df = pd.read_csv(url)
24
- df['FinBERT_label'] = df['FinBERT_label'].astype(str)
25
  df['date'] = pd.to_datetime(df['date'])
 
26
  df = df.rename(columns={df.columns[4]: "Veículos de notícias"})
27
 
 
 
 
 
 
 
 
28
  unique_topics = df['Topic'].unique()
29
  print(unique_topics)
30
 
 
 
 
 
 
 
 
 
31
 
32
  app.layout = dbc.Container(
33
  [ dbc.Row([ # row 1
@@ -73,17 +89,52 @@ dbc.Row([ # row 6
73
  )
74
  ]),
75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
 
77
  ])
78
 
79
  # callback decorator
80
  @app.callback(
81
  Output('line-graph-1', 'figure'),
 
 
 
82
  Input("topic-selector", "value"),
 
83
  Input('date-range', 'start_date'),
84
  Input('date-range', 'end_date')
85
  )
86
-
87
  # callback function
88
  def update_output(selected_topic, start_date, end_date):
89
  # filter dataframes based on updated data range
@@ -106,11 +157,6 @@ def update_output(selected_topic, start_date, end_date):
106
  return line_fig_1
107
 
108
 
109
- # df['FinBERT_label'].replace({
110
- # '3.0': 'positive',
111
- # '2.0': 'neutral',
112
- # '1.0': 'negative'
113
- # }, inplace=True)
114
 
115
  # df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/gapminder_unfiltered.csv')
116
 
 
21
 
22
  # reading of file
23
  df = pd.read_csv(url)
24
+
25
  df['date'] = pd.to_datetime(df['date'])
26
+
27
  df = df.rename(columns={df.columns[4]: "Veículos de notícias"})
28
 
29
+ df['FinBERT_label'] = df['FinBERT_label'].astype(str)
30
+ df['FinBERT_label'].replace({
31
+ '3.0': 'positive',
32
+ '2.0': 'neutral',
33
+ '1.0': 'negative'
34
+ }, inplace=True)
35
+
36
  unique_topics = df['Topic'].unique()
37
  print(unique_topics)
38
 
39
+ counts = df.groupby(['date', 'Topic', 'domain_folder_name', 'FinBERT_label']).size().reset_index(name='count')
40
+ counts['count'] = counts['count'].astype('float64')
41
+ counts['rolling_mean_counts'] = counts['count'].rolling(window=30, min_periods=2).mean()
42
+ df_pos = counts[[x in ['positive'] for x in counts.FinBERT_label]]
43
+ df_neu = counts[[x in ['neutral'] for x in counts.FinBERT_label]]
44
+ df_neg = counts[[x in ['negative'] for x in counts.FinBERT_label]]
45
+
46
+
47
 
48
  app.layout = dbc.Container(
49
  [ dbc.Row([ # row 1
 
89
  )
90
  ]),
91
 
92
+ dbc.Row([ # row 7
93
+ dbc.Label("Escolha um site de notícias:", className="fw-bold")
94
+ ]),
95
+
96
+ dbc.Row([ # row 8
97
+ dbc.Col(
98
+ dcc.Dropdown(
99
+ id="domain-selector",
100
+ options=[
101
+ {"label": domain, "value": domain} for domain in unique_domains
102
+ ],
103
+ value="expresso-pt", # Set the initial value
104
+ style={"width": "50%"})
105
+
106
+
107
+ )
108
+ ]),
109
+
110
+ dbc.Row([ # row 9
111
+ dbc.Col(dcc.Graph(id='line-graph-2'),
112
+ )
113
+ ]),
114
+
115
+ dbc.Row([ # row 10
116
+ dbc.Col(dcc.Graph(id='line-graph-3'),
117
+ )
118
+ ]),
119
+
120
+ dbc.Row([ # row 11
121
+ dbc.Col(dcc.Graph(id='line-graph-4'),
122
+ )
123
+ ])
124
 
125
  ])
126
 
127
  # callback decorator
128
  @app.callback(
129
  Output('line-graph-1', 'figure'),
130
+ Output('line-graph-2', 'figure'),
131
+ Output('line-graph-3', 'figure'),
132
+ Output('line-graph-4', 'figure'),
133
  Input("topic-selector", "value"),
134
+ Input ("domain-selector", "value"),
135
  Input('date-range', 'start_date'),
136
  Input('date-range', 'end_date')
137
  )
 
138
  # callback function
139
  def update_output(selected_topic, start_date, end_date):
140
  # filter dataframes based on updated data range
 
157
  return line_fig_1
158
 
159
 
 
 
 
 
 
160
 
161
  # df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/gapminder_unfiltered.csv')
162