38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
|
|
import json
|
||
|
|
|
||
|
|
|
||
|
|
class TrainData:
|
||
|
|
def __init__(self):
|
||
|
|
"""
|
||
|
|
初始化车辆数据类
|
||
|
|
参数与之前保持一致
|
||
|
|
"""
|
||
|
|
self.source_title = []
|
||
|
|
self.source_data = []
|
||
|
|
self.average_data = []
|
||
|
|
self.source_curve_data = {}
|
||
|
|
self.source_curve_data["legend"] = []
|
||
|
|
self.source_curve_data["xAxis"] = []
|
||
|
|
self.source_curve_data["series"] = []
|
||
|
|
|
||
|
|
def to_dict(self):
|
||
|
|
"""将类实例转换为字典格式"""
|
||
|
|
return {
|
||
|
|
'source_title': self.source_title,
|
||
|
|
'source_data': self.source_data,
|
||
|
|
'average_data': self.average_data,
|
||
|
|
'source_curve_data': self.source_curve_data
|
||
|
|
}
|
||
|
|
|
||
|
|
def to_json(self, indent=None):
|
||
|
|
"""将类实例序列化为JSON字符串"""
|
||
|
|
return json.dumps(self.to_dict(), indent=indent, ensure_ascii=False)
|
||
|
|
|
||
|
|
# 保留原有获取数据的方法
|
||
|
|
def get_source_title(self): return self.source_title
|
||
|
|
|
||
|
|
def get_source_data(self): return self.source_data
|
||
|
|
|
||
|
|
def get_average_data(self): return self.average_data
|
||
|
|
|
||
|
|
def get_curve_data(self): return self.source_curve_data
|