def dispatch(self, request, *args, **kwargs): if is_first_run(): return redirect('/start') return TemplateResponse(request, 'status.html', context=self.get_context_data())
def retrieve(self, request, *args, **kwargs): if not is_first_run(): queryset = AverageQuality.objects.latest() if queryset is None: # print('q: {0}'.format(queryset)) serializer = ErrorMsg('', many=False) else: serializer = QualitySerializer(queryset, many=False) else: serializer = ErrorMsg('', many=False) return Response(serializer.data)
def fill(): if is_first_run(): return speed_values = pyspeedtest.SpeedTest() ping = round(speed_values.ping()) download = round(speed_values.download()) upload = round(speed_values.upload()) entry = Speed(time=timezone.now(), server=speed_values.host, ping=ping, download=download, upload=upload) entry.save()
def push(): if is_first_run() or not use_prtg(): return logging.basicConfig(level=logging.DEBUG) queryset = Speed.objects.latest() prtg_settings = Settings.objects.first() payload = json.dumps(PrtgSpeedSerializer(queryset, many=False).data) resp = requests.get("{0}{1}?content={2}".format(prtg_settings.prtg_url, prtg_settings.prtg_token, payload)) if resp.status_code == 200 and 'application/json' in resp.headers['content-type']: a = resp.json() if 'status' in a.keys() and a["status"] == "Ok": return 0 return 1
def calc_qos(): if is_first_run(): return last_24 = Speed.objects.all().filter(time__gte=datetime.now() - timedelta(days=1)) avg_down = 0 avg_up = 0 for o in last_24: avg_down += o.download avg_up += o.upload avg_down /= len(last_24) avg_up /= len(last_24) qos = AverageQuality(time=timezone.now(), avg_download=avg_down, avg_upload=avg_up) qos.save()
def get(self, request): if is_first_run(): return redirect('/start') return TemplateResponse(request, 'overview.html')