예제 #1
0
    def __init__(self, path, tally, precision):
        """
        Constructor
        """
        self.__path = path
        self.__precision = precision

        self.__func = LinearRegression(tally, True)
예제 #2
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
예제 #3
0
 def __init__(self, path, tally):
     """
     Constructor
     """
     self.__path = path
     self.__func = LinearRegression(tally, False)
예제 #4
0
j1 = '{"rec": "2016-10-14T14:19:15.677+01:00", "val": {"opc_n2": {"pm1": 1.5, "pm2p5": 2.7, "pm10": 3.3, ' \
     '"per": 5.0, "bin": [95, 30, 11, 1, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], ' \
     '"mtf1": 31, "mtf3": 29, "mtf5": 0, "mtf7": 0}}}'

j2 = '{"rec": "2016-10-14T14:19:20.680+01:00", "val": {"opc_n2": {"pm1": 1.8, "pm2p5": 4.3, "pm10": 6.9, ' \
     '"per": 5.0, "bin": [76, 36, 19, 6, 1, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0], ' \
     '"mtf1": 26, "mtf3": 35, "mtf5": 26, "mtf7": 35}}}'

j3 = '{"rec": "2016-10-14T14:19:25.680+01:00", "val": {"opc_n2": {"pm1": 0.9, "pm2p5": 1.7, "pm10": 22.4, ' \
     '"per": 5.0, "bin": [62, 23, 8, 2, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0], ' \
     '"mtf1": 20, "mtf3": 24, "mtf5": 0, "mtf7": 0}}}'


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

lr = LinearRegression()
print(lr)
print("-")

d1 = PathDict.construct_from_jstr(j1)
print(d1)
print("-")

rec = LocalizedDatetime.construct_from_iso8601(d1.node('rec'))
val = d1.node('val.opc_n2.pm10')

lr.append(rec, val)
print(lr)
print("-")

d2 = PathDict.construct_from_jstr(j2)