Beispiel #1
0
    def _save(self, _key, _day, _hour, _value, **kwargs):
        if callable(_value):
            _value = _value(**kwargs)

        if type(_value) is list:
            for item in _value:
                StatLog.objects(key=_key.format(**item), day=_day, hour=_hour).update(
                    set__value=item['value'],
                    set__modified=datetime.now(),
                    set_on_insert__created=datetime.now(),
                    upsert=True,
                )
        else:
            StatLog.objects(key=_key, day=_day, hour=_hour).update(
                set__value=_value,
                set__modified=datetime.now(),
                set_on_insert__created=datetime.now(),
                upsert=True,
            )
Beispiel #2
0
def get_hour_list(key, day, tid=None, hour=23):
    query = dict(key=key, day=day)
    if tid:
        query['tid'] = tid

    items = StatLog.objects(**query)
    values = [0 for i in range(hour + 1)]
    for item in items:
        if item.hour <= hour:
            values[item.hour] = item.value
    return values
Beispiel #3
0
def get_value_list(key, days, tid=None):
    query = dict(key=key, day__in=days)
    if tid:
        query['tid'] = tid

    length = len(days)
    value_list = [0 for i in range(length)]
    items = StatLog.objects(**query)
    for item in items:
        value_list[days.index(item.day)] = item.value
    return value_list
Beispiel #4
0
    def _save(self, _key, _day, _hour, _value, **kwargs):
        if callable(_value):
            _value = _value(**kwargs)

        if type(_value) is list:
            for item in _value:
                StatLog.objects(key=_key.format(**item), day=_day,
                                hour=_hour).update(
                                    set__value=item['value'],
                                    set__modified=datetime.now(),
                                    set_on_insert__created=datetime.now(),
                                    upsert=True,
                                )
        else:
            StatLog.objects(key=_key, day=_day, hour=_hour).update(
                set__value=_value,
                set__modified=datetime.now(),
                set_on_insert__created=datetime.now(),
                upsert=True,
            )
Beispiel #5
0
def get_hour_list(key, day, tid=None, hour=23):
    query = dict(key=key, day=day)
    if tid:
        query['tid'] = tid

    items = StatLog.objects(**query)
    values = [0 for i in range(hour + 1)]
    for item in items:
        if item.hour <= hour:
            values[item.hour] = item.value
    return values
Beispiel #6
0
def get_value_list(key, days, tid=None):
    query = dict(key=key, day__in=days)
    if tid:
        query['tid'] = tid

    length = len(days)
    value_list = [0 for i in range(length)]
    items = StatLog.objects(**query)
    for item in items:
        value_list[days.index(item.day)] = item.value
    return value_list
Beispiel #7
0
    def _save(self, _key, _day, _hour, _value, **kwargs):
        if callable(_value):
            _value = _value(**kwargs)

        if type(_value) is list:
            for item in _value:
                if type(item['value']) == dict:
                    for sk, sv in item['value'].iteritems():
                        query = dict(key=_key.format(_id=item['_id'], key=sk),
                                     day=_day,
                                     hour=_hour)
                        StatLog.objects(**query).update(
                            set__value=sv,
                            set__modified=datetime.now(),
                            set_on_insert__created=datetime.now(),
                            upsert=True,
                        )
                else:
                    StatLog.objects(key=_key.format(**item),
                                    day=_day,
                                    hour=_hour).update(
                                        set__value=item['value'],
                                        set__modified=datetime.now(),
                                        set_on_insert__created=datetime.now(),
                                        upsert=True,
                                    )
        else:
            StatLog.objects(key=_key, day=_day, hour=_hour).update(
                set__value=_value,
                set__modified=datetime.now(),
                set_on_insert__created=datetime.now(),
                upsert=True,
            )