Commit ebb3b8c2 authored by Maude Le Jeune's avatar Maude Le Jeune
Browse files

working pb search panel for stimulator

parent ef1e071c
......@@ -19,4 +19,3 @@ from tracker import *
from pipeline import *
from task import *
from environment import *
......@@ -17,7 +17,7 @@ try:
import sqlite3
except ImportError:
import pysqlite2 as sqlite3
import pickle
import cPickle as pickle
import os
import glob
import cherrypy
......@@ -34,16 +34,16 @@ class PBView(TreeView):
TreeView.__init__(self, db_file, name)
self.js_file += ["../static/pb.js"]
self.lst_mjd,self.lst_patch,self.lst_obs = self.get_mjd()
self.lst_obj = ['DataFolder', 'GainFolder', 'MapFolder', 'CoaddedMap', 'JKFolder']
self.lst_obj = []#'DataFolder', 'GainFolder', 'MapFolder', 'CoaddedMap', 'JKFolder']
def get_mjd (self):
conn = sqlite3.connect(self.db_file,check_same_thread=True)
conn.text_factory=str
ll = []
with conn:
l = conn.execute('select seg_id from segments where seg=?',("first",)).fetchall()
l = conn.execute('select seg_id from segments where seg like "unpack%"').fetchall()
for s in l:
ll += conn.execute('select input,str_input from tasks where seg_id=?',(s[0],)).fetchall()
ll += conn.execute('select input,str_input from tasks where seg_id=? and status="done"',(s[0],)).fetchall()
conn.close()
lst_mjd = []
lst_patch= []
......@@ -60,8 +60,24 @@ class PBView(TreeView):
lst_patch= list(set(lst_patch))
lst_dir = list(set(lst_dir))
return (lst_mjd,lst_patch, lst_dir)
@cherrypy.expose
@auth.pipeauth.read_access()
def get_folder (self, mjd):
conn = sqlite3.connect(self.db_file,check_same_thread=True)
conn.text_factory=str
with conn:
l = conn.execute('select seg_id from segments where seg="stimtau"').fetchall()
segid = l[0][0]
sqlr = 'select input,str_input from tasks where seg_id=%s and status="done" and input like "XXX%sXXX"'%(segid,mjd)
sqlr = sqlr.replace("XXX", "%")
l = conn.execute(sqlr).fetchall()
conn.close()
ll = ["stim"+str(pickle.loads(e[0]).values()[0][0]) for e in l]
self.lst_obs = ll
self.selected_mjd = mjd
raise cherrypy.HTTPRedirect('/'+self.name+'/',303)
def filter_panel (self, l):
""" Return an html string containing the filter panel
"""
......@@ -71,7 +87,7 @@ class PBView(TreeView):
html += '<table width="100%">'
## Object chkbox
html += '<tr valign="top" id="tr_obj_id" class="filter"> <td style="width:150px;"><input id="cb_obj" type="checkbox"/><label>Object type</label></td>'
html += '<tr valign="top" id="tr_obj_id" class="filter"> <td style="width:150px;"><input id="cb_obj" type="checkbox"/><label></label></td>'
## Object select
html += '<td style="width:50px;"><select id="se_obj_id">'
......@@ -80,17 +96,23 @@ class PBView(TreeView):
html += '</select></td>'
## Input chkbox
dd = dict({"mjd":(self.lst_mjd,"MJD"), "patch":(self.lst_patch,"Patch name"), "obs":(self.lst_obs, "Obs type")})
dd = dict({"mjd":(self.lst_mjd,"mjd"), "patch":(self.lst_patch,"patchname"), "folder":(self.lst_obs, "folder")})
for k,v in dd.iteritems():
html += '<tr valign="top" id="tr_id" class="filter"> <td style="width:150px;"><input id="cb_%s" type="checkbox"/><label>%s</label></td>'%(k,v[1])
html += '<td style="width:50px;"><select id="se_%s_id">'%k
if k=='mjd':
html += '<td style="width:50px;"><select id="se_%s_id" onchange=javascript:updatemjd();>'%k
else:
html += '<td style="width:50px;"><select id="se_%s_id">'%k
for t in v[0]:
html +='<option value="%s">%s</option>'%(t, t)
if hasattr(self, 'selected_mjd') and k=="mjd":
html +='<option selected value="%s">%s</option>'%(self.selected_mjd, self.selected_mjd)
html += '</select></td>'
## Buttons
html += '<td class="buttons">'
html += '<a class="icon apply" href="javascript:search();"><small>Apply</small></a>'%()
html += '<a class="icon apply" href="javascript:ssearch();"><small>Apply</small></a>'
html += '</td><tr></tr></table>'
html += '</fieldset></div>'
......@@ -98,34 +120,52 @@ class PBView(TreeView):
@cherrypy.expose
@auth.pipeauth.read_access()
def search(self , mjd=None, obs=None, patch=None,obj=None):
def search(self , mjd=None, folder=None, patch=None,obj=None):
"""
"""
dd = dict({'DataFolder':"first", 'GainFolder':"second", 'MapFolder':"third", 'CoaddedMap':"fourth", 'JKFolder':"first"})
html = self.get_html_refresh() + '<a class="icon home" href="../%s/"><small>Home</small></a>'%(self.name)
html += '<h1> Data products in segment %s (%s) </h1>' % (dd[obj], obj)
import cPickle as pickle
conn = sqlite3.connect(self.db_file,check_same_thread=True)
conn.text_factory=str
ll = []
with conn:
l = conn.execute('select seg_id,curr_dir from segments where seg=?',(dd[obj],)).fetchall()
for s in l:
currdir = s[1]
html += '<div class="list"><p>Directory : %s</p> <br><br> '%( currdir)
ll = conn.execute('select str_input from tasks where seg_id=?',(s[0],)).fetchall()
r = os.path.relpath(ll[0][0], currdir)
currdir=ll[0][0].replace(r,'')
sss = ''.join(['<li><a href="pipedir?segid=%s&directory=%s"> %s </a></li>'%(s[0],e[0].replace(currdir,''),e[0]) for e in ll])
html += sss + '</ul></div>'
conn.close()
html += '</body></html>'
if folder != "None" and mjd != "None":
foldernum = int(folder.replace("stim", ""))
with conn:
l = conn.execute('select seg_id,curr_dir from segments where seg=?',("stimtau",)).fetchall()
segid = l[0][0]
currdir = l[0][1]
sqlr = 'select str_input,task_id from tasks where seg_id="%s" and status="done" and input like "XXX%sXXX%sXXX"'%(segid,pickle.dumps(foldernum)[:-1], mjd)
sqlr = sqlr.replace("XXX", "%")
l = conn.execute(sqlr).fetchall()
conn.close()
r = os.path.relpath(l[0][0], currdir)
directory = r.replace("../",'')
html = self.pipedir(segid=segid, directory=directory)
# elif folder =="None" and mjd != "None":
# with conn:
# l = conn.execute('select seg_id,curr_dir from segments where seg=?',("unpack_obs_stimulator",)).fetchall()
# segid = l[0][0]
# currdir = l[0][1]
# sqlr = 'select str_input,task_id from tasks where seg_id="%s" and status="done" and input like "XXX%sXXX"'%(segid,mjd)
# sqlr = sqlr.replace("XXX", "%")
# l = conn.execute(sqlr).fetchall()
# conn.close()
# r = os.path.relpath(l[0][0], currdir)
# directory = r.replace("../",'')
# html = self.pipedir(segid=segid, directory=directory)
else:
with conn:
l = conn.execute('select seg_id,curr_dir from segments where seg=?',("gatherstim",)).fetchall()
segid = l[0][0]
currdir = l[0][1]
sqlr = 'select str_input from tasks where seg_id="%s" and status="done"'%(segid)
l = conn.execute(sqlr).fetchall()
conn.close()
r = os.path.relpath(l[0][0], currdir)
directory = r.replace("../",'')
html = self.pipedir(segid=segid, directory=directory)
##html = self.pipedir(segid=None, directory=None)
return html
// Copyright (C) 2008, 2009, 2010 APC LPNHE CNRS Universite Paris Diderot <lejeune@apc.univ-paris7.fr> <betoule@apc.univ-paris7.fr>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see http://www.gnu.org/licenses/gpl.html
// filter pipelines
function ssearch(){
var cb1 = document.getElementById('cb_mjd') ;
var is1 = cb1.checked;
var mjd = "None";
if (is1)
{
var seltag = document.getElementById('se_mjd_id') ;
mjd = seltag.options[seltag.selectedIndex].text;
}
var cb2 = document.getElementById('cb_folder') ;
var is2 = cb2.checked;
var folder = "None";
if (is2)
{
var seldate = document.getElementById('se_folder_id') ;
folder = seldate.options[seldate.selectedIndex].text;
}
var url = "search?mjd="+mjd+"&folder="+folder;
//var url = "blala";
self.location.href=url;
}
function updatemjd () {
var seltag = document.getElementById('se_mjd_id') ;
var mjd = seltag.options[seltag.selectedIndex].text;
self.location.href="get_folder?mjd="+mjd;
}
......@@ -91,37 +91,26 @@ function del_prod(segid) {
}
self.location.href=url;
}
// filter pipelines
function filter(){
var recursive= document.getElementById('cb_rec').checked;
var cbtag = document.getElementById('cb_tag') ;
var istag = cbtag.checked;
var tag = "None"
if (istag)
{
var seltag = document.getElementById('se_tag_id') ;
tag = seltag.options[seltag.selectedIndex].text;
}
var cbdate = document.getElementById('cb_date') ;
var isdate = cbdate.checked;
var date = "None"
if (isdate)
var cbtag = document.getElementById('cb_tag') ;
var istag = cbtag.checked;
var tag = "None"
if (istag)
{
var seldate = document.getElementById('se_date_id') ;
date = seldate.options[seldate.selectedIndex].text;
var seltag = document.getElementById('se_tag_id') ;
tag = seltag.options[seltag.selectedIndex].text;
}
var url = "filter?tag="+tag+"&date="+date;
var cbseg = document.getElementById('cb_seg') ;
var isseg = cbseg.checked;
var seg = "None"
if (isseg)
var cbdate = document.getElementById('cb_date') ;
var isdate = cbdate.checked;
var date = "None"
if (isdate)
{
var selseg = document.getElementById('se_seg_id') ;
seg = selseg.options[selseg.selectedIndex].text;
url = "filter?seg="+seg;
var seldate = document.getElementById('se_date_id') ;
date = seldate.options[seldate.selectedIndex].text;
}
url = url+'&recursive='+recursive;
self.location.href=url;
var url = "filter?tag="+tag+"&date="+date;
self.location.href=url;
}
......@@ -188,7 +188,7 @@ class TreeView:
html += '</select></td>'
## rec button
html += '<td style="width:100px;"><input id="cb_rec" type="checkbox" checked="checked"/><label>Recursive</label></td>'
#html += '<td style="width:100px;"><input id="cb_rec" type="checkbox" checked="checked"/><label>Recursive</label></td>'
str_lst_tag = "\\n"
for t in lst_tag:
......@@ -202,18 +202,6 @@ class TreeView:
log_dir = os.path.isdir(os.path.join(last_dir, "log"))
log_dir = os.path.join(last_dir, "log")
## segment checkbox
html += '<tr valign="top" id="tr_seg_id" class="filter"> <td style="width:100px;"><input id="cb_seg" type="checkbox"/><label>Segment</label></td>'
## Date select
lst_seg = get_lst_seg(self.db_file)
html += '<td style="width:150px;"><select id="se_seg_id">'
for t in lst_seg:
html +='<option value="%s">%s</option>'%(t, t)
html += '</select></td>'
## Buttons
html += '<tr></tr>'
html += '</table>'
......@@ -467,7 +455,7 @@ class TreeView:
directory: string pipeline directory path.
"""
directory = self.check_path (segid, directory)
html = self.reg_html_refresh() + '<a class="icon home" href="../%s/"><small>Home</small></a>'%(self.name)
html = self.get_html_refresh() + '<a class="icon home" href="../%s/"><small>Home</small></a>'%(self.name)
html += '<h1> Content of %s </h1> <div class="list"><ul>'%directory
lstfile = (glob(os.path.join(directory,'*')))
imglist = []
......
......@@ -47,12 +47,13 @@ class PipeIndex():
""" Initialize the Web interface.
"""
## list of pipelines
import new
self.pipelist = []
if self.get_config(cherrypy.config['config_file']):
for pipe, dbfile in self.get_config(cherrypy.config['config_file']).iteritems():
self.pipelist.append(pipe)
view = self.which_view(cherrypy.config['config_file'], pipe)
setattr(self, pipe, view(os.path.expanduser(dbfile),pipe))
self.pipelist.append(pipe)
def which_view(self, config_file, pipe):
"""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment