-
Notifications
You must be signed in to change notification settings - Fork 1
/
crowdfunding_streamlit.py
194 lines (158 loc) · 5.61 KB
/
crowdfunding_streamlit.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import streamlit as st
# To make things easier later, we're also importing numpy and pandas for
# working with sample data.
import numpy as np
import pandas as pd
from PIL import Image
import sqlalchemy
import hvplot.pandas
import altair as alt
import plotly.express as px
import pydeck as pdk
import pandas as pd
import math
######## Config ########
# Setup vars that can only be called one time
def setup_streamlit():
# Setup page wide to make use of full screen
st.set_page_config(layout="wide")
# Connect to the db
def connect_db():
# Establishes Database Connection with a temporary SQL db (we can update to give it a name later)
database_connection_string = "sqlite:///crowdfunding.db"
engine = sqlalchemy.create_engine(database_connection_string)
return engine
######## Main for navbar ########
def main():
# Menu
menu = ['Intro',
'Members and Roles',
'Duration Analysis'
]
choice = st.sidebar.selectbox('Menu', menu)
if choice == 'Intro':
setup_intro_page()
elif choice == 'Members and Roles':
setup_member_and_role_page()
else:
setup_duration_page()
######## Pages setup ########
# Home page setup
def setup_intro_page():
# Add title
st.title('Welcome to Crowdfunder Analyzer')
# Add image at top
kickstarter_vs_indiegogo = Image.open('./Resources/Images/kickstarter_indiegogo.jpeg')
st.image(kickstarter_vs_indiegogo)
# Add discription
st.markdown('''
# Crowdfunding Analysis
This project attempts to help project creators understand how to market their project on Kickstarter vs Indiegogo or other crowdfunding platforms.
The purpose of this tool is to not only give them some advice on platforms but be able to efficiently market their project.
We did the following for this project:
- We analyzed Kickstarter vs. Indiegogo using Jupyter notebook
- We made an interactive command line "app" using questionary
''')
# Member and role page setup
def setup_member_and_role_page():
# Setup cols
col1, col2 = st.beta_columns(2)
# Add image at top
image_i = Image.open('./Resources/Images/i_wordcloud.png')
image_k = Image.open('./Resources/Images/k_wordcloud.png')
col1.image(image_k)
col2.image(image_i)
# Add title
st.title('Project Members and Roles')
# Add slide
team_members = Image.open('./Resources/Images/team_member.png')
st.image(team_members)
# Setup duration page
def setup_duration_page():
# Setup cols
col1, col2 = st.beta_columns(2)
st.title('Analysis of Duration')
# Setup cols
col1, col2 = st.beta_columns(2)
# Create a SQL query to get the main_category and duration of the Kickstarter Large dataframe.
query_ks = """
SELECT *
FROM ks_duration
"""
query_indiegogo = """
SELECT *
FROM ig_duration
"""
# This will let us read the query we applied earlier to create a dataframe.
ks_large_duration_dataframe = pd.read_sql_query(
query_ks,
con= engine)
col1.subheader('Categories with Duration for Kickstarter')
col1.dataframe(ks_large_duration_dataframe)
indiegogo_duration_dataframe = pd.read_sql_query(
query_indiegogo,
con= engine)
col2.subheader('Categories with Duration for Indiegogo')
col2.dataframe(indiegogo_duration_dataframe)
# Create a SQL query to get the main_category and
# duration of the Kickstarter Large dataframe and
# group them by main_category and get its average duration days.
query="""SELECT *
FROM ks_avg_duration
"""
# This will let us read the query we applied earlier to create a dataframe.
ks_large_groupby_maincategory_df = pd.read_sql_query(
query,
con= engine)
col1.subheader('Categories with Avg. Duration for Kickstarter')
col1.dataframe(ks_large_groupby_maincategory_df)
chart = alt.Chart(ks_large_groupby_maincategory_df).mark_bar().encode(
alt.X('main_category',
sort="-y"
),
alt.Y('average_duration_days',
scale=alt.Scale(zero=False)
)
)
col2.subheader('Categories with Avg. Duration for Kickstarter')
col2.altair_chart(chart)
# Create a SQL query to get the total number of projects in Kickstarter Large dataframe per country.
query_ks_country = """
SELECT *
FROM ks_total_projects_lat_long
"""
# This will let us read the query we applied earlier to create a dataframe.
ks_country_total_df = pd.read_sql_query(
query_ks_country,
con= engine)
# This will create a scatter mapbox plot for Kickstarter and their respective longitude and latitude plotted in with total number of projects.
# Define a layer to display on a map
layer = pdk.Layer(
"ScatterplotLayer",
ks_country_total_df,
pickable=True,
opacity=0.8,
stroked=True,
filled=True,
radius_scale=6,
radius_min_pixels=10,
radius_max_pixels=100,
line_width_min_pixels=1,
get_position='[lon, lat]',
get_radius="Total_number_of_projects",
get_fill_color=[124, 252, 0],
get_line_color=[0, 0, 0],
)
# Set the viewport location
view_state = pdk.ViewState(latitude=37.983810, longitude=-23.727539, zoom=1, bearing=0, pitch=0)
st.subheader('Kickstarter Number of Projects by Country')
st.pydeck_chart(pdk.Deck(
layers=[layer],
initial_view_state=view_state,
tooltip={"text": "{Country}\n{Total_number_of_projects}"}
))
######## Main ########
if __name__ == '__main__':
setup_streamlit()
engine = connect_db()
main()