Skip to content

Commit

Permalink
match estimate in grant checkout emails (#9841)
Browse files Browse the repository at this point in the history
* match estimate in grant checkout emails

* fix

* dpkg

* feat: adds lerp to find the match_amount for the contribution/subscription

* fix: use match_amount at time of contribution

Co-authored-by: Kevin Owocki <[email protected]>
Co-authored-by: Graham Dixon <[email protected]>
  • Loading branch information
3 people authored Dec 8, 2021
1 parent cc709fa commit b206269
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/grants/models/contribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ def presave_contrib(sender, instance, **kwargs):
'title': grant.title,
'amount_per_period_minus_gas_price': float(instance.subscription.amount_per_period_minus_gas_price),
'amount_per_period_to_gitcoin': float(instance.subscription.amount_per_period_to_gitcoin),
'match_amount_when_contributed': sub.match_amount,
'created_on': ele.created_on.strftime('%Y-%m-%d'),
'frequency': int(sub.frequency),
'frequency_unit': sub.frequency_unit,
Expand Down
59 changes: 59 additions & 0 deletions app/grants/models/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,65 @@ class Subscription(SuperModel):
def negative(self):
return self.is_postive_vote == False

@property
def match_amount(self):
# discover the match_amount based on amount_per_period_usdt
amount = self.amount_per_period_usdt

clr_prediction_curve_2d = self.grant.clr_prediction_curve
clr_prediction_curve = [clr[2] for clr in clr_prediction_curve_2d]

if (amount > 10000):
amount = 10000

contributions_axis = [ 0, 1, 10, 100, 1000, 10000 ]
predicted_clr = 0
index = 0

if amount == 0:
predicted_clr = clr_prediction_curve[index]
elif amount in contributions_axis:
index = contributions_axis.index(amount)
predicted_clr = clr_prediction_curve[index]
else:
x_lower = 0
x_upper = 0
y_lower = 0
y_upper = 0

if 0 < amount and amount < 1:
x_lower = 0
x_upper = 1
y_lower = clr_prediction_curve[0]
y_upper = clr_prediction_curve[1]
elif 1 < amount and amount < 10:
x_lower = 1
x_upper = 10
y_lower = clr_prediction_curve[1]
y_upper = clr_prediction_curve[2]
elif 10 < amount and amount < 100:
x_lower = 10
x_upper = 100
y_lower = clr_prediction_curve[2]
y_upper = clr_prediction_curve[3]
elif 100 < amount and amount < 1000:
x_lower = 100
x_upper = 1000
y_lower = clr_prediction_curve[3]
y_upper = clr_prediction_curve[4]
else:
x_lower = 1000
x_upper = 10000
y_lower = clr_prediction_curve[4]
y_upper = clr_prediction_curve[5]

# use lerp to discover the predicted match_amount
return y_lower + (((y_upper - y_lower) * (float(amount) - x_lower)) / (x_upper - x_lower))

@property
def match_amount_token(self):
return 'DAI'

@property
def status(self):
"""Return grants status, current or past due."""
Expand Down
7 changes: 7 additions & 0 deletions app/retail/emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,23 @@ def render_new_contributions_email(grant):

def render_thank_you_for_supporting_email(grants_with_subscription):
totals = {}
total_match_amount = 0
match_token = 'DAI'
for gws in grants_with_subscription:
key = gws['subscription'].token_symbol
val = float(gws['subscription'].amount_per_period)
if key not in totals.keys():
totals[key] = 0
totals[key] += float(val)
match_amount = float(gws.normalized_data['match_amount_when_contributed'])
total_match_amount += match_amount if match_amount else float(gws['subscription'].match_amount)
match_token = gws['subscription'].match_amount_token

params = {
'grants_with_subscription': grants_with_subscription,
"totals": totals,
'total_match_amount': total_match_amount,
'match_token': match_token,
'utm_tracking': build_utm_tracking('thank_you_for_supporting_email'),
}
response_html = premailer_transform(render_to_string("emails/grants/thank_you_for_supporting.html", params))
Expand Down
14 changes: 14 additions & 0 deletions app/retail/templates/emails/grants/thank_you_for_supporting.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
padding: 5px;
border-top: 1px solid black;
}
.green{
color: green;
}
</style>
<div id="content-body">
<img class="center-img bounties-img" src="{% static 'v2/images/emails/grants.png' %}">
Expand All @@ -87,6 +90,9 @@ <h1 style="text-align:center; margin-top: 10px;">🤖❤️{% trans "Thank you f
<td>
Amount
</td>
<td>
Match
</td>
<td>
Transaction
</td>
Expand All @@ -102,6 +108,9 @@ <h1 style="text-align:center; margin-top: 10px;">🤖❤️{% trans "Thank you f
<td>
{{ subscription.amount_per_period|floatformat:4|intcomma }} {{ subscription.token_symbol }}
</td>
<td class=green>
+ {{ subscription.match_amount|floatformat:4|intcomma }} {{ subscription.match_amount_token }}
</td>
<td>
<a href="{{subscription.subscription_contribution.first.blockexplorer_url_split_txid}}">view &gt;&gt;</a>
</td>
Expand All @@ -118,6 +127,11 @@ <h1 style="text-align:center; margin-top: 10px;">🤖❤️{% trans "Thank you f
{%for key, val in totals.items%}
{{val|floatformat:4}} {{key}}
{%endfor%}
</td>
<td class=green>
+ {{total_match_amount|floatformat:4}}
{{match_token}}

</td>
<td>
</td>
Expand Down

0 comments on commit b206269

Please sign in to comment.