-
-
Notifications
You must be signed in to change notification settings - Fork 775
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding table for storing relation between profile and his grant and r…
…ound_num contributors + command to compute that table (#10759) * Adding table for string relation between profile and his grant and round_num contributors + command to compute that table * fixing linter complaints
- Loading branch information
Showing
5 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
app/grants/management/commands/compute_grant_contribution_index.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import datetime as dt | ||
from datetime import timezone | ||
from time import sleep | ||
|
||
from django.core.management.base import BaseCommand | ||
|
||
import requests | ||
from grants.models import Contribution, GrantContributionIndex | ||
|
||
|
||
class Command(BaseCommand): | ||
|
||
help = "rebuilds the table GrantContributionIndex" | ||
|
||
def handle(self, *args, **kwargs): | ||
contributions = ( | ||
Contribution.objects.filter( | ||
success=True, | ||
subscription__network="mainnet", | ||
subscription__grant__clr_calculations__latest=True, | ||
) | ||
.order_by( | ||
"subscription__contributor_profile__id", | ||
"subscription__grant__clr_calculations__grantclr__round_num", | ||
"subscription__grant__id", | ||
) | ||
.distinct( | ||
"subscription__contributor_profile__id", | ||
"subscription__grant__clr_calculations__grantclr__round_num", | ||
"subscription__grant__id", | ||
) | ||
.values_list( | ||
"subscription__contributor_profile__id", | ||
"subscription__grant__clr_calculations__grantclr__round_num", | ||
"subscription__grant__id", | ||
) | ||
) | ||
|
||
contribIndexList = [ | ||
GrantContributionIndex( | ||
profile_id=contribInfo[0], | ||
grant_id=contribInfo[1], | ||
round_num=contribInfo[2], | ||
) | ||
for contribInfo in contributions | ||
] | ||
|
||
GrantContributionIndex.objects.bulk_create(contribIndexList, batch_size=100) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Generated by Django 2.2.24 on 2022-08-16 12:10 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import economy.models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('dashboard', '0210_auto_20220718_1306'), | ||
('grants', '0146_auto_20220809_1134'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='GrantContributionIndex', | ||
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)), | ||
('round_num', models.IntegerField(help_text='The round number a user contributed to')), | ||
('grant', models.ForeignKey(help_text='The grant a user contributed to', on_delete=django.db.models.deletion.CASCADE, to='grants.Grant')), | ||
('profile', models.ForeignKey(help_text='Contributor', on_delete=django.db.models.deletion.CASCADE, to='dashboard.Profile')), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from django.db import models | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from economy.models import SuperModel | ||
|
||
|
||
class GrantContributionIndex(SuperModel): | ||
"""Stores the grants and round number to shich a user contributed to. | ||
The purpose of this table is to allow a a fast query. This will be used from | ||
the `contributor_statistics`API """ | ||
|
||
profile = models.ForeignKey('dashboard.Profile', help_text=_('Contributor'), on_delete=models.CASCADE, db_index=True) | ||
grant = models.ForeignKey('Grant', help_text=_('The grant a user contributed to'), on_delete=models.CASCADE) | ||
round_num = models.IntegerField(help_text=_('The round number a user contributed to')) |