Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

manual stats via admin #5270

Merged
merged 3 commits into from
Oct 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/marketing/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@

from .models import (
AccountDeletionRequest, Alumni, EmailEvent, EmailSubscriber, EmailSupressionList, GithubEvent,
GithubOrgToTwitterHandleMapping, Keyword, LeaderboardRank, MarketingCallback, Match, SlackPresence, SlackUser, Stat,
GithubOrgToTwitterHandleMapping, Keyword, LeaderboardRank, ManualStat, MarketingCallback, Match, SlackPresence,
SlackUser, Stat,
)


Expand Down Expand Up @@ -120,6 +121,7 @@ def membership_length_in_days(self, instance):
admin.site.register(Alumni, AlumniAdmin)
admin.site.register(GithubEvent, GithubEventAdmin)
admin.site.register(Match, MatchAdmin)
admin.site.register(ManualStat, GeneralAdmin)
admin.site.register(Stat, GeneralAdmin)
admin.site.register(Keyword, GeneralAdmin)
admin.site.register(EmailEvent, EmailEventAdmin)
Expand Down
28 changes: 28 additions & 0 deletions app/marketing/migrations/0006_manualstat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 2.2.3 on 2019-09-26 17:34

from django.db import migrations, models
import economy.models


class Migration(migrations.Migration):

dependencies = [
('marketing', '0005_marketingcallback'),
]

operations = [
migrations.CreateModel(
name='ManualStat',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_on', models.DateTimeField(db_index=True, default=economy.models.get_time)),
('modified_on', models.DateTimeField(default=economy.models.get_time)),
('key', models.CharField(db_index=True, max_length=50)),
('date', models.DateTimeField(db_index=True)),
('val', models.FloatField()),
],
options={
'abstract': False,
},
),
]
11 changes: 11 additions & 0 deletions app/marketing/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,17 @@ def psave_es(sender, instance, **kwargs):
instance.build_email_preferences()


class ManualStat(SuperModel):
"""Define the manual stat model; which records stats that are not available on the platform
"""

key = models.CharField(max_length=50, db_index=True)
date = models.DateTimeField(db_index=True)
val = models.FloatField()

def __str__(self):
return f"{self.key}: {self.date}: {self.val}"

class Stat(SuperModel):

key = models.CharField(max_length=50, db_index=True)
Expand Down
3 changes: 2 additions & 1 deletion app/retail/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def get_ecosystem_history_at_date(date, keyword):


def get_codefund_history_at_date(date, keyword):
from marketing.models import ManualStat
date = date.replace(tzinfo=None)
amount = 0
# July => Feb 2019
Expand Down Expand Up @@ -179,7 +180,7 @@ def get_codefund_history_at_date(date, keyword):
if date > timezone.datetime(2019, 9, 9):
amount += 52000
if date > timezone.datetime(2019, 10, 9):
amount += 0 # october month to date
amount += sum(ManualStat.objects.filter(key='codefund_gmv', date__gt=date).values_list('val', flat=True))
return amount


Expand Down