Package omeroweb :: Package webclient :: Package controller :: Module search
[hide private]
[frames] | no frames]

Source Code for Module omeroweb.webclient.controller.search

  1  #!/usr/bin/env python 
  2  #  
  3  #  
  4  #  
  5  # Copyright (c) 2008-2011 University of Dundee. 
  6  #  
  7  # This program is free software: you can redistribute it and/or modify 
  8  # it under the terms of the GNU Affero General Public License as 
  9  # published by the Free Software Foundation, either version 3 of the 
 10  # License, or (at your option) any later version. 
 11  #  
 12  # This program is distributed in the hope that it will be useful, 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 15  # GNU Affero General Public License for more details. 
 16  #  
 17  # You should have received a copy of the GNU Affero General Public License 
 18  # along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 19  #  
 20  # Author: Aleksandra Tarkowska <A(dot)Tarkowska(at)dundee(dot)ac(dot)uk>, 2008. 
 21  #  
 22  # Version: 1.0 
 23  # 
 24   
 25  import datetime 
 26  import time 
 27   
 28  from omero.rtypes import * 
 29  from webclient.controller import BaseController 
 30   
31 -class BaseSearch(BaseController):
32 33 images = None 34 projects = None 35 datasets = None 36 imgSize = 0 37 dsSize = 0 38 prSize = 0 39 40 c_size = 0 41
42 - def __init__(self, conn, **kw):
43 BaseController.__init__(self, conn) 44 self.eContext['breadcrumb'] = ['Search']
45
46 - def batch_search(self, query_list):
47 im_list = list() 48 well_list = list() 49 for (plate_name, row, column) in query_list: 50 row = int(row) 51 column = int(column) 52 well = self.conn.findWellInPlate(plate_name, row, column) 53 if well is not None: 54 well_list.append(well) 55 for well in well_list: 56 img=well.getWellSample().image() 57 im_list.append(img) 58 59 im_ids = [im.id for im in im_list] 60 im_annotation_counter = self.conn.getCollectionCount("Image", "annotationLinks", im_ids) 61 62 im_list_with_counters = list() 63 for im in im_list: 64 im.annotation_counter = im_annotation_counter.get(im.id) 65 im_list_with_counters.append(im) 66 67 self.containers = {'projects': list(), 'datasets': list(), 'images': im_list_with_counters, 'screens': list(), 'plates': list()} 68 self.c_size = len(im_list_with_counters)
69 70
71 - def search(self, query, onlyTypes, date=None):
72 created = None 73 if date is not None: 74 p = str(date).split('_') 75 # only for python 2.5 76 # d1 = datetime.strptime(p[0]+" 00:00:00", "%Y-%m-%d %H:%M:%S") 77 # d2 = datetime.strptime(p[1]+" 23:59:59", "%Y-%m-%d %H:%M:%S") 78 if len(p)>1: 79 d1 = datetime.datetime(*(time.strptime((p[0]+" 00:00:00"), "%Y-%m-%d %H:%M:%S")[0:6])) 80 d2 = datetime.datetime(*(time.strptime((p[1]+" 23:59:59"), "%Y-%m-%d %H:%M:%S")[0:6])) 81 82 created = [rtime(long(time.mktime(d1.timetuple())+1e-6*d1.microsecond)*1000), rtime(long(time.mktime(d2.timetuple())+1e-6*d2.microsecond)*1000)] 83 else: 84 d1 = datetime.datetime(*(time.strptime((p[0]+" 00:00:00"), "%Y-%m-%d %H:%M:%S")[0:6])) 85 86 pr_list_with_counters = list() 87 ds_list_with_counters = list() 88 im_list_with_counters = list() 89 sc_list_with_counters = list() 90 pl_list_with_counters = list() 91 for ot in onlyTypes: 92 if ot == 'images': 93 im_list = list(self.conn.searchObjects(["image"], query, created)) 94 95 im_ids = [im.id for im in im_list] 96 im_annotation_counter = self.conn.getCollectionCount("Image", "annotationLinks", im_ids) 97 98 im_list_with_counters = list() 99 for im in im_list: 100 im.annotation_counter = im_annotation_counter.get(im.id) 101 im_list_with_counters.append(im) 102 elif ot == 'datasets': 103 ds_list = list(self.conn.searchObjects(["Dataset"], query, created)) 104 105 ds_ids = [ds.id for ds in ds_list] 106 ds_annotation_counter = self.conn.getCollectionCount("Dataset", "annotationLinks", ds_ids) 107 108 ds_list_with_counters = list() 109 for ds in ds_list: 110 ds.annotation_counter = ds_annotation_counter.get(ds.id) 111 ds_list_with_counters.append(ds) 112 elif ot == 'projects': 113 pr_list = list(self.conn.searchObjects(["Project"], query, created)) 114 115 pr_ids = [pr.id for pr in pr_list] 116 pr_annotation_counter = self.conn.getCollectionCount("Project", "annotationLinks", pr_ids) 117 118 pr_list_with_counters = list() 119 for pr in pr_list: 120 pr.annotation_counter = pr_annotation_counter.get(pr.id) 121 pr_list_with_counters.append(pr) 122 elif ot == 'plates': 123 pl_list = list(self.conn.searchObjects(["Plate"], query, created)) 124 pl_ids = [pl.id for pl in pl_list] 125 pl_annotation_counter = self.conn.getCollectionCount("Plate", "annotationLinks", pl_ids) 126 127 pl_list_with_counters = list() 128 for pl in pl_list: 129 pl.annotation_counter = pl_annotation_counter.get(pl.id) 130 pl_list_with_counters.append(pl) 131 elif ot == 'screens': 132 sc_list = list(self.conn.searchObjects(["Screen"], query, created)) 133 134 sc_ids = [sc.id for sc in sc_list] 135 sc_annotation_counter = self.conn.getCollectionCount("Screen", "annotationLinks", sc_ids) 136 137 sc_list_with_counters = list() 138 for sc in sc_list: 139 sc.annotation_counter = sc_annotation_counter.get(sc.id) 140 sc_list_with_counters.append(sc) 141 142 self.containers={'projects': pr_list_with_counters, 'datasets': ds_list_with_counters, 'images': im_list_with_counters, 'screens': sc_list_with_counters, 'plates': pl_list_with_counters} 143 144 self.c_size = len(pr_list_with_counters)+len(ds_list_with_counters)+len(im_list_with_counters)+len(sc_list_with_counters)+len(pl_list_with_counters)
145