adio.py 3.43 KB
Newer Older
lcn's avatar
lcn committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
# -*- coding:utf-8 -*-
#
# Author:jing
# Date: 2020/7/9
from dataclasses import dataclass

from pot_libs.common.components.fields import Item, DateTime
from pot_libs.sanic_api import Model
from pot_libs.sanic_api.column import List, Str, Float, Opt
from unify_api.utils.response_code import DbErr


@dataclass
class AdioHistory(Model):
    item: Item = Item
    value_slots: list = List('数值').items(Float())
    threhold: float = Opt(Float().eg(30))


@dataclass
class AdioHistoryResponse(Model, DbErr):
    temperature: list = List().items(AdioHistory)
    residual_current: list = List().items(AdioHistory)
    time_slots: list = List('时间轴').items(Str('时间'))


@dataclass
class AdioCurrent(Model):
    type: str = Str('location.type[temperature|residual_current]').eg(
        'temperature')
    item: Item = Item
    real_time: DateTime = DateTime
    value: float = Float('adio实时数值')


@dataclass
class AdioCurrentResponse(Model, DbErr):
    temperature: list = List('温度列表').items(AdioCurrent)
    residual_current: list = List('漏电流列表').items(AdioCurrent)


@dataclass
class AdioIndex(Model):
    type: str = Str('location.type[temperature|residual_current]').eg(
        'temperature')
    item: Item = Item
    max: float = Float('最大值')
    max_time: DateTime = DateTime
    min: float = Float('最小值')
    min_time: DateTime = DateTime
    avg: float = Float('平均值')


@dataclass
class AdioIndexResponse(Model, DbErr):
    adio_indexes: list = List('指标统计列表').items(AdioIndex)


adio_history_example = {
    "范例1": {
        "page_size": 20,
        "page_num": 1,
        "filter": {
            "equals": [
                {
                    "field": "point_id",
                    "value": 127
                }
            ],
            "ranges": [
                {
                    "field": "datetime",
                    "start": "2020-07-22 00:00:00",
                    "end": "2020-07-22 23:59:59"
                }
            ],
            "in_groups": [
                {
                    "field": "location_id",
                    "group": [
                        133, 134, 135
                    ]
                }
            ]
        },
        "sort": {
            "field": "datetime",
            "direction": "desc"
        }
    }
}

adio_current_example = {
    "范例1": {
        "filter": {
            "equals": [],
            "ranges": [],
            "in_groups": [
                {
                    "field": "location_id",
                    "group": [
                        259, 260, 261, 262, 263
                    ]
                }
            ]
        }
    }
}

adio_index_example = {
    "范例1": {
        "page_size": 20,
        "page_num": 1,
        "filter": {
            "equals": [
                {
                    "field": "point_id",
                    "value": 175
                }
            ],
            "ranges": [
                {
                    "field": "datetime",
                    "start": "2020-07-22 00:00:00",
                    "end": "2020-07-22 23:59:59"
                }
            ],
            "in_groups": [
                {
                    "field": "location_id",
                    "group": [
                        259, 260, 261, 262, 263
                    ]
                }
            ]
        },
        "sort": {
            "field": "datetime",
            "direction": "desc"
        }
    }
}