Demea9000 commited on
Commit
158a4eb
1 Parent(s): 461802c

some more minor changes

Browse files
Files changed (1) hide show
  1. app.py +33 -15
app.py CHANGED
@@ -1,17 +1,16 @@
1
  import numpy as np
2
-
3
  from textclassifier import TextClassifier as tc
4
  import pandas as pd
5
  import regex as re
6
-
7
  from pathlib import Path
8
  import glob
9
- import matplotlib
10
 
11
- matplotlib.use('Agg')
12
- import matplotlib.pyplot as plt
13
- from functions import functions as f
14
- import time
15
 
16
  SELECTED_COLUMN_DICT = {
17
  'merged_topic': ['tweet', 'main_topic', 'sub_topic', 'synonym_topic', 'cos_sim_topic', 'merged_topic'],
@@ -37,7 +36,7 @@ UserNameDict = dict(zip(['Jimmie Åkesson', 'Ebba Busch', 'Annie Lööf', 'Johan
37
 
38
  Columns = ['username', 'nlikes', 'nreplies', 'nretweets', 'main_topic', 'sub_topic', 'sentiment', 'target', 'tweet',
39
  'date', 'urls', 'id', 'class_tuple', 'user_id']
40
- num_tweet = 1000
41
  LIMIT = 0.05
42
 
43
 
@@ -172,14 +171,33 @@ def main(from_date,
172
  plt.title(title, fontdict=font1)
173
  return fig
174
 
175
- text_classifier = tc.TextClassifier(from_date=from_date, to_date=to_date, user_list=match_name_lower_case(usr_name_choices),
176
- num_tweets=num_tweet)
177
- text_classifier.run_main_pipeline()
178
- dataframe = text_classifier.get_dataframe()
179
- # dataframe= pd.read_csv(os.path.dirname(
180
- # os.path.dirname(os.path.abspath(__file__))) + "/politweet/data/twitterdata.csv") #
181
- df = dataframe
 
 
 
 
 
 
 
 
 
 
 
 
 
182
 
 
 
 
 
 
 
183
  if save_selected:
184
  user_list = match_name_lower_case(usr_name_choices)
185
  df_l = []
 
1
  import numpy as np
2
+ from matplotlib import pyplot as plt, use as plt_use
3
  from textclassifier import TextClassifier as tc
4
  import pandas as pd
5
  import regex as re
 
6
  from pathlib import Path
7
  import glob
8
+ import os
9
 
10
+ plt_use('Agg')
11
+
12
+ # from functions import functions as f
13
+ # import time
14
 
15
  SELECTED_COLUMN_DICT = {
16
  'merged_topic': ['tweet', 'main_topic', 'sub_topic', 'synonym_topic', 'cos_sim_topic', 'merged_topic'],
 
36
 
37
  Columns = ['username', 'nlikes', 'nreplies', 'nretweets', 'main_topic', 'sub_topic', 'sentiment', 'target', 'tweet',
38
  'date', 'urls', 'id', 'class_tuple', 'user_id']
39
+ NUM_TWEETS = 1000
40
  LIMIT = 0.05
41
 
42
 
 
171
  plt.title(title, fontdict=font1)
172
  return fig
173
 
174
+ # Define a function that gives the proportion of sentiments as a function of date
175
+ def sentiment_date(df, col_name, title):
176
+ if df.empty:
177
+ return None
178
+ else:
179
+ df = sentiment_date_input(df, col_name, LIMIT)
180
+ labels = df[col_name].to_list()
181
+ sizes = df['frequency'].values
182
+ # explode = (0, 0.1, 0, 0, 0) # only "explode" the 2nd slice (i.e. 'Hogs')
183
+ font1 = {'family': 'serif', 'color': 'blue', 'size': 20}
184
+ fig = plt.figure()
185
+ plt.pie(sizes, labels=labels, radius=1, autopct='%1.1f%%')
186
+ plt.title(title, fontdict=font1)
187
+ return fig
188
+
189
+ # text_classifier = tc.TextClassifier(from_date=from_date, to_date=to_date,
190
+ # user_list=match_name_lower_case(usr_name_choices),
191
+ # num_tweets=NUM_TWEETS)
192
+ # text_classifier.run_main_pipeline()
193
+ # dataframe = text_classifier.get_dataframe()
194
 
195
+ dataframe = pd.read_csv("{}/data/twitterdata.csv".format(tc.ROOT_PATH))
196
+ # choose subset between from_date and to_date and username is in usr_name_choices
197
+ df = dataframe.loc[(dataframe['date'] >= from_date) & (dataframe['date'] <= to_date) & \
198
+ (dataframe['username'].isin(match_name_lower_case(usr_name_choices)))].copy()
199
+ # Sort df by date
200
+ df.sort_values(by=['date'], inplace=True)
201
  if save_selected:
202
  user_list = match_name_lower_case(usr_name_choices)
203
  df_l = []