In [337]:
import pandas as pd
from collections import Counter
import matplotlib.pyplot as plt
%matplotlib inline
In [301]:
from idigbio import pandas, json
j = json()
In [213]:
def sumseries(series):
c= Counter()
c['count'] = 0
for s in series:
c.update(s)
c['count'] += 1
return c
sumseries([{'a':1}, {'a':13}])
Out[213]:
In [297]:
ssmonthly = j.stats(
'search', date_interval='month',
min_date='2015-07-01', max_date='2016-04-30')['dates']
sorted(ssmonthly.keys())
Out[297]:
In [306]:
ssweekly = j.stats(
'search', date_interval='week',
min_date='2015-06-29', max_date='2016-05-08')['dates']
len(ssweekly.keys()), min(ssweekly.keys()), max(ssweekly.keys())
Out[306]:
In [330]:
statsbymonth = {mon: sumseries(data.values())
for mon, data in ssmonthly.items()}
totals = sumseries(statsbymonth.values())
df = pd.DataFrame.from_dict(statsbymonth, orient='index')
dfmonth = df[['search','seen','download', 'viewed_records', 'viewed_media']]
In [331]:
dfmonth
Out[331]:
In [315]:
dfmonth.sum()
Out[315]:
In [332]:
statsbyweek = {week: sumseries(data.values())
for week, data in ssweekly.items()}
df = pd.DataFrame.from_dict(statsbyweek, orient='index')
dfweek = df[['search','seen','download', 'viewed_records', 'viewed_media']]
In [333]:
df = pd.DataFrame.from_dict(statsbyweek, orient='index')
df = df[['search','seen','download', 'viewed_records', 'viewed_media']]
In [334]:
dfweek
Out[334]:
In [319]:
dfweek.sum()
Out[319]:
In [338]:
dfweek.plot(figsize=(16,4))
Out[338]:
plotting all of them on one chart wasn't very useful because the search results is so much larger than everything else
In [339]:
fig = dfweek.plot(kind='bar',
figsize=(20,15),
subplots=True,
sharex=False,
fontsize=8,
rot=70,
)
In [ ]:
In [ ]:
In [ ]:
In [327]:
import pandas as pd
pd.set_option('display.notebook_repr_html', True)
def _repr_latex_(self):
return "\centering{%s}" % self.to_latex()
pd.DataFrame._repr_latex_ = _repr_latex_ # monkey patch pandas DataFrame
In [340]:
options(jupyter.plot_mimetypes = "image/svg+xml")
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]: