def plt_total_payments_by_source(save=True, title='Total payments by source', x_label="Terms", y_label="Source", is_long_title=False, file='total_payments_source.png', fig_size=PLOT_DIMENSIONS): """ Bar plots showing the total amount received from each 'Source'. """ # set the style sns.set(style="darkgrid") plt.figure(figsize=fig_size) df = roll.payments_overview_df() sns.barplot(data=df, x=common.SOURCE_COL, y=common.PENCE_COL) # tick range in pence (divisible by 240, which is £1) ticks_range = np.arange(0, 480000, 120000) # show the labels as £ rather than pennies ticks_labels = [] for x in np.nditer(ticks_range.T): ticks_labels.append(money.pence_to_psd(x)) plt.yticks(ticks_range, ticks_labels) plt.xticks(fontsize=ANNOTATION_FONT_SIZE, fontname=FONT_NAME, rotation=90) # plot labels set_labels(x_label, y_label) # plot title title_text(title, is_long_title) # show or save the image to file save_or_show(save=save, plot_file_name=file)
def plt_scatter_payments_year(save=True, title='Scatter plot of all payments', x_label="Date", y_label="Payment", is_long_title=False, file='scatter_plot_all_payments.png', fig_size=PLOT_DIMENSIONS): """ A scatter plot of payments across the year. """ # set a plot size plt.figure(figsize=fig_size) # get the data and remove rows with no payments df = roll.roll_with_entities_df() df['Date Time'] = df.apply(to_date, axis=1) df_plot = df[df[common.PENCE_COL] > 0] # create the plot plt.scatter(df_plot['Date Time'].tolist(), df_plot['Pence'], s=2) # tick range in pence (divisible by 240, which is £1) ticks_range = np.arange(0, 84000, 6000) # show the labels as £ rather than pennies ticks_labels = [] for x in np.nditer(ticks_range.T): ticks_labels.append(money.pence_to_psd(x)) plt.yticks(ticks_range, ticks_labels) plt.xticks(fontsize=ANNOTATION_FONT_SIZE, rotation=90, fontname=FONT_NAME) # plot labels set_labels(x_label, y_label) # plot title title_text(title, is_long_title) # show or save the image to file save_or_show(save=save, plot_file_name=file)
def plt_total_by_terms(save=True, title='Total payments, per term', x_label="Terms", y_label='Total payments', is_long_title=True, file='terms_total.png', fig_size=PLOT_DIMENSIONS): """ A basic bar graph that shows the total payments per term. """ # set a plot size plt.figure(figsize=fig_size) # get the totals terms_df = roll.terms_overview_df() # tick range in pence (divisible by 240, which is £1) ticks_range = np.arange(0, 600000, 120000) # show the labels as £ rather than pennies ticks_labels = [] for x in np.nditer(ticks_range.T): ticks_labels.append(money.pence_to_psd(x)) plt.yticks(ticks_range, ticks_labels, fontname=FONT_NAME) # plot the data ax = sns.barplot(x=terms_df.index, y=terms_df['Term total']) plt.xticks(fontname=FONT_NAME) # add the £.s.d. to each bar for patch, pence in zip(ax.patches, terms_df['Term total']): ax.text(patch.get_x() + patch.get_width() / 2, patch.get_height(), money.pence_to_psd(pence), ha="center", fontname=FONT_NAME, fontsize=ANNOTATION_FONT_SIZE, linespacing=2.0) # plot labels set_labels(x_label, y_label) # plot title title_text(title, is_long_title) # show or save the image to file save_or_show(save=save, plot_file_name=file)
def daily_sum_from_roll_df(df): """ Create a new data frame of daily sums in pence and the equivalent £.s.d. from the roll data """ data = [] columns = [common.DATE_COL, common.PENCE_COL, common.PSD_COL] date_group = df.groupby(common.DATE_COL) for date, group in date_group: pence = group[common.PENCE_COL].sum() row = [date, pence, money.pence_to_psd(pence)] data.append(row) return pd.DataFrame(data, columns=columns)
def test_14(self): self.assertEqual(money.pence_to_psd(4.25), "4¼d.")
def test_13(self): self.assertEqual(money.pence_to_psd(4), "4d.")
def test_12(self): self.assertEqual(money.pence_to_psd(76.75), "6s.4¾d.")
def test_20(self): self.assertEqual(money.pence_to_psd(2880), "£12.")
def test_18(self): self.assertEqual(money.pence_to_psd(192), "16s.")
def test_17(self): self.assertEqual(money.pence_to_psd(72), "6s.")
def test_7(self): self.assertEqual(money.pence_to_psd(2712), "£11.6s.")
def test_6(self): self.assertEqual(money.pence_to_psd(312), "£1.6s.")
def test_5(self): self.assertEqual(money.pence_to_psd(316.75), "£1.6s.4¾d.")
def test_4(self): self.assertEqual(money.pence_to_psd(316.25), '£1.6s.4¼d.')
def test_3(self): self.assertEqual(money.pence_to_psd(2716), '£11.6s.4d.')
def test_15(self): self.assertEqual(money.pence_to_psd(4.5), "4½d.")
def test_16(self): self.assertEqual(money.pence_to_psd(4.75), "4¾d.")
def test_8(self): self.assertEqual(money.pence_to_psd(76), "6s.4d.")
def test_1(self): self.assertEqual(money.pence_to_psd(160), '13s.4d.')
def test_9(self): self.assertEqual(money.pence_to_psd(201), "16s.9d.")
def test_19(self): self.assertEqual(money.pence_to_psd(240), "£1.")
def test_10(self): self.assertEqual(money.pence_to_psd(76.25), "6s.4¼d.")
def test_2(self): self.assertEqual(money.pence_to_psd(316), '£1.6s.4d.')
def test_11(self): self.assertEqual(money.pence_to_psd(76.5), "6s.4½d.")