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

Commit

Permalink
Data for Current Trust Score and Action Solved elements on every page.
Browse files Browse the repository at this point in the history
  • Loading branch information
a-martynovich committed Jan 16, 2020
1 parent 6453d0b commit d6585d8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
10 changes: 5 additions & 5 deletions backend/device_registry/templates/admin_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,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">{{ user.profile.average_trust_score_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 }}/5</p>
</div>
<div id="action-solved-graph">
<span id="action-solved-var"></span>
Expand Down Expand Up @@ -151,7 +151,7 @@ <h2>Status Overview</h2>
</main>
</div>
</div>

{% endblock %}

{% block scripts %}
Expand All @@ -165,7 +165,7 @@ <h2>Status Overview</h2>
#trust-graph-var {
width: 75%;
}

</style>
<script src="{% static '/js/csrf.js' %}"></script>
<script type="text/javascript">
Expand All @@ -192,7 +192,7 @@ <h2>Status Overview</h2>
"$email": "{{ user.email }}",
"$phone": "{{ user.profile.phone }}"
});

{% endif %}
</script>
{% endblock %}
11 changes: 11 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()
return RecommendedAction.objects.filter(device__owner=self.user, resolved_at__gte=monday)\
.values('action_id').distinct().count()

@property
def github_repos(self):
try:
Expand Down Expand Up @@ -80,6 +87,10 @@ def average_trust_score(self):
return None
return devices.aggregate(Avg('trust_score'))['trust_score__avg']

@property
def average_trust_score_100(self):
return int(self.average_trust_score * 100)

def sample_history(self):
"""
Count the number of newly resolved user's RAs in the last 24h, save it together with the user's average trust
Expand Down

0 comments on commit d6585d8

Please sign in to comment.