[Fixes #31] Create helper for success rates on stations
parent
838eb4a8d2
commit
9e0e53cbb8
|
@ -1,5 +1,3 @@
|
|||
from django.conf import settings
|
||||
from django.contrib.sites.models import Site
|
||||
from rest_framework import serializers
|
||||
|
||||
from network.base.models import Data
|
||||
|
|
|
@ -74,6 +74,12 @@ class Station(models.Model):
|
|||
else:
|
||||
return format_html('<span style="color:red">Offline</span>')
|
||||
|
||||
@property
|
||||
def success_rate(self):
|
||||
observations = self.data_set.all().count()
|
||||
success = self.data_set.exclude(payload='').count()
|
||||
return int(100 * (float(success) / float(observations)))
|
||||
|
||||
def __unicode__(self):
|
||||
return "%d - %s" % (self.pk, self.name)
|
||||
|
||||
|
|
|
@ -20,3 +20,11 @@ def frq(value):
|
|||
formatted = format(float(to_format) / 1000000, '.3f')
|
||||
formatted = formatted + ' Mhz'
|
||||
return formatted
|
||||
|
||||
|
||||
@register.filter
|
||||
def percentagerest(value):
|
||||
try:
|
||||
return 100 - value
|
||||
except (TypeError, ValueError):
|
||||
return 0
|
||||
|
|
|
@ -139,7 +139,8 @@ def observation_new(request):
|
|||
|
||||
def prediction_windows(request, sat_id, start_date, end_date):
|
||||
try:
|
||||
sat = Satellite.objects.filter(transmitters__alive=True).distinct().get(norad_cat_id=sat_id)
|
||||
sat = Satellite.objects.filter(transmitters__alive=True). \
|
||||
distinct().get(norad_cat_id=sat_id)
|
||||
except:
|
||||
data = {
|
||||
'error': 'You should select a Satellite first.'
|
||||
|
|
|
@ -59,8 +59,6 @@ body {
|
|||
font-family:'ClearSans';
|
||||
}
|
||||
|
||||
|
||||
|
||||
a:hover {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
@ -111,6 +109,10 @@ a:hover {
|
|||
margin-right: 5px;
|
||||
}
|
||||
|
||||
.progress {
|
||||
margin-bottom: 0px;
|
||||
}
|
||||
|
||||
footer {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
|
|
@ -72,21 +72,19 @@
|
|||
{% endfor %}
|
||||
</span>
|
||||
</div>
|
||||
<!--
|
||||
<div class="gs-front-line">
|
||||
<span class="label label-info">Success Rate</span>
|
||||
<span class="gs-front-data">
|
||||
<div class="progress">
|
||||
<div class="progress-bar progress-bar-success" style="width: 88%">
|
||||
<span class="sr-only">88% Complete (success)</span>
|
||||
<div class="progress" title="{{ featured_station.success_rate }}%">
|
||||
<div class="progress-bar progress-bar-success" style="width: {{ featured_station.success_rate }}%">
|
||||
<span class="sr-only">{{ featured_station.success_rate }}% Complete (success)</span>
|
||||
</div>
|
||||
<div class="progress-bar progress-bar-danger" style="width: 12%">
|
||||
<span class="sr-only">12% Complete (danger)</span>
|
||||
<div class="progress-bar progress-bar-danger" style="width: {{ featured_station.success_rate|percentagerest }}%">
|
||||
<span class="sr-only">{{ featured_station.success_rate|percentagerest }}% Complete (danger)</span>
|
||||
</div>
|
||||
</div>
|
||||
</span>
|
||||
</div>
|
||||
-->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -73,6 +73,19 @@
|
|||
{{ station.created|timesince }} ago
|
||||
</span>
|
||||
</div>
|
||||
<div class="gs-front-line">
|
||||
<span class="label label-default">Success Rate</span>
|
||||
<span class="gs-front-data">
|
||||
<div class="progress" title="{{ station.success_rate }}%">
|
||||
<div class="progress-bar progress-bar-success" style="width: {{ station.success_rate }}%">
|
||||
<span class="sr-only">{{ station.success_rate }}% Complete (success)</span>
|
||||
</div>
|
||||
<div class="progress-bar progress-bar-danger" style="width: {{ station.success_rate|percentagerest }}%">
|
||||
<span class="sr-only">{{ station.success_rate|percentagerest }}% Complete (danger)</span>
|
||||
</div>
|
||||
</div>
|
||||
</span>
|
||||
</div>
|
||||
<div class="gs-front-line">
|
||||
{% if station.online %}
|
||||
<span class="label label-success">Online</span>
|
||||
|
|
Loading…
Reference in New Issue