##// END OF EJS Templates
Remove test button
Remove test button

File last commit:

r39:b80dda8fb07c
r40:be0b5b84adad
Show More
views.py
239 lines | 7.3 KiB | text/x-python | PythonLexer
Developer
New version with cards and status alerts
r11 #!/usr/bin/python
# -*- coding: UTF-8 -*-
Juan C. Espinoza
Test Version
r22
First version RTI, Spectra, Noise + Docker
r0
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
Juan C. Espinoza
Add skynoise with python
r30 from django.http import HttpResponse
First version RTI, Spectra, Noise + Docker
r0
Reorganize models, smaller docker, others
r2 import mongoengine
First version RTI, Spectra, Noise + Docker
r0
Juan C. Espinoza
Test Version
r22 from plotter.models import Experiment, ExpDetail, PlotMeta, PlotData
Juan C. Espinoza
Docker working
r1
Juan C. Espinoza
Add skynoise with python
r30 from utils.plots import skynoise_plot
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.
Juan C. Espinoza
Better navigation, sidebar, update jroplots #TODO OverJRO
r39 def main(request, tag=None):
First version RTI, Spectra, Noise + Docker
r0
App only for realtime
r4 kwargs = {}
Juan C. Espinoza
Test Version
r22 date = request.GET.get('date', datetime.now().strftime('%d-%m-%Y'))
exps = ExpDetail.objects(date=datetime.strptime(date, '%d-%m-%Y'))
Developer
New version with cards and status alerts
r11
Juan C. Espinoza
Better navigation, sidebar, update jroplots #TODO OverJRO
r39 tmp = {}
Developer
New version with cards and status alerts
r11 for exp in exps:
Juan C. Espinoza
Better navigation, sidebar, update jroplots #TODO OverJRO
r39 label = exp.tag.lower().strip() if exp.tag else 'other'
if label in tmp:
tmp[label] += 1
else:
tmp[label] = 1
tags = []
for key, value in tmp.items():
if tag == key:
tags.append({'name': key, 'n': tmp[key], 'active': 'active'})
Developer
New version with cards and status alerts
r11 else:
Juan C. Espinoza
Better navigation, sidebar, update jroplots #TODO OverJRO
r39 tags.append({'name': key, 'n': tmp[key]})
kwargs['tags'] = tags
App only for realtime
r4
Juan C. Espinoza
Better navigation, sidebar, update jroplots #TODO OverJRO
r39 if tag:
experiments = []
for exp in exps:
label = exp.tag.lower().strip() if exp.tag else 'other'
if label != tag:
continue
dum = {}
dum['code'] = exp.experiment.code
dum['plots'] = []
dum['name'] = exp.experiment.name
dt = datetime.now()
t = time.mktime(dt.timetuple())
t -= 5*60*60
if (t-exp['last_time']) > 6*exp['interval']:
status = 'Offline'
clase = 'alertas-offline'
style = 'danger'
lastDataDate = exp['last_time']
elif (t-exp['last_time']) > 3*exp['interval']:
status = 'Delayed'
clase = 'alertas-delayed'
style = 'warning'
lastDataDate = exp['last_time']
else:
status = 'Online'
clase = 'alertas-online'
style = 'success'
lastDataDate = exp['last_time']
dum['status'] = status
dum['class'] = clase
dum['style']= style
dum['date']= datetime.utcfromtimestamp(lastDataDate)
for plot in exp.plots():
dum['plots'].append({'plot': plot.plot, 'name': plot.plot.replace('_', ' ').title(), 'id':plot.id})
experiments.append(dum)
kwargs['experiments'] = experiments
App only for realtime
r4 kwargs['date'] = date
Juan C. Espinoza
Better navigation, sidebar, update jroplots #TODO OverJRO
r39
Juan C. Espinoza
Work with static images, fix styles, fix default values in forms
r36 kwargs['title'] = 'Realtime Experiments at JRO'
Juan C. Espinoza
Better navigation, sidebar, update jroplots #TODO OverJRO
r39 kwargs['sidebar'] = True
Developer
New version with cards and status alerts
r11
return render(request, 'home.html', kwargs)
Juan C. Espinoza
Update templates
r35 def about(request):
'''
'''
kwargs = {
'title': 'About'
}
Juan C. Espinoza
Work with static images, fix styles, fix default values in forms
r36 return render(request, 'about.html', kwargs)
Juan C. Espinoza
Update templates
r35
Juan C. Espinoza
Styles and templates updated
r25 def tools(request):
'''
'''
kwargs = {
Juan C. Espinoza
Update templates
r35 'title': 'Tools'
Juan C. Espinoza
Styles and templates updated
r25 }
return render(request, 'tools.html', kwargs)
def reports(request):
'''
'''
kwargs = {
Juan C. Espinoza
Update templates
r35 'title': 'Reports',
Juan C. Espinoza
Styles and templates updated
r25 }
return render(request, 'reports.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:
Juan C. Espinoza
Test Version
r22 date = datetime.now().strftime('%d-%m-%Y')
Juan C. Espinoza
New template, clean code, workig for realtime
r21 realtime = True
exp = Experiment.objects.get(code=int(code))
Juan C. Espinoza
Test Version
r22 detail = ExpDetail.objects.get(experiment=exp, date=datetime.strptime(date, '%d-%m-%Y'))
meta = PlotMeta.objects.get(exp_detail=detail, plot=plot)
Juan C. Espinoza
Better navigation, sidebar, update jroplots #TODO OverJRO
r39
Developer
New version with cards and status alerts
r11 kwargs = {
'code': code,
'plot': plot,
Juan C. Espinoza
Test version ready
r27 'meta':meta,
Developer
New version with cards and status alerts
r11 'date': date,
Juan C. Espinoza
Test Version
r22 'id': meta.pk,
Juan C. Espinoza
New template, clean code, workig for realtime
r21 'realtime': realtime,
Juan C. Espinoza
Better navigation, sidebar, update jroplots #TODO OverJRO
r39 'title': 'Realtime Experiments at JRO',
'name' : exp.name,
'sidebar': True,
'plots': []
Developer
New version with cards and status alerts
r11 }
Juan C. Espinoza
Better navigation, sidebar, update jroplots #TODO OverJRO
r39
for plt in detail.plots():
kwargs['plots'].append({'plot': plt.plot, 'name': plt.plot.replace('_', ' ').title()})
Developer
New version with cards and status alerts
r11 # Logic to show my views
Juan C. Espinoza
Test version ready
r27 if meta.metadata['type'] == 'pcolorbuffer':
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'
return render(request, 'plot.html', kwargs)
Juan C. Espinoza
Test version ready
r27 elif meta.metadata['type'] == 'pcolor':
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'
return render(request, 'plot.html', kwargs)
Juan C. Espinoza
Update jroplots.js
r31 elif meta.metadata['type'] == 'scatterbuffer':
Plot's layout now can be updated
r5 kwargs['setup_form'] = ScatterSetupForm()
Juan C. Espinoza
Update jroplots.js
r31 kwargs['fn_plot'] = 'ScatterBuffer'
Juan C. Espinoza
New template, clean code, workig for realtime
r21 return render(request, 'plot.html', kwargs)
Juan C. Espinoza
Work with static images, fix styles, fix default values in forms
r36 elif meta.metadata['type'] == 'image':
kwargs['image'] = True
kwargs['fn_plot'] = 'StaticPlot'
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', {})
Juan C. Espinoza
Add skynoise with python
r30 def plot_skynoise(request):
date = request.GET.get('date', None)
if date is None:
date = datetime.now()
else:
Juan C. Espinoza
Better navigation, sidebar, update jroplots #TODO OverJRO
r39 date = datetime.strptime(date, '%Y-%m-%d')
Juan C. Espinoza
Add skynoise with python
r30
data = skynoise_plot(date.year, date.month, date.day)
response = HttpResponse(data.getvalue(), content_type='image/png')
Juan C. Espinoza
Update jroplots.js
r31
Juan C. Espinoza
Add skynoise with python
r30 return response
Juan C. Espinoza
Better navigation, sidebar, update jroplots #TODO OverJRO
r39
def plot_overjro(request):
date = request.GET.get('date', None)
if date is None:
date = datetime.now()
else:
date = datetime.strptime(date, '%Y-%m-%d')
data = skynoise_plot(date.year, date.month, date.day)
response = HttpResponse(data.getvalue(), content_type='image/png')
return response