From cd0ebbaa4105d62ce226189c90748208a5fdfedd Mon Sep 17 00:00:00 2001 From: Aditya Anand M C Date: Mon, 27 Jul 2020 15:50:51 +0530 Subject: [PATCH] restore var needed for mgmt command --- .../commands/grant_vitalik_shuffle.py | 8 ++-- .../management/commands/payout_round.py | 4 +- .../management/commands/sent_cart_reminder.py | 2 +- app/grants/management/commands/subminer.py | 9 ++-- app/grants/views.py | 4 +- .../management/commands/post_data.py | 42 +++++++++++++------ 6 files changed, 46 insertions(+), 23 deletions(-) diff --git a/app/grants/management/commands/grant_vitalik_shuffle.py b/app/grants/management/commands/grant_vitalik_shuffle.py index 19a210e861b..697c7ae4878 100644 --- a/app/grants/management/commands/grant_vitalik_shuffle.py +++ b/app/grants/management/commands/grant_vitalik_shuffle.py @@ -22,8 +22,7 @@ from django.core.management.base import BaseCommand -from grants.models import Grant -from grants.views import clr_active +from grants.models import Grant, GrantCLR # VB 2019/09/27 # > To prevent a winner-takes-all effect from grants with already the most funding being shown at the top, how about a randomized sort, where your probability of being first is equal to (your expected CLR match) / (total expected CLR match) and then you just do that recursively to position everyone? @@ -56,9 +55,12 @@ class Command(BaseCommand): def handle(self, *args, **options): - if not clr_active: + active_clr_rounds = GrantCLR.objects.filter(is_active=True) + if active_clr_rounds.count() == 0: return + # TODO-SELF-SERVICE: Check if it's alright to shuffle all grants even if 1 CLR round is active + # set default, for when no CLR match enabled for grant in Grant.objects.all(): grant.weighted_shuffle = 99999 diff --git a/app/grants/management/commands/payout_round.py b/app/grants/management/commands/payout_round.py index b30122481f7..2d607c629eb 100644 --- a/app/grants/management/commands/payout_round.py +++ b/app/grants/management/commands/payout_round.py @@ -30,7 +30,7 @@ from dashboard.utils import get_tx_status, get_web3, has_tx_mined from gas.utils import recommend_min_gas_price_to_confirm_in_time from grants.models import CLRMatch, Contribution, Grant, Subscription -from grants.views import clr_active, clr_round, next_round_start, round_end +from grants.views import clr_round # TODO-SELF-SERVICE: REMOVE THIS from marketing.mails import ( grant_match_distribution_final_txn, grant_match_distribution_kyc, grant_match_distribution_test_txn, ) @@ -44,7 +44,7 @@ class Command(BaseCommand): help = 'finalizes + sends grants round payouts' def add_arguments(self, parser): - parser.add_argument('what', + parser.add_argument('what', default='finalize', type=str, help="what do we do? (finalize, payout_test, payout_dai, prepare_final_payout)" diff --git a/app/grants/management/commands/sent_cart_reminder.py b/app/grants/management/commands/sent_cart_reminder.py index 0cb97a31f69..9458cce9a00 100644 --- a/app/grants/management/commands/sent_cart_reminder.py +++ b/app/grants/management/commands/sent_cart_reminder.py @@ -27,7 +27,7 @@ from dashboard.utils import get_tx_status, has_tx_mined from grants.clr import predict_clr from grants.models import CartActivity, Contribution, Grant, Subscription -from grants.views import clr_active, next_round_start, round_end +from grants.views import next_round_start, round_end # TODO-SELF-SERVICE: REMOVE THIS from marketing.mails import remember_your_cart, warn_subscription_failed from townsquare.models import MatchRound diff --git a/app/grants/management/commands/subminer.py b/app/grants/management/commands/subminer.py index bdb4992aa97..e126474034c 100644 --- a/app/grants/management/commands/subminer.py +++ b/app/grants/management/commands/subminer.py @@ -26,8 +26,7 @@ from django.utils import timezone from dashboard.utils import get_tx_status, has_tx_mined -from grants.models import Grant -from grants.views import clr_active +from grants.models import Grant, GrantCLR from marketing.mails import warn_subscription_failed logging.getLogger("urllib3").setLevel(logging.WARNING) @@ -151,6 +150,8 @@ def handle(self, *args, **options): grants = Grant.objects.filter(network=network).active() logger.info("got %d grants", grants.count()) + active_clr_rounds = GrantCLR.objects.filter(is_active=True) + for grant in grants: subs = grant.subscriptions.filter( active=True, @@ -158,7 +159,9 @@ def handle(self, *args, **options): next_contribution_date__lt=timezone.now(), num_tx_processed__lt=F('num_tx_approved') ) - if not clr_active: + + is_clr_active = active_clr_rounds.filter(grant_type=grant.grant_type) + if not is_clr_active: subs = subs.exclude(frequency_unit='roundup') #dont process grant subscriptions until next round logger.info(" - %d has %d subs ready for execution", grant.pk, subs.count()) diff --git a/app/grants/views.py b/app/grants/views.py index ef9d7e5a327..bcfb518c9f7 100644 --- a/app/grants/views.py +++ b/app/grants/views.py @@ -76,13 +76,14 @@ logger = logging.getLogger(__name__) w3 = Web3(HTTPProvider(settings.WEB3_HTTP_PROVIDER)) -# clr_active = False # Round Schedule # from canonical source of truth https://gitcoin.co/blog/gitcoin-grants-round-4/ # Round 5 - March 23th — April 7th 2020 # Round 6 - June 15th — June 29th 2020 # Round 7 - September 14th — September 28th 2020 +# TODO-SELF-SERVICE: REMOVE BELOW VARIABLES NEEDED FOR MGMT +clr_round=6 last_round_start = timezone.datetime(2020, 3, 23, 12, 0) last_round_end = timezone.datetime(2020, 4, 7, 12, 0) # TODO, also update grants.clr:CLR_START_DATE, PREV_CLR_START_DATE, PREV_CLR_END_DATE @@ -90,6 +91,7 @@ after_that_next_round_begin = timezone.datetime(2020, 9, 14, 12, 0) round_end = timezone.datetime(2020, 7, 3, 16, 0) #tz=utc, not mst round_types = ['media', 'tech', 'change'] +# TODO-SELF-SERVICE: END kudos_reward_pks = [12580, 12584, 12572, 125868, 12552, 12556, 12557, 125677, 12550, 12392, 12307, 12343, 12156, 12164] diff --git a/app/marketing/management/commands/post_data.py b/app/marketing/management/commands/post_data.py index 74cb8b1674b..45d249ccc72 100644 --- a/app/marketing/management/commands/post_data.py +++ b/app/marketing/management/commands/post_data.py @@ -30,7 +30,7 @@ from economy.utils import convert_token_to_usdt from grants.models import * from grants.models import CartActivity, Contribution, PhantomFunding -from grants.views import clr_round, next_round_start, round_end +from grants.views import clr_round, next_round_start, round_end # TODO-SELF-SERVICE: REMOVE THIS from townsquare.models import Comment text = '' @@ -344,16 +344,32 @@ def grants(): pprint("=======================") pprint("") - active_rounds = ['tech', 'media', 'change'] - from grants.clr import TOTAL_POT_TECH, TOTAL_POT_MEDIA, TOTAL_POT_CHANGE - active_round_threshold = { - 'tech': TOTAL_POT_TECH, - 'media': TOTAL_POT_MEDIA, - 'change': TOTAL_POT_CHANGE, - } + # active_rounds = ['tech', 'media', 'change'] + # from grants.clr import TOTAL_POT_TECH, TOTAL_POT_MEDIA, TOTAL_POT_CHANGE + # active_round_threshold = { + # 'tech': TOTAL_POT_TECH, + # 'media': TOTAL_POT_MEDIA, + # 'change': TOTAL_POT_CHANGE, + # } + # active_round_threshold = { + # 'tech': 0, + # 'media': 0, + # 'change': 0, + # } + + active_rounds = [] + active_round_threshold = {} + active_clr_rounds = GrantCLR.objects.filter(is_active=True) + + for active_clr_round in active_clr_rounds: + grant_type_name = active_clr_round.grant_type.name + + active_round_threshold[grant_type_name] = active_clr_round.total_pot + active_rounds.append(grant_type_name) + active_rounds_allocation = {key: 0 for key in active_rounds} for ar in active_rounds: - grants = Grant.objects.filter(active=True, grant_type=ar, is_clr_eligible=True, hidden=False) + grants = Grant.objects.filter(active=True, grant_type__name=ar, is_clr_eligible=True, hidden=False) for grant in grants: try: active_rounds_allocation[ar] += grant.clr_prediction_curve[0][1] @@ -374,7 +390,7 @@ def grants(): ############################################################################3 - # new feature stats for round {clr_round} + # new feature stats for round {clr_round} ############################################################################3 subs_stats = False @@ -397,10 +413,10 @@ def grants(): contributions = Contribution.objects.filter(created_on__gt=start, created_on__lt=end, success=True, subscription__network='mainnet')[0:100] pprint("tx_id1, tx_id2, from address, amount, amount_minus_gitcoin, token_address") for contribution in contributions: - pprint(contribution.tx_id, + print(contribution.tx_id, contribution.split_tx_id, contribution.subscription.contributor_address, - contribution.subscription.amount_per_period, + contribution.subscription.amount_per_period, contribution.subscription.amount_per_period_minus_gas_price, contribution.subscription.token_address) @@ -418,7 +434,7 @@ class Command(BaseCommand): help = 'puts grants stats on town suqare' def add_arguments(self, parser): - parser.add_argument('what', + parser.add_argument('what', default='', type=str, help="what to post"