install.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. from demeter.core import *
  4. def manage():
  5. model = Demeter.model('manage_admin')
  6. model.id = 1
  7. info = model.select(type='fetchone')
  8. if not info:
  9. model.role_id = 1
  10. model.username = 'admin'
  11. model.mobile = '15810090845'
  12. model.password = '123456'
  13. model.insert()
  14. model = Demeter.model('manage_role')
  15. model.id = 1
  16. info = model.select(type='fetchone')
  17. if not info:
  18. model.name = '管理员'
  19. model.insert()
  20. def web():
  21. model = Demeter.model('web_set')
  22. model.id = 1
  23. info = model.select(type='fetchone')
  24. if not info:
  25. model.name = '农小盒'
  26. model.subname = '农作物生长监测与产品溯源'
  27. model.keywords = '农小盒,智慧云平台,智能硬件,大数据,农业,农业互联网'
  28. model.description = '农小盒'
  29. model.icp = '京ICP备12045252号-2'
  30. model.tel = '18701029660'
  31. model.passtel = '18701029660'
  32. model.mobile = ''
  33. model.buy = ''
  34. model.insert()
  35. model = Demeter.model('web_article_category')
  36. data = ('站点介绍', '日志', '产品功能', '客户案例')
  37. for value in data:
  38. model.name = value
  39. info = model.select(type='fetchone')
  40. if not info:
  41. model.name = value
  42. model.insert()
  43. model = Demeter.model('web_article')
  44. data = ('联系我们',)
  45. for value in data:
  46. model.name = value
  47. info = model.select(type='fetchone')
  48. if not info:
  49. model.category_id = 1
  50. model.name = value
  51. model.insert()
  52. model = Demeter.model('web_menu')
  53. data = (
  54. {'name':'首页','link':'/main'}
  55. ,{'name':'农小盒日志','link':'/article'}
  56. ,{'name':'联系我们','link':'/us'}
  57. )
  58. for value in data:
  59. model.link = value['link']
  60. info = model.select(type='fetchone')
  61. if not info:
  62. model.name = value['name']
  63. model.link = value['link']
  64. model.insert()
  65. def farm():
  66. farm_id = 1
  67. model = Demeter.model('farm')
  68. model.id = farm_id
  69. info = model.select(type='fetchone')
  70. if not info:
  71. model.name = '默认园区'
  72. model.insert()
  73. # 初始化网关,测试用
  74. hardware_id = 10086
  75. model = Demeter.model('device_gateway')
  76. model.hardware_id = hardware_id
  77. info = model.select(type='fetchone')
  78. if not info:
  79. model.farm_id = farm_id
  80. model.hardware_id = hardware_id
  81. model.name = '默认网关'
  82. id = model.insert()
  83. Demeter.service('device').upGatewayStatus(farm_id, id, hardware_id)
  84. def device():
  85. # 以下类型只能新增,不能随意更改或删除
  86. # 初始化设备类型
  87. device_type = (
  88. {'name':'温度', 'key':'temprature', 'unit':'℃'}
  89. ,{'name':'湿度', 'key':'humidity','unit':'%RH'}
  90. ,{'name':'光照', 'key':'light','unit':'LUX'}
  91. ,{'name':'二氧化碳', 'key':'co2','unit':'PPM'}
  92. ,{'name':'风速', 'key':'speed','unit':'km/h'}
  93. ,{'name':'风向', 'key':'direction','unit':''}
  94. ,{'name':'PM2.5', 'key':'pm2.5','unit':'μg/m3'}
  95. ,{'name':'电源', 'key':'power','unit':'V'}
  96. )
  97. model = Demeter.model('device_type')
  98. for value in device_type:
  99. model.key = value['key']
  100. info = model.select(type='fetchone')
  101. if not info:
  102. model.key = value['key']
  103. model.name = value['name']
  104. #model.exp = '{n}'
  105. model.unit = value['unit']
  106. model.insert()
  107. # 初始化硬件类型 1/1/2/3/4/5/6
  108. hardware_type = (
  109. {'name':'网关', 'key':'gateway'}
  110. ,{'name':'传感器', 'key':'sensor'}
  111. ,{'name':'控制器', 'key':'control'}
  112. ,{'name':'电源', 'key':'power'}
  113. ,{'name':'状态', 'key':'status'}
  114. ,{'name':'摄像头', 'key':'pic'}
  115. ,{'name':'摄像机', 'key':'camera'}
  116. )
  117. model = Demeter.model('hardware_type')
  118. for value in hardware_type:
  119. model.key = value['key']
  120. info = model.select(type='fetchone')
  121. if not info:
  122. model.key = value['key']
  123. model.name = value['name']
  124. model.insert()
  125. # 初始化消息类型
  126. msg_type = (
  127. {'name':'系统消息', 'key':'system'}
  128. ,{'name':'警告提醒', 'key':'notice'}
  129. ,{'name':'操作提示', 'key':'oper'}
  130. ,{'name':'新闻', 'key':'news'}
  131. )
  132. model = Demeter.model('msg_type')
  133. for value in msg_type:
  134. model.key = value['key']
  135. info = model.select(type='fetchone')
  136. if not info:
  137. model.key = value['key']
  138. model.name = value['name']
  139. model.insert()
  140. # 初始化农事分类
  141. msg_type = (
  142. {'name':'施肥'}
  143. ,{'name':'劳作'}
  144. ,{'name':'除虫'}
  145. )
  146. model = Demeter.model('farm_work_category')
  147. for value in msg_type:
  148. model.name = value['name']
  149. info = model.select(type='fetchone')
  150. if not info:
  151. model.name = value['name']
  152. model.insert()
  153. manage()
  154. web()
  155. farm()
  156. device()
  157. print 'install success!'