示例#1
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
示例#2
0
print("-")

# --------------------------------------------------------------------------------------------------------------------

jdict = json.loads(jstr)

datum = PathDict(jdict)
print(datum)
print("=")

# --------------------------------------------------------------------------------------------------------------------

path = None
print("%s is path: %s is sub-path:%s" %
      (path, datum.has_path(path), datum.has_sub_path(path)))
leaves = datum.paths(path)
print("%s: %s" % (path, leaves))
print("-")

path = 'val'
print("%s is path: %s is sub-path:%s" %
      (path, datum.has_path(path), datum.has_sub_path(path)))
leaves = datum.paths(path)
print("%s: %s" % (path, leaves))
print("-")

path = 'val.CO'
print("%s is path: %s is sub-path:%s" %
      (path, datum.has_path(path), datum.has_sub_path(path)))
leaves = datum.paths(path)
print("%s: %s" % (path, leaves))
示例#3
0
# --------------------------------------------------------------------------------------------------------------------
# Construction...

jdict = json.loads(jstr)
print(jdict)
print("-")

datum = PathDict(jdict)
print(datum)
print("-")

jstr = JSONify.dumps(datum)
print(jstr)
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("-")