|
|
# -*- coding: utf-8 -*-
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
import os
|
|
|
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
|
|
|
|
|
|
from bootstrap3_datetime.widgets import DateTimePicker
|
|
|
|
|
|
import mongoengine
|
|
|
|
|
|
from plotter.models import Experiment, ExpMeta
|
|
|
|
|
|
host = os.environ.get('HOST_MONGO', 'localhost')
|
|
|
mongoengine.connect('dbplots', host=host, port=27017)
|
|
|
|
|
|
# Forms
|
|
|
class SearchForm(forms.Form):
|
|
|
|
|
|
experiment = forms.ChoiceField()
|
|
|
plot = forms.ChoiceField(
|
|
|
choices = [(0, 'Select Plot'), ('rti', 'RTI'),('spc', 'Spectra'),('noise', 'Noise')]
|
|
|
)
|
|
|
date = forms.DateField(
|
|
|
widget=DateTimePicker(options={"format": "DD/MM/YYYY"})
|
|
|
)
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
|
|
exp_choices = kwargs.pop('exp_choices', [])
|
|
|
super(SearchForm, self).__init__(*args, **kwargs)
|
|
|
self.fields['experiment'].choices = [(0, 'Select Experiment')] + exp_choices
|
|
|
|
|
|
# Create your views here.
|
|
|
def main(request, code=None, plot=None):
|
|
|
|
|
|
initial = {}
|
|
|
date = request.GET.get('date', datetime.now().strftime('%d/%m/%Y'))
|
|
|
initial['date'] = date
|
|
|
|
|
|
if code is not None:
|
|
|
initial['experiment'] = code
|
|
|
if plot is not None:
|
|
|
initial['plot'] = plot
|
|
|
|
|
|
exps = [(q['code'], q['name']) for q in Experiment.objects.all()]
|
|
|
|
|
|
form = SearchForm(
|
|
|
initial = initial,
|
|
|
exp_choices = [(e[0], e[1]) for e in exps]
|
|
|
)
|
|
|
|
|
|
try:
|
|
|
exp = ExpMeta.objects.get(code=int(code), date=datetime.strptime(date, '%d/%m/%Y'))
|
|
|
exp_id = exp.id
|
|
|
except:
|
|
|
exp_id = 0
|
|
|
|
|
|
|
|
|
kwargs = {
|
|
|
'code': code,
|
|
|
'plot': plot,
|
|
|
'date': date,
|
|
|
'form': form,
|
|
|
'id': exp_id
|
|
|
}
|
|
|
|
|
|
if code and exps:
|
|
|
kwargs['title'] = [t[1] for t in exps if t[0]==int(code)][0]
|
|
|
else:
|
|
|
kwargs['title'] = 'JRO'
|
|
|
|
|
|
if plot == 'rti':
|
|
|
return render(request, 'rti.html', kwargs)
|
|
|
elif plot == 'spc':
|
|
|
return render(request, 'spectra.html', kwargs)
|
|
|
elif plot == 'noise':
|
|
|
return render(request, 'scatter.html', kwargs)
|
|
|
else:
|
|
|
return render(request, 'base.html', kwargs)
|