def test_compute_ratio_songs(self): serie = pd.Series([1, 1, 1, 1, 2, 2, 3, 3, 3, 3]) result = Utility.compute_ratio_songs(serie).tolist() self.assertEqual(result, [40.0, 40.0, 20.0])
df_viz = viz_df_instance.get_df_viz() # note that you can filter this df_viz using queries (see query.py for examples!) # BUILD A BAR CHART FOR DAY OF THE WEEK WITH RATIO OF SONGS ########################################################################################################################### # create the BarChart instance years_to_plot = sorted(df_viz['Play_Year'].dropna().unique()) bar_chart = BarChartVisualization(df_viz) bar_chart.hover_unit = '%' # for each year, build the x and y series, computing the percentage of songs, and generate the traces for year in years_to_plot: x_serie = df_viz[df_viz['Play_Year']==year]['Play_DOW'].unique() y_serie = Utility.compute_ratio_songs(df_viz[df_viz['Play_Year']==year]['Play_DOW']) bar_chart.render_bar_chart(x_serie, y_serie, str(year)) # edit the layout of the xaxis and show the rendered plot xaxis=dict(categoryorder='array', tickangle = -45, categoryarray = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']) bar_chart.figure.update_layout(xaxis =xaxis) bar_chart.figure.show() # BUILD A BAR CHART FOR MONTH WITH COUNT OF SONGS ########################################################################################################################### # create the BarChart instance