Open melinath opened 5 years ago
# published events run by orgs that have previous events
# published events run by orgs that don't have previous events
from django.db.models import Count
from django.db import connection
truncate_date = connection.ops.date_trunc_sql('month', 'start_date')
from collections import OrderedDict
from brambling.models import Event
events = Event.objects.annotate(txn_count=Count('transaction')).filter(is_published=True, txn_count__gt=0, api_type='live').extra({'month': truncate_date}).order_by('month')
data = OrderedDict()
seen_orgs = set()
import datetime
for year in range(2015, 2020):
for month in range(1, 13):
first_day = datetime.date(year, month, 1)
data[first_day.strftime('%Y-%m-%d')] = {
'repeat': 0,
'new': 0,
}
for event in events:
month_data = data[event.month.strftime('%Y-%m-%d')]
if event.organization_id in seen_orgs:
month_data['repeat'] += 1
else:
month_data['new'] += 1
seen_orgs.add(event.organization_id)
import csv
from io import BytesIO
out = BytesIO()
writer = csv.writer(out)
writer.writerow(['Month', 'New events', 'Repeat events'])
for month, month_data in data.items():
_ = writer.writerow([month, month_data['new'], month_data['repeat']])
out.seek(0)
print out.read()
from django.db.models import Sum, Count
from django.db import connection
from brambling.models import Transaction
truncate_date = connection.ops.date_trunc_sql('month', 'timestamp')
txns = Transaction.objects.extra({'month': truncate_date})
x = txns.values_list('month').annotate(Sum('amount'), Sum('application_fee'), Sum('processing_fee'), Count('id')).order_by('month')
import csv
from io import BytesIO
out = BytesIO()
writer = csv.writer(out)
writer.writerow(['Month', 'Amount', 'Application fee', 'Processing fee', 'Count'])
for txn in x:
_ = writer.writerow([txn[0].strftime('%Y-%m-%d'), txn[1], txn[2], txn[3], txn[4]])
out.seek(0)
print out.read()
It's useful to have data on how Dancerfly is doing. We should have a standard way to generate these kinds of reports. For now I'll keep scripts here for generating reports.