|
@@ -37,6 +37,60 @@ class Common(object):
|
|
|
self.out('验证失败')
|
|
|
|
|
|
|
|
|
+class test_path(Load):
|
|
|
+ @Web.setting
|
|
|
+ def get(self):
|
|
|
+ import csv,codecs
|
|
|
+ from datetime import *
|
|
|
+ file_name = 'test.csv'
|
|
|
+ day = str(date.today())
|
|
|
+ day = day.split('-')
|
|
|
+ file_path = day[0] + '/' + day[1] + '/' + day[2]
|
|
|
+ file_path = File.mkdirs(os.path.join(Demeter.path, 'runtime','upload', file_path)) + '/' + file_name
|
|
|
+
|
|
|
+ data = [{'data': {'rows': [['2017-11-01 00:02:27', 10.95], ['2017-11-01 00:07:27', 9.45], ['2017-11-01 00:12:27', 9.4], ['2017-11-01 00:17:27', 9.45], ['2017-11-01 00:22:27', 9.45], ['2017-11-01 00:27:27', 9.35], ['2017-11-01 00:32:27', 9.35], ['2017-11-01 00:37:27', 9.25], ['2017-11-01 00:42:27', 9.3], ['2017-11-01 00:47:27', 10.55], ['2017-11-01 00:52:27', 9.55], ['2017-11-01 00:57:31', 9.25]], 'value': '[10.95, 9.45, 9.4, 9.45, 9.45, 9.35, 9.35, 9.25, 9.3, 10.55, 9.55, 9.25]', 'time': '["2017-11-01 00:02:27", "2017-11-01 00:07:27", "2017-11-01 00:12:27", "2017-11-01 00:17:27", "2017-11-01 00:22:27", "2017-11-01 00:27:27", "2017-11-01 00:32:27", "2017-11-01 00:37:27", "2017-11-01 00:42:27", "2017-11-01 00:47:27", "2017-11-01 00:52:27", "2017-11-01 00:57:31"]'}, 'name': '\xe6\x98\x8e\xe7\xbb\x86'}]
|
|
|
+
|
|
|
+ data1 = [{'data': {'rows': [['2017-11-01 00:07:27', 3.45], ['2017-11-01 00:12:27', 4.4], ['2017-11-01 00:17:27', 6.45], ['2017-11-01 00:22:27', 5.45], ['2017-11-01 00:27:27', 5.35], ['2017-11-01 00:32:27', 3.35], ['2017-11-01 00:37:27', 3.25], ['2017-11-01 00:42:27', 4.3], ['2017-11-01 00:47:27', 3.55], ['2017-11-01 00:52:27', 4.55], ['2017-11-01 00:57:31', 5.25]], 'value': '[10.95, 9.45, 9.4, 9.45, 9.45, 9.35, 9.35, 9.25, 9.3, 10.55, 9.55, 9.25]', 'time': '["2017-11-01 00:02:27", "2017-11-01 00:07:27", "2017-11-01 00:12:27", "2017-11-01 00:17:27", "2017-11-01 00:22:27", "2017-11-01 00:27:27", "2017-11-01 00:32:27", "2017-11-01 00:37:27", "2017-11-01 00:42:27", "2017-11-01 00:47:27", "2017-11-01 00:52:27", "2017-11-01 00:57:31"]'}, 'name': '\xe6\x98\x8e\xe7\xbb\x86'}]
|
|
|
+
|
|
|
+ datad = {}
|
|
|
+ for t,v in data[0]['data']['rows']:
|
|
|
+ if t not in datad:
|
|
|
+ datad[t] = [t,v]
|
|
|
+ else:
|
|
|
+ datad[t].append(v)
|
|
|
+
|
|
|
+ newdata = sorted(datad.keys())
|
|
|
+ newds = []
|
|
|
+ for i in newdata:
|
|
|
+ newds.append(datad[i])
|
|
|
+
|
|
|
+ datad = newds
|
|
|
+ header = ['日期', '温度', '湿度']
|
|
|
+ datad.insert(0, header)
|
|
|
+
|
|
|
+ date = '日期'
|
|
|
+ datas = [[date, 'dfdf'],
|
|
|
+ ['Bob', 14],
|
|
|
+ ['Tom', 23],
|
|
|
+ ['Jerry', '18']]
|
|
|
+
|
|
|
+ #self.set_header("Content-Type","text/csv,charset=UTF-8")
|
|
|
+ #self.set_header('Content-Disposition', 'attachment; filename=' + file_name)
|
|
|
+
|
|
|
+ with open(file_path, 'w') as f:
|
|
|
+ f.write(codecs.BOM_UTF8)
|
|
|
+ writer = csv.writer(f)
|
|
|
+ for row in datad:
|
|
|
+ writer.writerow(row)
|
|
|
+
|
|
|
+ url = self.request.protocol + "://" + self.request.host
|
|
|
+
|
|
|
+ file_path = url + file_path.replace(Demeter.path + 'runtime', '')
|
|
|
+
|
|
|
+ self.redirect(file_path)
|
|
|
+ #self.out('yes', datad)
|
|
|
+
|
|
|
+
|
|
|
# 请求转换 /main/convert 接口必须后端获取,token不允许暴露
|
|
|
class convert_path(Load):
|
|
|
@Web.setting
|