Add script to import old card scan counts
This commit is contained in:
parent
ea3f1fc6e4
commit
bdbf21f75a
1
apiserver/.gitignore
vendored
1
apiserver/.gitignore
vendored
|
@ -114,3 +114,4 @@ missing_paypal/
|
||||||
backups/
|
backups/
|
||||||
secrets.py
|
secrets.py
|
||||||
old_counts.csv
|
old_counts.csv
|
||||||
|
scans.csv
|
||||||
|
|
|
@ -141,6 +141,10 @@ class StatsSignupCount(models.Model):
|
||||||
retain_count = models.IntegerField(default=0)
|
retain_count = models.IntegerField(default=0)
|
||||||
vetted_count = models.IntegerField(default=0)
|
vetted_count = models.IntegerField(default=0)
|
||||||
|
|
||||||
|
class StatsSpaceActivity(models.Model):
|
||||||
|
date = models.DateField(default=today_alberta_tz)
|
||||||
|
card_scans = models.IntegerField()
|
||||||
|
|
||||||
class HistoryIndex(models.Model):
|
class HistoryIndex(models.Model):
|
||||||
content_type = models.ForeignKey(ContentType, null=True, on_delete=models.SET_NULL)
|
content_type = models.ForeignKey(ContentType, null=True, on_delete=models.SET_NULL)
|
||||||
object_id = models.PositiveIntegerField()
|
object_id = models.PositiveIntegerField()
|
||||||
|
|
43
apiserver/import_card_scans.py
Normal file
43
apiserver/import_card_scans.py
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
# Expects a scans.csv of the historical scans in format:
|
||||||
|
# date,card_number
|
||||||
|
|
||||||
|
import django, sys, os
|
||||||
|
os.environ['DJANGO_SETTINGS_MODULE'] = 'apiserver.settings'
|
||||||
|
django.setup()
|
||||||
|
|
||||||
|
import csv
|
||||||
|
from datetime import datetime
|
||||||
|
from apiserver.api import models
|
||||||
|
from django.utils.timezone import now, pytz
|
||||||
|
|
||||||
|
days = {}
|
||||||
|
|
||||||
|
with open('scans.csv', newline='') as csvfile:
|
||||||
|
reader = csv.DictReader(csvfile)
|
||||||
|
for row in reader:
|
||||||
|
datetime_obj = datetime.strptime(row['date'], "%Y-%m-%d %H:%M:%S")
|
||||||
|
datetime_obj_utc = datetime_obj.replace(tzinfo=pytz.timezone('UTC'))
|
||||||
|
date = datetime_obj_utc.astimezone(pytz.timezone('America/Edmonton'))
|
||||||
|
|
||||||
|
card = row['card_number']
|
||||||
|
|
||||||
|
print('Processing', date, card)
|
||||||
|
day = str(date.date())
|
||||||
|
|
||||||
|
if day not in days:
|
||||||
|
days[day] = set()
|
||||||
|
|
||||||
|
days[day].add(card)
|
||||||
|
|
||||||
|
print(days)
|
||||||
|
|
||||||
|
for day, cards in days.items():
|
||||||
|
print(day, len(cards))
|
||||||
|
|
||||||
|
models.StatsSpaceActivity.objects.update_or_create(
|
||||||
|
date=day,
|
||||||
|
defaults=dict(card_scans=len(cards)),
|
||||||
|
)
|
||||||
|
|
||||||
|
print('Done.')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user