|
import json |
|
import numpy as np |
|
import prettyplotlib as ppl |
|
import matplotlib.pyplot as plt |
|
import datetime |
|
|
|
from collections import defaultdict |
|
import operator |
|
|
|
def saveFigures(figure, filename): |
|
figure.savefig(filename + '.png', bbox_inches='tight') |
|
figure.savefig(filename + '.pdf', bbox_inches='tight') |
|
figure.savefig(filename + '.svg', bbox_inches='tight') |
|
|
|
def parseDate(datestring): |
|
return datetime.datetime.strptime(datestring, "%Y-%m-%d %H:%M:%S") |
|
|
|
with open('data-2014.json', 'r') as f: |
|
data = json.load(f) |
|
|
|
|
|
filenames = [f for f in data] |
|
times = [datetime.datetime.strptime(data[f][0], "%Y-%m-%d %H:%M:%S") for f in data] |
|
|
|
creators = [] |
|
for f in data: |
|
for entry in data[f][1]: |
|
if 'von' in str(entry): |
|
creators.append(str(entry)) |
|
|
|
######################### |
|
# Number Pictures per Day |
|
######################### |
|
fig = plt.figure(figsize=(14, 8)) |
|
ax = fig.add_subplot(111) |
|
|
|
ppl.hist(ax, np.asarray([date.day for date in times]), bins=17, color=ppl.colors.set2[0]) |
|
ax.set_xticks(np.arange(1, 18)) |
|
ax.set_xticklabels(["Tag " + str(i) for i in range(0, 17)]) |
|
ax.set_ylabel("Anzahl Fotos pro Tag") |
|
ax.set_xlabel("Tag des Sommerlagers") |
|
ax.set_xlim(1, 17) |
|
saveFigures(fig, '2014-anzahl_fotos_pro_tag') |
|
|
|
|
|
######################### |
|
# Number Pictures per Day per Photographer |
|
######################### |
|
date_andreas, date_tobias, date_susanne, date_peter, date_matthias, = [], [], [], [], [] |
|
for f in data: |
|
for rawentry in data[f][1]: |
|
entry = str(rawentry) |
|
currentDatetime = parseDate(data[f][0]) |
|
if 'von Andreas' in entry: |
|
date_andreas.append(currentDatetime) |
|
elif 'von Tobias' in entry: |
|
date_tobias.append(currentDatetime) |
|
elif 'von Susanne' in entry: |
|
date_susanne.append(currentDatetime) |
|
elif 'von Peter' in entry: |
|
date_peter.append(currentDatetime) |
|
elif 'von Matthias' in entry: |
|
date_matthias.append(currentDatetime) |
|
|
|
def extractDays(a, b, c, d, e): |
|
newa = [date.day for date in a] |
|
newb = [date.day for date in b] |
|
newc = [date.day for date in c] |
|
newd = [date.day for date in d] |
|
newe = [date.day for date in e] |
|
return [np.asarray(newa), np.asarray(newb), np.asarray(newc), np.asarray(newd), np.asarray(newe)] |
|
|
|
convertedDays = np.asarray(extractDays(date_andreas, date_tobias, date_susanne, date_peter, date_matthias)) |
|
|
|
fig2 = plt.figure(figsize=(14, 8)) |
|
ax2 = fig2.add_subplot(111) |
|
ppl.hist(ax2, [convertedDays[0], convertedDays[1], convertedDays[2], convertedDays[3], convertedDays[4]], bins=17, stacked=True, label=['von Andreas', 'von Tobias', 'von Susanne', 'von Peter', 'von Matthias'], color=ppl.colors.set2[0:5]) |
|
legend = ax2.legend(loc='upper right') |
|
ax2.set_xticks(np.arange(1, 18)) |
|
ax2.set_xticklabels(["Tag " + str(i) for i in range(0, 17)]) |
|
ax2.set_ylabel("Anzahl Fotos pro Tag") |
|
ax2.set_xlabel("Tag des Sommerlagers") |
|
ax2.set_xlim(1, 17) |
|
saveFigures(fig2, '2014-anzahl_fotos_pro_tag_pro_fotograf') |
|
|
|
|
|
######################### |
|
# Number Pictures per Hour of Day |
|
######################### |
|
def toSeconds(d): |
|
return 60 * 60 * d.hour + 60 * d.minute + d.second |
|
|
|
timesInSeconds = np.asarray([toSeconds(day) for day in times]) |
|
|
|
fig3 = plt.figure(figsize=(14, 8)) |
|
ax3 = fig3.add_subplot(111) |
|
ppl.hist(ax3, timesInSeconds, bins=23, range=[0, 23 * 60 * 60], color=ppl.colors.set2[0]) |
|
ax3.set_xticks(np.arange(0, 24 * 60 * 60, 60 * 60)) |
|
ax3.set_xticklabels([str(i) + " Uhr" for i in range(0,24)]) |
|
ax3.set_ylabel("Anzahl Fotos pro Uhrzeit") |
|
ax3.set_xlabel("Uhrzeit") |
|
ax3.set_xlim(0, 24 * 60 * 60) |
|
fig3.autofmt_xdate() |
|
saveFigures(fig3, '2014-anzahl_fotos_pro_uhrzeit') |
|
# plt.show() |
|
|
|
|
|
######################### |
|
# Number Pictures per Hour of Day per Photographer |
|
######################### |
|
def extractSeconds(a, b, c, d, e): |
|
newa = [toSeconds(date) for date in a] |
|
newb = [toSeconds(date) for date in b] |
|
newc = [toSeconds(date) for date in c] |
|
newd = [toSeconds(date) for date in d] |
|
newe = [toSeconds(date) for date in e] |
|
return [np.asarray(newa), np.asarray(newb), np.asarray(newc), np.asarray(newd), np.asarray(newe)] |
|
|
|
convertedSeconds = np.asarray(extractSeconds(date_andreas, date_tobias, date_susanne, date_peter, date_matthias)) |
|
|
|
fig4 = plt.figure(figsize=(14, 8)) |
|
ax4 = fig4.add_subplot(111) |
|
ppl.hist(ax4, [convertedSeconds[0], convertedSeconds[1], convertedSeconds[2], convertedSeconds[3], convertedSeconds[4]], bins=23, range=[0, 23 * 60 * 60], stacked=True, label=['von Andreas', 'von Tobias', 'von Susanne', 'von Peter', 'von Matthias'], color=ppl.colors.set2[0:5]) |
|
legend = ax4.legend(loc='upper right') |
|
ax4.set_xticks(np.arange(0, 24 * 60 * 60, 60 * 60)) |
|
ax4.set_xticklabels([str(i) + " Uhr" for i in range(0,24)]) |
|
ax4.set_ylabel("Anzahl Fotos pro Uhrzeit") |
|
ax4.set_xlabel("Uhrzeit") |
|
ax4.set_xlim(0, 24 * 60 * 60) |
|
fig4.autofmt_xdate() |
|
saveFigures(fig4, '2014-anzahl_fotos_pro_uhrzeit_pro_fotograf') |
|
|
|
|
|
######################### |
|
# Number of Face being Found |
|
######################### |
|
allNames = defaultdict(list) |
|
namesAndPhotographers = defaultdict(list) |
|
for entry in data: |
|
nameTags = data[entry][2] |
|
if nameTags is not None: |
|
for name in nameTags if not isinstance(nameTags, basestring) else [nameTags]: |
|
# print name, entry, parseDate(data[entry][0]) |
|
allNames[name].append(parseDate(data[entry][0])) |
|
photographer = None |
|
for rawentry in data[entry][1]: |
|
# print rawentry |
|
if 'von' in str(rawentry): |
|
photographer = str(rawentry) |
|
namesAndPhotographers[name].append(photographer) |
|
heights = dict() |
|
for key in allNames.keys(): |
|
heights[key] = len(allNames[key]) |
|
sortedHeights = sorted(heights.iteritems(), key=operator.itemgetter(1), reverse=True) |
|
numberOfBars = len(sortedHeights) |
|
|
|
fig5 = plt.figure(figsize=(14, 8)) |
|
# fig5.subplots_adjust(bottom=0.28) |
|
ax5 = fig5.add_subplot(111) |
|
# fig5.tight_layout() |
|
ppl.bar(ax5, np.arange(numberOfBars), [nameanzahl[1] for nameanzahl in sortedHeights], color=ppl.colors.set2[0]) |
|
ax5.set_xticks(np.arange(0.2, numberOfBars + 0.2)) |
|
ax5.set_xticklabels([nameanzahl[0].split()[0] for nameanzahl in sortedHeights], rotation=90) |
|
ax5.set_xlim(0,numberOfBars) |
|
ax5.set_ylabel("Anzahl der automatisch gefundenen Gesichter") |
|
ax5.set_xlabel("Personennamen") |
|
saveFigures(fig5, '2014-anzahl_personen_gefunden') |
|
# plt.autoscale() |
|
# plt.show() |
|
|
|
|
|
######################### |
|
# Number of Face being Found per Photographer, Top 7 |
|
######################### |
|
def extractSecondsForPersons(a, b, c, d, e, f, g): |
|
newa = [toSeconds(date) for date in a] |
|
newb = [toSeconds(date) for date in b] |
|
newc = [toSeconds(date) for date in c] |
|
newd = [toSeconds(date) for date in d] |
|
newe = [toSeconds(date) for date in e] |
|
newf = [toSeconds(date) for date in f] |
|
newg = [toSeconds(date) for date in g] |
|
return [np.asarray(newa), np.asarray(newb), np.asarray(newc), np.asarray(newd), np.asarray(newe), np.asarray(newf), np.asarray(newg)] |
|
|
|
shownPersons = ['Peter Dick', 'Mark Hermann', 'Jonas Kox', 'Benedikt Dassen', 'Daniel Samer', 'Bastian Soiron', 'Luise Kessler'] |
|
|
|
convertedSecondsForPersons = np.asarray(extractSecondsForPersons(allNames[shownPersons[0]], allNames[shownPersons[1]], allNames[shownPersons[2]], allNames[shownPersons[3]], allNames[shownPersons[4]], allNames[shownPersons[5]], allNames[shownPersons[6]])) |
|
|
|
fig6 = plt.figure(figsize=(14, 8)) |
|
ax6 = fig6.add_subplot(111) |
|
ppl.hist(ax6, [convertedSecondsForPersons[0], convertedSecondsForPersons[1], convertedSecondsForPersons[2], convertedSecondsForPersons[3], convertedSecondsForPersons[4], convertedSecondsForPersons[5], convertedSecondsForPersons[6]], bins=23, range=[0, 23 * 60 * 60], stacked=True, label=[entry.split()[0] for entry in shownPersons], color=ppl.colors.set2[0:7]) |
|
legend = ax6.legend(loc='upper left') |
|
ax6.set_xticks(np.arange(0, 24 * 60 * 60, 60 * 60)) |
|
ax6.set_xticklabels([str(i) + " Uhr" for i in range(0,24)]) |
|
ax6.set_ylabel("Anzahl der automatisch gefundenen Gesichter pro Uhrzeit") |
|
ax6.set_xlabel("Uhrzeit") |
|
ax6.set_xlim(0, 24 * 60 * 60) |
|
fig6.autofmt_xdate() |
|
saveFigures(fig6, '2014-anzahl_personen_gefunden_top7_pro_uhrzeit') |
|
plt.show() |