def is_valid(self):
        if self.path is None or (self.__opts.start is None and self.minutes is None):
            return False

        if self.__opts.start is not None and LocalizedDatetime.construct_from_iso8601(self.__opts.start) is None:
            return False

        if self.__opts.end is not None and LocalizedDatetime.construct_from_iso8601(self.__opts.end) is None:
            return False

        return True
Example #2
0
    def construct_from_jdict(cls, jdict):
        if not jdict:
            return None

        date = LocalizedDatetime.construct_from_iso8601(jdict.get('date'))
        payload = MessagePayload.construct_from_jdict(jdict.get('payload'))

        return Message(date, payload)
Example #3
0
    def construct_from_jdict(cls, jdict):
        if not jdict:
            return None

        time = LocalizedDatetime.construct_from_iso8601(jdict.get('time'))
        period = Timedelta.construct_from_jdict(jdict.get('up'))
        users = int(jdict.get('users'))
        load = UptimeLoad.construct_from_jdict(jdict.get('load'))

        return UptimeDatum(time, period, users, load)
Example #4
0
    def datetime(iso_datetime):
        if iso_datetime is None:
            return None

        try:
            value = LocalizedDatetime.construct_from_iso8601(iso_datetime)
        except ValueError:
            return None

        return value
Example #5
0
    def construct_from_jdict(cls, jdict):
        if not jdict:
            return None

        device = jdict.get('device')
        topic = jdict.get('topic')
        upload = LocalizedDatetime.construct_from_iso8601(jdict.get('upload'))

        payload = jdict.get('payload')

        return Message(device, topic, upload, payload)
Example #6
0
    def construct_from_uri(cls, uri):
        if not uri:
            return None

        # parse...
        parse = urllib.parse.urlparse(urllib.parse.unquote(uri))
        params = urllib.parse.parse_qs(parse[4])

        if 'start-date' not in params or 'end-date' not in params:
            return None

        # construct...
        start_date = LocalizedDatetime.construct_from_iso8601(
            params['start-date'][0])
        end_date = LocalizedDatetime.construct_from_iso8601(
            params['end-date'][0])

        if not start_date or not end_date:
            return None

        return NextMessageQuery(start_date, end_date)
Example #7
0
    def construct_from_jdict(cls, jdict):
        if not jdict:
            return None

        tag = jdict.get('tag')

        rec = LocalizedDatetime.construct_from_iso8601(jdict.get('rec'))
        command = Command.construct_from_jdict(jdict.get('cmd'))
        omd = jdict.get('omd')
        digest = jdict.get('digest')

        datum = ControlReceipt(tag, rec, command, omd, digest)

        return datum
Example #8
0
    def construct_from_jdict(cls, jdict):
        if not jdict:
            return None

        tag = jdict.get('tag')
        attn = jdict.get('attn')

        rec = LocalizedDatetime.construct_from_iso8601(jdict.get('rec'))
        cmd_tokens = jdict.get('cmd_tokens')
        digest = jdict.get('digest')

        datum = ControlDatum(tag, attn, rec, cmd_tokens, digest)

        return datum
Example #9
0
 def start(self):
     return LocalizedDatetime.construct_from_iso8601(
         self.__opts.start) if self.__opts.start else None
Example #10
0
 def end(self):
     return LocalizedDatetime.construct_from_iso8601(
         self.__opts.end) if self.__opts.end else None

# --------------------------------------------------------------------------------------------------------------------
# run...

print("now...")
now = LocalizedDatetime.now()
print(now)

iso = now.as_iso8601()
print(iso)
print("-")


print("from iso...")
loc = LocalizedDatetime.construct_from_iso8601(iso)
print(loc)

iso = loc.as_iso8601()
print(iso)
print("-")


print("from truncated iso...")
iso = "2017-05-18T10:42:50+00:00"
print("iso: %s" % iso)

loc = LocalizedDatetime.construct_from_iso8601(iso)
print(loc)
print("-")
Example #12
0
 def end(self):
     return None if self.__opts.end is None else LocalizedDatetime.construct_from_iso8601(
         self.__opts.end)
Example #13
0
 def start(self):
     return None if self.__opts.start is None else LocalizedDatetime.construct_from_iso8601(
         self.__opts.start)
Example #14
0
    def is_valid_end(self):
        if self.__opts.end is None:
            return True

        return LocalizedDatetime.construct_from_iso8601(
            self.__opts.end) is not None
Example #15
0
    def is_valid_start(self):
        if self.__opts.start is None:
            return True

        return LocalizedDatetime.construct_from_iso8601(
            self.__opts.start) is not None
        for line in sys.stdin:
            # sample...
            datum = PathDict.construct_from_jstr(line)

            if datum is None:
                continue

            document_count += 1

            try:
                rec_node = datum.node(cmd.iso)
            except KeyError:
                continue

            rec = LocalizedDatetime.construct_from_iso8601(rec_node)

            # set checkpoint...
            if checkpoint is None:
                checkpoint = generator.enclosing_localised_datetime(rec)

            # report and reset...
            if rec.datetime > checkpoint.datetime:
                aggregate.print(checkpoint)
                aggregate.reset()

                filler = checkpoint
                checkpoint = generator.enclosing_localised_datetime(rec)

                # fill missing...
                while cmd.fill:
Example #17
0
        # run...

        prev_time = None

        for line in sys.stdin:
            if cmd.verbose:
                print(line, file=sys.stderr)

            datum = PathDict.construct_from_jstr(line)

            if datum is None:
                break

            document_count += 1

            time = LocalizedDatetime.construct_from_iso8601(
                datum.node(cmd.path))

            interval = Interval.construct(prev_time, time, cmd.precision)
            print(JSONify.dumps(interval))
            sys.stdout.flush()

            prev_time = time

            processed_count += 1

    # ----------------------------------------------------------------------------------------------------------------
    # end...

    except KeyboardInterrupt:
        if cmd.verbose:
            print("sample_interval: KeyboardInterrupt", file=sys.stderr)
Example #18
0
        for line in sys.stdin:
            try:
                jdict = json.loads(line)
            except ValueError:
                continue

            document_count += 1

            try:
                rec = jdict['rec']
            except KeyError:
                continue

            # zone shift...
            datetime = LocalizedDatetime.construct_from_iso8601(rec)

            if datetime is None:
                continue

            jdict['rec'] = datetime.localize(zone).as_iso8601()

            # report...
            print(JSONify.dumps(jdict))
            sys.stdout.flush()

            processed_count += 1

    # ----------------------------------------------------------------------------------------------------------------
    # end...
Example #19
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": {"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.pm10')

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

d2 = PathDict.construct_from_jstr(j2)
print(d2)
print("-")

rec = LocalizedDatetime.construct_from_iso8601(d2.node('rec'))
val = d2.node('val.opc.pm10')

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