def _do_test(self, level, stream): setup_module_logging(level=level, stream=stream) log = logging.getLogger("timestreamlib") self.assertEqual(len(log.handlers), 1) self.assertEqual(type(log.handlers[0]), logging.StreamHandler) self.assertEqual(log.handlers[0].level, level) self.assertEqual(log.getEffectiveLevel(), level)
def main(opts): setup_module_logging(logging.ERROR) ts_name = opts["-i"] out_fh = open(opts['-o'], 'w') ts_info = ts_get_manifest(ts_name) times = setup_header(ts_info) out_csv = csv.writer(out_fh) header = ["Date", ] header.extend(times) out_csv.writerow(header) ts = TimeStream() ts.load(ts_name) res_dict = {} print("Collecting image data for {}...".format(ts_name)) count = 0 for img in ts.iter_by_timepoints(): if count % 5 == 0: print("Processed {} images!".format(count), end='\r') sys.stdout.flush() count += 1 img_dt = img.datetime try: res_dict[img_dt.date()][img_dt.time().isoformat()] = 1 except KeyError: res_dict[img_dt.date()] = {img_dt.time().isoformat(): 1} print("Processed {} images!".format(count)) print("Done collecting image sums, now making the table") for this_date, times in sorted(res_dict.items()): row = [] row.append(this_date.isoformat()) start_today = datetime.combine(this_date.today(), time.min) end_today = datetime.combine(this_date.today(), time.max) all_times = iter_date_range(start_today, end_today, ts_info['interval'] * 60) for timepoint in all_times: try: row.append(times[timepoint.time().isoformat()]) except KeyError: row.append("0") out_csv.writerow(row) print("All done!")
if opts['--set']: for setelem in opts["--set"].split(','): #FIXME: print help if any exceptions. cName, cVal = setelem.split("=") plConf.setVal(cName, cVal) # Show the user the resulting configuration: print(plConf) if plConf.general.hasSubSecName("visualise"): visualise = plConf.general.visualise else: visualise = False # initialise input timestream for processing timestream.setup_module_logging(level=logging.INFO) TSList = [] for InTSFolder in InTSFolderList: ts = timestream.TimeStream() ts.load(InTSFolder) # FIXME: ts.data cannot have plConf because it cannot be handled by json. ts.data["settings"] = plConf.asDict() ts.data["configFile"] = tmpPath #FIXME: TimeStream should have a __str__ method. print("Timestream ingiot stance loaded:") print(" ts.path:", ts.path) for attr in timestream.parse.validate.TS_MANIFEST_KEYS: print(" ts.%s:" % attr, getattr(ts, attr)) # TSList.append(ts) # Initialize the context