Skip to content

Commit

Permalink
clr: update estimate_clr command to query by grant type
Browse files Browse the repository at this point in the history
- estimate_clr.py -> new arguments clr_type, network
- clr logic updated to query grants by network + grant_type + not hidden
- grant str updated to also print grant_type
- crontab updated to run both clr for media and tech grants
  • Loading branch information
thelostone-mc committed Dec 15, 2019
1 parent e0d626b commit 4cdc30f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
12 changes: 10 additions & 2 deletions app/grants/clr.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,22 @@ def calculate_clr_for_donation(donation_grant, donation_amount, total_pot, base_
print('error: could not find grant in final grants_clr data')
return (None, None)

def predict_clr(random_data=False, save_to_db=False, from_date=None):
def predict_clr(random_data=False, save_to_db=False, from_date=None, clr_type=None, network='mainnet'):
# setup
clr_calc_start_time = timezone.now()

# get all the eligible contributions and calculate total
contributions = Contribution.objects.prefetch_related('subscription').filter(created_on__gte=CLR_START_DATE, created_on__lte=from_date)
debug_output = []
grants = Grant.objects.all()

grants = Grant.objects.none()

if clr_type == 'tech':
grants = Grant.objects.filter(network=network, hidden=False, grant_type='tech')
elif clr_type == 'media':
grants = Grant.objects.filter(network=network, hidden=False, grant_type='tech')
else:
grants = Grant.objects.filter(network=network, hidden=False)

# set up data to load contributions for each grant
if not random_data:
Expand Down
18 changes: 16 additions & 2 deletions app/grants/management/commands/estimate_clr.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,27 @@ class Command(BaseCommand):

help = 'calculate CLR estimates for all grants'

def add_arguments(self, parser):

parser.add_argument('clr_type', type=str, default='all', choices=['tech', 'media', 'all'])
parser.add_argument('network', type=str, default='mainnet', choices=['rinkeby', 'mainnet'])

def handle(self, *args, **options):
clr_prediction_curves = predict_clr(random_data=False, save_to_db=True, from_date=timezone.now())
clr_type = options['clr_type']
network = options['network']

clr_prediction_curves = predict_clr(
random_data=False,
save_to_db=True,
from_date=timezone.now(),
clr_type=clr_type,
network=network
)

# Uncomment these for debugging and sanity checking
# for grant in clr_prediction_curves:
#print("CLR predictions for grant {}".format(grant['grant']))
#print("All grants: {}".format(grant['grants_clr']))
#print("All grants: {}".clr_typeformat(grant['grants_clr']))
#print("prediction curve: {}\n\n".format(grant['clr_prediction_curve']))

# sanity check: sum all the estimated clr distributions - should be close to CLR_DISTRIBUTION_AMOUNT
Expand Down
2 changes: 1 addition & 1 deletion app/grants/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ class Meta:

def __str__(self):
"""Return the string representation of a Grant."""
return f"id: {self.pk}, active: {self.active}, title: {self.title}"
return f"id: {self.pk}, active: {self.active}, title: {self.title}, type: {self.grant_type}"


def percentage_done(self):
Expand Down
4 changes: 2 additions & 2 deletions scripts/crontab
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/us
1 1 1 * * cd gitcoin/coin; bash scripts/run_management_command.bash activity_report $(date --date='-1 month' +%Y/%m/%d) $(date +%Y/%m/%d) >> /var/log/gitcoin/activity_report.log 2>&1

## CLR
### NOT ACTIVE
#### 0 */4 * * * cd gitcoin/coin; bash scripts/run_management_command_if_not_already_running.bash estimate_clr >> /var/log/gitcoin/estimate_clr.log 2>&1
#### 0 */4 * * * cd gitcoin/coin; bash scripts/run_management_command_if_not_already_running.bash estimate_clr tech mainnet >> /var/log/gitcoin/estimate_clr_tech.log 2>&1
#### 0 */4 * * * cd gitcoin/coin; bash scripts/run_management_command_if_not_already_running.bash estimate_clr media mainnet >> /var/log/gitcoin/estimate_clr_media.log 2>&1

## GITCOIN MARKETING
30 */12 * * * cd gitcoin/coin; bash scripts/run_management_command_if_not_already_running.bash sync_mail >> /var/log/gitcoin/sync_mail.log 2>&1
Expand Down

0 comments on commit 4cdc30f

Please sign in to comment.