def concat_ngdp_vis(year, geo): nominal_gdp = alt.Chart( eco, title="Total GDP").mark_bar().transform_aggregate( groupby=['Geography', 'Year'], GDP='sum(Nominal GDP)').encode( x=alt.X('sum(GDP):Q', title='CA$ (MM)', axis=alt.Axis(titleFontSize=20, grid=False, ticks=False, labels=False)), y=alt.Y('Geography:O', sort='-x', title=None, axis=alt.Axis(labelFontSize=20, ticks=False, grid=False)), tooltip=[ alt.Tooltip('Geography', title='Province/territory'), alt.Tooltip('Year') ]).transform_filter( alt.FieldEqualPredicate( field='Geography', equal=geo)).transform_filter( alt.FieldEqualPredicate( field='Year', equal=year)).properties( height=200, width=400).mark_text( dx=-175, color='darkblue', size=40).encode(text=alt.Text( 'sum(GDP):Q', format=('$,'))) nominal_gdp_gr = alt.Chart( eco_gr, title="Growth rate").mark_bar().transform_aggregate( groupby=['Geography', 'Year'], GDP='sum(Nominal GDP)').encode( x=alt.X('sum(GDP):Q', title='Yearly %', axis=alt.Axis(titleFontSize=20, grid=False, ticks=False, labels=False)), y=alt.Y('Geography:O', sort='-x', title=None, axis=alt.Axis(grid=False, ticks=False, labels=False)), tooltip=[ alt.Tooltip('Geography', title='Province/territory'), alt.Tooltip('Year') ]).transform_filter( alt.FieldEqualPredicate( field='Geography', equal=geo)).transform_filter( alt.FieldEqualPredicate( field='Year', equal=year)).properties( height=200, width=400).mark_text( dx=-175, color='darkblue', size=40).encode(text=alt.Text( 'sum(GDP):Q', format=('.2%'))) nominal_gdp_evo = alt.Chart(eco, title="GDP evolution").mark_area( point=alt.OverlayMarkDef(filled=False, fill='darkblue')).encode( x=alt.X('Year', title='Year', axis=alt.Axis(tickCount=5, titleFontSize=20, grid=False, ticks=False, format='Y')), y=alt.Y('sum(Nominal GDP):Q', axis=alt.Axis(tickCount=3, titleFontSize=20, grid=False, ticks=False, format=('$,f')), title=None), tooltip=[ alt.Tooltip('Geography', title='Province/territory'), alt.Tooltip('Year'), alt.Tooltip('sum(Nominal GDP):Q', format=('$,'), title='GDP') ]).transform_filter( alt.FieldEqualPredicate(field='Geography', equal=geo)).transform_filter( alt.FieldRangePredicate( 'Year', [2000, year])) nominal_gdp_rank = alt.Chart( eco, title="Contribution by province/territory").mark_bar().encode( x=alt.X('sum(Nominal GDP):Q', title='CA$ (MM)', axis=alt.Axis(tickCount=3, titleFontSize=20, grid=False, format=('$,f'))), y=alt.Y('Geography:O', sort='-x', axis=alt.Axis(labelFontSize=18), title=None), color=alt.condition((alt.datum.Geography == geo) | (alt.datum.Geography == 'Canada'), alt.value('darkblue'), alt.value('lightblue')), tooltip=[ alt.Tooltip('Geography', title='Province/territory'), alt.Tooltip('Year'), alt.Tooltip('sum(Nominal GDP):Q', format=('$,'), title='GDP') ]).transform_filter( alt.FieldEqualPredicate(field='Year', equal=year)) nominal_gdp_gr_evo = alt.Chart(eco_gr, title="GDP growth rates").mark_bar( point=alt.OverlayMarkDef(filled=False, fill='darkblue'), size=16).encode(x=alt.X('Year', title='Year', axis=alt.Axis(tickCount=5, titleFontSize=20, grid=False, ticks=False, format='Y')), y=alt.Y('sum(Nominal GDP):Q', axis=alt.Axis(tickCount=3, grid=False, ticks=False, format=('%')), title=None), color=alt.condition((alt.datum.Year == year), alt.value('darkblue'), alt.value('lightblue')), tooltip=[ alt.Tooltip('Geography', title='Province/territory'), alt.Tooltip('Year'), alt.Tooltip('sum(Nominal GDP):Q', format=('.2%'), title='Growth rate') ]).transform_filter( alt.FieldEqualPredicate( field='Geography', equal=geo)).transform_filter( alt.FieldRangePredicate( 'Year', [2000, year])) nominal_gdp_gr_rank = alt.Chart( eco_gr, title="By province/territory").mark_bar().encode( x=alt.X('sum(Nominal GDP):Q', title=None, axis=alt.Axis(tickCount=3, titleFontSize=20, grid=False, format=('%'))), y=alt.Y('Geography:O', sort='-x', axis=alt.Axis(labelFontSize=18), title=None), color=alt.condition((alt.datum.Geography == geo) | (alt.datum.Geography == 'Canada'), alt.value('darkblue'), alt.value('lightblue')), tooltip=[ alt.Tooltip('Geography', title='Province/territory'), alt.Tooltip('Year'), alt.Tooltip('sum(Nominal GDP):Q', format=('.2%'), title='Growth rate') ]).transform_filter( alt.FieldEqualPredicate(field='Year', equal=year)) w = 300 h = 200 nominal_gdp = nominal_gdp.properties(width=w, height=h) nominal_gdp_gr = nominal_gdp_gr.properties(width=w, height=h) nominal_gdp_evo = nominal_gdp_evo.properties(width=w, height=h) nominal_gdp_rank = nominal_gdp_rank.properties(width=w, height=h) nominal_gdp_gr_evo = nominal_gdp_gr_evo.properties(width=w, height=h) nominal_gdp_gr_rank = nominal_gdp_gr_rank.properties(width=w, height=h) ngdp_summary = (nominal_gdp | nominal_gdp_gr) ngdp_total = (nominal_gdp_evo | nominal_gdp_rank) ngdp_gr = (nominal_gdp_gr_evo | nominal_gdp_gr_rank) ngdp_vis = ((ngdp_summary & ngdp_total) & ngdp_gr).configure_view(strokeOpacity=0).configure_axis( domain=False).configure_title(fontSize=30) return ngdp_vis.to_html()
def concat_employment_vis(year, geo): er_evo = alt.Chart(eco, title="Unemployment rate evolution").mark_area( point=alt.OverlayMarkDef(filled=False, fill='darkblue')).encode( x=alt.X('Year', title='Year', axis=alt.Axis(tickCount=5, titleFontSize=20, grid=False, ticks=False, format='Y')), y=alt.Y('average(Unemployment rate):Q', axis=alt.Axis(tickCount=3, titleFontSize=20, grid=False, ticks=False, format=('%')), title=None), tooltip=[ alt.Tooltip('Geography', title='Province/territory'), alt.Tooltip('Year'), alt.Tooltip('average(Unemployment rate):Q', format=('.2%'), title='Unemployment rate') ]).transform_filter( alt.FieldEqualPredicate( field='Geography', equal=geo)).transform_filter( alt.FieldRangePredicate( 'Year', [2000, year])).properties(height=430) er_rank = alt.Chart( eco, title="Unemployment rate by province/territory").mark_bar().encode( x=alt.X('average(Unemployment rate):Q', axis=alt.Axis(tickCount=3, titleFontSize=20, grid=False, ticks=False, format=('%')), title=None), y=alt.Y('Geography:O', sort='-x', axis=alt.Axis(labelFontSize=18), title=None), color=alt.condition((alt.datum.Geography == geo) | (alt.datum.Geography == 'Canada'), alt.value('darkblue'), alt.value('lightblue')), tooltip=[ alt.Tooltip('Geography', title='Province/territory'), alt.Tooltip('Year'), alt.Tooltip('average(Unemployment rate):Q', format=('.2%'), title='Unemployment rate') ]).transform_filter( alt.FieldEqualPredicate(field='Year', equal=year)) er_ind_rank = alt.Chart( labour, title="Unemployment rate by industry").mark_bar().encode( x=alt.X('Unemployment rate:Q', axis=alt.Axis(tickCount=3, grid=False, ticks=False, format=('%')), title=None), y=alt.Y('Industry:O', sort='-x', axis=alt.Axis(labelFontSize=18), title=None), color=alt.value('lightblue'), tooltip=[ alt.Tooltip('Geography', title='Province/territory'), alt.Tooltip('Year'), alt.Tooltip('Industry'), alt.Tooltip('Unemployment rate:Q', format=('.2%'), title='Unemployment rate') ]).transform_filter( alt.FieldEqualPredicate( field='Year', equal=year)).transform_filter( alt.FieldEqualPredicate(field='Geography', equal=geo)) w = 300 h = 200 # nominal_gdp = nominal_gdp.properties( # width=w, # height=h # ) # # nominal_gdp_gr = nominal_gdp_gr.properties( # width=w, # height=h # ) # # nominal_gdp_evo = nominal_gdp_evo.properties( # width=w, # height=h # ) er_ind_rank = er_ind_rank.properties(width=w, height=h) er_rank = er_rank.properties(width=w, height=h) er_evo = er_evo.properties(width=w, height=h) employment_plot = ((er_evo | er_rank) & er_ind_rank).configure_view( strokeOpacity=0).configure_axis(domain=False).configure_title( fontSize=30) return employment_plot.to_html()
def main(): #st.write(pd.value_counts(dados_covid["resultadoTeste"])) st.sidebar.title('HACKATHON 1') st.sidebar.subheader('Análise dados COVID-19') filtro_coluna = st.sidebar.selectbox( 'Selecione o filtro', ('Dados Gerais', 'Idade', 'Sexo', 'Sintomas')) if filtro_coluna: if filtro_coluna == 'Dados Gerais': st.write(dados_covid.head(1000)) if st.checkbox("Mostrar colunas"): st.write(dados_covid.count()) if filtro_coluna == 'Sexo': st.subheader('Sexo por resultado do teste') sexo_barras = alt.Chart(dados_covid, width=200).mark_bar().encode( alt.X('sexo:O', axis=alt.Axis(title='')), alt.Y('count():Q'), alt.Column('resultadoTeste:O'), color=alt.Color('sexo:N', scale=alt.Scale(range=["#EA98D2", "#659CCA"])), tooltip='count()').interactive() st.altair_chart(sexo_barras) # count_sexo = pd.value_counts(dados_covid['sexo'])color=alt.Color('gender:N', scale=alt.Scale(range=["#EA98D2", "#659CCA"])) # st.write(count_sexo) # st.bar_chart(count_sexo) if filtro_coluna == 'Idade': st.markdown('Describe da coluna Idade') st.write(dados_covid.idade.describe()) st.subheader('Idade por resultado teste') idade_barras = alt.Chart(dados_covid, width=200).mark_bar().encode( alt.X('idade', bin=alt.Bin(maxbins=20)), alt.Y('count():Q'), alt.Column('resultadoTeste:O'), color='resultadoTeste', tooltip=['idade', 'count()']).transform_filter( alt.FieldRangePredicate(field='idade', range=[0, 120])).interactive() st.altair_chart(idade_barras, use_container_width=True) idade_line = alt.Chart(dados_covid, width=600).mark_line().encode( x='idade', y='count():Q', color='resultadoTeste:O').transform_filter( alt.FieldRangePredicate(field='idade', range=[0, 100])) st.altair_chart(idade_line) if filtro_coluna == 'Sintomas': st.subheader('Sintomas relatados') sintomas = dados_covid.columns[4:] df_sintomas = dados_covid[sintomas].sum().reset_index() df_sintomas.columns = ['sintoma', 'count'] st.write(df_sintomas) sintomas_bar = alt.Chart(df_sintomas, width=700).mark_bar().encode( x='sintoma', y='count', tooltip=['count']).interactive() st.write("\n\n") st.altair_chart(sintomas_bar) st.subheader('Sintomas por resultado do teste') grouped = dados_covid.groupby(['resultadoTeste'])[sintomas].sum() st.write(grouped) st.write("\n\n\n") st.bar_chart(grouped) select = st.multiselect( "Selecione combinação de sintomas apresentados", dados_covid.columns[4:].tolist(), default=["Febre"]) df_select = countsintomas(select, sintomas) df_select # st.write("Numero de ocorrências: ", len(df_select.index)) st.write(df_select.groupby(['resultadoTeste'])[sintomas].sum()) st.markdown( '->Número de pessoas que aprensentaram apenas os sintomas selecionados' ) st.sidebar.subheader('Grupo 1') st.sidebar.markdown('Daniel Santos Pereira') st.sidebar.markdown('Fernando Henrique De Brito Borges') st.sidebar.markdown('Gláucio Ribeiro Santos') st.sidebar.markdown('Rafael Rodrigues dos Santos')
def concat_earnings_vis(year, geo): all_ear_evo = alt.Chart(eco, title="All industries").mark_area( point=alt.OverlayMarkDef(filled=False, fill='darkblue')).encode( x=alt.X('Year', title='CA$', axis=alt.Axis(tickCount=5, titleFontSize=20, grid=False, ticks=False, format='Y')), y=alt.Y('average(All industries):Q', axis=alt.Axis(tickCount=3, titleFontSize=20, grid=False, ticks=False, format=('$,f')), title=None), tooltip=[ alt.Tooltip('Geography', title='Province/territory'), alt.Tooltip('Year'), alt.Tooltip('average(All industries):Q', format=('$,'), title='Earnings') ]).transform_filter( alt.FieldEqualPredicate(field='Geography', equal=geo)).transform_filter( alt.FieldRangePredicate( 'Year', [2002, year])) all_ear_gr_evo = alt.Chart(eco_gr, title="Growth rates").mark_bar( point=alt.OverlayMarkDef(filled=False, fill='darkblue'), size=16).encode(x=alt.X('Year', title='Year', axis=alt.Axis(tickCount=5, titleFontSize=20, grid=False, ticks=False, format='Y')), y=alt.Y('average(All industries):Q', axis=alt.Axis(tickCount=3, grid=False, ticks=False, format=('%')), title=None), color=alt.condition((alt.datum.Year == year), alt.value('darkblue'), alt.value('lightblue')), tooltip=[ alt.Tooltip('Geography', title='Province/territory'), alt.Tooltip('Year'), alt.Tooltip('average(All industries):Q', format=('.2%'), title='Growth rate') ]).transform_filter( alt.FieldEqualPredicate( field='Geography', equal=geo)).transform_filter( alt.FieldRangePredicate( 'Year', [2002, year])) goods_ear_evo = alt.Chart(eco, title="Goods-producing sector").mark_area( point=alt.OverlayMarkDef(filled=False, fill='darkblue')).encode( x=alt.X('Year', title='CA$', axis=alt.Axis(tickCount=5, titleFontSize=20, grid=False, ticks=False, format='Y')), y=alt.Y('average(Goods-producing sector):Q', axis=alt.Axis(tickCount=3, titleFontSize=20, grid=False, ticks=False, format=('$,f')), title=None), tooltip=[ alt.Tooltip('Geography', title='Province/territory'), alt.Tooltip('Year'), alt.Tooltip('average(Goods-producing sector):Q', format=('$,'), title='Earnings') ]).transform_filter( alt.FieldEqualPredicate(field='Geography', equal=geo)).transform_filter( alt.FieldRangePredicate( 'Year', [2002, year])) goods_ear_gr_evo = alt.Chart(eco_gr, title="Growth rates").mark_bar( point=alt.OverlayMarkDef(filled=False, fill='darkblue'), size=16).encode(x=alt.X('Year', title='Year', axis=alt.Axis(tickCount=5, titleFontSize=20, grid=False, ticks=False, format='Y')), y=alt.Y('average(Goods-producing sector):Q', axis=alt.Axis(tickCount=3, grid=False, ticks=False, format=('%')), title=None), color=alt.condition((alt.datum.Year == year), alt.value('darkblue'), alt.value('lightblue')), tooltip=[ alt.Tooltip('Geography', title='Province/territory'), alt.Tooltip('Year'), alt.Tooltip('average(Goods-producing sector):Q', format=('.2%'), title='Growth rate') ]).transform_filter( alt.FieldEqualPredicate( field='Geography', equal=geo)).transform_filter( alt.FieldRangePredicate( 'Year', [2002, year])) serv_ear_evo = alt.Chart(eco, title="Service-producing").mark_area( point=alt.OverlayMarkDef(filled=False, fill='darkblue')).encode( x=alt.X('Year', title='CA$', axis=alt.Axis(tickCount=5, titleFontSize=20, grid=False, ticks=False, format='Y')), y=alt.Y('average(Service-producing sector):Q', axis=alt.Axis(tickCount=3, titleFontSize=20, grid=False, ticks=False, format=('$,f')), title=None), tooltip=[ alt.Tooltip('Geography', title='Province/territory'), alt.Tooltip('Year'), alt.Tooltip('average(Service-producing sector):Q', format=('$,'), title='Earnings') ]).transform_filter( alt.FieldEqualPredicate(field='Geography', equal=geo)).transform_filter( alt.FieldRangePredicate( 'Year', [2002, year])) serv_ear_gr_evo = alt.Chart(eco_gr, title="Growth rates").mark_bar( point=alt.OverlayMarkDef(filled=False, fill='darkblue'), size=16).encode(x=alt.X('Year', title='Year', axis=alt.Axis(tickCount=5, titleFontSize=20, grid=False, ticks=False, format='Y')), y=alt.Y('average(Service-producing sector):Q', axis=alt.Axis(tickCount=3, grid=False, ticks=False, format=('%')), title=None), color=alt.condition((alt.datum.Year == year), alt.value('darkblue'), alt.value('lightblue')), tooltip=[ alt.Tooltip('Geography', title='Province/territory'), alt.Tooltip('Year'), alt.Tooltip('average(Service-producing sector):Q', format=('.2%'), title='Growth rate') ]).transform_filter( alt.FieldEqualPredicate( field='Geography', equal=geo)).transform_filter( alt.FieldRangePredicate( 'Year', [2002, year])) w = 300 h = 200 serv_ear_gr_evo = serv_ear_gr_evo.properties(width=w, height=h) serv_ear_evo = serv_ear_evo.properties(width=w, height=h) goods_ear_gr_evo = goods_ear_gr_evo.properties(width=w, height=h) goods_ear_evo = goods_ear_evo.properties(width=w, height=h) all_ear_gr_evo = all_ear_gr_evo.properties(width=w, height=h) all_ear_evo = all_ear_evo.properties(width=w, height=h) all_ear = (all_ear_evo | all_ear_gr_evo) goods_ear = (goods_ear_evo | goods_ear_gr_evo) serv_ear = (serv_ear_evo | serv_ear_gr_evo) earnings_plot = ((all_ear & serv_ear) & goods_ear).configure_view( strokeOpacity=0).configure_axis(domain=False).configure_title( fontSize=30) return earnings_plot.to_html()
def concat_cpi_vis(year, geo): all_cpi_evo = alt.Chart(eco, title="CPI all-items evolution").mark_area( point=alt.OverlayMarkDef(filled=False, fill='darkblue')).encode( x=alt.X('Year', title='2002=100', axis=alt.Axis(tickCount=5, titleFontSize=20, grid=False, ticks=False, format='Y')), y=alt.Y('average(All-items):Q', axis=alt.Axis(tickCount=3, titleFontSize=20, grid=False, ticks=False, format=(',.0f')), title=None), tooltip=[ alt.Tooltip('Geography', title='Province/territory'), alt.Tooltip('Year'), alt.Tooltip('average(All-items):Q', format=('.0f'), title='CPI') ]).transform_filter( alt.FieldEqualPredicate(field='Geography', equal=geo)).transform_filter( alt.FieldRangePredicate( 'Year', [2000, year])) all_cpi_gr = alt.Chart(eco_gr, title="Growth rates").mark_bar( point=alt.OverlayMarkDef(filled=False, fill='darkblue'), size=16).encode(x=alt.X('Year', title='Year', axis=alt.Axis(tickCount=5, titleFontSize=20, grid=False, ticks=False, format='Y')), y=alt.Y('sum(All-items):Q', axis=alt.Axis(tickCount=3, grid=False, ticks=False, format=('%')), title=None), color=alt.condition((alt.datum.Year == year), alt.value('darkblue'), alt.value('lightblue')), tooltip=[ alt.Tooltip('Geography', title='Province/territory'), alt.Tooltip('Year'), alt.Tooltip('sum(All-items):Q', format=('.2%'), title='Growth rate') ]).transform_filter( alt.FieldEqualPredicate( field='Geography', equal=geo)).transform_filter( alt.FieldRangePredicate( 'Year', [2000, year])) gasoline_cpi_evo = alt.Chart( eco, title="CPI gasoline evolution").mark_area( point=alt.OverlayMarkDef(filled=False, fill='darkblue')).encode( x=alt.X('Year', title='2002=100', axis=alt.Axis(tickCount=5, titleFontSize=20, grid=False, ticks=False, format='Y')), y=alt.Y('average(Gasoline):Q', axis=alt.Axis(tickCount=3, titleFontSize=20, grid=False, ticks=False, format=(',.0f')), title=None), tooltip=[ alt.Tooltip('Geography', title='Province/territory'), alt.Tooltip('Year'), alt.Tooltip('average(Gasoline):Q', title='CPI') ]).transform_filter( alt.FieldEqualPredicate(field='Geography', equal=geo)).transform_filter( alt.FieldRangePredicate( 'Year', [2000, year])) gasoline_cpi_gr = alt.Chart(eco_gr, title="Growth rates").mark_bar( point=alt.OverlayMarkDef(filled=False, fill='darkblue'), size=16).encode(x=alt.X('Year', title='Year', axis=alt.Axis(tickCount=5, titleFontSize=20, grid=False, ticks=False, format='Y')), y=alt.Y('sum(Gasoline):Q', axis=alt.Axis(tickCount=3, grid=False, ticks=False, format=('%')), title=None), color=alt.condition((alt.datum.Year == year), alt.value('darkblue'), alt.value('lightblue')), tooltip=[ alt.Tooltip('Geography', title='Province/territory'), alt.Tooltip('Year'), alt.Tooltip('sum(Gasoline):Q', format=('.2%'), title='Growth rate') ]).transform_filter( alt.FieldEqualPredicate( field='Geography', equal=geo)).transform_filter( alt.FieldRangePredicate( 'Year', [2000, year])) cpi_rank = alt.Chart( eco, title="CPI all-items by province/territory").mark_bar().encode( x=alt.X('average(All-items):Q', title='2002=100', axis=alt.Axis(tickCount=3, titleFontSize=20, grid=False, format=(',.0f'))), y=alt.Y('Geography:O', sort='-x', axis=alt.Axis(labelFontSize=18), title=None), color=alt.condition((alt.datum.Geography == geo) | (alt.datum.Geography == 'Canada'), alt.value('darkblue'), alt.value('lightblue')), tooltip=[ alt.Tooltip('Geography', title='Province/territory'), alt.Tooltip('Year'), alt.Tooltip('average(All-items):Q', title='CPI') ]).transform_filter( alt.FieldEqualPredicate(field='Year', equal=year)) cpi_gr_rank = alt.Chart( eco_gr, title="Growth rate by province/territory").mark_bar().encode( x=alt.X('average(All-items):Q', title=None, axis=alt.Axis(tickCount=3, titleFontSize=20, grid=False, format=('%'))), y=alt.Y('Geography:O', sort='-x', axis=alt.Axis(labelFontSize=18), title=None), color=alt.condition((alt.datum.Geography == geo) | (alt.datum.Geography == 'Canada'), alt.value('darkblue'), alt.value('lightblue')), tooltip=[ alt.Tooltip('Geography', title='Province/territory'), alt.Tooltip('Year'), alt.Tooltip('average(All-items):Q', format=('.2%'), title='CPI') ]).transform_filter( alt.FieldEqualPredicate(field='Year', equal=year)) w = 300 h = 200 all_cpi_evo = all_cpi_evo.properties(width=w, height=h) all_cpi_gr = all_cpi_gr.properties(width=w, height=h) gasoline_cpi_evo = gasoline_cpi_evo.properties(width=w, height=h) gasoline_cpi_gr = gasoline_cpi_gr.properties(width=w, height=h) cpi_rank = cpi_rank.properties(width=w, height=h) cpi_gr_rank = cpi_gr_rank.properties(width=w, height=h) all_cpi = (all_cpi_evo | all_cpi_gr) gasoline_cpi = (gasoline_cpi_evo | gasoline_cpi_gr) rank_cpi = (cpi_rank | cpi_gr_rank) cpi_plot = ((all_cpi & gasoline_cpi) & rank_cpi).configure_view(strokeOpacity=0).configure_axis( domain=False).configure_title(fontSize=30) return cpi_plot.to_html()