Add volunteer frequency histogram code.

This commit is contained in:
Ben Rog-Wilhelm 2023-06-11 05:29:47 -05:00
parent f42974dcd7
commit 9d088cf93c
5 changed files with 130 additions and 1 deletions

View file

@ -5,6 +5,7 @@ from files.__main__ import app
from files.commands.cron import cron_app_worker
from files.commands.seed_db import seed_db
from files.commands.volunteer_janitor_recalc import volunteer_janitor_recalc
from files.commands.volunteer_janitor_histogram import volunteer_janitor_histogram_cmd
from files.commands.cron_setup import cron_setup
import files.classes

View file

@ -0,0 +1,35 @@
import pprint
from files.classes.volunteer_janitor import VolunteerJanitorRecord
from files.__main__ import app, db_session
@app.cli.command('volunteer_janitor_histogram')
def volunteer_janitor_histogram_cmd():
import pandas as pd
import matplotlib.pyplot as plt
result_set = db_session().query(VolunteerJanitorRecord.recorded_utc).all()
# convert the result into a pandas DataFrame
df = pd.DataFrame(result_set, columns=['recorded_utc'])
# convert the date column to datetime
df['recorded_utc'] = pd.to_datetime(df['recorded_utc'])
# set 'recorded_utc' as the index of the DataFrame
df.set_index('recorded_utc', inplace=True)
# resample the data to daily frequency
df_resampled = df.resample('D').size()
# plot the resampled DataFrame
df_resampled.plot(kind='line')
plt.title('Density of Dates over Time')
plt.xlabel('Date')
plt.ylabel('Count')
# save the figure in SVG format
plt.savefig('output.svg', format='svg')
print(len(result_set))