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

replace match_direction -> is_positive_vote #6272

Merged
merged 5 commits into from
Mar 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
25 changes: 2 additions & 23 deletions app/assets/v2/css/grants/fund.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
border-bottom: 1px solid #515151;
}
}

.est_direction{
font-weight: 900;
}

.admin_profile a,
#grant-link {
color: #0D0764;
Expand All @@ -15,17 +17,6 @@
width: 100%;
}

.banner-img {
max-height: 22rem;
overflow-y: hidden;
}

.banner-img img {
height: auto;
width: 100%;
object-fit: cover;
}

#grants_form .nav-link {
border-top-left-radius: 4px;
border-top-right-radius: 4px;
Expand Down Expand Up @@ -266,18 +257,6 @@
}
}

@media (max-width: 767.98px) {

.banner-img {
text-align: center;
}

.banner-img img {
width: auto;
max-width: 100%;
}
}

@media (max-width: 1199.98px) {
.clr_estimate {
display: none;
Expand Down
2 changes: 1 addition & 1 deletion app/assets/v2/js/grants/detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ $(document).ready(function() {

if (lgi) {
$('#backgrants').attr('href', lgi);
$('#backgrants').text('< Back to ' + lgt);
$('#backgrants').text('<i class="fas fa-chevron-left mr-2"></i> Back to ' + lgt);
}


Expand Down
25 changes: 11 additions & 14 deletions app/assets/v2/js/grants/fund.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ $(document).ready(function() {
gitcoinDonationAddress = $('#gitcoin_donation_address').val();
splitterAddress = $('#splitter_contract_address').val();

$('.select2-selection__rendered').hover(function() {
$(this).removeAttr('title');
});

updateSummary();

$('#grants_form .nav-item').click(function(e) {
Expand Down Expand Up @@ -127,22 +123,19 @@ $(document).ready(function() {
});

$('input[name=match_direction]').change(function(e) {
var direction = $(this).val();
let direction = $(this).val();

if (direction == '+') {
$('.est_direction').text('increase').css('background-color', 'yellow');
setTimeout(function() {
$('.est_direction').css('background-color', 'white');
}, 500);
// $('.comment_container').removeClass('hidden');
$('.hide_wallet_address_container').removeClass('hidden');
} else {
$('.est_direction').text('decrease').css('background-color', 'yellow');
setTimeout(function() {
$('.est_direction').css('background-color', 'white');
}, 500);
// $('.comment_container').addClass('hidden');
// $('.comment_container').val('');
$('.hide_wallet_address_container').addClass('hidden');
}
});
Expand Down Expand Up @@ -209,6 +202,8 @@ $(document).ready(function() {
localStorage.setItem('grantstoken_address', $('#js-token').val());
localStorage.setItem('grantsgitcoin-grant-input-amount', $('#gitcoin-grant-input-amount').val());

data.is_postive_vote = (data.match_direction == '-') ? 0 : 1;

if (data.frequency_unit) {

// translate timeAmount&timeType to requiredPeriodSeconds
Expand Down Expand Up @@ -253,11 +248,10 @@ $(document).ready(function() {
}

// eth payments
var is_eth = $('#js-token').val() == '0x0000000000000000000000000000000000000000';
const is_eth = $('#js-token').val() == '0x0000000000000000000000000000000000000000';

if (is_eth) {
const percent = $('#gitcoin-grant-input-amount').val();
const to_addr_amount = percent * 0.01 * data.amount_per_period * 10 ** 18;
const gitcoin_amount = (100 - percent) * 0.01 * data.amount_per_period * 10 ** 18;

web3.eth.getAccounts(function(err, accounts) {
Expand Down Expand Up @@ -440,6 +434,9 @@ $(document).ready(function() {
});
$('#js-token').select2();
$('.contribution_type select').trigger('change');
$('.select2-selection__rendered').hover(function() {
$(this).removeAttr('title');
});
updateSummary();
}); // waitforWeb3
}); // document ready
Expand All @@ -462,7 +459,6 @@ const subscribeToGrant = (transactionHash) => {
web3.eth.getAccounts(function(err, accounts) {
deployedToken.methods.decimals().call(function(err, decimals) {
const linkURL = get_etherscan_url(transactionHash);
let token_address = $('#js-token').length ? $('#js-token').val() : $('#sub_token_address').val();
let data = {
'contributor_address': $('#contributor_address').val(),
'amount_per_period': grant_amount,
Expand All @@ -479,11 +475,13 @@ const subscribeToGrant = (transactionHash) => {
'csrfmiddlewaretoken': $("#js-fundGrant input[name='csrfmiddlewaretoken']").val()
};

data.is_postive_vote = (data.match_direction == '-') ? 0 : 1;

$.ajax({
type: 'post',
url: '',
data: data,
success: json => {
success: () => {
console.log('successfully saved subscription');
},
error: () => {
Expand Down Expand Up @@ -831,5 +829,4 @@ const predictCLRLive = (amount) => {
console.error(`error: predictCLRLive - status ${response.status} - ${response.message}`);
}
});
};

};
19 changes: 11 additions & 8 deletions app/grants/clr.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ def calculate_new_clr(aggregated_contributions, pair_totals, threshold=0.0, tota
def calculate_new_clr_final(totals_pos, totals_neg, total_pot=0.0):
# calculate final totals

# print(f'+ve {len(totals_pos)} {totals_pos}')
# print(f'-ve {len(totals_neg)} {totals_neg}')

if len(totals_neg) == 0:
totals = totals_pos
elif len(totals_pos) == 0:
Expand Down Expand Up @@ -298,8 +301,8 @@ def populate_data_for_clr(clr_type=None, network='mainnet'):
grant_id = grant.defer_clr_to.pk if grant.defer_clr_to else grant.id

# Get the +ve and -ve contributions
positive_contributions = copy.deepcopy(contributions).filter(subscription__grant_id=grant.id, subscription__match_direction='+')
negative_contributions = copy.deepcopy(contributions).filter(subscription__grant_id=grant.id, subscription__match_direction='-')
positive_contributions = copy.deepcopy(contributions).filter(subscription__grant_id=grant.id, subscription__is_postive_vote=True)
negative_contributions = copy.deepcopy(contributions).filter(subscription__grant_id=grant.id, subscription__is_postive_vote=False)

# Generate list of profiles who've made +ve and -ve contributions to the grant
phantom_funding_profiles = PhantomFunding.objects.filter(grant_id=grant.id, created_on__gte=CLR_START_DATE, created_on__lte=from_date)
Expand Down Expand Up @@ -411,7 +414,7 @@ def predict_clr(save_to_db=False, from_date=None, clr_type=None, network='mainne
grant: <Grant> - grant to be funded
contributor: <Profile> - contributor making a contribution
amount: <float> - amount with which is grant is to be funded
match_direction: <char> + , -
is_postive_vote: <boolean>
positive_grant_contributions: [Object]
negative_grant_contributions: [Object]
total_pot: <float>
Expand All @@ -420,7 +423,7 @@ def predict_clr(save_to_db=False, from_date=None, clr_type=None, network='mainne
Returns:
clr_amount
'''
def calculate_clr_for_donation_live(grant, contributor, amount, match_direction, positive_grant_contributions, negative_grant_contributions, total_pot, threshold):
def calculate_clr_for_donation_live(grant, contributor, amount, is_postive_vote, positive_grant_contributions, negative_grant_contributions, total_pot, threshold):

if amount == 0:
return 0
Expand All @@ -430,7 +433,7 @@ def calculate_clr_for_donation_live(grant, contributor, amount, match_direction,

profile_id = str(contributor.pk)

if match_direction == '+':
if is_postive_vote:
for grant_contribution in _positive_grant_contributions:
if grant_contribution['id'] == grant.id:
grant_contribution['contributions'].append({
Expand Down Expand Up @@ -464,12 +467,12 @@ def calculate_clr_for_donation_live(grant, contributor, amount, match_direction,
grant: <Grant>
contributor: <Profile>
amount: <float>
match_direction: <char> + , -
is_postive_vote: <boolean>

Returns:
predicted_clr_match
'''
def predict_clr_live(grant, contributor, amount, match_direction='+'):
def predict_clr_live(grant, contributor, amount, is_postive_vote=True):

if not grant or not contributor:
print('error: predict_clr_live - missing parameters')
Expand All @@ -483,7 +486,7 @@ def predict_clr_live(grant, contributor, amount, match_direction='+'):
_, positive_contrib_data, negative_contrib_data , total_pot, threshold = populate_data_for_clr(clr_type, network)

predicted_clr_match = calculate_clr_for_donation_live(
grant, contributor, amount, match_direction, positive_contrib_data, negative_contrib_data, total_pot, threshold
grant, contributor, amount, is_postive_vote, positive_contrib_data, negative_contrib_data, total_pot, threshold
)

return predicted_clr_match
22 changes: 22 additions & 0 deletions app/grants/migrations/0046_auto_20200321_2043.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 2.2.4 on 2020-03-21 20:43

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('grants', '0045_flag'),
]

operations = [
migrations.RemoveField(
model_name='subscription',
name='match_direction',
),
migrations.AddField(
model_name='subscription',
name='is_postive_vote',
field=models.BooleanField(default=True, help_text='Whether this is positive or negative vote'),
),
]
15 changes: 5 additions & 10 deletions app/grants/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def org_name(self):
@property
def get_contribution_count(self):
num = 0
for sub in self.subscriptions.filter(match_direction='+'):
for sub in self.subscriptions.filter(is_postive_vote=True):
for contrib in sub.subscription_contribution.filter(success=True):
num += 1
for pf in self.phantom_funding.all():
Expand All @@ -329,7 +329,7 @@ def get_contribution_count(self):
@property
def contributors(self):
return_me = []
for sub in self.subscriptions.filter(match_direction='+'):
for sub in self.subscriptions.filter(is_postive_vote=True):
for contrib in sub.subscription_contribution.filter(success=True):
return_me.append(contrib.subscription.contributor_profile)
for pf in self.phantom_funding.all():
Expand All @@ -339,7 +339,7 @@ def contributors(self):
@property
def get_contributor_count(self):
contributors = []
for sub in self.subscriptions.filter(match_direction='+'):
for sub in self.subscriptions.filter(is_postive_vote=True):
for contrib in sub.subscription_contribution.filter(success=True):
contributors.append(contrib.subscription.contributor_profile.handle)
for pf in self.phantom_funding.all():
Expand Down Expand Up @@ -511,12 +511,7 @@ class Subscription(SuperModel):
help_text=_('The tx id of the split transfer'),
blank=True,
)
match_direction = models.CharField(
default='+',
max_length=255,
help_text=_('The direction of the match'),
blank=True,
)
is_postive_vote = models.BooleanField(default=True, help_text=_('Whether this is positive or negative vote'))
split_tx_confirmed = models.BooleanField(default=False, help_text=_('Whether or not the split tx succeeded.'))

subscription_hash = models.CharField(
Expand Down Expand Up @@ -638,7 +633,7 @@ class Subscription(SuperModel):

@property
def negative(self):
return self.match_direction == "-"
return self.is_postive_vote == False

@property
def status(self):
Expand Down
37 changes: 0 additions & 37 deletions app/grants/templates/grants/banner.html

This file was deleted.

4 changes: 1 addition & 3 deletions app/grants/templates/grants/cancel.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,9 @@
<div class="row" id="grants_form">

<div class="col-12 text-center mt-md-3">
<h2 class="font-title-lg my-5">{% trans "Cancel Contribution" %}</h2>
<h2 class="font-title-lg my-5">Cancel Contribution for {{ grant.title }}</h2>
</div>

{% include 'grants/banner.html' %}

<div class="col-12 offset-md-2 col-md-10 offset-lg-3 col-lg-5 mt-5 font-subheader mx-0 mx-md-auto row">

<div class="col-12 summary font-body my-4">
Expand Down
5 changes: 4 additions & 1 deletion app/grants/templates/grants/detail/info.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
{% endcomment %}
{% load static humanize i18n grants_extra %}
<div class="summary p-5 px-md-3 pt-1" style="padding-top: 0px !important;">
<a id=backgrants href="/grants">&lt; Back to Grants</a>
<a id="backgrants" class="font-caption" href="/grants">
<i class="fas fa-chevron-left mr-1"></i>
Back to Grants
</a>
<!-- GRANT LOGO -->
<div class="grant-logo pb-2" style="padding-top: 20px !important;">
{% if is_team_member %}
Expand Down
7 changes: 3 additions & 4 deletions app/grants/templates/grants/fund.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@
<h2 class="font-title-lg my-4">{% trans "Fund Grant" %}</h2>
</div>

{% include 'grants/banner.html' %}

{% if can_phantom_fund %}
<div class="col-12 offset-md-2 col-md-10 offset-lg-3 col-lg-6 mt-5 font-subheader mx-0 mx-md-auto row">
<ul class="nav">
Expand Down Expand Up @@ -115,14 +113,15 @@ <h2 class="font-title-lg my-4">{% trans "Fund Grant" %}</h2>
</div>
</div>
<div id="original_fund" class="tab_target {% if active_tab == "phantom" %} hidden {% endif %}">
<div class="col-12 offset-md-2 col-md-10 offset-xl-3 col-xl-6 mt-5 font-subheader mx-0 mx-md-auto row">
<div class="col-12 offset-md-2 col-md-10 offset-xl-3 col-xl-6 mt-0 font-subheader mx-0 mx-md-auto row">
<p class="col-12 font-weight-semibold my-4 text-center">
{{ grant.admin_profile }} {% trans "is accepting contributions in "%}
{% if grant_has_no_token %}
{% trans "any token." %}
{% trans "any token" %}
{% else %}
{{ grant.token_symbol }}
{% endif %}
for {{ grant.title }}
</p>

<div id="grants_form" class="col-12">
Expand Down
2 changes: 1 addition & 1 deletion app/grants/templates/grants/shared/landing_announce.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% load humanize static i18n %}
<div style="border-top: 10px solid #ccc; border-bottom: 10px solid #eee; background-image: url('/static/v2/images/bg/{{mid_back}}'); background-size: cover;">
<div style="background-image: url('/static/v2/images/bg/{{mid_back}}'); background-size: cover;">
<div style="background-color: rgba(255, 255, 255, 0.1);">

<a id="skip" href="#content_navbar">
Expand Down
Loading