コード例 #1
0
    def _from_json(obj, version="2.0"):
        channels, teams, totals = [], [], []
        # <ch0> ... <ch15> .. not all will always be available
        CTs = obj["CTs"]
        for ch_id in range(16):
            if ch_id not in EG_CTCFG.CT_MAP:
                continue

            ctname = EG_CTCFG.CT_MAP[ch_id]
            if ctname in ["L1", "L2", "L3"]:
                channels.append(Channel._make((ch_id, EG_CTCFG.get_ch_row("PT", version=version))))
            else:
                ct = CTs[ctname]
                cal = None
                if "cal" in ct:
                    cal = ct["cal"]
                mul = None
                if "mul" in ct:
                    mul = ct["mul"]
                ch_row = EG_CTCFG.get_ch_row(ct["rating"], cal, mul, version=version)
                channels.append(Channel._make((ch_id, ch_row)))

        # process team --> registers
        REGS = obj["Registers"]
        regnames = sorted(REGS.keys(), key=lambda rg: int(rg[1:]))
        for idx, regname in enumerate(regnames):
            ridx = regname[1:]
            reg = REGS[regname]
            rg = Reg._make((int(ridx), reg["name"], reg["val"], reg["type"]))
            teams.append(rg)

        return channels, teams, totals
コード例 #2
0
    def _to_json(channels, team, totals, version="2.0"):
        chmap = dict((ch.id, ch) for ch in channels)
        teammap = dict((tm.id, tm) for tm in team)

        obj = {}
        obj['Registers'] = REGS = {}
        obj['CTs'] = CTs = {}

        # we are only interested in CT1.. CT12 here
        # The PTs are considered
        for ctnum in range(1, 13):
            visualCTNAME = 'CT%d' % (ctnum)
            if visualCTNAME in EG_CTCFG.CT_MAP_REV and EG_CTCFG.CT_MAP_REV[visualCTNAME] in chmap:
                ct = chmap[EG_CTCFG.CT_MAP_REV[visualCTNAME]]
                mul, _, _, calibration, _ = ct.val.split(',')
                mul_str = "{:.3f}".format(float(mul))

            cts = {}
            ct_type = EG_CTCFG.get_ct_type_by_mul(mul_str, version=version)
            if ct_type is None:
                ct_type = 'custom'
                cts['mul'] = mul_str

            cts['rating'] = ct_type
            if calibration:
                cts['cal'] = calibration
            CTs[visualCTNAME] = cts

        for regnum in range(17):
            if regnum in teammap:
                reg = teammap[regnum]
                REGS["R{}".format(regnum)] = {'name': reg.name,
                                              'val': reg.val, 'type': reg.type}

        return obj
コード例 #3
0
    def _to_json(channels, team, totals, version="2.0"):
        chmap = dict((ch.id, ch) for ch in channels)
        teammap = dict((tm.id, tm) for tm in team)

        obj = {}
        obj["Registers"] = REGS = {}
        obj["CTs"] = CTs = {}
        # we are only interested in CT1.. CT12 here
        # The PTs are considered
        for ctnum in range(1, 13):
            visualCTNAME = "CT%d" % (ctnum)
            if visualCTNAME in EG_CTCFG.CT_MAP_REV and EG_CTCFG.CT_MAP_REV[visualCTNAME] in chmap:
                ct = chmap[EG_CTCFG.CT_MAP_REV[visualCTNAME]]
                mul, _, _, calibration, _ = ct.val.split(",")
                mul_str = "{:.3f}".format(float(mul))

            cts = {}
            ct_type = EG_CTCFG.get_ct_type_by_mul(mul_str, version=version)
            if ct_type is None:
                ct_type = "custom"
                cts["mul"] = mul_str

            cts["rating"] = ct_type
            if calibration:
                cts["cal"] = calibration
            CTs[visualCTNAME] = cts

        for regnum in range(128):
            if regnum in teammap:
                reg = teammap[regnum]
                REGS["R{}".format(regnum)] = {"name": reg.name, "val": reg.val, "type": reg.type}

        return obj
コード例 #4
0
    def _to_json(channels, team, totals, version="2.0"):
        chmap = dict((ch.id, ch) for ch in channels)
        teammap = dict((tm.id, tm) for tm in team)

        obj = {}
        obj['Registers'] = REGS = {}
        obj['CTs'] = CTs = {}

        # we are only interested in CT1.. CT12 here
        # The PTs are considered
        for ctnum in range(1, 13):
            visualCTNAME = 'CT%d' % (ctnum)
            if visualCTNAME in EG_CTCFG.CT_MAP_REV and EG_CTCFG.CT_MAP_REV[visualCTNAME] in chmap:
                ct = chmap[EG_CTCFG.CT_MAP_REV[visualCTNAME]]
                mul, _, _, calibration, _ = ct.val.split(',')
                mul_str = "{:.3f}".format(float(mul))

            cts = {}
            ct_type = EG_CTCFG.get_ct_type_by_mul(mul_str, version=version)
            if ct_type is None:
                ct_type = 'custom'
                cts['mul'] = mul_str

            cts['rating'] = ct_type
            if calibration:
                cts['cal'] = calibration
            CTs[visualCTNAME] = cts

        for regnum in range(17):
            if regnum in teammap:
                reg = teammap[regnum]
                REGS["R{}".format(regnum)] = {'name': reg.name,
                                              'val': reg.val, 'type': reg.type}

        return obj
コード例 #5
0
    def _from_json(obj):
        channels, teams, totals = [], [], []
        # <ch0> ... <ch15> .. not all will always be available
        CTs = obj['CTs']
        for ch_id in range(16):
            if ch_id not in EG_CTCFG.CT_MAP:
                continue

            ctname = EG_CTCFG.CT_MAP[ch_id]
            if ctname in ["L1", "L2", "L3"]:
                channels.append(
                    Channel._make((ch_id, EG_CTCFG.get_ch_row('PT'))))
            else:
                ct = CTs[ctname]
                cal = None
                if 'cal' in ct:
                    cal = ct['cal']
                mul = None
                if 'mul' in ct:
                    mul = ct['mul']
                ch_row = EG_CTCFG.get_ch_row(ct['rating'], cal, mul)
                channels.append(Channel._make((ch_id, ch_row)))

        # process team --> registers
        REGS = obj['Registers']
        regnames = sorted(REGS.keys(), key=lambda rg: int(rg[1:]))
        for idx, regname in enumerate(regnames):
            ridx = regname[1:]
            reg = REGS[regname]
            rg = Reg._make((int(ridx),
                           reg['name'],
                           reg['val'],
                           reg['type']))
            teams.append(rg)

        return channels, teams, totals
コード例 #6
0
    def _from_json(obj, version="2.0"):
        channels, teams, totals = [], [], []
        # <ch0> ... <ch15> .. not all will always be available
        CTs = obj['CTs']
        for ch_id in range(16):
            if ch_id not in EG_CTCFG.CT_MAP:
                continue

            ctname = EG_CTCFG.CT_MAP[ch_id]
            if ctname in ["L1", "L2", "L3"]:
                channels.append(
                    Channel._make((ch_id, EG_CTCFG.get_ch_row('PT', version=version))))
            else:
                ct = CTs[ctname]
                cal = None
                if 'cal' in ct:
                    cal = ct['cal']
                mul = None
                if 'mul' in ct:
                    mul = ct['mul']
                ch_row = EG_CTCFG.get_ch_row(ct['rating'], cal, mul, version=version)
                channels.append(Channel._make((ch_id, ch_row)))

        # process team --> registers
        REGS = obj['Registers']
        regnames = sorted(REGS.keys(), key=lambda rg: int(rg[1:]))
        for idx, regname in enumerate(regnames):
            ridx = regname[1:]
            reg = REGS[regname]
            rg = Reg._make((int(ridx),
                           reg['name'],
                           reg['val'],
                           reg['type']))
            teams.append(rg)

        return channels, teams, totals