-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(api): add address field to contribution index * refactor(api): update cgrants api to return contributions from protocol and cgrants * feat(api): update rescoring command to propogate new weights * fix(api): adjust tests to match settings update and query bug
- Loading branch information
1 parent
fd99efb
commit 610345a
Showing
13 changed files
with
889 additions
and
800 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ gql = "*" | |
requests-toolbelt = "*" | ||
pyarrow = "*" | ||
pynacl = "*" | ||
faker = "*" | ||
|
||
[dev-packages] | ||
black = "*" | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
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
53 changes: 53 additions & 0 deletions
53
api/cgrants/management/commands/add_address_to_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,53 @@ | ||
from cgrants.models import Contribution, GrantContributionIndex, Profile | ||
from django.core.management.base import BaseCommand | ||
from tqdm import tqdm | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "This command will update the contributor_address field in GrantContributionIndex" | ||
|
||
batch_size = 1000 | ||
|
||
def handle(self, *args, **options): | ||
self.stdout.write("Adding contributor_address to GrantContributionIndex") | ||
last_id = None | ||
while True: | ||
contributions = self.get_data(last_id) | ||
|
||
with tqdm( | ||
unit="records", | ||
unit_scale=True, | ||
desc=f"Aggregating cGrants contributions by address", | ||
) as progress_bar: | ||
if contributions: | ||
progress_bar.update(len(contributions)) | ||
for contribution_index in contributions: | ||
last_id = contribution_index.pk | ||
try: | ||
address = contribution_index.contribution.data["fields"][ | ||
"originated_address" | ||
] | ||
except: | ||
self.stdout.write(f"Error parsing address: {last_id}") | ||
address = None | ||
contribution_index.contributor_address = address | ||
|
||
GrantContributionIndex.objects.bulk_update( | ||
contributions, ["contributor_address"] | ||
) | ||
else: | ||
break # No more data to process | ||
|
||
def get_data(self, last_id): | ||
q = ( | ||
GrantContributionIndex.objects.select_related("contribution") | ||
.all() | ||
.order_by("id") | ||
) | ||
|
||
if last_id: | ||
q = q.filter(id__gt=last_id) | ||
|
||
data = q[: self.batch_size] | ||
|
||
return data |
18 changes: 18 additions & 0 deletions
18
api/cgrants/migrations/0007_grantcontributionindex_contributor_address.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,18 @@ | ||
# Generated by Django 4.2.6 on 2023-10-26 16:23 | ||
|
||
import account.models | ||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("cgrants", "0006_profile_github_id_profile_notes_alter_profile_handle"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="grantcontributionindex", | ||
name="contributor_address", | ||
field=account.models.EthAddressField(blank=True, max_length=100, null=True), | ||
), | ||
] |
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
Oops, something went wrong.