dever 7 anos atrás
pai
commit
cbb4f609d5
2 arquivos alterados com 57 adições e 2 exclusões
  1. 3 2
      admin/page/site.py
  2. 54 0
      front/api/main.py

+ 3 - 2
admin/page/site.py

@@ -63,9 +63,10 @@ class convert_path(Load):
 			,path = '/site/convert'
 			,width = '600'
 			,height = '600'
+			,edit = False
 			,search = (('label-1','cdate-time-start','cdate-time-end','site_id-select-','name-input-mlike'), (u'日期范围',u'开始时间',u'截止时间',u'选择站点',u'文件名'))
-			,thead = (u'文件id',u'所属站点', u'文件名', u'访问路径', u'状态', u'更新时间')
-			,tbody = ('id','site', 'name', 'url', 'status', 'cdate')
+			,thead = (u'文件id',u'所属站点', u'源文件', u'文件名', u'访问路径', u'状态', u'更新时间')
+			,tbody = ('id','site', 'file','name', 'url', 'status', 'cdate')
 			,state = True
 		)
 		self.data['common']['search_site_id-select-'] = self.service('common').list('site')

+ 54 - 0
front/api/main.py

@@ -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