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

clr: update estimate_clr command to query by grant type #5639

Merged
merged 2 commits into from
Dec 16, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this line some kind of fallback? It seems the following if else block would assign grants to something without needing this line

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah ! Just kept it as fallback -> Ideally we would never need this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thelostone-mc I think from a programming logic standpoint there is no case where this would be undefined after the if else block, so I think it should be removed

Copy link
Member Author

@thelostone-mc thelostone-mc Dec 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make's sense. removed ^_^


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