123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- """
- demeter web page
- name:main.py
- author:rabin
- """
- from __load__ import *
- class Origin(object):
- @staticmethod
- def init(self, search={}):
- id = self.input('id')
- if not id:
- self.redirect('/')
- if 'work' in self.request.uri:
- self.data['cur'] = 'work'
- elif 'env' in self.request.uri:
- self.data['cur'] = 'env'
- elif 'farm' in self.request.uri:
- self.data['cur'] = 'farm'
- else:
- self.data['cur'] = 'index'
- self.data['info'] = self.service('common').one('origin_batch', id=id)
- if not self.data['info']:
- self.redirect('/')
- self.data['farm'] = self.service('common').one('farm', id=self.data['info']['farm_id'])
- self.data['product'] = self.service('common').one('farm_product', id=self.data['info']['product_id'])
- if self.data['info']['csdate'] > self.data['info']['zzdate']:
- self.data['zhou'] = self.data['info']['csdate'] - self.data['info']['zzdate']
- else:
- self.data['zhou'] = self.data['info']['zzdate'] - self.data['info']['csdate']
- self.data['zhou'] = self.data['zhou']/64800
- self.data['path'] = 'mobile/'
- self.data['url'] = Origin.url('id=' + id + '#menu')
- @staticmethod
- def url(param):
- config = {}
- config['index'] = '/origin?' + param;
- config['work'] = '/origin/work?' + param;
- config['env'] = '/origin/env?' + param;
- config['farm'] = '/origin/farm?' + param;
- return config
- class index_path(Load):
- @Web.setting
- def get(self):
- Origin.init(self)
- self.data['growth'] = self.service('common').list('origin_growth', search={'batch_id':self.data['info']['id']}, order='date asc,cdate asc')
- self.data['device'] = self.service('common').one('device_info', id=self.data['info']['device_camera_id'])
- self.view(self.data['path'] + "origin/index.html")
- class work_path(Load):
- @Web.setting
- def get(self):
- Origin.init(self)
- self.data['work'] = self.service('common').list('farm_work', search={'farm_id':self.data['info']['farm_id']}, order='workdate asc,cdate asc')
- self.data['cate'] = {}
- self.data['list'] = []
- if self.data['work']:
- for key, value in enumerate(self.data['work']):
- method = self.service('common').one('farm_work_method', id=value['method_id'])
- value['method'] = method['name']
- value['workdates'] = Demeter.date(value['workdate'], '%Y.%m.%d')
- if value['category_id'] not in self.data['list']:
- self.data['list'].append(value['category_id'])
- self.data['cate'][value['category_id']] = self.service('common').one('farm_work_category', id=value['category_id'])
- if 'work' not in self.data['cate'][value['category_id']]:
- self.data['cate'][value['category_id']]['work'] = []
- self.data['cate'][value['category_id']]['work'].append(value)
- self.view(self.data['path'] + "origin/work.html")
- class env_path(Load):
- @Web.setting
- def get(self):
- Origin.init(self)
-
- self.data['info']['devices'] = tuple(eval(self.data['info']['devices']))
- search = {}
- search['id--ins'] = self.data['info']['devices']
- self.data['list'] = self.service('common').list('device_info', search=search)
- if self.data['list']:
- for key, value in enumerate(self.data['list']):
- self.data['list'][key] = self.stat(value)
- self.view(self.data['path'] + "origin/env.html")
- def stat(self, value):
- method = 'maxmin'
- value['type'] = self.service('common').one('device_type', id=value['type_id'])
- model = Demeter.model('data', 'tsdb')
- value['group'] = model.dateConfig()
- search = {}
- search['device'] = value['id']
- #search['group'] = '1'
- search['start'] = Demeter.date(self.data['info']['zzdate'])
- search['end'] = Demeter.date(self.data['info']['csdate'])
- value['search'] = search
- value['stat'] = model.getData(method, search, value)
- return value
- class farm_path(Load):
- @Web.setting
- def get(self):
- Origin.init(self)
- self.view(self.data['path'] + "origin/farm.html")
|