def event2stat(edict, top_dt, end_dt, dur, binarize = True): d_stat = {} l_label = dtutil.label(top_dt, end_dt, dur) for eid, l_ev in edict.iteritems(): d_stat[eid] = dtutil.discretize(l_ev, l_label, binarize) return d_stat
def update(self, conf): ld = log_db.LogData(conf) db_top_dt, db_end_dt = ld.dt_term() if self._end_dt is not None and \ self._end_dt + self._binsize < db_end_dt: _logger.warning("New data is too small or not found") return self._evmap = log2event.generate_evmap(conf, ld, None, None) if self._end_dt is None: top_dt = dtutil.adj_sep(db_top_dt, self._binsize) else: top_dt = self._end_dt # The last bin will not be added, because it may be uncompleted end_dt = dtutil.adj_sep(db_end_dt, self._binsize) l_label = dtutil.label(top_dt, end_dt, self._binsize) _logger.info("updating changepoint data ({0} - {1})".format( top_dt, end_dt)) for eid in self._evmap.iter_eid(): evdef = self._evmap.info(eid) _logger.info("processing {0}".format(self._evmap.info_str(eid))) cf = self._load_cf(evdef) l_data, l_score = self._load_data(evdef) if cf is None: cf = self._new_cf() l_data = [] l_score = [] l_dt = [ line.dt for line in ld.iter_lines( **self._evmap.iterline_args(eid, top_dt, end_dt)) ] if len(l_dt) > 0: _logger.info("{0} messages in given term".format(len(l_dt))) l_val = dtutil.discretize(l_dt, l_label, binarize=False) for val in l_val: l_data.append(val) score = cf.update(val) l_score.append(score) self._dump_cf(evdef, cf) self._dump_data(evdef, l_data, l_score) else: _logger.info("no message found in processing term, passed") self._end_dt = end_dt self._dt_label += l_label if self._top_dt is None: self._top_dt = top_dt _logger.info("task completed")
def update(self, conf): ld = log_db.LogData(conf) db_top_dt, db_end_dt = ld.dt_term() if self._end_dt is not None and \ self._end_dt + self._binsize < db_end_dt: _logger.warning("New data is too small or not found") return self._evmap = log2event.generate_evmap(conf, ld, None, None) if self._end_dt is None: top_dt = dtutil.adj_sep(db_top_dt, self._binsize) else: top_dt = self._end_dt # The last bin will not be added, because it may be uncompleted end_dt = dtutil.adj_sep(db_end_dt, self._binsize) l_label = dtutil.label(top_dt, end_dt, self._binsize) _logger.info("updating changepoint data ({0} - {1})".format( top_dt, end_dt)) for eid in self._evmap.iter_eid(): evdef = self._evmap.info(eid) _logger.info("processing {0}".format(self._evmap.info_str(eid))) cf = self._load_cf(evdef) l_data, l_score = self._load_data(evdef) if cf is None: cf = self._new_cf() l_data = [] l_score = [] l_dt = [line.dt for line in ld.iter_lines( **self._evmap.iterline_args(eid, top_dt, end_dt))] if len(l_dt) > 0: _logger.info("{0} messages in given term".format(len(l_dt))) l_val = dtutil.discretize(l_dt, l_label, binarize = False) for val in l_val: l_data.append(val) score = cf.update(val) l_score.append(score) self._dump_cf(evdef, cf) self._dump_data(evdef, l_data, l_score) else: _logger.info("no message found in processing term, passed") self._end_dt = end_dt self._dt_label += l_label if self._top_dt is None: self._top_dt = top_dt _logger.info("task completed")