origin.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. demeter web page
  5. name:main.py
  6. author:rabin
  7. """
  8. from __load__ import *
  9. class Origin(object):
  10. @staticmethod
  11. def init(self, search={}):
  12. id = self.input('id')
  13. if not id:
  14. self.redirect('/')
  15. if 'work' in self.request.uri:
  16. self.data['cur'] = 'work'
  17. elif 'env' in self.request.uri:
  18. self.data['cur'] = 'env'
  19. elif 'farm' in self.request.uri:
  20. self.data['cur'] = 'farm'
  21. else:
  22. self.data['cur'] = 'index'
  23. self.data['info'] = self.service('common').one('origin_batch', id=id)
  24. if not self.data['info']:
  25. self.redirect('/')
  26. self.data['farm'] = self.service('common').one('farm', id=self.data['info']['farm_id'])
  27. self.data['product'] = self.service('common').one('farm_product', id=self.data['info']['product_id'])
  28. if self.data['info']['csdate'] > self.data['info']['zzdate']:
  29. self.data['zhou'] = self.data['info']['csdate'] - self.data['info']['zzdate']
  30. else:
  31. self.data['zhou'] = self.data['info']['zzdate'] - self.data['info']['csdate']
  32. self.data['zhou'] = self.data['zhou']/64800
  33. self.data['path'] = 'mobile/'
  34. self.data['url'] = Origin.url('id=' + id + '#menu')
  35. @staticmethod
  36. def url(param):
  37. config = {}
  38. config['index'] = '/origin?' + param;
  39. config['work'] = '/origin/work?' + param;
  40. config['env'] = '/origin/env?' + param;
  41. config['farm'] = '/origin/farm?' + param;
  42. return config
  43. class index_path(Load):
  44. @Web.setting
  45. def get(self):
  46. Origin.init(self)
  47. self.data['growth'] = self.service('common').list('origin_growth', search={'batch_id':self.data['info']['id']}, order='date asc,cdate asc')
  48. self.data['device'] = self.service('common').one('device_info', id=self.data['info']['device_camera_id'])
  49. self.view(self.data['path'] + "origin/index.html")
  50. class work_path(Load):
  51. @Web.setting
  52. def get(self):
  53. Origin.init(self)
  54. self.data['work'] = self.service('common').list('farm_work', search={'farm_id':self.data['info']['farm_id']}, order='workdate asc,cdate asc')
  55. self.data['cate'] = {}
  56. self.data['list'] = []
  57. if self.data['work']:
  58. for key, value in enumerate(self.data['work']):
  59. method = self.service('common').one('farm_work_method', id=value['method_id'])
  60. value['method'] = method['name']
  61. value['workdates'] = Demeter.date(value['workdate'], '%Y.%m.%d')
  62. if value['category_id'] not in self.data['list']:
  63. self.data['list'].append(value['category_id'])
  64. self.data['cate'][value['category_id']] = self.service('common').one('farm_work_category', id=value['category_id'])
  65. if 'work' not in self.data['cate'][value['category_id']]:
  66. self.data['cate'][value['category_id']]['work'] = []
  67. self.data['cate'][value['category_id']]['work'].append(value)
  68. self.view(self.data['path'] + "origin/work.html")
  69. class env_path(Load):
  70. @Web.setting
  71. def get(self):
  72. Origin.init(self)
  73. self.data['info']['devices'] = tuple(eval(self.data['info']['devices']))
  74. search = {}
  75. search['id--ins'] = self.data['info']['devices']
  76. self.data['list'] = self.service('common').list('device_info', search=search)
  77. if self.data['list']:
  78. for key, value in enumerate(self.data['list']):
  79. self.data['list'][key] = self.stat(value)
  80. self.view(self.data['path'] + "origin/env.html")
  81. def stat(self, value):
  82. method = 'maxmin'
  83. value['type'] = self.service('common').one('device_type', id=value['type_id'])
  84. model = Demeter.model('data', 'tsdb')
  85. value['group'] = model.dateConfig()
  86. search = {}
  87. search['device'] = value['id']
  88. #search['group'] = '1'
  89. search['start'] = Demeter.date(self.data['info']['zzdate'])
  90. search['end'] = Demeter.date(self.data['info']['csdate'])
  91. value['search'] = search
  92. value['stat'] = model.getData(method, search, value)
  93. return value
  94. class farm_path(Load):
  95. @Web.setting
  96. def get(self):
  97. Origin.init(self)
  98. self.view(self.data['path'] + "origin/farm.html")