-
Notifications
You must be signed in to change notification settings - Fork 0
/
Twitter_SOV.py
113 lines (80 loc) · 3.89 KB
/
Twitter_SOV.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
"""Third party imports."""
import streamlit as st
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
# Read data from CSV
def read_data(filename):
"""Read data from csv."""
df = pd.read_csv(filename)
df['Date'] = pd.to_datetime(df['Date']) # Convert 'Date' column to datetime
return df
def generate_line_chart(data,metrics1="",metrics2="",metrics3=""):
"""Generate Line chart."""
chart_data = data.set_index('Date') # Set 'Date' column as index
# Get user selection from multiselect checkbox
options = st.multiselect('Select Counts to Display', [metrics1, metrics2, metrics3], default=[metrics1,metrics2,metrics3])
# Plot the line chart based on user selection
selected_columns = [option for option in options if option in chart_data.columns]
if selected_columns:
st.line_chart(chart_data[selected_columns])
else:
st.write("Please select at least one count to display.")
def generate_pie_chart(data,widget_id,chart_title):
"""Generate Pie Chart."""
options = ['Tweet', 'Retweet Count', 'Likes Count']
selected_options = st.multiselect(widget_id, options, default=options)
fig = go.Figure()
for option in selected_options:
fig.add_trace(go.Pie(labels=data['Game'], values=data[option], name=option, textinfo='label+percent', textposition='inside'))
fig.update_layout(title=chart_title)
st.plotly_chart(fig)
def generate_bar_chart(data,widget_id):
"""Generate Bar Chart."""
options = ['Tweet', 'Retweet Count', 'Likes Count']
selected_options = st.multiselect(widget_id, options, default=options)
counts = data.groupby('Game')[selected_options].sum().reset_index()
counts['Total'] = counts[selected_options].sum(axis=1) # Calculate the sum of selected options as the 'Total' column
counts_sorted = counts.sort_values(by='Total', ascending=True) # Sort by the 'Total' column
labels = counts_sorted['Game']
values = counts_sorted[selected_options]
fig = go.Figure()
for option in selected_options:
fig.add_trace(go.Bar(y=labels, x=values[option], orientation='h', name=option))
fig.update_layout(title='Count of Tweets, Retweets, and Likes',
xaxis_title='Count',
yaxis_title='Game',
barmode='stack')
st.plotly_chart(fig, use_container_width=True)
# Main function
def main():
"""Initialize the program."""
st.title("Twitter Share of Voice")
# Read CSV file
filename = 'csvs/SOV - SoV_twitter.csv'
data = read_data(filename)
# ronin_filename = 'csvs/SOV - SoV_Ronin.csv'
# ronin_data = read_data(ronin_filename)
# cyber_filename = 'csvs/SOV - SoV_CyberKong.csv'
# cyber_data = read_data(cyber_filename)
# Generate line chart
st.subheader("Axie Infinity Trend")
generate_line_chart(data,'Tweet','Likes Count','Retweet Count')
# st.subheader("Ronin Network Trend")
# generate_line_chart(ronin_data,'Tweet ','Likes Count ','Retweet Count ')
# st.subheader("CyberKongz Trend")
# generate_line_chart(cyber_data,'Tweet Count','Likes Count ','Retweet Count ')
pie_df = pd.read_csv('csvs/SOV - Twitter_axie_vs_field.csv')
generate_pie_chart(pie_df,'Select AVF metrics','Axie Infinity vs Field')
generate_bar_chart(pie_df,' ')
chains = pd.read_csv('csvs/SOV - Twitter_RVF - Copy.csv')
generate_pie_chart(chains,'Select chain metrics','Ronin Network vs Other Chains')
generate_bar_chart(chains,' ')
ronin_games_df = pd.read_csv('csvs/SOV - Twitter_ronin_games.csv')
generate_pie_chart(ronin_games_df,'Select Ronin Games metrics','Ronin Games VS Each Other')
generate_bar_chart(ronin_games_df,' ')
rvf_df = pd.read_csv('csvs/SOV - Twitter_RVF.csv')
generate_pie_chart(rvf_df,'Select RVF metrics','Ronin Games VS Field')
generate_bar_chart(rvf_df,' ')
if __name__ == '__main__':
main()