origin.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. if self.data['info']['pic']:
  27. pic = self.data['info']['pic'].split(',')
  28. self.data['info']['pic'] = pic[0]
  29. self.data['farm'] = self.service('common').one('farm', id=self.data['info']['farm_id'])
  30. if self.data['info']['csdate'] > self.data['info']['zzdate']:
  31. self.data['zhou'] = self.data['info']['csdate'] - self.data['info']['zzdate']
  32. else:
  33. self.data['zhou'] = self.data['info']['zzdate'] - self.data['info']['csdate']
  34. self.data['zhou'] = self.data['zhou']/64800
  35. self.data['info']['zzdates'] = Demeter.date(self.data['info']['zzdate'], '%Y-%m-%d')
  36. self.data['info']['csdates'] = Demeter.date(self.data['info']['csdate'], '%Y-%m-%d')
  37. self.data['path'] = 'mobile/'
  38. self.data['url'] = Origin.url('id=' + id + '#menu')
  39. @staticmethod
  40. def url(param):
  41. config = {}
  42. config['index'] = '/origin?' + param;
  43. config['work'] = '/origin/work?' + param;
  44. config['env'] = '/origin/env?' + param;
  45. config['farm'] = '/origin/farm?' + param;
  46. return config
  47. class index_path(Load):
  48. @Web.setting
  49. def get(self):
  50. Origin.init(self)
  51. self.data['list'] = self.service('common').list('farm_work_land_pic', search={'farm_id':self.data['info']['farm_id'], 'land_id':self.data['info']['land_id']}, page={'num':10})
  52. if self.data['list']:
  53. for key, value in enumerate(self.data['list']):
  54. self.data['list'][key]['cdates'] = Demeter.date(value['cdate'], '%Y-%m-%d')
  55. self.data['pic'] = {}
  56. if self.data['info']['pic_id']:
  57. self.data['pic'] = self.service('common').one('device_info', id=self.data['info']['pic_id'])
  58. if self.data['pic']:
  59. self.data['pic']['cdates'] = Demeter.date(self.data['pic']['cdate'], '%Y-%m-%d')
  60. self.view(self.data['path'] + "origin/index.html")
  61. class work_path(Load):
  62. @Web.setting
  63. def get(self):
  64. Origin.init(self)
  65. self.data['work'] = self.service('common').list('farm_work', search={'farm_id':self.data['info']['farm_id']}, order='workdate asc,cdate asc')
  66. self.data['cate'] = {}
  67. self.data['list'] = []
  68. if self.data['work']:
  69. for key, value in enumerate(self.data['work']):
  70. value['workdates'] = Demeter.date(value['workdate'], '%Y.%m.%d')
  71. if value['category_id'] not in self.data['list']:
  72. self.data['list'].append(value['category_id'])
  73. self.data['cate'][value['category_id']] = self.service('common').one('farm_work_category', id=value['category_id'])
  74. if 'work' not in self.data['cate'][value['category_id']]:
  75. self.data['cate'][value['category_id']]['work'] = []
  76. self.data['cate'][value['category_id']]['work'].append(value)
  77. self.view(self.data['path'] + "origin/work.html")
  78. class env_path(Load):
  79. @Web.setting
  80. def get(self):
  81. Origin.init(self)
  82. search = {}
  83. search['farm_id'] = self.data['info']['farm_id']
  84. search['gateway_id'] = self.data['info']['gateway_id']
  85. search['hardware_type'] = 2
  86. self.data['list'] = self.service('common').list('device_info', search=search)
  87. if self.data['list']:
  88. for key, value in enumerate(self.data['list']):
  89. self.data['list'][key] = self.stat(value)
  90. self.view(self.data['path'] + "origin/env.html")
  91. def stat(self, value):
  92. method = 'maxmin'
  93. value['type'] = self.service('common').one('device_type', id=value['type_id'])
  94. model = Demeter.model('data', 'tsdb')
  95. value['group'] = model.dateConfig()
  96. search = {}
  97. search['device'] = value['id']
  98. #search['group'] = '1'
  99. search['start'] = Demeter.date(self.data['info']['zzdate'])
  100. search['end'] = Demeter.date(self.data['info']['csdate'])
  101. value['search'] = search
  102. value['stat'] = model.getData(method, search, value)
  103. return value
  104. class farm_path(Load):
  105. @Web.setting
  106. def get(self):
  107. Origin.init(self)
  108. self.view(self.data['path'] + "origin/farm.html")