import seaborn as sns
import pandas as pd
import datetime, sys
import matplotlib, statistics
%config InlineBackend.figure_format = 'retina'
%matplotlib inline
SELECT date_trunc('week', created_at) as week, count(distinct(uid)) as users, count(id) as changesets, sum(num_changes) as edits
FROM changesets
WHERE lower(tags['created_by']) LIKE '%potlatch%'
GROUP BY date_trunc('week', created_at)
ORDER BY date_trunc('week', created_at) desc
df = pd.read_csv('./data/potlatch_edits_weekly.csv')
df['week'] = df.week.apply(lambda t: pd.Timestamp(t).date())
df.head(2)
sns.set_style("whitegrid")
ax = df.set_index('week')['users'].plot(figsize=(15,8), style="-")
ax.set_ylabel("Number of users submitting changesets with Potlatch each week", fontsize=14);
ax.set_xlabel("Date", fontsize=14);
ax.set_title("Use of the Potlatch editor over time", fontsize=16);
ax2 = ax.twinx();
df.set_index('week')['edits'].plot(figsize=(15,8), style="--", ax=ax2, color='orange')
ax2.set_ylabel("Number of weekly OSM edits", fontsize=14)
ax.legend(['Users active each week'], loc='upper left');
ax2.legend(['Edits to OSM'], loc='upper right');
print("The last 25 weeks of Potlatch Stats: ")
df.sort_values(by='week',ascending=False).head(25)