##// END OF EJS Templates
New template, clean code, workig for realtime
New template, clean code, workig for realtime

File last commit:

r21:dc5f8680b6e1
r21:dc5f8680b6e1
Show More
views.py
155 lines | 5.1 KiB | text/x-python | PythonLexer
Developer
New version with cards and status alerts
r11 #!/usr/bin/python
# -*- coding: UTF-8 -*-
First version RTI, Spectra, Noise + Docker
r0 from __future__ import unicode_literals
Juan C. Espinoza
Docker working
r1 import os
Developer
New version with cards and status alerts
r11 import time
First version RTI, Spectra, Noise + Docker
r0 from datetime import datetime
from django import forms
from django.contrib import messages
from django.utils.safestring import mark_safe
from django.shortcuts import render
Reorganize models, smaller docker, others
r2 import mongoengine
First version RTI, Spectra, Noise + Docker
r0
Developer
New version with cards and status alerts
r11 from plotter.models import Experiment, ExpMeta, ExpData
Juan C. Espinoza
Docker working
r1
Reorganize models, smaller docker, others
r2 host = os.environ.get('HOST_MONGO', 'localhost')
mongoengine.connect('dbplots', host=host, port=27017)
First version RTI, Spectra, Noise + Docker
r0
Developer
New version with cards and status alerts
r11
First version RTI, Spectra, Noise + Docker
r0 # Forms
class SearchForm(forms.Form):
experiment = forms.ChoiceField()
App only for realtime
r4 plot = forms.ChoiceField()
First version RTI, Spectra, Noise + Docker
r0
def __init__(self, *args, **kwargs):
exp_choices = kwargs.pop('exp_choices', [])
App only for realtime
r4 plt_choices = kwargs.pop('plt_choices', [])
First version RTI, Spectra, Noise + Docker
r0 super(SearchForm, self).__init__(*args, **kwargs)
self.fields['experiment'].choices = [(0, 'Select Experiment')] + exp_choices
App only for realtime
r4 self.fields['plot'].choices = [(0, 'Select Plot')] + plt_choices
Developer
New version with cards and status alerts
r11 # we use this class to change the parameter in Scatter plot using the function plotly.restyle in jroplot.js
Plot's layout now can be updated
r5 class ScatterSetupForm(forms.Form):
plotdiv = forms.CharField(widget=forms.HiddenInput())
ymax = forms.CharField(initial=30)
ymin = forms.CharField(initial=10)
Developer
New version with cards and status alerts
r11 # we use this class to change the parameter in RTI plot using the function plotly.restyle in jroplot.js
Plot's layout now can be updated
r5 class RTISetupForm(forms.Form):
plotdiv = forms.CharField(widget=forms.HiddenInput())
colormap = forms.ChoiceField(choices=[('Jet', 'Jet'), ('Viridis', 'Viridis'), ('RdBu', 'RdBu')])
zmax = forms.CharField(initial=30)
zmin = forms.CharField(initial=10)
ymax = forms.CharField(initial=180)
ymin = forms.CharField(initial=80)
Developer
New version with cards and status alerts
r11 # we use this class to change the parameter in SPC plot using the function plotly.restyle in jroplot.js
Plot's layout now can be updated
r5 class SPCSetupForm(forms.Form):
plotdiv = forms.CharField(widget=forms.HiddenInput())
colormap = forms.ChoiceField(choices=[('Jet', 'Jet'), ('Viridis', 'Viridis'), ('RdBu', 'RdBu')])
Developer
New version with cards and status alerts
r11 #como es un perfil xmin y xmax deben ser iguales a zmin y zmax
Plot's layout now can be updated
r5 xmax = forms.CharField(initial=30)
xmin = forms.CharField(initial=10)
Developer
New version with cards and status alerts
r11 #x2max = forms.CharField(initial=30)
#x2min = forms.CharField(initial=10)
Plot's layout now can be updated
r5 ymax = forms.CharField(initial=180)
ymin = forms.CharField(initial=80)
zmax = forms.CharField(initial=30)
zmin = forms.CharField(initial=10)
First version RTI, Spectra, Noise + Docker
r0 # Create your views here.
Developer
New version with cards and status alerts
r11 def main(request):
First version RTI, Spectra, Noise + Docker
r0
App only for realtime
r4 kwargs = {}
Developer
New version with cards and status alerts
r11 date = request.GET.get('date', datetime.now().strftime('%d/%m/%Y'))
exps = ExpMeta.objects.filter(date=datetime.strptime(date, '%d/%m/%Y'))
experiments = []
for exp in exps:
dum = {}
dum['code'] = exp.code
dum['plots'] = exp.plots
dum['name'] = Experiment.objects.get(code=exp.code).name
dt = datetime.now()
data = ExpData.objects(expmeta=exp).order_by('-time')[0] #Get the time from the last data
t = time.mktime(dt.timetuple())
if exp['localtime'] == True: #Ask which type of time is coming: LT o UTC
t -= 5*60*60
# COnditionals to know which state are my clients
if (t-data['time']) > 6*exp['interval']:
status = 'Offline'
clase = 'alertas-offline'
Juan C. Espinoza
New template, clean code, workig for realtime
r21 style = 'danger'
Developer
New version with cards and status alerts
r11 lastDataDate = data['time']
elif (t-data['time']) > 3*exp['interval']:
status = 'Delayed'
clase = 'alertas-delayed'
Juan C. Espinoza
New template, clean code, workig for realtime
r21 style = 'warning'
Developer
New version with cards and status alerts
r11 lastDataDate = data['time']
else:
status = 'Online'
clase = 'alertas-online'
Juan C. Espinoza
New template, clean code, workig for realtime
r21 style = 'success'
Developer
New version with cards and status alerts
r11 lastDataDate = data['time']
dum['status'] = status
dum['class'] = clase
Juan C. Espinoza
New template, clean code, workig for realtime
r21 dum['style']= style
dum['date']= datetime.utcfromtimestamp(lastDataDate)
Developer
New version with cards and status alerts
r11
experiments.append(dum)
App only for realtime
r4
kwargs['date'] = date
Developer
New version with cards and status alerts
r11 kwargs['experiments'] = experiments
return render(request, 'home.html', kwargs)
First version RTI, Spectra, Noise + Docker
r0
Developer
New version with cards and status alerts
r11 def plot(request, code=None, plot=None):
'''
'''
Juan C. Espinoza
New template, clean code, workig for realtime
r21
realtime = False
date = request.GET.get('date', None)
if date is None:
date = datetime.now().strftime('%d/%m/%Y')
realtime = True
exp = Experiment.objects.get(code=int(code))
expmeta = ExpMeta.objects.get(code=int(code), date=datetime.strptime(date, '%d/%m/%Y'))
Developer
New version with cards and status alerts
r11
kwargs = {
'code': code,
'plot': plot,
'date': date,
Juan C. Espinoza
New template, clean code, workig for realtime
r21 'id': expmeta.id,
'realtime': realtime,
'title': exp.name,
Developer
New version with cards and status alerts
r11 }
# Logic to show my views
First version RTI, Spectra, Noise + Docker
r0 if plot == 'rti':
Plot's layout now can be updated
r5 kwargs['setup_form'] = RTISetupForm()
Juan C. Espinoza
New template, clean code, workig for realtime
r21 kwargs['fn_plot'] = 'PcolorBuffer'
kwargs['subtitle'] = 'RTI plot'
return render(request, 'plot.html', kwargs)
First version RTI, Spectra, Noise + Docker
r0 elif plot == 'spc':
Plot's layout now can be updated
r5 kwargs['setup_form'] = SPCSetupForm()
Juan C. Espinoza
New template, clean code, workig for realtime
r21 kwargs['fn_plot'] = 'Pcolor'
kwargs['subtitle'] = 'Spectra plot'
return render(request, 'plot.html', kwargs)
First version RTI, Spectra, Noise + Docker
r0 elif plot == 'noise':
Plot's layout now can be updated
r5 kwargs['setup_form'] = ScatterSetupForm()
Juan C. Espinoza
New template, clean code, workig for realtime
r21 kwargs['fn_plot'] = 'Scatter'
kwargs['subtitle'] = 'Noise plot'
return render(request, 'plot.html', kwargs)
First version RTI, Spectra, Noise + Docker
r0 else:
Developer
New version with cards and status alerts
r11 return render(request, 'home.html', {})