1
0
Fork 0

Merge branch 'performance-improvements' into 'master'

Performance improvements on Station page

See merge request librespacefoundation/satnogs/satnogs-network!792
merge-requests/792/merge
Alfredos-Panagiotis Damkalis 2019-11-25 19:00:28 +00:00
commit 12b8083d56
5 changed files with 79 additions and 23 deletions

View File

@ -0,0 +1,47 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.25 on 2019-11-25 18:23
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('base', '0060_add_latest_tle_proxy_model'),
]
operations = [
migrations.AlterField(
model_name='observation',
name='end',
field=models.DateTimeField(db_index=True),
),
migrations.AlterField(
model_name='observation',
name='start',
field=models.DateTimeField(db_index=True),
),
migrations.AlterField(
model_name='satellite',
name='norad_cat_id',
field=models.PositiveIntegerField(db_index=True),
),
migrations.AlterField(
model_name='tle',
name='tle0',
field=models.CharField(blank=True, db_index=True, max_length=100),
),
migrations.AddIndex(
model_name='observation',
index=models.Index(fields=[b'-start', b'-end'], name='base_observ_start_bbb297_idx'),
),
migrations.AddIndex(
model_name='stationstatuslog',
index=models.Index(fields=[b'-changed'], name='base_statio_changed_71df65_idx'),
),
migrations.AddIndex(
model_name='station',
index=models.Index(fields=[b'-status', b'id'], name='base_statio_status_797b1c_idx'),
),
]

View File

@ -182,7 +182,8 @@ class Station(models.Model):
)
class Meta:
ordering = ['-status', 'id']
ordering = ['-status']
indexes = [models.Index(fields=['-status', 'id'])]
def get_image(self):
"""Return the image of the station or the default image if there is a defined one"""
@ -274,6 +275,7 @@ class StationStatusLog(models.Model):
class Meta:
ordering = ['-changed']
indexes = [models.Index(fields=['-changed'])]
def __unicode__(self):
return '{0} - {1}'.format(self.station, self.status)
@ -281,7 +283,7 @@ class StationStatusLog(models.Model):
class Satellite(models.Model):
"""Model for SatNOGS satellites."""
norad_cat_id = models.PositiveIntegerField()
norad_cat_id = models.PositiveIntegerField(db_index=True)
norad_follow_id = models.PositiveIntegerField(blank=True, null=True)
name = models.CharField(max_length=45)
names = models.TextField(blank=True)
@ -306,7 +308,7 @@ class Satellite(models.Model):
class Tle(models.Model):
"""Model for TLEs."""
tle0 = models.CharField(max_length=100, blank=True)
tle0 = models.CharField(max_length=100, blank=True, db_index=True)
tle1 = models.CharField(max_length=200, blank=True)
tle2 = models.CharField(max_length=200, blank=True)
updated = models.DateTimeField(auto_now=True, blank=True)
@ -369,8 +371,8 @@ class Observation(models.Model):
author = models.ForeignKey(
User, related_name='observations', on_delete=models.SET_NULL, null=True, blank=True
)
start = models.DateTimeField()
end = models.DateTimeField()
start = models.DateTimeField(db_index=True)
end = models.DateTimeField(db_index=True)
ground_station = models.ForeignKey(
Station, related_name='observations', on_delete=models.SET_NULL, null=True, blank=True
)
@ -499,6 +501,7 @@ class Observation(models.Model):
class Meta:
ordering = ['-start', '-end']
indexes = [models.Index(fields=['-start', '-end'])]
def __unicode__(self):
return str(self.id)

View File

@ -546,24 +546,36 @@ def observation_vet(request, observation_id):
def stations_list(request):
"""View to render Stations page."""
stations = Station.objects.all()
scheduled_obs_queryset = Observation.objects.filter(end__gt=now())
stations = Station.objects.prefetch_related(
'antenna', 'owner',
Prefetch('observations', queryset=scheduled_obs_queryset, to_attr='scheduled_obs')
).order_by('-status', 'id')
stations_total_obs = {
x['id']: x['total_obs']
for x in Station.objects.values('id').annotate(total_obs=Count('observations'))
}
form = StationForm()
antennas = Antenna.objects.all()
online = stations.filter(status=2).count()
testing = stations.filter(status=1).count()
stations_by_status = {'online': 0, 'testing': 0, 'offline': 0, 'future': 0}
for station in stations:
if station.last_seen is None:
stations_by_status['future'] += 1
elif station.status == 2:
stations_by_status['online'] += 1
elif station.status == 1:
stations_by_status['testing'] += 1
else:
stations_by_status['offline'] += 1
return render(
request, 'base/stations.html', {
'stations': stations,
'total_obs': stations_total_obs,
'form': form,
'antennas': antennas,
'online': online,
'testing': testing,
'online': stations_by_status['online'],
'testing': stations_by_status['testing'],
'offline': stations_by_status['offline'],
'future': stations_by_status['future'],
'mapbox_id': settings.MAPBOX_MAP_ID,
'mapbox_token': settings.MAPBOX_TOKEN
}

View File

@ -3,12 +3,6 @@
$(document).ready(function() {
'use strict';
$('.stations-totals .label-offline').html($('span.station.label-offline').length);
$('.stations-totals .label-future').html($('span.station.label-future').length);
$('.station-row:has(\'.label-offline\')').hide();
$('.station-row:has(\'.label-future\')').hide();
$('#stations-online').click(function() {
$('.station-row:has(\'.label-online\')').toggle();
$(this).toggleClass('active').blur();

View File

@ -22,10 +22,10 @@
<span class="label label-testing">{{ testing }}</span> Testing
</button>
<button type="button" id="stations-offline" class="btn btn-sm btn-default">
<span class="label label-offline">0</span> Offline
<span class="label label-offline">{{ offline }}</span> Offline
</button>
<button type="button" id="stations-future" class="btn btn-sm btn-default">
<span class="label label-future">0</span> Future
<span class="label label-future">{{ future }}</span> Future
</button>
</div>
</h2>
@ -43,7 +43,7 @@
</thead>
<tbody>
{% for station in stations %}
<tr class="station-row clickable-row" data-href="{% url 'base:station_view' station_id=station.id %}">
<tr class="station-row clickable-row" data-href="{% url 'base:station_view' station_id=station.id %}" {% if station.status < 1 %}style="display:none;"{% endif %}>
<td>
<a href="{% url 'base:station_view' station_id=station.id %}">
<span class="station
@ -83,13 +83,13 @@
</td>
{% endif %}
<td>
<a href="{% url 'base:observations_list' %}?station={{ station.id }}" class="badge total-pill" data-toggle="tooltip" data-placement="bottom" title={% if not station.success_rate %} "No data" {%else %} "{{station.success_rate}}% Success" {% endif %}>
<a href="{% url 'base:observations_list' %}?station={{ station.id }}" class="badge total-pill" data-toggle="tooltip" data-placement="bottom">
{{ total_obs|get_count_from_id:station.id }}
</a>
</td>
<td>
<a href="{% url 'base:observations_list' %}?future=1&good=0&bad=0&unvetted=0&failed=0&station={{ station.id }}" class="badge badge-info">
{{ station.observations_future_count }}
{{ station.scheduled_obs|length }}
</a>
</td>
<td class="station-antennas">