Skip to content

Commit

Permalink
Merge branch 'feature/delete-portfolio-item' of github.com:chibie/web…
Browse files Browse the repository at this point in the history
… into feature/delete-portfolio-item
  • Loading branch information
chibie committed Sep 24, 2020
2 parents 122ef2a + 538f6d6 commit 4851a12
Show file tree
Hide file tree
Showing 25 changed files with 452 additions and 251 deletions.
9 changes: 9 additions & 0 deletions app/assets/v2/css/grants/grant.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
padding: 5px;
}

#stats_history td{
padding: 5px;
border: 1px #ddd solid;
}
#stats_history tr.table_header{
background-color: #ddd;
font-weight: bold;
}

#negative_fund:hover,
#flag:hover{
background-color: #F9309C;
Expand Down
Binary file modified app/assets/v2/images/emails/rect-kudos.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/assets/v2/images/emails/rect-news.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/assets/v2/images/emails/rect-stats.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/assets/v2/images/emails/rect-townsquare.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/assets/v2/images/emails/rect-updates.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/assets/v2/images/emails/rect-videos.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/v2/images/top-bar/grants-pos.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/v2/images/top-bar/hackathons-pos.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/assets/v2/js/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Vue.component('grants-cart', {
selectedNetwork: undefined, // used to force computed properties to update when document.web3network changes
zkSyncFeeTotals: {}, // used to dispaly a string showing the total zkSync fees when checking out with Flow B
zkSyncFeesString: undefined, // string generated from the above property
isZkSyncDown: true, // true if zkSync is having issues with their servers
isZkSyncDown: false, // true if zkSync is having issues with their servers
// SMS validation
csrf: $("input[name='csrfmiddlewaretoken']").val(),
validationStep: 'intro',
Expand Down
496 changes: 272 additions & 224 deletions app/dashboard/models.py

Large diffs are not rendered by default.

25 changes: 21 additions & 4 deletions app/grants/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@

import twitter
from grants.models import (
CartActivity, CLRMatch, Contribution, Flag, Grant, GrantCategory, GrantCLR, GrantCollection, GrantType, MatchPledge,
PhantomFunding, Subscription,
CartActivity, CLRMatch, Contribution, Flag, Grant, GrantCategory, GrantCLR, GrantCollection, GrantStat, GrantType,
MatchPledge, PhantomFunding, Subscription,
)


Expand Down Expand Up @@ -95,13 +95,13 @@ class GrantAdmin(GeneralAdmin):
'subscriptions_links', 'contributions_links', 'logo', 'logo_svg', 'image_css',
'link', 'clr_prediction_curve', 'hidden', 'next_clr_calc_date', 'last_clr_calc_date',
'metadata', 'twitter_handle_1', 'twitter_handle_2', 'view_count', 'is_clr_eligible', 'in_active_clrs',
'last_update', 'funding_info', 'twitter_verified', 'twitter_verified_by', 'twitter_verified_at'
'last_update', 'funding_info', 'twitter_verified', 'twitter_verified_by', 'twitter_verified_at', 'stats_history'
]
readonly_fields = [
'logo_svg_asset', 'logo_asset',
'team_member_list', 'clr_prediction_curve',
'subscriptions_links', 'contributions_links', 'link',
'migrated_to', 'view_count', 'in_active_clrs'
'migrated_to', 'view_count', 'in_active_clrs', 'stats_history',
]
list_display =['pk', 'sybil_score', 'weighted_risk_score', 'match_amount', 'positive_round_contributor_count', 'is_clr_eligible', 'title', 'active', 'link', 'hidden', 'migrated_to']
raw_id_fields = ['admin_profile', 'twitter_verified_by']
Expand Down Expand Up @@ -181,6 +181,22 @@ def migrated_to(self, instance):
html = f"<a href='{instance.link_to_new_grant.pk}'>{instance.link_to_new_grant.pk}</a>"
return mark_safe(html)

def stats_history(self, instance):
html = "<table>"
html += "<tr><td>Date</td><td>Impressions</td><td>Contributions</td></tr>"
for ele in instance.stats.filter(snapshot_type='increment').order_by('-created_on'):
html += f'''<tr>
<td>
{ele.created_on.strftime("%m/%d/%Y")}
</td><td>
{ele.data.get('impressions')}
</td><td>
{ele.data.get('contributions')}
</td>
</tr>'''
html += "</table>"
return mark_safe(html)

logo_svg_asset.short_description = 'Logo SVG Asset'
logo_asset.short_description = 'Logo Image Asset'

Expand Down Expand Up @@ -376,3 +392,4 @@ class GrantCollectionAdmin(admin.ModelAdmin):
admin.site.register(GrantCategory, GrantCategoryAdmin)
admin.site.register(GrantCLR, GrantCLRAdmin)
admin.site.register(GrantCollection, GrantCollectionAdmin)
admin.site.register(GrantStat, GeneralAdmin)
41 changes: 41 additions & 0 deletions app/grants/management/commands/create_stats_snapshot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from django.core.management.base import BaseCommand

from grants.models import Grant, GrantStat


class Command(BaseCommand):

help = 'creates a grants snapshot'

def handle(self, *args, **kwargs):
for grant in Grant.objects.all():
# setup
last_snapshot = grant.stats.filter(snapshot_type='total').order_by('-created_on').first()

# snapshot
data = {
'impressions': grant.get_view_count,
'in_cart': grant.cart_actions.filter(latest=True).count(),
'contributions': grant.contribution_count
}
snapshot_type = 'total'
GrantStat.objects.create(
snapshot_type=snapshot_type,
data=data,
grant=grant,
)

# increment
if last_snapshot:
snapshot_type = "increment"
increment_data = {
}
for key in data.keys():
increment_data[key] = data[key] - last_snapshot.data[key]
GrantStat.objects.create(
snapshot_type=snapshot_type,
data=increment_data,
grant=grant,
)

print(grant.pk)
30 changes: 30 additions & 0 deletions app/grants/migrations/0087_grantstat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 2.2.4 on 2020-09-23 21:39

import django.contrib.postgres.fields.jsonb
from django.db import migrations, models
import django.db.models.deletion
import economy.models


class Migration(migrations.Migration):

dependencies = [
('grants', '0086_grantcollections'),
]

operations = [
migrations.CreateModel(
name='GrantStat',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_on', models.DateTimeField(db_index=True, default=economy.models.get_time)),
('modified_on', models.DateTimeField(default=economy.models.get_time)),
('data', django.contrib.postgres.fields.jsonb.JSONField(blank=True, default=dict, help_text='Stats for this Grant')),
('snapshot_type', models.CharField(choices=[('total', 'total'), ('increment', 'increment')], db_index=True, help_text='Snapshot Type', max_length=50)),
('grant', models.ForeignKey(help_text='Grant to add stats for ', on_delete=django.db.models.deletion.CASCADE, related_name='stats', to='grants.Grant')),
],
options={
'abstract': False,
},
),
]
21 changes: 21 additions & 0 deletions app/grants/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1803,3 +1803,24 @@ def to_json_dict(self):
'grants': self.cache['grants'],
'curators': curators + [owner]
}

class GrantStat(SuperModel):
SNAPSHOT_TYPES = [
('total', 'total'),
('increment', 'increment')
]

grant = models.ForeignKey(Grant, on_delete=models.CASCADE, related_name='stats',
help_text=_('Grant to add stats for this grant'))
data = JSONField(default=dict, blank=True, help_text=_('Stats for this Grant'))
snapshot_type = models.CharField(
max_length=50,
blank=False,
null=False,
help_text=_('Snapshot Type'),
db_index=True,
choices=SNAPSHOT_TYPES,
)

def __str__(self):
return f'{self.snapshot_type} {self.created_on} for {self.grant.title}'
36 changes: 34 additions & 2 deletions app/grants/templates/grants/detail/tabs.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
<span class="nav-badge">({{ activity_count }})</span>
</button>

{% if is_team_member %}
<button type="button" id="nav-stats" href="{{grant.url}}?tab=stats" class="section-tab {% if tab == "stats" %} active {% endif %}">
{% trans "TRENDS" %}
</button>
{% endif %}

<button type="button" id="nav-contributors" href="{{grant.url}}?tab=contributors" class="section-tab {% if tab == "contributors" %} active {% endif %}">
{% trans "CONTRIBUTORS" %}
Expand Down Expand Up @@ -232,15 +234,45 @@ <h4>{{ele.0}}: (avg {{ele.1.1|floatformat:2}})</h4>
</div>
{% endif %}

{% if tab == "stats" %}
{% if tab == "stats" and is_team_member %}
<script src="https://www.gstatic.com/charts/loader.js"></script>
<script src="{% static "v2/js/grants/stats.js" %}"></script>
<div id=grant_stats_graph class="content-block content-block--white">
<div class="container">

<div class="value-container">
<div class="chart_container chart_container--big">
<p class="sub-title font-weight-semibold font-caption mb-1 pt-1">CONTRIBUTION HISTORY OVER TIME (in USD)</p>
{% if stats_history|length %}
<p class="sub-title font-weight-semibold font-caption mb-1 pt-1">Marketing History Over Time</p>
<table id=stats_history>
<tr class="table_header">
<td>
When
</td>
<td>
Impressions
</td>
<td>
Contributions
</td>
</tr>
{% for ele in stats_history %}
<tr>
<td>
{{ele.created_on|date:"Y/m/d"}}
</td>
<td>
{{ele.data.impressions}}
</td>
<td>
{{ele.data.contributions}}
</td>
</tr>
{% endfor %}
</table>
{% endif %}

<p class="sub-title font-weight-semibold font-caption mt-4 mb-1 pt-1">Contribution History (in USD)</p>
<div class="chart_container__content">
<div id="grant_chart"></div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/grants/templates/grants/shared/hidden_inputs.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<input type="hidden" id="grant_logo" name="grant_logo" value="{% if grant.logo and grant.logo.url %}{{ grant.logo.url }}{% else %}{% with grant_logo='v2/images/grants/logos/' id=grant.id|modulo:3 %} {% static grant_logo|addstr:id|add:'.png' %} {% endwith %} {% endif %}">
<input type="hidden" id="grant_clr_prediction_curve" name="grant_clr_prediction_curve" value="{{ grant.clr_prediction_curve }}">
<input type="hidden" id="grant_image_css" name="grant_image_css" value="{{ grant.image_css }}">
<input type="hidden" id="is_clr_eligible" name="is_clr_eligible" {% if grant.is_clr_eligible %} value="{{ grant.is_clr_eligible }}" {% endif %}>
<input type="hidden" id="is_clr_eligible" name="is_clr_eligible" {% if grant.is_clr_eligible %} value="true" {% endif %}>
{% if amount %}
<input type="hidden" id="grant_donation_amount" name="grant_donation_amount" value="{{ amount }}">
{% endif %}
Expand Down
3 changes: 2 additions & 1 deletion app/grants/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def clr_grants(request, round_num):
"""CLR grants explorer."""

try:
clr_round = GrantCLR.objects.get(round_num=round_num)
clr_round = GrantCLR.objects.get(round_num__icontains=round_num)

except GrantCLR.DoesNotExist:
return redirect('/grants')
Expand Down Expand Up @@ -1182,6 +1182,7 @@ def grant_details(request, grant_id, grant_slug):
if tab == 'stats':
params['max_graph'] = grant.history_by_month_max
params['history'] = json.dumps(grant.history_by_month)
params['stats_history'] = grant.stats.filter(snapshot_type='increment').order_by('-created_on')

if add_cancel_params:
add_in_params = {
Expand Down
6 changes: 4 additions & 2 deletions app/marketing/management/commands/new_bounties_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

THROTTLE_S = 0.005


class Command(BaseCommand):

help = 'sends new_bounty_daily _emails'
Expand Down Expand Up @@ -63,15 +64,16 @@ def handle(self, *args, **options):
# stats
speed = counter_total / (time.time() - start_time)
ETA = round((total_count - counter_total) / speed / 3600, 1)
print(f"{counter_sent} sent/{counter_total} enabled/ {total_count} total, {round(speed, 2)}/s, ETA:{ETA}h, working on {to_email} ")
print(
f"{counter_sent} sent/{counter_total} enabled/ {total_count} total, {round(speed, 2)}/s, ETA:{ETA}h, working on {to_email} ")

# send
did_send = new_bounty_daily(es.pk)
if did_send:
counter_sent += 1

time.sleep(THROTTLE_S)

except Exception as e:
logging.exception(e)
print(e)
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@

import pytest
from dashboard.models import Bounty, Profile
from marketing.management.commands.new_bounties_email import get_bounties_for_keywords
from marketing.mails import get_bounties_for_keywords
from marketing.models import Keyword
from test_plus.test import TestCase


@pytest.mark.django_db
class TestNewBountiesEmail(TestCase):
"""Define tests for testing new bounties email."""

def setUp(self):
"""Perform setup for the testcase."""

Profile.objects.create(
data={},
handle='fred',
Expand Down Expand Up @@ -69,8 +69,7 @@ def setUp(self):
network='mainnet',
)


def test_get_bounties_for_keywords(self):
"""Test get_bounties_for_keywords function to confirm a bounty reserved for a specific user is excluded."""
new_bounties, _all_bounties = get_bounties_for_keywords('Python',24)
new_bounties, _all_bounties = get_bounties_for_keywords('Python', 24)
assert new_bounties.count() == 1
14 changes: 7 additions & 7 deletions app/marketing/tests/management/commands/test_roundup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ def test_handle_no_options(self, mock_weekly_roundup, *args):

assert mock_weekly_roundup.call_count == 0

@patch('time.sleep')
@patch('marketing.management.commands.roundup.weekly_roundup')
def test_handle_with_options(self, mock_weekly_roundup, *args):
"""Test command roundup which various options."""
Command().handle(exclude_startswith='f', filter_startswith='jack', start_counter=0, live=True)
# @patch('time.sleep')
# @patch('marketing.management.commands.roundup.weekly_roundup')
# def test_handle_with_options(self, mock_weekly_roundup, *args):
# """Test command roundup which various options."""
# Command().handle(exclude_startswith='f', filter_startswith='jack', start_counter=0, live=True)

assert mock_weekly_roundup.call_count == 1
# assert mock_weekly_roundup.call_count == 1

mock_weekly_roundup.assert_called_once_with(['[email protected]'])
# mock_weekly_roundup.assert_called_once_with(['[email protected]'])
4 changes: 2 additions & 2 deletions app/retail/templates/emails/bounty_roundup.html
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ <h2 style="font-weight:500; text-transform:capitalize; font-size:1.6rem; text-al
{% if updates %}
{% if updates.hackathons %}
<div width="100%" style="height: 60px">
<img src="{% static 'v2/images/top-bar/hackathons-pos.svg' %}" width="35%" style="border-style:none; vertical-align:middle; text-align: left" valign="middle" class="updates">
<img src="{% static 'v2/images/top-bar/hackathons-pos.png' %}" width="35%" style="border-style:none; vertical-align:middle; text-align: left" valign="middle" class="updates">
</div>
<br>
<p style="text-align: left">{{ updates.hackathons.description|safe }}</p>
Expand Down Expand Up @@ -180,7 +180,7 @@ <h3 style="font-weight:bold; text-transform:capitalize; line-height:30px; color:
{% if updates.grants %}
<br>
<div width="100%" style="height: 90px">
<img src="{% static 'v2/images/top-bar/grants-pos.svg' %}" width="35%" style="border-style:none; vertical-align:middle; text-align: left" valign="middle" class="updates">
<img src="{% static 'v2/images/top-bar/grants-pos.png' %}" width="35%" style="border-style:none; vertical-align:middle; text-align: left" valign="middle" class="updates">
</div>
<br>
{% for grant in updates.grants %}
Expand Down
2 changes: 1 addition & 1 deletion docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ life easier for you if you are the kind who enjoys multiple things parallely.
These should also be created directly off of the `master` branch.

```shell
git checkout -b my-branch -t upstream/master
git checkout -b my-branch
```

### Step 3: Code
Expand Down
2 changes: 1 addition & 1 deletion docs/GRANTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ can use this account to send transfers without prompting you for each transfer!
only held by this account temporarily to improve UX. Because it does not permanently hold funds
there is no additional security risk.

### Checkout Fow
### Checkout Flow

Based on the items in your cart, we check your zkSync balances to see if you already have enough
funds on zkSync to complete checkout.
Expand Down
1 change: 1 addition & 0 deletions scripts/crontab
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/us
00 10 * * 5 cd gitcoin/coin; bash scripts/run_management_command_if_not_already_running.bash post_leaderboard_to_slack >> /var/log/gitcoin/post_leaderboard_to_slack.log 2>&1
0 9 * * * cd gitcoin/coin; bash scripts/run_management_command_if_not_already_running.bash no_applicants_email >> /var/log/gitcoin/no_applicants_email.log 2>&1
0 10 * * * cd gitcoin/coin; bash scripts/run_management_command_if_not_already_running.bash pull_grant_twitter_info >> /var/log/gitcoin/pull_grant_twitter_info.log 2>&1
0 5 * * * cd gitcoin/coin; bash scripts/run_management_command_if_not_already_running.bash create_stats_snapshot >> /var/log/gitcoin/create_stats_snapshot.log 2>&1


## PERFTOOLS
Expand Down

0 comments on commit 4851a12

Please sign in to comment.