Get the stats sorted by an alias (if present) or key.
551753
def sorted_stats(self):
        """"""
        key = self.get_key()
        return sorted(self.stats, key=lambda stat: tuple(map(
            lambda part: int(part) if part.isdigit() else part.lower(),
            re.split(r"(\d+|\D+)", self.has_alias(stat[key]) or stat[key])
        )))
1354473
def sort_func(self, key):
        """"""
        if key == self._KEYS.TIME:
            return 'aaa'
        if key == self._KEYS.DATA:
            return 'zzy'
        if key == self._KEYS.SOURCE:
            return 'zzz'
        return key
460943
def sort_by_name(self):
        """"""
        super(JSSObjectList, self).sort(key=lambda k: k.name)
571719
def get_desc2nts(self, **kws_usr):
        """"""
        # desc2nts contains: (sections hdrgo_prt sortobj) or (flat hdrgo_prt sortobj)
        # keys_nts: hdrgo_prt section_prt top_n use_sections
        kws_nts = {k:v for k, v in kws_usr.items() if k in self.keys_nts}
        return self.get_desc2nts_fnc(**kws_nts)
360676
def _dict_key_priority(s):
        """"""
        if isinstance(s, Hook):
            return _priority(s._schema) - 0.5
        if isinstance(s, Optional):
            return _priority(s._schema) + 0.5
        return _priority(s)
48538
def sortkey(x):
    """"""
    k = str(x[1]).zfill(3) + str(x[2]).zfill(3) + str(x[3]).zfill(3)
    return k
80900
def sort(self, key, *get_patterns,
             by=None, offset=None, count=None,
             asc=None, alpha=False, store=None):
        """"""
        args = []
        if by is not None:
            args += [b'BY', by]
        if offset is not None and count is not None:
            args += [b'LIMIT', offset, count]
        if get_patterns:
            args += sum(([b'GET', pattern] for pattern in get_patterns), [])
        if asc is not None:
            args += [asc is True and b'ASC' or b'DESC']
        if alpha:
            args += [b'ALPHA']
        if store is not None:
            args += [b'STORE', store]
        return self.execute(b'SORT', key, *args)
150228
def _get_key_id(alias, region=None, key=None, keyid=None, profile=None):
    '''
    
    '''
    key_metadata = describe_key(
        alias, region, key, keyid, profile
    )['key_metadata']
    return key_metadata['KeyId']
925961
def get_svc_stats(self, svcs):
        
        stats = {
            "services.total": 0,
            "services.ok": 0,
            "services.warning": 0,
            "services.critical": 0,
            "services.unknown": 0,
            "services.flapping": 0,
            "services.in_downtime": 0,
            "services.checked": 0,
            "services.scheduled": 0,
            "services.active_checks": 0,
            "services.passive_checks": 0,
        }
        for svc in svcs:
            if type(svc) is not dict:
                continue

            sane = self._sanitize_entity(svc)
            stats["services.total"] += 1
            stats["services.flapping"] += self._trans_binary(sane["flapping"])
            stats["services.in_downtime"] += self._trans_dtime(
                sane["in_downtime"])
            stats["services.checked"] += self._trans_binary(sane["checked"])
            stats[
                "services.scheduled"] += self._trans_binary(sane["scheduled"])
            stats["services.active_checks"] += sane["active_checks"]
            stats["services.passive_checks"] += sane["passive_checks"]
            state_key = self._trans_svc_state(sane["state"])
            stats["services.%s" % (state_key)] += 1

        return stats
180784
def get_prototype(self, alias):
        
        output = sort([
            a.index
            for a in self.get_aliases()
            if re.match(re.escape(alias) + "\\d{8}_\\d{6}", a.index) and not a.alias
        ])
        return output
229286
def sort_func(self, key):
        
        if key == self._KEYS.SCHEMA:
            return 'aaa'
        if key == self._KEYS.NAME:
            return 'aab'
        if key == self._KEYS.SOURCES:
            return 'aac'
        if key == self._KEYS.ALIAS:
            return 'aad'
        if key == self._KEYS.MODELS:
            return 'aae'
        if key == self._KEYS.PHOTOMETRY:
            return 'zzy'
        if key == self._KEYS.SPECTRA:
            return 'zzz'
        return key
1233636
def get(self):
        
        stats = {}
        if self.start_date is not None:
            stats["start_date"] = self.start_date
        if self.end_date is not None:
            stats["end_date"] = self.end_date
        if self.aggregated_by is not None:
            stats["aggregated_by"] = self.aggregated_by
        if self.sort_by_metric is not None:
            stats["sort_by_metric"] = self.sort_by_metric
        if self.sort_by_direction is not None:
            stats["sort_by_direction"] = self.sort_by_direction
        if self.limit is not None:
            stats["limit"] = self.limit
        if self.offset is not None:
            stats["offset"] = self.offset
        if self.categories is not None:
            stats['categories'] = [category.get() for category in
                                   self.categories]
        return stats
331641
def get_worksheet_keys(data_dict, result_info_key):
    
    keys = set(data_dict.keys())
    keys.remove(result_info_key)
    if 'meta' in keys:
        keys.remove('meta')
    return sorted(keys)
40629
def sort_func(self, key):
        """"""
        if key == self._KEYS.VALUE:
            return 'aaa'
        if key == self._KEYS.SOURCE:
            return 'zzz'
        return key
866327
def statistic_record(self, desc=True, timeout=3, is_async=False, only_read=True, *keys):
        
        if len(keys) == 0:
            records = self._generate_statistic_records()
        else:
            records = self._generate_statistic_records_by_keys(keys)
        return sorted(records, key=lambda t: t['hit_counts'], reverse=desc)
429163
def stats(self, key=None):
        
        # TODO: Stats with key is not working.
        if key is not None:
            if isinstance(key, text_type):
                key = str_to_bytes(key)
            keylen = len(key)
            packed = struct.pack(
                self.HEADER_STRUCT + '%ds' % keylen,
                self.MAGIC['request'],
                self.COMMANDS['stat']['command'],
                keylen, 0, 0, 0, keylen, 0, 0, key)
        else:
            packed = struct.pack(
                self.HEADER_STRUCT,
                self.MAGIC['request'],
                self.COMMANDS['stat']['command'],
                0, 0, 0, 0, 0, 0, 0)

        self._send(packed)

        value = {}

        while True:
            response = self._get_response()

            status = response[5]
            if status == self.STATUS['server_disconnected']:
                break

            keylen = response[2]
            bodylen = response[6]

            if keylen == 0 and bodylen == 0:
                break

            extra_content = response[-1]
            key = extra_content[:keylen]
            body = extra_content[keylen:bodylen]
            value[key.decode() if isinstance(key, bytes) else key] = body

        return value
776503
def sortkey(x):
    """"""
    r = x[1] / 255.
    g = x[2] / 255.
    b = x[3] / 255.
    cmax = max(r, g, b)
    V = str(int(round(cmax * 100))).zfill(3)
    cmin = min(r, g, b)
    delta = cmax - cmin
    if delta == 0:
        hue = 0
    elif cmax == r:
        hue = 60. * (((g - b)/delta) % 6)
    elif cmax == g:
        hue = 60. * (((b - r)/delta) + 2)
    else:
        hue = 60. * (((r - g)/delta) + 4)
        
    H = str(int(round(hue))).zfill(3)
    
    if cmax == 0:
        sat = 0
    else:
        sat = delta / cmax
    S = str(int(round(sat  * 100))).zfill(3)

    return H + S + V