示例#1
0
    def construct_from_jstr(cls, jstr):
        if not jstr:
            return None

        # document...
        document = PathDict.construct_from_jstr(jstr)

        if not document:
            return None

        # upload...
        upload_node = document.node(cls.UPLOAD_FIELD)
        upload = LocalizedDatetime.construct_from_iso8601(upload_node)

        if upload is None:
            raise ValueError(upload_node)

        # rec...
        rec_node = document.node(cls.REC_FIELD)
        rec = LocalizedDatetime.construct_from_iso8601(rec_node)

        if rec is None:
            raise ValueError(rec_node)

        # offset...
        td = upload - rec
        offset = Timedelta(days=td.days, seconds=td.seconds)

        return UploadInterval(upload, rec, offset)
示例#2
0
    def construct_from_jdict(cls, jdict):
        if not jdict:
            return None

        topic = jdict.get('topic')
        date = datetime.datetime.fromtimestamp(jdict.get('date') / 1e3)         # Warning: JavaScript timestamp!
        message_jstr = jdict.get('message')

        message_jdict = PathDict.construct_from_jstr(message_jstr)

        return MessageEvent(topic, date, message_jdict)
示例#3
0
    cmd = CmdNode()

    if not cmd.is_valid():
        cmd.print_help(sys.stderr)
        exit(2)

    if cmd.verbose:
        print(cmd, file=sys.stderr)
        sys.stderr.flush()

    try:
        # ------------------------------------------------------------------------------------------------------------
        # run...

        for line in sys.stdin:
            datum = PathDict.construct_from_jstr(line)

            if datum is None:
                continue

            if cmd.ignore and not datum.has_path(cmd.path):
                continue

            node = datum.node(cmd.path)

            print(JSONify.dumps(node))
            sys.stdout.flush()

    # ----------------------------------------------------------------------------------------------------------------
    # end...
示例#4
0
        '"scs-status": {"tally": 1.0, "interval": 60.0}, ' \
        '"scs-climate": {"tally": 1.0, "interval": 60.0}, "scs-gases": {"tally": 1.0, "interval": 10.0}}, ' \
        '"gps": {"pos": [50.83390976, -0.13919364], "qual": 1.0, "elv": 44.1}, ' \
        '"airnow": {"site": 826987654321.0}}, ' \
        '"tag": "scs-bgx-401"}}'

print(jstr)
print("=")

duration = 1

mapping = DatumMapping("particulates", "pm1")
print(mapping)
print("-")

datum = PathDict.construct_from_jstr(jstr)
print(datum)
print("-")

print("         tag: %s" % mapping.environment_tag(datum))
print("       value: %s" % mapping.value(datum))
print("      source: %s" % mapping.source(datum))
print("     mapping: %s" % mapping.aqcsv_source_mapping(datum))
print("-")

print(JSONify.dumps(mapping))
print("-")

record = mapping.aqcsv_record(datum, duration)
print(record)
print("-")
        ndir.power_on()

        if cmd.default:
            calib = calib_class.default()

            # save...
            ndir.store_calib(calib)

        elif cmd.restart:
            ndir.reload_calib()

        elif cmd.set():
            # retrieve...
            calib = ndir.retrieve_calib()
            dictionary = PathDict.construct_from_jstr(JSONify.dumps(calib))

            # validate...
            if not dictionary.has_path(cmd.path):
                print("ndir_calib: field name not known: %s" % cmd.path,
                      file=sys.stderr)
                exit(2)

            # set...
            dictionary.append(cmd.path, cmd.value)
            calib = calib_class.construct_from_jdict(dictionary.as_json())

            # validate...
            dictionary = PathDict.construct_from_jstr(JSONify.dumps(calib))

            if dictionary.node(cmd.path) is None:
示例#6
0
        # ------------------------------------------------------------------------------------------------------------
        # resources...

        join = Join.construct(cmd.left_prefix, cmd.left_pk, cmd.right_prefix,
                              cmd.right_pk, cmd.iso8601)

        try:
            reader = CSVReader(filename=cmd.left_filename)
        except FileNotFoundError:
            print("csv_join: file not found: %s" % cmd.left_filename,
                  file=sys.stderr)
            exit(1)

        for row in reader.rows:
            jstr = row.strip()
            datum = PathDict.construct_from_jstr(row)

            if datum is None:
                continue

            left_document_count += 1

            if cmd.left_pk not in datum.paths():
                print("csv_join: pk '%s' missing: %s" % (cmd.left_pk, jstr),
                      file=sys.stderr)
                exit(1)

            if datum.node(cmd.left_pk) == '':
                continue

            try:
示例#7
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)
print(d2)
print("-")

rec = LocalizedDatetime.construct_from_iso8601(d2.node('rec'))
示例#8
0
print(join)
print("-")

print("left...")
for jstr in left_data:
    print(jstr)
print("-")

print("right...")
for jstr in right_data:
    print(jstr)
print("-")

print("import...")
for jstr in left_data:
    join.append_to_left(PathDict.construct_from_jstr(jstr))

for jstr in right_data:
    join.append_to_right(PathDict.construct_from_jstr(jstr))

print(join)
print("-")

print("inner...")
for row in join.inner():
    print(JSONify.dumps(row))
print("-")

print("left...")
for row in join.left():
    print(JSONify.dumps(row))