|
14 | 14 | limitations under the License.
|
15 | 15 | """
|
16 | 16 |
|
17 |
| -#!/usr/bin/env python3 |
| 17 | +# !/usr/bin/env python3 |
18 | 18 | # -*- coding:utf8 -*-
|
| 19 | +import json |
19 | 20 | from typing import List, Mapping
|
20 | 21 |
|
21 | 22 |
|
@@ -92,3 +93,122 @@ def from_json(metric_info):
|
92 | 93 | result.task_info.append(task_info)
|
93 | 94 | statistics_job_detail_info.result.append(result)
|
94 | 95 | return statistics_job_detail_info
|
| 96 | + |
| 97 | + |
| 98 | +class JobInfo: |
| 99 | + job_id: str |
| 100 | + card_time: float |
| 101 | + create_time: str |
| 102 | + start_time: str |
| 103 | + finish_time: str |
| 104 | + device_count: int |
| 105 | + |
| 106 | + def __init__(self, job_id: str, card_time: float, create_time: str, start_time: str, finish_time: str, |
| 107 | + device_count: int) -> None: |
| 108 | + self.job_id = job_id |
| 109 | + self.card_time = card_time |
| 110 | + self.create_time = create_time |
| 111 | + self.start_time = start_time |
| 112 | + self.finish_time = finish_time |
| 113 | + self.device_count = device_count |
| 114 | + |
| 115 | + def to_json(self): |
| 116 | + job_info = { |
| 117 | + "jobId": self.job_id, |
| 118 | + "cardTime": self.card_time, |
| 119 | + "createTime": self.create_time, |
| 120 | + "startTime": self.start_time, |
| 121 | + "finishTime": self.finish_time, |
| 122 | + "deviceCount": self.device_count |
| 123 | + } |
| 124 | + return job_info |
| 125 | + |
| 126 | + |
| 127 | +class Detail: |
| 128 | + user_name: str |
| 129 | + job_info_list: List[JobInfo] |
| 130 | + job_count: int |
| 131 | + total_card_time: float |
| 132 | + |
| 133 | + def __init__(self, user_name: str, job_info_list: List[JobInfo], job_count: int, total_card_time: float) -> None: |
| 134 | + self.user_name = user_name |
| 135 | + self.job_info_list = job_info_list |
| 136 | + self.job_count = job_count |
| 137 | + self.total_card_time = total_card_time |
| 138 | + |
| 139 | + def __str__(self): |
| 140 | + json.dumps(self.__dict__) |
| 141 | + |
| 142 | + def to_str(self): |
| 143 | + return "Detail: user name: {}, job info list: {}, job count: {}, total card time: {},". \ |
| 144 | + format(self.user_name, self.job_info_list, self.job_count, self.total_card_time) |
| 145 | + |
| 146 | + |
| 147 | +class CardTimeResult: |
| 148 | + queue_name: str |
| 149 | + card_time: float |
| 150 | + device_type: str |
| 151 | + detail: List[Detail] |
| 152 | + |
| 153 | + def __init__(self, queue_name: str, card_time: float, device_type: str, detail: List[Detail]) -> None: |
| 154 | + self.queue_name = queue_name |
| 155 | + self.card_time = card_time |
| 156 | + self.device_type = device_type |
| 157 | + self.detail = detail |
| 158 | + |
| 159 | + def __str__(self): |
| 160 | + return "Detail: queue name: {}, card time: {}, device type: {}, detail: {},". \ |
| 161 | + format(self.queue_name, self.card_time, self.device_type, self.detail) |
| 162 | + |
| 163 | + |
| 164 | +class CardTimeInfo: |
| 165 | + data: List[CardTimeResult] |
| 166 | + |
| 167 | + def __init__(self, data: List[CardTimeResult]) -> None: |
| 168 | + self.data = data |
| 169 | + |
| 170 | + def __str__(self) -> str: |
| 171 | + """ str """ |
| 172 | + return "CardTimeInfo: data: {}".format(self.data) |
| 173 | + |
| 174 | + @staticmethod |
| 175 | + def from_json(card_time_stat_info): |
| 176 | + card_time_info = CardTimeInfo( |
| 177 | + data=[], |
| 178 | + ) |
| 179 | + try: |
| 180 | + for result_json in card_time_stat_info['data']: |
| 181 | + result = CardTimeResult( |
| 182 | + queue_name=result_json['queueName'], |
| 183 | + card_time=result_json['cardTime'], |
| 184 | + device_type=result_json['deviceType'], |
| 185 | + detail=[] |
| 186 | + ) |
| 187 | + try: |
| 188 | + for detail_json in result_json['detail']: |
| 189 | + detail = Detail( |
| 190 | + user_name=detail_json['userName'], |
| 191 | + job_info_list=[], |
| 192 | + job_count=detail_json['jobCount'], |
| 193 | + total_card_time=detail_json['totalCardTime'] |
| 194 | + ) |
| 195 | + try: |
| 196 | + for job_info_json in detail_json['jobInfoList']: |
| 197 | + job_info = JobInfo( |
| 198 | + job_id=job_info_json['jobId'], |
| 199 | + card_time=job_info_json['cardTime'], |
| 200 | + create_time=job_info_json['createTime'], |
| 201 | + start_time=job_info_json['startTime'], |
| 202 | + finish_time=job_info_json['finishTime'], |
| 203 | + device_count=job_info_json['deviceCount'], |
| 204 | + ) |
| 205 | + detail.job_info_list.append(job_info) |
| 206 | + except: |
| 207 | + pass |
| 208 | + result.detail.append(detail) |
| 209 | + except: |
| 210 | + pass |
| 211 | + card_time_info.data.append(result) |
| 212 | + except: |
| 213 | + pass |
| 214 | + return card_time_info |
0 commit comments