rabin 7 years ago
parent
commit
83616f0922

+ 7 - 1
admin/page/device.py

@@ -306,7 +306,13 @@ class stat_path(Load):
 				search.append('group by time(1d) where time > now() – 1m')
 			elif value == '6m':
 				search.append('group by time(10d) where time > now() – 6m')
-		self.data['list'] = model.select(data['farm_id'], data['hardware_id'], search=search)
+		search = "".join(search)
+		self.data['list'] = model.get(data['farm_id'], data['hardware_id'], search=search)
+		#print self.data['list']
+		if self.data['list']:
+			self.data['category'] = json.dumps(self.data['list'][0])
+			self.data['value'] = json.dumps(self.data['list'][1])
+		self.data['info'] = data
 		self.commonView('stat')
 
 

File diff suppressed because it is too large
+ 0 - 0
admin/static/js/echarts.common.min.js


+ 86 - 0
admin/templates/common/stat.html

@@ -0,0 +1,86 @@
+{% extends "../theme/stat.html" %}
+
+{% block search %}
+  {% for index,key in enumerate(data['common']['search'][0]) %}
+    {%set value = data['common']['search'][1][index] %}
+    {%set param = key.split('-') %}
+    {% if 'label' in key %}
+    <label class="layui-form-label">{{value}}</label>
+    {% elif param[1] == 'input' %}
+    <div class="layui-input-inline"  style="width:auto" >
+      <input type="text" name="search_{{key}}"id="search_{{key}}" placeholder="{{value}}" autocomplete="off" class="layui-input" value="{% if data['search'] and key in data['search'] %}{{data['search'][key]}}{% end %}">
+    </div>
+    {% elif param[1] == 'time' %}
+    <div class="layui-input-inline"  style="width:auto">
+      <input type="text" name="search_{{key}}" id="search_{{key}}" placeholder="{{value}}" autocomplete="off" class="layui-input time" value="{% if data['search'] and key in data['search'] %}{{data['search'][key]}}{% end %}">
+    </div>
+    {% elif param[1] == 'select' %}
+    <label class="layui-form-label">{{value}}</label>
+    <div class="layui-input-inline"  style="width:auto">
+        {%set option = 'search_' + key %}
+        {% if option in data['common'] %}
+        {%set select = data['common'][option] %}
+        <select name="search_{{key}}" id="search_{{key}}" lay-verify="" lay-search>
+              <option value="">请选择一项</option>
+          {% for v in select %}
+              <option value="{{v['id']}}" {% if data['search'] and key in data['search'] and data['search'][key] == str(v['id']) %}selected{% end %}>{{v['name']}}</option>
+              {% end %}
+        </select>
+        {% end %}
+    </div>
+    {% end %}
+  {% end %}
+{% end %}
+
+
+{% block script %}
+<script src="{{static_url('js/echarts.common.min.js')}}" charset="utf-8"></script>
+<script type="text/javascript">
+// 基于准备好的dom,初始化echarts实例
+var myChart = echarts.init(document.getElementById('main'));
+
+// 指定图表的配置项和数据
+var option = {
+    title: {
+        text: '{{data['info']['name']}}'
+    },
+    tooltip: {
+        trigger: 'axis'
+    },
+    legend: {
+        data:['{{data['info']['name']}}']
+    },
+    grid: {
+        left: '3%',
+        right: '4%',
+        bottom: '3%',
+        containLabel: true
+    },
+    toolbox: {
+        feature: {
+            saveAsImage: {}
+        }
+    },
+    xAxis: {
+        type: 'category',
+        boundaryGap: false,
+        data: {% raw data['category'] %}
+    },
+    yAxis: {
+        type: 'value'
+    },
+    series: [
+        {
+            name:'{{data['info']['name']}}',
+            type:'line',
+            stack: '总量',
+            data:{% raw data['value'] %}
+        }
+    ]
+};
+
+
+// 使用刚指定的配置项和数据显示图表。
+myChart.setOption(option);
+</script>
+{% end %}

+ 103 - 0
admin/templates/theme/stat.html

@@ -0,0 +1,103 @@
+{% if data['page']['ajax'] == False %}
+<!DOCTYPE html>
+<html>
+    <head>
+        {%include '../inc/header.html'%}
+    </head>
+    <body>
+        <div class="x-nav">
+            <span class="layui-breadcrumb">
+                {% block breadcrumb %}
+                    <a><cite>首页</cite></a>
+                    <a><cite><script>document.write(parent.config.parentTitle)</script></cite></a>
+                    <a><cite><script>document.write(parent.config.subTitle)</script></cite></a>
+                {% end %}
+            </span>
+            <span id="currentUrl"><script>var cur = parent.config.cur;</script></span>
+            <a class="layui-btn layui-btn-small" style="margin-top:3px;float:right"  href="javascript:window.history.back();" title="返回"><i class="layui-icon">&#xe619;</i></a>
+        </div>
+        <div class="x-body">
+            <form class="layui-form x-center" action="" style="width:auto">
+                <div class="layui-form-pane" style="margin-top: 15px;">
+                  <div class="layui-form-item">
+                   {% block search %}
+                    <label class="layui-form-label">日期范围</label>
+                    <div class="layui-input-inline">
+                      <input class="layui-input" placeholder="开始时间" id="LAY_demorange_s" name="search_start">
+                    </div>
+                    <div class="layui-input-inline">
+                      <input class="layui-input" placeholder="截止时间" id="LAY_demorange_e" name="search_end">
+                    </div>
+                    <div class="layui-input-inline">
+                      <input type="text" name="search_name"  placeholder="标题" autocomplete="off" class="layui-input">
+                    </div>
+                    {% end %}
+                    <div class="layui-input-inline" style="width:80px">
+                        <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
+                    </div>
+                  </div>
+                </div> 
+            </form>
+            <div id="main" style="width: 100%;height:400px;"></div>
+        </div>
+        {%include '../inc/footer.html'%}
+        {%include '../inc/script.html'%}
+    </body>
+<script>
+    layui.use(['laydate','element','laypage','layer', 'form'], function(){
+$ = layui.jquery;//jquery
+lement = layui.element();//面包导航
+laypage = layui.laypage;//分页
+layer = layui.layer;//弹出层
+
+if ($('.load').length) {
+    $('.load').each(function()
+    {
+        load($(this))
+    })
+}
+if ($('.time').length) {
+    laydate = layui.laydate;//日期插件
+    var start = {
+        //min: laydate.now()
+        max: '2099-06-16 23:59:59'
+        ,format: 'YYYY-MM-DD hh:mm:ss'
+        ,istoday: true
+        ,istime: true
+        ,choose: function(datas){
+          end.min = datas; //开始日选好后,重置结束日的最小日期
+          end.start = datas //将结束日的初始值设定为开始日
+        }
+    };
+
+    var end = {
+        //min: laydate.now()
+        max: '2099-06-16 23:59:59'
+        ,format: 'YYYY-MM-DD hh:mm:ss'
+        ,istoday: true
+        ,istime: true
+        ,choose: function(datas){
+          start.max = datas; //结束日选好后,重置开始日的最大日期
+        }
+    };
+    $('.time').each(function()
+    {
+        type = $(this).attr('id').indexOf('start')
+        $(this).click(function()
+        {
+            if (type > -1) {
+                start.elem = this;
+                laydate(start);
+            } else {
+                end.elem = this
+                laydate(end);
+            }
+        })
+    })
+}
+});
+</script>
+    {% block script %}
+    {% end %}
+</html>
+{% end %}

+ 25 - 1
model/data.py

@@ -6,6 +6,8 @@
     author:rabin
 """
 from __load__ import *
+import datetime
+import calendar
 
 class Data(Model):
 	__table__ = 'data'
@@ -55,4 +57,26 @@ class Data(Model):
 		#group by time(30m) where time > now() – 1d 30分钟聚合,大于昨天的数据 1d 1h
 		sql = 'select value from ' + self.table + where
 		data = self.db.query(sql)
-		return [value for value in data.raw['series'][0]['values']]
+		return [value for value in data.raw['series'][0]['values']]
+
+	def get(self, farm, device, search=''):
+		data = {}
+		data['farm'] = farm
+		data['device'] = device
+		self.setTable(data)
+		sql = 'select value from ' + self.table + search
+		data = self.db.query(sql)
+		value = []
+		time = []
+		rows = []
+		utc_format='%Y-%m-%dT%H:%M:%S'
+		local_format = "%Y-%m-%d %H:%M:%S"
+		if data.raw['series'][0]['values']:
+			for values in data.raw['series'][0]['values']:
+				temp = values[0].split('.')
+				utc = Demeter.mktime(temp[0], utc_format) + 3600*8
+				date = Demeter.date(utc, local_format)
+				value.append(values[1])
+				time.append(date)
+				rows.append([values[0], values[1]])
+		return (time, value, rows)

Some files were not shown because too many files changed in this diff