|
@@ -290,8 +290,8 @@ class Device(object):
|
|
|
self.data['pic'][key]['cdates'] = Demeter.date(value['sdate'])
|
|
|
|
|
|
@staticmethod
|
|
|
- def statBase(self, deviceInfo={}, state=False):
|
|
|
- device = self.input('device')
|
|
|
+ def statBase(self, deviceInfo={}, device):
|
|
|
+
|
|
|
method = self.input('method', 'maxmin')
|
|
|
if not device:
|
|
|
|
|
@@ -324,15 +324,16 @@ class Device(object):
|
|
|
search['type'] = type
|
|
|
search['id'] = id
|
|
|
self.data['search'] = search
|
|
|
- out = self.input('out')
|
|
|
- if not out:
|
|
|
- self.data['statList'] = model.getData(method, search, self.data['deviceInfo'])
|
|
|
+ self.data['statList'] = model.getData(method, search, self.data['deviceInfo'])
|
|
|
+ return self.data
|
|
|
+
|
|
|
@staticmethod
|
|
|
def stat(self):
|
|
|
id, type = Device.init(self, search={'hardware_type--ins':[2,4]})
|
|
|
if not id:
|
|
|
return
|
|
|
- Device.statBase(self, self.data['device'][0])
|
|
|
+ device = self.input('device')
|
|
|
+ Device.statBase(self, self.data['device'][0], device)
|
|
|
self.data['url'] = Device.url('type='+type+'&id=' + id)
|
|
|
|
|
|
@staticmethod
|
|
@@ -340,30 +341,51 @@ class Device(object):
|
|
|
id, type = Device.init(self, search={'hardware_type--ins':[2,4]})
|
|
|
if not id:
|
|
|
return
|
|
|
- Device.statBase(self, self.data['device'][0])
|
|
|
- self.data['url'] = Device.url('type='+type+'&id=' + id)
|
|
|
|
|
|
- if 'statList' in self.data:
|
|
|
- import csv
|
|
|
- from datetime import *
|
|
|
- import uuid
|
|
|
- self.set_header("Content-Type","text/csv,charset=UTF-8")
|
|
|
- datas = [['name', 'age'],
|
|
|
- ['Bob', 14],
|
|
|
- ['Tom', 23],
|
|
|
- ['Jerry', '18']]
|
|
|
-
|
|
|
- day = str(date.today())
|
|
|
- day = day.split('-')
|
|
|
- file_name = self.data['deviceInfo']['name']
|
|
|
- file_path = day[0] + '/' + day[1] + '/' + day[2]
|
|
|
- file_path = File.mkdirs(os.path.join(Demeter.path, 'runtime','upload', file_path)) + '/' + file_name + '.csv'
|
|
|
- with open(file_path, 'w', newline='') as f:
|
|
|
- writer = csv.writer(f)
|
|
|
- for row in datas:
|
|
|
- writer.writerow(row)
|
|
|
- self.finish()
|
|
|
- return
|
|
|
+ out = self.input('out')
|
|
|
+ if not out:
|
|
|
+ device = self.input('device')
|
|
|
+ data = []
|
|
|
+ header = []
|
|
|
+ datas = {}
|
|
|
+ header.append('日期')
|
|
|
+ for i in device:
|
|
|
+ result = Device.statBase(self, self.data['device'][0], device[i])
|
|
|
+ if result['statList']:
|
|
|
+ header.append(result['deviceInfo']['name'])
|
|
|
+
|
|
|
+ for t,v in result['statList'][0]['data']['rows']:
|
|
|
+ if t not in datas:
|
|
|
+ datas[t] = [t,v]
|
|
|
+ else:
|
|
|
+ datas[t].append(v)
|
|
|
+
|
|
|
+
|
|
|
+ self.data['url'] = Device.url('type='+type+'&id=' + id)
|
|
|
+
|
|
|
+ if datas:
|
|
|
+ import csv,codecs
|
|
|
+ from datetime import *
|
|
|
+ import uuid
|
|
|
+ data = list(datas.values())
|
|
|
+ data.insert(0, header)
|
|
|
+ fileData = data
|
|
|
+
|
|
|
+ day = str(date.today())
|
|
|
+ day = day.split('-')
|
|
|
+ file_name = self.data['info']['name'] + '.csv'
|
|
|
+ file_path = day[0] + '/' + day[1] + '/' + day[2]
|
|
|
+ file_path = File.mkdirs(os.path.join(Demeter.path, 'runtime','upload', file_path)) + '/' + file_name
|
|
|
+ with open(file_path, 'w', newline='') as f:
|
|
|
+ f.write(codecs.BOM_UTF8)
|
|
|
+ writer = csv.writer(f)
|
|
|
+ for row in fileData:
|
|
|
+ writer.writerow(row)
|
|
|
+ url = self.request.protocol + "://" + self.request.host
|
|
|
+ file_path = url + file_path.replace(Demeter.path + 'runtime', '')
|
|
|
+ self.set_header("Content-Type","text/csv,charset=UTF-8")
|
|
|
+ self.set_header('Content-Disposition', 'attachment; filename=' + file_name)
|
|
|
+ self.redirect(file_path)
|
|
|
|
|
|
@staticmethod
|
|
|
def log(self):
|