def process(mj, since, till, path_incoming, path_to, force_unpack=False): if force_unpack or not os.path.isdir('tmp/%s' % mj): logging.debug('will unpack') utils.unpack(mj, since, till, path_incoming, path_to) production_times, unmatched_files = get_production_times(path_to, mj) logging.debug('production times count: %s' % len(production_times)) base_ini_fn = '%s/%s/atx300/set/base/base.ini' % (path_incoming, mj) base_to_ior, ior_to_base = atxutils.build_signal_maps(base_ini_fn) signals_fns = utils.get_signals_files('%s/%s' % (path_incoming, mj), since, till) ''' for fn in signals_fns: header = atxsignals.read_header(fn) assert(header['is_deaggregated']) ''' logging.debug('reading signals') deaggregated = atxsignals.read_deaggregated(signals_fns, since, till) illegal_cement_openings = [] cem_bin_closed = None cem_scale_value = None for rec in deaggregated: if rec['type'] == 'header': continue k = rec['k'] v = rec['v'] if 'v' in rec else rec['avg'] #v_recalc = rec['v'] * coeffs[rec['k']] - offs[rec['k']] if ior_to_base.get(k) == 'Cement_Scale1': cem_scale_value = v elif ior_to_base.get(k) == 'I_Bin1CEMclosed': if v == 0 and cem_bin_closed != 0: is_illegal = True for prod_since, prod_till in production_times: if prod_since <= rec['t'] <= prod_till: is_illegal = False break if is_illegal: #logging.debug('%s %s' % (dt, cem_scale_value)) illegal_cement_openings.append((rec['t'], cem_scale_value)) cem_bin_closed = v logging.debug('found %d illegal cement openings' % len(illegal_cement_openings)) return unmatched_files, illegal_cement_openings
def process(mj, since, till, path, threshold): base_ini_fn = '%s/atx300/set/base/base.ini' % path base_to_ior, ior_to_base = atxutils.build_signal_maps(base_ini_fn) signals_fns = utils.get_signals_files(path, since, till) signal_stream = atxsignals.read(signals_fns, since, till) signal_stream_digital = filter(lambda x: '_DI' in x['k'], signal_stream) pulses = get_pulses(signal_stream_digital) short_pulses = filter(lambda x: x['t_diff'] < threshold, pulses) pulses_with_base_names = map(lambda x: add_base_name(x, ior_to_base), short_pulses) #pulses_with_base_names = thread_last( # signal_stream, # (filter, lambda x: '_DI' in x['k']), # get_pulses, # (filter, lambda x: x['t_diff'] < threshold), # (map, lambda x: add_base_name(x, ior_to_base)), #)() for i in pulses_with_base_names: i = assoc(i, 't_begin_isoformat', arrow.get(i['t_begin']).to('Europe/Prague').isoformat()) i['mj'] = mj #pprint.pprint(i) yield i