comparison utils/seriestables/series.py @ 224:0515a8901c6a

Corrigé un bug avec store_timestamp/cpuclock, et tests pour éviter ce cas
author fsavard
date Thu, 11 Mar 2010 11:52:43 -0500
parents 02d9c1279dd8
children
comparison
equal deleted inserted replaced
221:02d9c1279dd8 224:0515a8901c6a
16 otherwise. 16 otherwise.
17 ''' 17 '''
18 18
19 def _get_description_timestamp_cpuclock_columns(store_timestamp, store_cpuclock, pos=0): 19 def _get_description_timestamp_cpuclock_columns(store_timestamp, store_cpuclock, pos=0):
20 toexec = "" 20 toexec = ""
21 21
22 if store_timestamp: 22 if store_timestamp:
23 toexec += "\ttimestamp = tables.Time32Col(pos="+str(pos)+")\n" 23 toexec += "\ttimestamp = tables.Time32Col(pos="+str(pos)+")\n"
24 pos += 1 24 pos += 1
25 25
26 if store_cpuclock: 26 if store_cpuclock:
208 208
209 def append(self, index, element): 209 def append(self, index, element):
210 raise NotImplementedError 210 raise NotImplementedError
211 211
212 def _timestamp_cpuclock(self, newrow): 212 def _timestamp_cpuclock(self, newrow):
213 newrow["timestamp"] = time.time() 213 if self.store_timestamp:
214 newrow["cpuclock"] = time.clock() 214 newrow["timestamp"] = time.time()
215
216 if self.store_cpuclock:
217 newrow["cpuclock"] = time.clock()
215 218
216 class DummySeries(): 219 class DummySeries():
217 """ 220 """
218 To put in a series dictionary instead of a real series, to do nothing 221 To put in a series dictionary instead of a real series, to do nothing
219 when we don't want a given series to be saved. 222 when we don't want a given series to be saved.
265 268
266 self._create_table() 269 self._create_table()
267 270
268 def _create_table(self): 271 def _create_table(self):
269 table_description = _get_description_with_n_ints_n_floats( \ 272 table_description = _get_description_with_n_ints_n_floats( \
270 self.index_names, (self.error_name,)) 273 self.index_names, (self.error_name,),
274 store_timestamp=self.store_timestamp,
275 store_cpuclock=self.store_cpuclock)
271 276
272 self._table = self.hdf5_file.createTable(self.hdf5_group, 277 self._table = self.hdf5_file.createTable(self.hdf5_group,
273 self.table_name, 278 self.table_name,
274 table_description, 279 table_description,
275 title=self.title) 280 title=self.title)
538 This inherits from SeriesArrayWrapper, which provides the append() 543 This inherits from SeriesArrayWrapper, which provides the append()
539 method. 544 method.
540 ''' 545 '''
541 546
542 def __init__(self, arrays_names, new_group_name, hdf5_file, 547 def __init__(self, arrays_names, new_group_name, hdf5_file,
543 base_group='/', index_names=('epoch',), title=""): 548 base_group='/', index_names=('epoch',), title="",
549 store_timestamp=True, store_cpuclock=True):
544 """ 550 """
545 For other parameters, see Series.__init__ 551 For other parameters, see Series.__init__
546 552
547 Parameters 553 Parameters
548 ---------- 554 ----------
558 Path of the group under which to create the new group which will 564 Path of the group under which to create the new group which will
559 store the series. 565 store the series.
560 566
561 title : str 567 title : str
562 Here the title is attached to the new group, not a table. 568 Here the title is attached to the new group, not a table.
569
570 store_timestamp : bool
571 Here timestamp and cpuclock are stored in *each* table
572
573 store_cpuclock : bool
574 Here timestamp and cpuclock are stored in *each* table
563 """ 575 """
564 576
565 # most other checks done when calling BasicStatisticsSeries 577 # most other checks done when calling BasicStatisticsSeries
566 if type(new_group_name) != str: 578 if type(new_group_name) != str:
567 raise TypeError("new_group_name must be a string") 579 raise TypeError("new_group_name must be a string")
582 BasicStatisticsSeries( 594 BasicStatisticsSeries(
583 table_name=name, 595 table_name=name,
584 hdf5_file=hdf5_file, 596 hdf5_file=hdf5_file,
585 index_names=index_names, 597 index_names=index_names,
586 stats_functions=stats_functions, 598 stats_functions=stats_functions,
587 hdf5_group=new_group._v_pathname)) 599 hdf5_group=new_group._v_pathname,
600 store_timestamp=store_timestamp,
601 store_cpuclock=store_cpuclock))
588 602
589 SeriesArrayWrapper.__init__(self, base_series_list) 603 SeriesArrayWrapper.__init__(self, base_series_list)
590 604
591 605