Esempio n. 1
0
    def construct_from_jdict(cls, jdict):
        if not jdict:
            return None

        timedelta = Timedelta.construct_from_ps_elapsed_report(jdict.get('period'))

        return NDIRUptime(timedelta.delta.total_seconds())
Esempio n. 2
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)
Esempio n. 3
0
    def read_time_until_full(self):
        raw_ttf = self.__read_reg(self.__REG_TTF, signed=True)

        if raw_ttf < 1:
            return None

        ttf = raw_ttf * 5.625

        return Timedelta(seconds=round(ttf))
Esempio n. 4
0
    def read_time_until_empty(self):
        raw_tte = self.__read_reg(self.__REG_TTE, signed=True)

        if raw_tte < 1:
            return None

        tte = raw_tte * 5.625

        return Timedelta(seconds=round(tte))
Esempio n. 5
0
    def construct_from_jdict(cls, jdict):
        if not jdict:
            return None

        ppid = int(jdict.get('ppid'))
        pid = int(jdict.get('pid'))
        uid = int(jdict.get('uid'))
        tty = jdict.get('tty')

        pcpu = float(jdict.get('pcpu'))
        pmem = float(jdict.get('pmem'))

        cpu_time = Timedelta.construct_from_jdict(jdict.get('cpu'))
        elapsed_time = Timedelta.construct_from_jdict(jdict.get('elapsed'))

        cmd = jdict.get('cmd')

        return PsDatum(ppid, pid, uid, tty, pcpu, pmem, cpu_time, elapsed_time, cmd)
Esempio n. 6
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)
Esempio n. 7
0
    def construct_from_jdict(cls, jdict):
        if not jdict:
            return None

        input_power_present = jdict.get('in')

        charge = ChargeLevel.construct_from_jdict(jdict.get('chrg'))

        tte = Timedelta.construct_from_jdict(jdict.get('tte'))
        ttf = Timedelta.construct_from_jdict(jdict.get('ttf'))

        v = jdict.get('v')
        current = jdict.get('curr')
        temperature = jdict.get('g-tmp')

        capacity = jdict.get('cap')
        cycles = jdict.get('cyc')

        return cls(input_power_present, charge, tte, ttf, v, current,
                   temperature, capacity, cycles)
Esempio n. 8
0
    def construct_from_report(cls, report):
        match = re.match('^\s*(\d+)\s+(\d+)\s+(\d+)\s+([^\s]+)\s+(\d+\.\d+)\s+(\d+\.\d+)\s+([^\s]+)\s+([^\s]+)\s+(.+)$',
                         report)

        if match is None:
            return None

        fields = match.groups()

        ppid = int(fields[0])
        pid = int(fields[1])
        uid = int(fields[2])
        tty = fields[3]

        pcpu = float(fields[4])
        pmem = float(fields[5])

        cpu_time = Timedelta.construct_from_ps_time_report(fields[6])
        elapsed_time = Timedelta.construct_from_ps_elapsed_report(fields[7])
        cmd = fields[8]

        return PsDatum(ppid, pid, uid, tty, pcpu, pmem, cpu_time, elapsed_time, cmd)
Esempio n. 9
0
    def construct_from_report(cls, time, report):
        # period...
        period = Timedelta.construct_from_uptime_report(report)

        # users...
        users_match = re.match('.*(\d+) user(?:s)?,', report)

        if users_match:
            fields = users_match.groups()
            users = int(fields[0])

        else:
            users = None

        # load...
        load = UptimeLoad.construct_from_period_report(report)

        return UptimeDatum(time, period, users, load)
Esempio n. 10
0
"""
Created on 3 Jan 2018

@author: Bruno Beloff ([email protected])

Timedelta objects may or may not have a milliseconds component...
"""


from scs_core.data.json import JSONify
from scs_core.data.timedelta import Timedelta


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

td = Timedelta(weeks=1, days=2, hours=3, minutes=4, seconds=5, milliseconds=6, microseconds=7)
print("td: %s" % td)
print("total_seconds: %s" % td.total_seconds())

jdict = td.as_json()
print("jdict: %s" % jdict)

print("jstr: %s" % JSONify.dumps(td))
print("-")

td = Timedelta.construct_from_jdict(jdict)
print("reconstructed: %s" % td)

print("=")

td = Timedelta(weeks=1, days=2, hours=3, minutes=4, seconds=5)
Esempio n. 11
0
from collections import OrderedDict

from scs_core.data.json import JSONify
from scs_core.data.timedelta import Timedelta

from scs_psu.batt_pack.fuel_gauge.batt_status import BattStatus, ChargeLevel


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

charge = ChargeLevel(23.2, 2057)
print(charge)
print("-")

tte = Timedelta(hours=1, minutes=2, seconds=3)
ttf = Timedelta(hours=11, minutes=21, seconds=31)


datum = BattStatus(True, charge, tte, ttf, 3.3, 1024, 31.2, 4096, 66.5)
print(datum)
print("-")

jstr = JSONify.dumps(datum)
print(jstr)
print("-")

jdict = json.loads(jstr, object_hook=OrderedDict)

datum = BattStatus.construct_from_jdict(jdict)
print(datum)
Esempio n. 12
0
 def timedelta(self):
     return Timedelta.construct_from_flag(self.__opts.timedelta)
Esempio n. 13
0
    def as_timedelta(self):
        minutes = self.sign * ((self.hours * 60) + self.minutes)

        return Timedelta(minutes=minutes)
Esempio n. 14
0
 def timedelta(self):
     return Timedelta(seconds=self.seconds)