Exemplo n.º 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)
    def is_valid(self):
        if self.client_id 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
Exemplo n.º 3
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)
Exemplo n.º 4
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)
Exemplo n.º 5
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)
Exemplo n.º 6
0
    def datetime(iso_datetime):
        if iso_datetime is None:
            return None

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

        return value
Exemplo n.º 7
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)
Exemplo n.º 8
0
    def construct_from_jdict(cls, jdict):
        if not jdict:
            return None

        device = jdict.get('device')
        topic = jdict.get('topic')

        rec = LocalizedDatetime.construct_from_iso8601(
            jdict.get('last_write'))  # as provided by web API

        return cls(device, topic, rec)
Exemplo n.º 9
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
Exemplo n.º 10
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
Exemplo n.º 11
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
Exemplo n.º 12
0
    def construct_from_jdict(cls, jdict, skeleton=False):
        if not jdict:
            return None

        calibrated_on = LocalizedDatetime.construct_from_iso8601(
            jdict.get('calibrated-on'))

        r_comp_0 = jdict.get('r-comp-0')
        temp_co = jdict.get('temp-co')
        full_cap_rep = jdict.get('full-cap-rep')
        full_cap_nom = jdict.get('full-cap-nom')

        cycles = jdict.get('cycles')

        return cls(calibrated_on, r_comp_0, temp_co, full_cap_rep,
                   full_cap_nom, cycles)
Exemplo n.º 13
0
Created on 5 Mar 2019

@author: Bruno Beloff ([email protected])
"""

import pytz

from scs_core.aqcsv.data.aqcsv_datetime import AQCSVDatetime

from scs_core.data.datetime import LocalizedDatetime
from scs_core.data.json import JSONify

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

print("LocalizedDatetime...")
now = LocalizedDatetime.construct_from_iso8601("2019-03-05T23:00:00.709+00:00")
print("now: %s" % now)
print("-")

datetime = now.datetime
print("datetime: %s" % datetime)
print("-")

tzinfo = now.tzinfo
print("tzinfo: %s" % tzinfo)
print("-")

timezone = pytz.timezone('Europe/Athens')
print("timezone: %s" % timezone)

localised = now.localize(timezone)
Exemplo n.º 14
0

# --------------------------------------------------------------------------------------------------------------------
# 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("-")
Exemplo n.º 15
0
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'))
val = d2.node('val.opc_n2.pm10')

lr.append(rec, val)
print(lr)
#!/usr/bin/env python3
"""
Created on 14 Jan 2020

@author: Bruno Beloff ([email protected])
"""

from scs_core.csv.csv_logger_conf import CSVLoggerConf

from scs_core.data.datetime import LocalizedDatetime

from scs_host.sys.host import Host

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

start_iso = '2020-01-20T09:50:00Z'
topic_subject = 'climate'
rec_field = 'rec'

start = LocalizedDatetime.construct_from_iso8601(start_iso)
start_datetime = start.datetime

print("start_datetime: %s" % start_datetime)
print("-")

conf = CSVLoggerConf.load(Host)
print(conf)

log = conf.csv_log(topic_subject, timeline_start=start_datetime)
print(log)
 def end(self):
     return None if self.__opts.end is None else LocalizedDatetime.construct_from_iso8601(
         self.__opts.end)
 def start(self):
     return None if self.__opts.start is None else LocalizedDatetime.construct_from_iso8601(
         self.__opts.start)