-
Notifications
You must be signed in to change notification settings - Fork 3
/
redditgraph.py
executable file
·79 lines (71 loc) · 2.52 KB
/
redditgraph.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
75
76
77
78
79
from Reddit import top_posts
from Reddit import to_id_list
from Reddit import mine_comments
import plotly.graph_objs as go
from Senti import analyse_sentiment,pretty_txt
#FUNCTION TO PLOT REDDIT GRAPH
def REDDIT_graph(n_clicks,input_value):
input_value = pretty_txt(input_value)
df1=top_posts(input_value)
list1=to_id_list(df1)
comment=mine_comments(list1)
comment=analyse_sentiment(comment,"comments")
comment['Date'] = comment.apply(lambda row: str(row.c_date).split(" ", 1)[0], axis = 1)
comment2 = comment.groupby('Date', as_index=False)[['sentiment']].mean()
data=[]
trace_close = go.Scatter(x = list(comment2.Date),
y=list(comment2.sentiment),
mode='lines',
name="Close",
line=dict(color="#ff3333"))
data.append(trace_close)
figure1 = go.Figure(data)
figure1.update_layout(
title="Date-Wise Mean Sentiment Score Line Plot",
xaxis_title="Date",
yaxis_title="Mean Score",
template='plotly_dark',
plot_bgcolor= 'rgba(0, 0, 0, 0)'
)
data=[]
trace_close = go.Scatter(x = list(comment.c_date),
y=list(comment.sentiment),
mode='markers',
name="markers",
marker_color=comment['sentiment'])
data.append(trace_close)
figure2 = go.Figure(data)
figure2.update_layout(
title="Date-Wise Sentiment Score Scatter Plot [negative(-1) to positive(+1)]",
xaxis_title="Date",
yaxis_title="(-ve) Sentiment Score (+ve)",
template='plotly_dark',
plot_bgcolor= 'rgba(0, 0, 0, 0)'
)
data=[]
trace_close = go.Box(x = list(comment.Date),
y=list(comment.sentiment),
name="Close",
line=dict(color="#ff3333"))
data.append(trace_close)
figure3 = go.Figure(data)
figure3.update_layout(
title="Date-Wise Sentiment Score Box Plot [negative(-1) to positive(+1)]",
xaxis_title="Date",
yaxis_title="(-ve) Sentiment Score (+ve)",
template='plotly_dark',
plot_bgcolor= 'rgba(0, 0, 0, 0)'
)
data=[]
trace_close = go.Pie(labels=list(comment.roundoff),
name="Close"
)
data.append(trace_close)
figure4 = go.Figure(data)
figure4.update_layout(
title="Pie-Chart",
template='plotly_dark',
plot_bgcolor= 'rgba(0, 0, 0, 0)'
)
figure = (figure1,figure2,figure3,figure4)
return figure