##// END OF EJS Templates
Add static images and fix template
Add static images and fix template

File last commit:

r45:08ba8fe1a748
r45:08ba8fe1a748
Show More
views.py
238 lines | 7.2 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 = {}
Add static images and fix template
r45 date = request.GET.get('date', datetime.now().strftime('%d-%m-%Y'))
Juan C. Espinoza
Test Version
r22 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
Juan C. Espinoza
Fix utc time handling
r44
t = time.time()
Juan C. Espinoza
Better navigation, sidebar, update jroplots #TODO OverJRO
r39
if (t-exp['last_time']) > 6*exp['interval']:
status = 'Offline'
clase = 'alertas-offline'
style = 'danger'
elif (t-exp['last_time']) > 3*exp['interval']:
status = 'Delayed'
clase = 'alertas-delayed'
style = 'warning'
else:
status = 'Online'
clase = 'alertas-online'
style = 'success'
dum['status'] = status
dum['class'] = clase
dum['style']= style
Juan C. Espinoza
Fix utc time handling
r44 dum['date']= datetime.fromtimestamp(exp['last_time'])
Juan C. Espinoza
Better navigation, sidebar, update jroplots #TODO OverJRO
r39 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
Juan C. Espinoza
Fix breadcrum in header
r43 kwargs['tag'] = tag
Juan C. Espinoza
Better navigation, sidebar, update jroplots #TODO OverJRO
r39
Juan C. Espinoza
Update new igp styles and templates, remove unused images
r41 kwargs['date'] = date
kwargs['title'] = 'Home'
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
Fix utc time handling
r44 'title': 'Tools',
'doy': (datetime.today().date()-datetime.today().date().replace(month=1, day=1)).days + 1
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:
Add static images and fix template
r45 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
Fix breadcrum in header
r43 tag = detail.tag.lower().strip() if detail.tag else 'other'
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
Update new igp styles and templates, remove unused images
r41 'title': 'Home',
Juan C. Espinoza
Better navigation, sidebar, update jroplots #TODO OverJRO
r39 'name' : exp.name,
'sidebar': True,
Juan C. Espinoza
Fix breadcrum in header
r43 'tag' : tag,
Juan C. Espinoza
Better navigation, sidebar, update jroplots #TODO OverJRO
r39 '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')
Add static images and fix template
r45 return response