예제 #1
0
    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()
예제 #2
0
    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

        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()
예제 #4
0
    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()
예제 #5
0
    def site_conf(cls, datum: PathDict):
        jdict = datum.node('status.val.airnow')

        conf = AirNowSiteConf.construct_from_jdict(jdict)

        if conf is None:
            raise KeyError("no site configuration found for %s" % str(jdict))

        return conf
예제 #6
0
    def append(self, document: PathDict):
        pk_value = document.node(self.pk_path)

        if self.pk_is_iso8601:
            datetime = LocalizedDatetime.construct_from_iso8601(pk_value)

            if datetime is None:
                raise ValueError(pk_value)

            pk_value = datetime

        self.__documents[pk_value] = document
예제 #7
0
    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()
예제 #8
0
    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()
예제 #9
0
    def append(self, datetime: LocalizedDatetime, sample: PathDict):
        # initialise...
        if not self.__initialised:
            for node in self.__nodes:
                try:
                    paths = sample.paths(node)

                except KeyError:
                    continue

                except IndexError as ex:
                    paths = None
                    print("sample_aggregate: %s: IndexError: %s" % (node, ex), file=sys.stderr)
                    sys.stderr.flush()
                    exit(1)

                for path in paths:
                    if path == 'rec':
                        continue

                    self.__precisions[path] = Precision()
                    self.__regressions[path] = LinearRegression() if Datum.is_numeric(sample.node(path)) else \
                        CategoricalRegression()

            self.__initialised = True

        # values...
        for path in self.__precisions.keys():
            try:
                value = sample.node(path)
            except KeyError:
                continue

            if value is None:
                continue

            try:
                self.__precisions[path].widen(value)
                self.__regressions[path].append(datetime, value)
            except InvalidOperation:
                continue
예제 #10
0
    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()
예제 #11
0
    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()
예제 #12
0
    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()
예제 #13
0
                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))

            else:
                if cmd.array:
                    if first:
                        print(JSONify.dumps(target), end='')
                        first = False

                    else:
예제 #14
0
    def timezone(cls, datum: PathDict):
        jdict = datum.node('status.val.tz')

        return Timezone.construct_from_jdict(jdict)
예제 #15
0
    def gps(cls, datum: PathDict):
        jdict = datum.node('status.val.gps')

        return GPSDatum.construct_from_jdict(jdict)
예제 #16
0
 def status_tag(cls, datum: PathDict):
     return datum.node('status.tag')
예제 #17
0
    def source(self, datum: PathDict):
        source_path = '.'.join([self.topic, 'src'])

        return datum.node(source_path)
예제 #18
0
    def value(self, datum: PathDict):
        species_path = '.'.join([self.topic, 'val', self.species])

        return datum.node(species_path)
예제 #19
0
    def aqcsv_rec(self, datum: PathDict):
        localised = LocalizedDatetime.construct_from_jdict(datum.node('rec'))
        timezone = self.timezone(datum)

        return AQCSVDatetime(localised.datetime, timezone.zone)
예제 #20
0
    def environment_tag(self, datum: PathDict):
        tag_path = '.'.join([self.topic, 'tag'])

        return datum.node(tag_path)
예제 #21
0
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("-")

예제 #22
0
path1 = "val.opc.bin1"
print("path:%s" % path1)

has_path = datum.has_path(path1)
print("has_path:%s" % has_path)
print("-")

path2 = "val.opc.bin1.0"
print("path:%s" % path2)

has_path = datum.has_path(path2)
print("has_path:%s" % has_path)
print("-")

nodes = datum.node(path1, path2)
print("nodes:%s" % str(nodes))
print("=")

path = "val.opx.bin1.0"
print("path:%s" % path)

has_path = datum.has_path(path)
print("has_path:%s" % has_path)

try:
    node = datum.node(path)
    print("node:%s" % node)
except Exception as ex:
    print(type(ex).__name__)
print("=")
예제 #23
0
            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...

    except KeyboardInterrupt:
        if cmd.verbose:
            print("sample_ah: KeyboardInterrupt", file=sys.stderr)

    finally:
        if cmd.verbose:
            print("sample_ah: documents: %d processed: %d" % (document_count, processed_count), file=sys.stderr)
예제 #24
0
print("-")

paths = datum.paths()
print(paths)
print("=")

# --------------------------------------------------------------------------------------------------------------------
# Accessing nodes...

path1 = "val.opc_n2.bin1"
print("path1: %s" % path1)

has_path = datum.has_path(path1)
print("has_path:%s" % has_path)

node = datum.node(path1)
print("node: %s" % node)
print("-")

path2 = "val.opc_n2.bin1.1"
print("path2: %s" % path2)

has_path = datum.has_path(path2)
print("has_path:%s" % has_path)

node = datum.node(path2)
print("node: %s" % node)
print("-")

path3 = "val.opc_n2.bin2"
print("path3: %s" % path3)