def retrieve(self, pk_value): try: document = self.__documents[pk_value] except KeyError: return None node = PathDict() for path in document.paths(): if path != self.pk_path: node.append(path, document.node(path)) return node
def datum(self, sample): if not sample.has_path(self.__path): return None rec = LocalizedDatetime.construct_from_jdict(sample.node('rec')) value = sample.node(self.__path) self.__func.append(rec, value) if not self.__func.has_tally(): return None mid_rec, mid = self.__func.midpoint() if rec is None: return None target = PathDict() target.append('rec', rec) target.append('mid-rec', mid_rec) target.append(self.__path + '.src', value) target.append(self.__path + '.mid', round(mid, 6)) return target.node()
def datum(self, sample): if not sample.has_path(self.__path): return None try: rec_node = sample.node('rec') except KeyError: return None rec = LocalizedDatetime.construct_from_jdict(rec_node) value = sample.node(self.__path) self.__func.append(rec, value) if not self.__func.has_midpoint(): return None mid_rec, mid = self.__func.midpoint() if rec is None: return None target = PathDict() target.append('rec', rec.as_iso8601()) target.append('mid-rec', mid_rec.as_iso8601()) target.append(self.__path + '.src', value) target.append(self.__path + '.mid', round(mid, self.__precision)) return target.node()
def datum(self, datum): we_v = float(datum.node(self.__path + '.weV')) ae_v = float(datum.node(self.__path + '.aeV')) diff = we_v - ae_v conversion = (diff * 1000) / float( self.__sensitivity ) # value [ppb] = raw [mV] / sensitivity [mV / ppb] target = PathDict() target.copy(datum, 'rec', self.__path + '.weV', self.__path + '.aeV') target.append(self.__path + '.diff', round(diff, 6)) target.append(self.__path + '.conv', round(conversion, 6)) return target.node()
def datum(self, sample): if not sample.has_path(self.__path): return None value = sample.node(self.__path) self.__func.append(value) avg = self.__func.compute() if avg is None: return None target = PathDict() if sample.has_path('rec'): target.copy(sample, 'rec') target.append(self.__path + '.src', value) target.append(self.__path + '.avg', round(avg, self.__precision)) return target.node()
def datum(self, sample): if not sample.has_path(self.__path): return None try: rec_node = sample.node('rec') except KeyError: return None rec = LocalizedDatetime.construct_from_jdict(rec_node) value = sample.node(self.__path) self.__func.append(rec, value) if not self.__func.has_regression(): return None slope, intercept = self.__func.line() if slope is None: return None target = PathDict() if sample.has_path('rec'): target.copy(sample, 'rec') target.append(self.__path + '.src', value) target.append(self.__path + '.slope', round(slope, self.__precision)) target.append(self.__path + '.intercept', round(intercept, self.__precision)) return target.node()
def datum(self, sample): if not sample.has_path(self.__path): return None rec = LocalizedDatetime.construct_from_jdict(sample.node('rec')) value = sample.node(self.__path) self.__func.append(rec, value) if not self.__func.has_tally(): return None slope, intercept = self.__func.compute() if slope is None: return None target = PathDict() target.copy(datum, 'rec') target.append(self.__path + '.src', value) target.append(self.__path + '.slope', round(slope * 60 * 60, 6)) # x-scale is hours target.append(self.__path + '.intercept', round(intercept, 6)) return target.node()
def report(self, localised_datetime): report = PathDict() # rec... report.append(self.__iso_path, localised_datetime.as_iso8601()) # values... for path, precision in self.__precisions.items(): regression = self.__regressions[path] if self.__regressions[path].has_midpoint(): _, midpoint = regression.midpoint(precision.digits) if self.__min_max: report.append(path + '.min', regression.min(precision.digits)) report.append(path + '.mid', midpoint) report.append(path + '.max', regression.max(precision.digits)) else: report.append(path, midpoint) return report
def datum(self, sample): if not sample.has_path(self.__path): return None value = sample.node(self.__path) self.__func.append(value) if not self.__func.has_tally(): return None avg = self.__func.compute() if avg is None: return None target = PathDict() target.copy(datum, 'rec') target.append(self.__path + '.src', value) target.append(self.__path + '.avg', round(avg, 6)) return target.node()
def datum(self, datum): latest = float(datum.node(self.__path)) if self.__aggregate is None: self.__aggregate = latest return None self.__aggregate = (0.9 * self.__aggregate) + (0.1 * latest) error = latest - self.__aggregate target = PathDict() target.copy(datum, 'rec') target.append(self.__path + '.src', latest) target.append(self.__path + '.agr', round(self.__aggregate, 6)) target.append(self.__path + '.err', round(error, 6)) return target.node()
def datum(self, sample): latest = float(sample.node(self.__path)) if self.__aggregate is None: self.__aggregate = latest return None self.__aggregate = (0.9 * self.__aggregate) + (0.1 * latest) error = latest - self.__aggregate target = PathDict() if sample.has_path('rec'): target.copy(sample, 'rec') target.append(self.__path + '.src', latest) target.append(self.__path + '.agr', round(self.__aggregate, self.__precision)) target.append(self.__path + '.err', round(error, self.__precision)) return target.node()
print(path2) print("-") path3 = "val.opc.bin1.1" print(path3) print("-") target.copy(datum, path1, path2, path3) print(target) print("-") source = "val.opc.extra" print(source) print("-") target.append("val.opc.extra", "hello") print(target) print("-") jstr = JSONify.dumps(target.node()) print(jstr) print("-") jdict = json.loads(jstr, object_pairs_hook=OrderedDict) print(jdict) print("-") target = PathDict(jdict) print(target) print("-")
if datum is None: continue document_count += 1 value = datum.node(cmd.path) if value is None: continue target = PathDict() if datum.has_path('rec'): target.copy(datum, 'rec') target.append(cmd.path + '.src', value) target.append(cmd.path + '.med', round(median_filter.compute(value), cmd.precision)) print(JSONify.dumps(target.node())) sys.stdout.flush() processed_count += 1 # ---------------------------------------------------------------------------------------------------------------- # end... except KeyboardInterrupt: if cmd.verbose: print("sample_median: KeyboardInterrupt", file=sys.stderr)
# ISO 8601... iso = LocalizedDatetime.construct_from_date_time(parser, date, time, tz=zone) if iso is None: print("sample_iso_8601: malformed datetime in %s" % jstr, file=sys.stderr) exit(1) if cmd.timezone is not None and cmd.utc: iso = iso.utc() target = PathDict() target.append(cmd.iso, iso.as_iso8601()) # copy... for path in paths: if path not in cmd.datetime_paths(): target.append(path, datum.node(path)) # report... print(JSONify.dumps(target)) sys.stdout.flush() processed_count += 1 # ---------------------------------------------------------------------------------------------------------------- # end...
if datum is None: break document_count += 1 value = datum.node(cmd.path) if value is None: break target = PathDict() if datum.has_path('rec'): target.copy(datum, 'rec') target.append(cmd.path + '.src', value) target.append(cmd.path + '.lpf', round(lpf.line(value), cmd.precision)) print(JSONify.dumps(target.node())) sys.stdout.flush() processed_count += 1 # ---------------------------------------------------------------------------------------------------------------- # end... except KeyboardInterrupt: if cmd.verbose: print("sample_low_pass: KeyboardInterrupt", file=sys.stderr)
print("sample_concentration: invalid value for p in %s" % jstr, file=sys.stderr) exit(1) else: p = cmd.pressure cnc = round(Gas.concentration(cmd.gas, density, t, p), 1) target = PathDict() # copy... for path in paths: if path == concentration_path: continue target.append(path, datum.node(path)) if path == cmd.density_path: target.append(concentration_path, cnc) # report... print(JSONify.dumps(target)) sys.stdout.flush() processed_count += 1 # ---------------------------------------------------------------------------------------------------------------- # end... except KeyboardInterrupt:
def as_json(self): jdict = PathDict() jdict.append('domain', self.domain()) jdict.append('domain-midpoint', self.domain_midpoint()) jdict.append(self.ind_name + '.min', self.ind_min()) jdict.append(self.ind_name + '.avg', self.ind_avg()) jdict.append(self.ind_name + '.max', self.ind_max()) for name in self.dep_names: jdict.append(name + '.avg', self.dep_avg(name)) jdict.append(name + '.stdev', self.dep_stdev(name)) jdict.append('samples', len(self)) return jdict
document_count += 1 if cmd.exclude and not cmd.sub_paths: continue # everything is excluded # build... if not cmd.sub_paths: target = datum else: target = PathDict() for path in datum.paths(): if cmd.includes(path): target.append(path, datum.node(path)) # report... if not target: continue # skip empty outputs if cmd.sequence: for path in cmd.sub_paths: node = target.node(path) try: for item in node: print(JSONify.dumps(item)) except TypeError as ex: print(ex) print(JSONify.dumps(node))
print(path2) print("-") path3 = "val.opc.bin1.1" print(path3) print("-") target.copy(datum, path1, path2, path3) print(target) print("-") source = "val.opc.extra" print(source) print("-") target.append("val.opc.extra", "hello") print(target) print("-") target.append("val.opc" + ".number", 123.34) print(target) print("-") jstr = JSONify.dumps(target.node()) print(jstr) print("-") jdict = json.loads(jstr, object_pairs_hook=OrderedDict) print(jdict) print("-")
print("sample_wec_sens: invalid value for %s in %s" % (wec_path, jstr), file=sys.stderr) exit(1) wec_sens = round(wec / (cmd.sens / 1000), 1) target = PathDict() # copy... for path in paths: if path == wec_sens_path: continue # ignore any existing wec_sens_path if path == wec_path: target.append(wec_path, wec) target.append(wec_sens_path, wec_sens) else: target.append(path, datum.node(path)) # report... print(JSONify.dumps(target.node())) sys.stdout.flush() processed_count += 1 # ---------------------------------------------------------------------------------------------------------------- # end... except KeyboardInterrupt:
try: t = float(t_node) except ValueError: t = None print("sample_ah: invalid value for t in %s" % jstr, file=sys.stderr) exit(1) ah = round(AbsoluteHumidity.from_rh_t(rh, t), 1) target = PathDict() # copy... for path in paths: if path == cmd.rh_path: target.append(path + '.rH', rh) target.append(path + '.aH', ah) else: target.append(path, datum.node(path)) # report... print(JSONify.dumps(target.node())) sys.stdout.flush() processed_count += 1 # ---------------------------------------------------------------------------------------------------------------- # end...
source = "val.opc_n2.bin2:0:0" print(source) print("-") target.copy(datum, source) print(target) jstr = JSONify.dumps(target) print(jstr) print("-") new = "val.opc_n2.extra" print(new) print("-") target.append(new, "hello") print(target) jstr = JSONify.dumps(target) print(jstr) print("-") new = "val.opc_n2.bin2:0:1" print(new) print("-") target.append(new, "bye") print(target) jstr = JSONify.dumps(target) print(jstr) print("-")