Skip to content
This repository has been archived by the owner on Sep 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request #624 from GreatFruitOmsk/616-bottom-left-data
Browse files Browse the repository at this point in the history
Average Trust Score and Action Solved on every page
  • Loading branch information
vpetersson authored Jan 17, 2020
2 parents 62923cb + d3c8684 commit 2e63375
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
2 changes: 2 additions & 0 deletions backend/backend/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,5 @@ def check_ip_range(ipr):
GITHUB_APP_CLIENT_ID = os.getenv('GITHUB_APP_CLIENT_ID') # Github app Client ID
GITHUB_APP_CLIENT_SECRET = os.getenv('GITHUB_APP_CLIENT_SECRET') # Github App Client Secret
GITHUB_APP_REDIRECT_URL = os.getenv('GITHUB_APP_REDIRECT_URL') # Github App Redirect URL

MAX_WEEKLY_RA = 5 # The number of RAs for the user to resolve in a week (starting this Monday)
22 changes: 7 additions & 15 deletions backend/device_registry/templates/admin_base.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% extends "base.html" %}
{% load static %}
{% load highlight_selector %}
{% load misc %}

{% block css %}
{% endblock %}
Expand Down Expand Up @@ -101,14 +102,14 @@ <h2>Status Overview</h2>
<div class="sidebar-bottom-box">
<div class="sidebar-bottom-item">
<p>Current Trust Score</p>
<p id="trust-score">75%</p>
<p id="trust-score">{% widthratio user.profile.average_trust_score 1 100 %}</p>
</div>
<div id="trust-graph-100">
<span id="trust-graph-var"></span>
</div>
<div id="action-solved-block" class="sidebar-bottom-item">
<p>Actions Solved</p>
<p id="action-solved">29/50</p>
<p id="action-solved">{{ user.profile.actions_resolved_since_monday }}/{% settings_value "MAX_WEEKLY_RA" %}</p>
</div>
<div id="action-solved-graph">
<span id="action-solved-var"></span>
Expand Down Expand Up @@ -151,26 +152,17 @@ <h2>Status Overview</h2>
</main>
</div>
</div>

{% endblock %}

{% block scripts %}
{{ block.super }}
<!-- Hardcoded style for graphic -->
<style>
#action-solved-var {
width: 58%;
}

#trust-graph-var {
width: 75%;
}

</style>
<script src="{% static '/js/csrf.js' %}"></script>
<script type="text/javascript">
$(() => {
feather.replace();
$('#action-solved-var').width("{% widthratio user.profile.actions_resolved_since_monday 5 100 %}%");
$('#trust-graph-var').width("{% widthratio user.profile.average_trust_score 1 100 %}%");
});
{% if MIXPANEL_TOKEN %}
$('.sidebar-link').click((e) => {
Expand All @@ -192,7 +184,7 @@ <h2>Status Overview</h2>
"$email": "{{ user.email }}",
"$phone": "{{ user.profile.phone }}"
});

{% endif %}
</script>
{% endblock %}
7 changes: 7 additions & 0 deletions backend/device_registry/templatetags/misc.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
from django import template
from django.conf import settings
from django.utils import timezone

ALLOWED_SETTINGS = ['MAX_WEEKLY_RA']
register = template.Library()


@register.filter(name='fromunix')
def fromunix(value):
return timezone.datetime.fromtimestamp(value, timezone.get_default_timezone())


@register.simple_tag
def settings_value(name):
return getattr(settings, name, '') if name in ALLOWED_SETTINGS else ''
7 changes: 7 additions & 0 deletions backend/profile_page/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.dispatch import receiver
from django.utils import timezone

from dateutil.relativedelta import relativedelta, MO
from mixpanel import Mixpanel, MixpanelException
from phonenumber_field.modelfields import PhoneNumberField

Expand Down Expand Up @@ -53,6 +54,12 @@ def actions_count(self):
Q(device__owner=self.user) & RecommendedAction.get_affected_query()) \
.values('action_id').distinct().count()

@property
def actions_resolved_since_monday(self):
monday = (timezone.now() - relativedelta(weekday=MO(-1))).date() # Find this week's monday
return min(RecommendedAction.objects.filter(device__owner=self.user, resolved_at__gte=monday)\
.values('action_id').distinct().count(), settings.MAX_WEEKLY_RA)

@property
def github_repos(self):
try:
Expand Down

0 comments on commit 2e63375

Please sign in to comment.