Skip to content
Snippets Groups Projects
Verified Commit 91f324d9 authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Add first time-based stats.

parent 045b04ea
No related branches found
No related tags found
No related merge requests found
...@@ -47,6 +47,7 @@ class Log(Base): ...@@ -47,6 +47,7 @@ class Log(Base):
geocacher_account_id = Column(Integer, ForeignKey('geocacher_accounts.id')) geocacher_account_id = Column(Integer, ForeignKey('geocacher_accounts.id'))
geocacher_account = relationship('GeocacherAccount', back_populates='logs') geocacher_account = relationship('GeocacherAccount', back_populates='logs')
geocacher = association_proxy('geocacher_account', 'geocacher')
platform_prefix = association_proxy('listing', 'platform_prefix') platform_prefix = association_proxy('listing', 'platform_prefix')
......
...@@ -15,3 +15,4 @@ def all_stats(db, geocacher_name): ...@@ -15,3 +15,4 @@ def all_stats(db, geocacher_name):
return res return res
from .basic import * from .basic import *
from .time import *
from . import stats_plugin
from ..model import Log
def _finds_by_date(db, geocacher):
session = db.Session()
logs = session.query(Log).filter_by(geocacher=geocacher, type='Found it').all()
res = {}
for log in logs:
date = log.date.date()
if not date in res:
res[date] = 0
res[date] += 1
return res
@stats_plugin
def finds_by_day(db, geocacher):
data = _finds_by_date(db, geocacher)
res = {}
for date, count in data.items():
res[date.strftime('%Y-%m-%d')] = count
return res
@stats_plugin
def finds_by_month(db, geocacher):
data = _finds_by_date(db, geocacher)
res = {}
for date, count in data.items():
if not date.strftime('%Y-%m') in res:
res[date.strftime('%Y-%m')] = 0
res[date.strftime('%Y-%m')] += count
return res
@stats_plugin
def finds_by_year(db, geocacher):
data = _finds_by_date(db, geocacher)
res = {}
for date, count in data.items():
if not date.strftime('%Y') in res:
res[date.strftime('%Y')] = 0
res[date.strftime('%Y')] += count
return res
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment