123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- from demeter.core import *
- def manage():
- model = Demeter.model('manage_admin')
- model.id = 1
- info = model.select(type='fetchone')
- if not info:
- model.role_id = 1
- model.username = 'admin'
- model.mobile = '15810090845'
- model.password = '123456'
- model.insert()
- model = Demeter.model('manage_role')
- model.id = 1
- info = model.select(type='fetchone')
- if not info:
- model.name = '管理员'
- model.insert()
- def web():
- model = Demeter.model('web_set')
- model.id = 1
- info = model.select(type='fetchone')
- if not info:
- model.name = '新农宝盒智慧云平台'
- model.keywords = '新农宝盒,智慧云平台,智能硬件,大数据,农业,农业互联网'
- model.description = '新农宝盒智慧云平台'
- model.icp = '京ICP备12045252号-2'
- model.tel = '18701029660'
- model.passtel = '18701029660'
- model.mobile = ''
- model.buy = ''
- model.insert()
- model = Demeter.model('web_article_category')
- data = ('站点介绍', '焦点图', '系统优势')
- for value in data:
- model.name = value
- info = model.select(type='fetchone')
- if not info:
- model.name = value
- model.insert()
- model = Demeter.model('web_article')
- data = ('合作伙伴', '免责声明', '联系我们', '帮助文档', '团队介绍')
- for value in data:
- model.name = value
- info = model.select(type='fetchone')
- if not info:
- model.category_id = 1
- model.name = value
- if model.name == '帮助文档':
- model.link = '/help'
- model.insert()
- model = Demeter.model('web_menu')
- data = (
- {'name':'新农宝盒首页','link':'/main'}
- ,{'name':'灌溉商城','link':'http://www.guangaishangcheng.com/'}
- ,{'name':'帮助中心','link':'/help'}
- )
- for value in data:
- model.link = value['link']
- info = model.select(type='fetchone')
- if not info:
- model.name = value['name']
- model.link = value['link']
- model.insert()
- def farm():
- farm_id = 1
- model = Demeter.model('farm')
- model.id = farm_id
- info = model.select(type='fetchone')
- if not info:
- model.name = '默认园区'
- model.insert()
- # 初始化网关,测试用
- hardware_id = 10086
- model = Demeter.model('device_gateway')
- model.hardware_id = hardware_id
- info = model.select(type='fetchone')
- if not info:
- model.farm_id = farm_id
- model.hardware_id = hardware_id
- model.name = '默认网关'
- id = model.insert()
- Demeter.service('device').upGatewayStatus(farm_id, id, hardware_id)
- def device():
- # 以下类型只能新增,不能随意更改或删除
- # 初始化设备类型
- device_type = (
- {'name':'温度', 'key':'temprature', 'unit':'℃'}
- ,{'name':'湿度', 'key':'humidity','unit':'%RH'}
- ,{'name':'光照', 'key':'light','unit':'LUX'}
- ,{'name':'二氧化碳', 'key':'co2','unit':'PPM'}
- ,{'name':'风速', 'key':'speed','unit':'km/h'}
- ,{'name':'风向', 'key':'direction','unit':''}
- ,{'name':'PM2.5', 'key':'pm2.5','unit':'μg/m3'}
- ,{'name':'电源', 'key':'power','unit':'V'}
- ,{'name':'阀门', 'key':'valve','unit':''}
- ,{'name':'放风机', 'key':'blower','unit':''}
- ,{'name':'卷帘机', 'key':'curtain','unit':''}
- )
- model = Demeter.model('device_type')
- for value in device_type:
- model.key = value['key']
- info = model.select(type='fetchone')
- if not info:
- model.key = value['key']
- model.name = value['name']
- #model.exp = '{n}'
- model.unit = value['unit']
- model.insert()
- # 初始化硬件类型 1/1/2/3/4/5/6
- hardware_type = (
- {'name':'网关', 'key':'gateway'}
- ,{'name':'传感器', 'key':'sensor'}
- ,{'name':'控制器', 'key':'control'}
- ,{'name':'电源', 'key':'power'}
- ,{'name':'状态', 'key':'status'}
- ,{'name':'摄像头', 'key':'pic'}
- ,{'name':'摄像机', 'key':'camera'}
- )
- model = Demeter.model('hardware_type')
- for value in hardware_type:
- model.key = value['key']
- info = model.select(type='fetchone')
- if not info:
- model.key = value['key']
- model.name = value['name']
- model.insert()
- # 初始化消息类型
- msg_type = (
- {'name':'系统消息', 'key':'system'}
- ,{'name':'警告提醒', 'key':'notice'}
- ,{'name':'操作提示', 'key':'oper'}
- ,{'name':'新闻', 'key':'news'}
- )
- model = Demeter.model('msg_type')
- for value in msg_type:
- model.key = value['key']
- info = model.select(type='fetchone')
- if not info:
- model.key = value['key']
- model.name = value['name']
- model.insert()
- # 初始化错误码类型
- notice_type = (
- {'name':'设备离线', 'key':'offline'}
- ,{'name':'请求超时', 'key':'timeout'}
- )
- model = Demeter.model('notice_type')
- for value in notice_type:
- model.key = value['key']
- info = model.select(type='fetchone')
- if not info:
- model.key = value['key']
- model.name = value['name']
- model.insert()
- manage()
- web()
- farm()
- device()
- print 'install success!'
|