This diff has been collapsed as it changes many lines, (609 lines changed) Show them Hide them | |||||
@@ -0,0 +1,609 | |||||
|
1 | ''' | |||
|
2 | Created on September , 2012 | |||
|
3 | @author: | |||
|
4 | ''' | |||
|
5 | from xml.etree.ElementTree import Element, SubElement, ElementTree | |||
|
6 | from xml.etree import ElementTree as ET | |||
|
7 | from xml.dom import minidom | |||
|
8 | ||||
|
9 | import sys | |||
|
10 | import datetime | |||
|
11 | from model.jrodataIO import * | |||
|
12 | from model.jroprocessing import * | |||
|
13 | ||||
|
14 | def prettify(elem): | |||
|
15 | """Return a pretty-printed XML string for the Element. | |||
|
16 | """ | |||
|
17 | rough_string = ET.tostring(elem, 'utf-8') | |||
|
18 | reparsed = minidom.parseString(rough_string) | |||
|
19 | return reparsed.toprettyxml(indent=" ") | |||
|
20 | ||||
|
21 | class ParameterConf(): | |||
|
22 | ||||
|
23 | id = None | |||
|
24 | name = None | |||
|
25 | value = None | |||
|
26 | type = None | |||
|
27 | ||||
|
28 | ELEMENTNAME = 'Parameter' | |||
|
29 | ||||
|
30 | def __init__(self): | |||
|
31 | ||||
|
32 | self.type = 'str' | |||
|
33 | ||||
|
34 | def getElementName(self): | |||
|
35 | ||||
|
36 | return self.ELEMENTNAME | |||
|
37 | ||||
|
38 | def getValue(self): | |||
|
39 | ||||
|
40 | if self.type == 'list': | |||
|
41 | strList = self.value.split(',') | |||
|
42 | return strList | |||
|
43 | ||||
|
44 | if self.type == 'intlist': | |||
|
45 | strList = self.value.split(',') | |||
|
46 | intList = [int(x) for x in strList] | |||
|
47 | return intList | |||
|
48 | ||||
|
49 | if self.type == 'floatlist': | |||
|
50 | strList = self.value.split(',') | |||
|
51 | floatList = [float(x) for x in strList] | |||
|
52 | return floatList | |||
|
53 | ||||
|
54 | if self.type == 'date': | |||
|
55 | strList = self.value.split('/') | |||
|
56 | intList = [int(x) for x in strList] | |||
|
57 | date = datetime.date(intList[0], intList[1], intList[2]) | |||
|
58 | return date | |||
|
59 | ||||
|
60 | if self.type == 'time': | |||
|
61 | strList = self.value.split(':') | |||
|
62 | intList = [int(x) for x in strList] | |||
|
63 | time = datetime.time(intList[0], intList[1], intList[2]) | |||
|
64 | return time | |||
|
65 | ||||
|
66 | func = eval(self.type) | |||
|
67 | ||||
|
68 | return func(self.value) | |||
|
69 | ||||
|
70 | def setup(self, id, name, value, type='str'): | |||
|
71 | ||||
|
72 | self.id = id | |||
|
73 | self.name = name | |||
|
74 | self.value = str(value) | |||
|
75 | self.type = type | |||
|
76 | ||||
|
77 | def makeXml(self, opElement): | |||
|
78 | ||||
|
79 | parmElement = SubElement(opElement, self.ELEMENTNAME) | |||
|
80 | parmElement.set('id', str(self.id)) | |||
|
81 | parmElement.set('name', self.name) | |||
|
82 | parmElement.set('value', self.value) | |||
|
83 | parmElement.set('type', self.type) | |||
|
84 | ||||
|
85 | def readXml(self, parmElement): | |||
|
86 | ||||
|
87 | self.id = parmElement.get('id') | |||
|
88 | self.name = parmElement.get('name') | |||
|
89 | self.value = parmElement.get('value') | |||
|
90 | self.type = parmElement.get('type') | |||
|
91 | ||||
|
92 | def printattr(self): | |||
|
93 | ||||
|
94 | print "Parameter[%s]: name = %s, value = %s, type = %s" %(self.id, self.name, self.value, self.type) | |||
|
95 | ||||
|
96 | class OperationConf(): | |||
|
97 | ||||
|
98 | id = None | |||
|
99 | name = None | |||
|
100 | priority = None | |||
|
101 | type = None | |||
|
102 | ||||
|
103 | parmConfObjList = [] | |||
|
104 | ||||
|
105 | ELEMENTNAME = 'Operation' | |||
|
106 | ||||
|
107 | def __init__(self): | |||
|
108 | ||||
|
109 | id = 0 | |||
|
110 | name = None | |||
|
111 | priority = None | |||
|
112 | type = 'self' | |||
|
113 | ||||
|
114 | ||||
|
115 | def __getNewId(self): | |||
|
116 | ||||
|
117 | return int(self.id)*10 + len(self.parmConfObjList) + 1 | |||
|
118 | ||||
|
119 | def getElementName(self): | |||
|
120 | ||||
|
121 | return self.ELEMENTNAME | |||
|
122 | ||||
|
123 | def getParameterObjList(self): | |||
|
124 | ||||
|
125 | return self.parmConfObjList | |||
|
126 | ||||
|
127 | def setup(self, id, name, priority, type): | |||
|
128 | ||||
|
129 | self.id = id | |||
|
130 | self.name = name | |||
|
131 | self.type = type | |||
|
132 | self.priority = priority | |||
|
133 | ||||
|
134 | self.parmConfObjList = [] | |||
|
135 | ||||
|
136 | def addParameter(self, name, value, type='str'): | |||
|
137 | ||||
|
138 | id = self.__getNewId() | |||
|
139 | ||||
|
140 | parmConfObj = ParameterConf() | |||
|
141 | parmConfObj.setup(id, name, value, type) | |||
|
142 | ||||
|
143 | self.parmConfObjList.append(parmConfObj) | |||
|
144 | ||||
|
145 | return parmConfObj | |||
|
146 | ||||
|
147 | def makeXml(self, upElement): | |||
|
148 | ||||
|
149 | opElement = SubElement(upElement, self.ELEMENTNAME) | |||
|
150 | opElement.set('id', str(self.id)) | |||
|
151 | opElement.set('name', self.name) | |||
|
152 | opElement.set('type', self.type) | |||
|
153 | opElement.set('priority', str(self.priority)) | |||
|
154 | ||||
|
155 | for parmConfObj in self.parmConfObjList: | |||
|
156 | parmConfObj.makeXml(opElement) | |||
|
157 | ||||
|
158 | def readXml(self, opElement): | |||
|
159 | ||||
|
160 | self.id = opElement.get('id') | |||
|
161 | self.name = opElement.get('name') | |||
|
162 | self.type = opElement.get('type') | |||
|
163 | self.priority = opElement.get('priority') | |||
|
164 | ||||
|
165 | self.parmConfObjList = [] | |||
|
166 | ||||
|
167 | parmElementList = opElement.getiterator(ParameterConf().getElementName()) | |||
|
168 | ||||
|
169 | for parmElement in parmElementList: | |||
|
170 | parmConfObj = ParameterConf() | |||
|
171 | parmConfObj.readXml(parmElement) | |||
|
172 | self.parmConfObjList.append(parmConfObj) | |||
|
173 | ||||
|
174 | def printattr(self): | |||
|
175 | ||||
|
176 | print "%s[%s]: name = %s, type = %s, priority = %s" %(self.ELEMENTNAME, | |||
|
177 | self.id, | |||
|
178 | self.name, | |||
|
179 | self.type, | |||
|
180 | self.priority) | |||
|
181 | ||||
|
182 | for parmConfObj in self.parmConfObjList: | |||
|
183 | parmConfObj.printattr() | |||
|
184 | ||||
|
185 | def createObject(self): | |||
|
186 | ||||
|
187 | if self.type == 'self': | |||
|
188 | raise ValueError, "This operation type cannot be created" | |||
|
189 | ||||
|
190 | if self.type == 'other': | |||
|
191 | className = eval(self.name) | |||
|
192 | opObj = className() | |||
|
193 | ||||
|
194 | return opObj | |||
|
195 | ||||
|
196 | class ProcUnitConf(): | |||
|
197 | ||||
|
198 | id = None | |||
|
199 | name = None | |||
|
200 | type = None | |||
|
201 | inputId = None | |||
|
202 | ||||
|
203 | opConfObjList = [] | |||
|
204 | ||||
|
205 | procUnitObj = None | |||
|
206 | opObjList = [] | |||
|
207 | ||||
|
208 | ELEMENTNAME = 'ProcUnit' | |||
|
209 | ||||
|
210 | def __init__(self): | |||
|
211 | ||||
|
212 | self.id = None | |||
|
213 | self.type = None | |||
|
214 | self.name = None | |||
|
215 | self.inputId = None | |||
|
216 | ||||
|
217 | self.opConfObjList = [] | |||
|
218 | ||||
|
219 | self.procUnitObj = None | |||
|
220 | self.opObjDict = {} | |||
|
221 | ||||
|
222 | def __getPriority(self): | |||
|
223 | ||||
|
224 | return len(self.opConfObjList)+1 | |||
|
225 | ||||
|
226 | def __getNewId(self): | |||
|
227 | ||||
|
228 | return int(self.id)*10 + len(self.opConfObjList) + 1 | |||
|
229 | ||||
|
230 | def getElementName(self): | |||
|
231 | ||||
|
232 | return self.ELEMENTNAME | |||
|
233 | ||||
|
234 | def getId(self): | |||
|
235 | ||||
|
236 | return str(self.id) | |||
|
237 | ||||
|
238 | def getInputId(self): | |||
|
239 | ||||
|
240 | return str(self.inputId) | |||
|
241 | ||||
|
242 | def getOperationObjList(self): | |||
|
243 | ||||
|
244 | return self.opConfObjList | |||
|
245 | ||||
|
246 | def getProcUnitObj(self): | |||
|
247 | ||||
|
248 | return self.procUnitObj | |||
|
249 | ||||
|
250 | def setup(self, id, name, type, inputId): | |||
|
251 | ||||
|
252 | self.id = id | |||
|
253 | self.name = name | |||
|
254 | self.type = type | |||
|
255 | self.inputId = inputId | |||
|
256 | ||||
|
257 | self.opConfObjList = [] | |||
|
258 | ||||
|
259 | self.addOperation(name='init', optype='self') | |||
|
260 | ||||
|
261 | def addOperation(self, name, optype='self'): | |||
|
262 | ||||
|
263 | id = self.__getNewId() | |||
|
264 | priority = self.__getPriority() | |||
|
265 | ||||
|
266 | opConfObj = OperationConf() | |||
|
267 | opConfObj.setup(id, name=name, priority=priority, type=optype) | |||
|
268 | ||||
|
269 | self.opConfObjList.append(opConfObj) | |||
|
270 | ||||
|
271 | return opConfObj | |||
|
272 | ||||
|
273 | def makeXml(self, procUnitElement): | |||
|
274 | ||||
|
275 | upElement = SubElement(procUnitElement, self.ELEMENTNAME) | |||
|
276 | upElement.set('id', str(self.id)) | |||
|
277 | upElement.set('name', self.name) | |||
|
278 | upElement.set('type', self.type) | |||
|
279 | upElement.set('inputId', str(self.inputId)) | |||
|
280 | ||||
|
281 | for opConfObj in self.opConfObjList: | |||
|
282 | opConfObj.makeXml(upElement) | |||
|
283 | ||||
|
284 | def readXml(self, upElement): | |||
|
285 | ||||
|
286 | self.id = upElement.get('id') | |||
|
287 | self.name = upElement.get('name') | |||
|
288 | self.type = upElement.get('type') | |||
|
289 | self.inputId = upElement.get('inputId') | |||
|
290 | ||||
|
291 | self.opConfObjList = [] | |||
|
292 | ||||
|
293 | opElementList = upElement.getiterator(OperationConf().getElementName()) | |||
|
294 | ||||
|
295 | for opElement in opElementList: | |||
|
296 | opConfObj = OperationConf() | |||
|
297 | opConfObj.readXml(opElement) | |||
|
298 | self.opConfObjList.append(opConfObj) | |||
|
299 | ||||
|
300 | def printattr(self): | |||
|
301 | ||||
|
302 | print "%s[%s]: name = %s, type = %s, inputId = %s" %(self.ELEMENTNAME, | |||
|
303 | self.id, | |||
|
304 | self.name, | |||
|
305 | self.type, | |||
|
306 | self.inputId) | |||
|
307 | ||||
|
308 | for opConfObj in self.opConfObjList: | |||
|
309 | opConfObj.printattr() | |||
|
310 | ||||
|
311 | def createObjects(self): | |||
|
312 | ||||
|
313 | className = eval(self.name) | |||
|
314 | procUnitObj = className() | |||
|
315 | ||||
|
316 | for opConfObj in self.opConfObjList: | |||
|
317 | ||||
|
318 | if opConfObj.type == 'self': | |||
|
319 | continue | |||
|
320 | ||||
|
321 | opObj = opConfObj.createObject() | |||
|
322 | ||||
|
323 | self.opObjDict[opConfObj.id] = opObj | |||
|
324 | procUnitObj.addOperation(opObj, opConfObj.id) | |||
|
325 | ||||
|
326 | self.procUnitObj = procUnitObj | |||
|
327 | ||||
|
328 | return procUnitObj | |||
|
329 | ||||
|
330 | def run(self): | |||
|
331 | ||||
|
332 | for opConfObj in self.opConfObjList: | |||
|
333 | kwargs = {} | |||
|
334 | for parmConfObj in opConfObj.getParameterObjList(): | |||
|
335 | kwargs[parmConfObj.name] = parmConfObj.getValue() | |||
|
336 | ||||
|
337 | self.procUnitObj.call(opConfObj, **kwargs) | |||
|
338 | ||||
|
339 | ||||
|
340 | ||||
|
341 | class ReadUnitConf(ProcUnitConf): | |||
|
342 | ||||
|
343 | ||||
|
344 | path = None | |||
|
345 | startDate = None | |||
|
346 | endDate = None | |||
|
347 | startTime = None | |||
|
348 | endTime = None | |||
|
349 | online = None | |||
|
350 | expLabel = None | |||
|
351 | delay = None | |||
|
352 | ||||
|
353 | ELEMENTNAME = 'ReadUnit' | |||
|
354 | ||||
|
355 | def __init__(self): | |||
|
356 | ||||
|
357 | self.id = None | |||
|
358 | self.type = None | |||
|
359 | self.name = None | |||
|
360 | self.inputId = 0 | |||
|
361 | ||||
|
362 | self.opConfObjList = [] | |||
|
363 | self.opObjList = [] | |||
|
364 | ||||
|
365 | def getElementName(self): | |||
|
366 | ||||
|
367 | return self.ELEMENTNAME | |||
|
368 | ||||
|
369 | def setup(self, id, name, type, path, startDate, endDate, startTime, endTime, online=0, expLabel='', delay=60): | |||
|
370 | ||||
|
371 | self.id = id | |||
|
372 | self.name = name | |||
|
373 | self.type = type | |||
|
374 | ||||
|
375 | self.path = path | |||
|
376 | self.startDate = startDate | |||
|
377 | self.endDate = endDate | |||
|
378 | self.startTime = startTime | |||
|
379 | self.endTime = endTime | |||
|
380 | self.online = online | |||
|
381 | self.expLabel = expLabel | |||
|
382 | self.delay = delay | |||
|
383 | ||||
|
384 | self.addRunOperation() | |||
|
385 | ||||
|
386 | def addRunOperation(self): | |||
|
387 | ||||
|
388 | opObj = self.addOperation(name = 'run', optype = 'self') | |||
|
389 | ||||
|
390 | opObj.addParameter(name='path' , value=self.path, type='str') | |||
|
391 | opObj.addParameter(name='startDate' , value=self.startDate, type='date') | |||
|
392 | opObj.addParameter(name='endDate' , value=self.endDate, type='date') | |||
|
393 | opObj.addParameter(name='startTime' , value=self.startTime, type='time') | |||
|
394 | opObj.addParameter(name='endTime' , value=self.endTime, type='time') | |||
|
395 | opObj.addParameter(name='expLabel' , value=self.expLabel, type='str') | |||
|
396 | opObj.addParameter(name='online' , value=self.online, type='bool') | |||
|
397 | opObj.addParameter(name='delay' , value=self.delay, type='float') | |||
|
398 | ||||
|
399 | return opObj | |||
|
400 | ||||
|
401 | ||||
|
402 | class Controller(): | |||
|
403 | ||||
|
404 | id = None | |||
|
405 | name = None | |||
|
406 | description = None | |||
|
407 | # readUnitConfObjList = None | |||
|
408 | procUnitConfObjDict = None | |||
|
409 | ||||
|
410 | ELEMENTNAME = 'Controller' | |||
|
411 | ||||
|
412 | def __init__(self): | |||
|
413 | ||||
|
414 | self.id = None | |||
|
415 | self.name = None | |||
|
416 | self.description = None | |||
|
417 | ||||
|
418 | # self.readUnitConfObjList = [] | |||
|
419 | self.procUnitConfObjDict = {} | |||
|
420 | ||||
|
421 | def __getNewId(self): | |||
|
422 | ||||
|
423 | id = int(self.id)*10 + len(self.procUnitConfObjDict) + 1 | |||
|
424 | ||||
|
425 | return str(id) | |||
|
426 | ||||
|
427 | def getElementName(self): | |||
|
428 | ||||
|
429 | return self.ELEMENTNAME | |||
|
430 | ||||
|
431 | def setup(self, id, name, description): | |||
|
432 | ||||
|
433 | self.id = id | |||
|
434 | self.name = name | |||
|
435 | self.description = description | |||
|
436 | ||||
|
437 | def addReadUnit(self, type, path, startDate='', endDate='', startTime='', endTime='', online=0, expLabel='', delay=60): | |||
|
438 | ||||
|
439 | id = self.__getNewId() | |||
|
440 | name = '%sReader' %(type) | |||
|
441 | ||||
|
442 | readUnitConfObj = ReadUnitConf() | |||
|
443 | readUnitConfObj.setup(id, name, type, path, startDate, endDate, startTime, endTime, online, expLabel, delay) | |||
|
444 | ||||
|
445 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj | |||
|
446 | ||||
|
447 | return readUnitConfObj | |||
|
448 | ||||
|
449 | def addProcUnit(self, type, inputId): | |||
|
450 | ||||
|
451 | id = self.__getNewId() | |||
|
452 | name = '%sProc' %(type) | |||
|
453 | ||||
|
454 | procUnitConfObj = ProcUnitConf() | |||
|
455 | procUnitConfObj.setup(id, name, type, inputId) | |||
|
456 | ||||
|
457 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj | |||
|
458 | ||||
|
459 | return procUnitConfObj | |||
|
460 | ||||
|
461 | def makeXml(self): | |||
|
462 | ||||
|
463 | projectElement = Element('Controller') | |||
|
464 | projectElement.set('id', str(self.id)) | |||
|
465 | projectElement.set('name', self.name) | |||
|
466 | projectElement.set('description', self.description) | |||
|
467 | ||||
|
468 | # for readUnitConfObj in self.readUnitConfObjList: | |||
|
469 | # readUnitConfObj.makeXml(projectElement) | |||
|
470 | ||||
|
471 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |||
|
472 | procUnitConfObj.makeXml(projectElement) | |||
|
473 | ||||
|
474 | self.projectElement = projectElement | |||
|
475 | ||||
|
476 | def writeXml(self, filename): | |||
|
477 | ||||
|
478 | self.makeXml() | |||
|
479 | ||||
|
480 | print prettify(self.projectElement) | |||
|
481 | ||||
|
482 | ElementTree(self.projectElement).write(filename, method='xml') | |||
|
483 | ||||
|
484 | def readXml(self, filename): | |||
|
485 | ||||
|
486 | #tree = ET.parse(filename) | |||
|
487 | self.projectElement = None | |||
|
488 | # self.readUnitConfObjList = [] | |||
|
489 | self.procUnitConfObjDict = {} | |||
|
490 | ||||
|
491 | self.projectElement = ElementTree().parse(filename) | |||
|
492 | ||||
|
493 | self.project = self.projectElement.tag | |||
|
494 | ||||
|
495 | self.id = self.projectElement.get('id') | |||
|
496 | self.name = self.projectElement.get('name') | |||
|
497 | self.description = self.projectElement.get('description') | |||
|
498 | ||||
|
499 | readUnitElementList = self.projectElement.getiterator(ReadUnitConf().getElementName()) | |||
|
500 | ||||
|
501 | for readUnitElement in readUnitElementList: | |||
|
502 | readUnitConfObj = ReadUnitConf() | |||
|
503 | readUnitConfObj.readXml(readUnitElement) | |||
|
504 | ||||
|
505 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj | |||
|
506 | ||||
|
507 | procUnitElementList = self.projectElement.getiterator(ProcUnitConf().getElementName()) | |||
|
508 | ||||
|
509 | for procUnitElement in procUnitElementList: | |||
|
510 | procUnitConfObj = ProcUnitConf() | |||
|
511 | procUnitConfObj.readXml(procUnitElement) | |||
|
512 | ||||
|
513 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj | |||
|
514 | ||||
|
515 | def printattr(self): | |||
|
516 | ||||
|
517 | print "Controller[%s]: name = %s, description = %s" %(self.id, | |||
|
518 | self.name, | |||
|
519 | self.description) | |||
|
520 | ||||
|
521 | # for readUnitConfObj in self.readUnitConfObjList: | |||
|
522 | # readUnitConfObj.printattr() | |||
|
523 | ||||
|
524 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |||
|
525 | procUnitConfObj.printattr() | |||
|
526 | ||||
|
527 | def createObjects(self): | |||
|
528 | ||||
|
529 | # for readUnitConfObj in self.readUnitConfObjList: | |||
|
530 | # readUnitConfObj.createObjects() | |||
|
531 | ||||
|
532 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |||
|
533 | procUnitConfObj.createObjects() | |||
|
534 | ||||
|
535 | def __connect(self, objIN, obj): | |||
|
536 | ||||
|
537 | obj.setInput(objIN.getOutput()) | |||
|
538 | ||||
|
539 | def connectObjects(self): | |||
|
540 | ||||
|
541 | for puConfObj in self.procUnitConfObjDict.values(): | |||
|
542 | ||||
|
543 | inputId = puConfObj.getInputId() | |||
|
544 | ||||
|
545 | if int(inputId) == 0: | |||
|
546 | continue | |||
|
547 | ||||
|
548 | puConfINObj = self.procUnitConfObjDict[inputId] | |||
|
549 | ||||
|
550 | puObj = puConfObj.getProcUnitObj() | |||
|
551 | puINObj = puConfINObj.getProcUnitObj() | |||
|
552 | ||||
|
553 | self.__connect(puINObj, puObj) | |||
|
554 | ||||
|
555 | def run(self): | |||
|
556 | ||||
|
557 | # for readUnitConfObj in self.readUnitConfObjList: | |||
|
558 | # readUnitConfObj.run() | |||
|
559 | while(True): | |||
|
560 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |||
|
561 | procUnitConfObj.run() | |||
|
562 | ||||
|
563 | if __name__ == '__main__': | |||
|
564 | ||||
|
565 | desc = "Segundo Test" | |||
|
566 | filename = "schain.xml" | |||
|
567 | ||||
|
568 | controllerObj = Controller() | |||
|
569 | ||||
|
570 | controllerObj.setup(id = '191', name='test01', description=desc) | |||
|
571 | ||||
|
572 | readUnitConfObj = controllerObj.addReadUnit(type='Voltage', | |||
|
573 | path='/home/roj-idl71/Data/RAWDATA/Meteors', | |||
|
574 | startDate='2012/01/01', | |||
|
575 | endDate='2012/12/31', | |||
|
576 | startTime='00:00:00', | |||
|
577 | endTime='23:59:59', | |||
|
578 | online=0) | |||
|
579 | ||||
|
580 | procUnitConfObj1 = controllerObj.addProcUnit(type='Voltage', inputId=readUnitConfObj.getId()) | |||
|
581 | ||||
|
582 | procUnitConfObj2 = controllerObj.addProcUnit(type='Voltage', inputId=procUnitConfObj1.getId()) | |||
|
583 | ||||
|
584 | opObj11 = procUnitConfObj1.addOperation(name='selectChannels') | |||
|
585 | opObj11.addParameter(name='channelList', value='1,2', type='intlist') | |||
|
586 | ||||
|
587 | # opObj12 = procUnitConfObj1.addOperation(name='decoder') | |||
|
588 | # opObj12.addParameter(name='ncode', value='2', type='int') | |||
|
589 | # opObj12.addParameter(name='nbauds', value='8', type='int') | |||
|
590 | # opObj12.addParameter(name='code0', value='001110011', type='int') | |||
|
591 | # opObj12.addParameter(name='code1', value='001110011', type='int') | |||
|
592 | ||||
|
593 | opObj21 = procUnitConfObj2.addOperation(name='CohInt', optype='other') | |||
|
594 | opObj21.addParameter(name='nCohInt', value='10', type='int') | |||
|
595 | ||||
|
596 | ||||
|
597 | print "Escribiendo el archivo XML" | |||
|
598 | ||||
|
599 | controllerObj.writeXml(filename) | |||
|
600 | ||||
|
601 | print "Leyendo el archivo XML" | |||
|
602 | controllerObj.readXml(filename) | |||
|
603 | #controllerObj.printattr() | |||
|
604 | ||||
|
605 | controllerObj.createObjects() | |||
|
606 | controllerObj.connectObjects() | |||
|
607 | controllerObj.run() | |||
|
608 | ||||
|
609 | No newline at end of file |
@@ -0,0 +1,1 | |||||
|
1 | <Controller description="Segundo Test" id="191" name="test01"><ReadUnit id="1911" inputId="0" name="VoltageReader" type="Voltage"><Operation id="19111" name="run" priority="1" type="self"><Parameter id="191111" name="path" type="str" value="/home/roj-idl71/Data/RAWDATA/Meteors" /><Parameter id="191112" name="startDate" type="date" value="2012/01/01" /><Parameter id="191113" name="endDate" type="date" value="2012/12/31" /><Parameter id="191114" name="startTime" type="time" value="00:00:00" /><Parameter id="191115" name="endTime" type="time" value="23:59:59" /><Parameter id="191116" name="expLabel" type="str" value="" /><Parameter id="191117" name="online" type="bool" value="0" /><Parameter id="191118" name="delay" type="float" value="60" /></Operation></ReadUnit><ProcUnit id="1913" inputId="1912" name="VoltageProc" type="Voltage"><Operation id="19131" name="init" priority="1" type="self" /><Operation id="19132" name="CohInt" priority="2" type="other"><Parameter id="191321" name="nCohInt" type="int" value="10" /></Operation></ProcUnit><ProcUnit id="1912" inputId="1911" name="VoltageProc" type="Voltage"><Operation id="19121" name="init" priority="1" type="self" /><Operation id="19122" name="selectChannels" priority="2" type="self"><Parameter id="191221" name="channelList" type="intlist" value="1,2" /></Operation></ProcUnit></Controller> No newline at end of file |
1 | NO CONTENT: file renamed from schainpy/graphics/__init__.py to schainpy/model/graphics/__init__.py |
|
NO CONTENT: file renamed from schainpy/graphics/__init__.py to schainpy/model/graphics/__init__.py |
1 | NO CONTENT: file renamed from schainpy/graphics/figure.py to schainpy/model/graphics/figure.py |
|
NO CONTENT: file renamed from schainpy/graphics/figure.py to schainpy/model/graphics/figure.py |
@@ -1,7 +1,7 | |||||
1 | import matplotlib |
|
1 | import matplotlib | |
2 |
matplotlib.use(" |
|
2 | matplotlib.use("Agg") | |
3 | import matplotlib.pyplot |
|
3 | import matplotlib.pyplot | |
4 | import scitools.numpyutils |
|
4 | #import scitools.numpyutils | |
5 | from mpl_toolkits.axes_grid1 import make_axes_locatable |
|
5 | from mpl_toolkits.axes_grid1 import make_axes_locatable | |
6 |
|
6 | |||
7 | def init(idfigure, wintitle, width, height): |
|
7 | def init(idfigure, wintitle, width, height): |
@@ -13,6 +13,7 import time, datetime | |||||
13 |
|
13 | |||
14 | from jrodata import * |
|
14 | from jrodata import * | |
15 | from jroheaderIO import * |
|
15 | from jroheaderIO import * | |
|
16 | from jroprocessing import * | |||
16 |
|
17 | |||
17 | def isNumber(str): |
|
18 | def isNumber(str): | |
18 | """ |
|
19 | """ | |
@@ -236,7 +237,7 class JRODataIO: | |||||
236 |
|
237 | |||
237 | return self.dataOut |
|
238 | return self.dataOut | |
238 |
|
239 | |||
239 | class JRODataReader(JRODataIO): |
|
240 | class JRODataReader(JRODataIO, ProcessingUnit): | |
240 |
|
241 | |||
241 | nReadBlocks = 0 |
|
242 | nReadBlocks = 0 | |
242 |
|
243 | |||
@@ -420,79 +421,7 class JRODataReader(JRODataIO): | |||||
420 |
|
421 | |||
421 | return directory, filename, year, doy, set |
|
422 | return directory, filename, year, doy, set | |
422 |
|
423 | |||
423 | def setup(self, |
|
|||
424 | path=None, |
|
|||
425 | startDate=None, |
|
|||
426 | endDate=None, |
|
|||
427 | startTime=datetime.time(0,0,0), |
|
|||
428 | endTime=datetime.time(23,59,59), |
|
|||
429 | set=0, |
|
|||
430 | expLabel = "", |
|
|||
431 | ext = None, |
|
|||
432 | online = False, |
|
|||
433 | delay = 60): |
|
|||
434 |
|
424 | |||
435 | if path == None: |
|
|||
436 | raise ValueError, "The path is not valid" |
|
|||
437 |
|
||||
438 | if ext == None: |
|
|||
439 | ext = self.ext |
|
|||
440 |
|
||||
441 | if online: |
|
|||
442 | print "Searching files in online mode..." |
|
|||
443 | doypath, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext) |
|
|||
444 |
|
||||
445 | if not(doypath): |
|
|||
446 | for nTries in range( self.nTries ): |
|
|||
447 | print '\tWaiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1) |
|
|||
448 | time.sleep( self.delay ) |
|
|||
449 | doypath, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=exp) |
|
|||
450 | if doypath: |
|
|||
451 | break |
|
|||
452 |
|
||||
453 | if not(doypath): |
|
|||
454 | print "There 'isn't valied files in %s" % path |
|
|||
455 | return None |
|
|||
456 |
|
||||
457 | self.year = year |
|
|||
458 | self.doy = doy |
|
|||
459 | self.set = set - 1 |
|
|||
460 | self.path = path |
|
|||
461 |
|
||||
462 | else: |
|
|||
463 | print "Searching files in offline mode ..." |
|
|||
464 | pathList, filenameList = self.__searchFilesOffLine(path, startDate, endDate, startTime, endTime, set, expLabel, ext) |
|
|||
465 |
|
||||
466 | if not(pathList): |
|
|||
467 | print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path, |
|
|||
468 | datetime.datetime.combine(startDate,startTime).ctime(), |
|
|||
469 | datetime.datetime.combine(endDate,endTime).ctime()) |
|
|||
470 |
|
||||
471 | sys.exit(-1) |
|
|||
472 |
|
||||
473 |
|
||||
474 | self.fileIndex = -1 |
|
|||
475 | self.pathList = pathList |
|
|||
476 | self.filenameList = filenameList |
|
|||
477 |
|
||||
478 | self.online = online |
|
|||
479 | self.delay = delay |
|
|||
480 | ext = ext.lower() |
|
|||
481 | self.ext = ext |
|
|||
482 |
|
||||
483 | if not(self.setNextFile()): |
|
|||
484 | if (startDate!=None) and (endDate!=None): |
|
|||
485 | print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime()) |
|
|||
486 | elif startDate != None: |
|
|||
487 | print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime()) |
|
|||
488 | else: |
|
|||
489 | print "No files" |
|
|||
490 |
|
||||
491 | sys.exit(-1) |
|
|||
492 |
|
||||
493 | # self.updateDataHeader() |
|
|||
494 |
|
||||
495 | return self.dataOut |
|
|||
496 |
|
425 | |||
497 | def __setNextFileOffline(self): |
|
426 | def __setNextFileOffline(self): | |
498 |
|
427 | |||
@@ -766,6 +695,80 class JRODataReader(JRODataIO): | |||||
766 |
|
695 | |||
767 | return True |
|
696 | return True | |
768 |
|
697 | |||
|
698 | def setup(self, | |||
|
699 | path=None, | |||
|
700 | startDate=None, | |||
|
701 | endDate=None, | |||
|
702 | startTime=datetime.time(0,0,0), | |||
|
703 | endTime=datetime.time(23,59,59), | |||
|
704 | set=0, | |||
|
705 | expLabel = "", | |||
|
706 | ext = None, | |||
|
707 | online = False, | |||
|
708 | delay = 60): | |||
|
709 | ||||
|
710 | if path == None: | |||
|
711 | raise ValueError, "The path is not valid" | |||
|
712 | ||||
|
713 | if ext == None: | |||
|
714 | ext = self.ext | |||
|
715 | ||||
|
716 | if online: | |||
|
717 | print "Searching files in online mode..." | |||
|
718 | doypath, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext) | |||
|
719 | ||||
|
720 | if not(doypath): | |||
|
721 | for nTries in range( self.nTries ): | |||
|
722 | print '\tWaiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1) | |||
|
723 | time.sleep( self.delay ) | |||
|
724 | doypath, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=exp) | |||
|
725 | if doypath: | |||
|
726 | break | |||
|
727 | ||||
|
728 | if not(doypath): | |||
|
729 | print "There 'isn't valied files in %s" % path | |||
|
730 | return None | |||
|
731 | ||||
|
732 | self.year = year | |||
|
733 | self.doy = doy | |||
|
734 | self.set = set - 1 | |||
|
735 | self.path = path | |||
|
736 | ||||
|
737 | else: | |||
|
738 | print "Searching files in offline mode ..." | |||
|
739 | pathList, filenameList = self.__searchFilesOffLine(path, startDate, endDate, startTime, endTime, set, expLabel, ext) | |||
|
740 | ||||
|
741 | if not(pathList): | |||
|
742 | print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path, | |||
|
743 | datetime.datetime.combine(startDate,startTime).ctime(), | |||
|
744 | datetime.datetime.combine(endDate,endTime).ctime()) | |||
|
745 | ||||
|
746 | sys.exit(-1) | |||
|
747 | ||||
|
748 | ||||
|
749 | self.fileIndex = -1 | |||
|
750 | self.pathList = pathList | |||
|
751 | self.filenameList = filenameList | |||
|
752 | ||||
|
753 | self.online = online | |||
|
754 | self.delay = delay | |||
|
755 | ext = ext.lower() | |||
|
756 | self.ext = ext | |||
|
757 | ||||
|
758 | if not(self.setNextFile()): | |||
|
759 | if (startDate!=None) and (endDate!=None): | |||
|
760 | print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime()) | |||
|
761 | elif startDate != None: | |||
|
762 | print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime()) | |||
|
763 | else: | |||
|
764 | print "No files" | |||
|
765 | ||||
|
766 | sys.exit(-1) | |||
|
767 | ||||
|
768 | # self.updateDataHeader() | |||
|
769 | ||||
|
770 | return self.dataOut | |||
|
771 | ||||
769 | def getData(): |
|
772 | def getData(): | |
770 | pass |
|
773 | pass | |
771 |
|
774 | |||
@@ -785,7 +788,7 class JRODataReader(JRODataIO): | |||||
785 |
|
788 | |||
786 | self.getData() |
|
789 | self.getData() | |
787 |
|
790 | |||
788 | class JRODataWriter(JRODataIO): |
|
791 | class JRODataWriter(JRODataIO, Operation): | |
789 |
|
792 | |||
790 | """ |
|
793 | """ | |
791 | Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura |
|
794 | Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura |
@@ -36,6 +36,10 class ProcessingUnit: | |||||
36 |
|
36 | |||
37 | self.objectDict = {} |
|
37 | self.objectDict = {} | |
38 |
|
38 | |||
|
39 | def init(self): | |||
|
40 | ||||
|
41 | raise ValueError, "Not implemented" | |||
|
42 | ||||
39 | def addOperation(self, object, objId): |
|
43 | def addOperation(self, object, objId): | |
40 |
|
44 | |||
41 | """ |
|
45 | """ | |
@@ -79,6 +83,13 class ProcessingUnit: | |||||
79 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. |
|
83 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. | |
80 |
|
84 | |||
81 | """ |
|
85 | """ | |
|
86 | if name != 'run': | |||
|
87 | ||||
|
88 | if name == 'init' and self.dataIn.isEmpty(): | |||
|
89 | return | |||
|
90 | ||||
|
91 | if name != 'init' and self.dataOut.isEmpty(): | |||
|
92 | return | |||
82 |
|
93 | |||
83 | methodToCall = getattr(self, name) |
|
94 | methodToCall = getattr(self, name) | |
84 |
|
95 | |||
@@ -100,6 +111,9 class ProcessingUnit: | |||||
100 | None |
|
111 | None | |
101 | """ |
|
112 | """ | |
102 |
|
113 | |||
|
114 | if self.dataOut.isEmpty(): | |||
|
115 | return | |||
|
116 | ||||
103 | object = self.objectDict[objId] |
|
117 | object = self.objectDict[objId] | |
104 |
|
118 | |||
105 | object.run(self.dataOut, **kwargs) |
|
119 | object.run(self.dataOut, **kwargs) | |
@@ -128,8 +142,6 class ProcessingUnit: | |||||
128 | Operation : Objeto del tipo operacion con los atributos: name, type y id. |
|
142 | Operation : Objeto del tipo operacion con los atributos: name, type y id. | |
129 |
|
143 | |||
130 | """ |
|
144 | """ | |
131 | if self.dataIn.isEmpty(): |
|
|||
132 | return None |
|
|||
133 |
|
145 | |||
134 | if operationConf.type == 'self': |
|
146 | if operationConf.type == 'self': | |
135 | self.callMethod(operationConf.name, **kwargs) |
|
147 | self.callMethod(operationConf.name, **kwargs) | |
@@ -227,6 +239,7 class VoltageProc(ProcessingUnit): | |||||
227 |
|
239 | |||
228 | for channel in channelIndexList: |
|
240 | for channel in channelIndexList: | |
229 | if channel not in self.dataOut.channelIndexList: |
|
241 | if channel not in self.dataOut.channelIndexList: | |
|
242 | print channelIndexList | |||
230 | raise ValueError, "The value %d in channelIndexList is not valid" %channel |
|
243 | raise ValueError, "The value %d in channelIndexList is not valid" %channel | |
231 |
|
244 | |||
232 | nChannels = len(channelIndexList) |
|
245 | nChannels = len(channelIndexList) |
General Comments 0
You need to be logged in to leave comments.
Login now