# MAS-GLMNService **Repository Path**: wzgcode/MAS-GLMNService ## Basic Information - **Project Name**: MAS-GLMNService - **Description**: 梅安森管廊模拟服务 - **Primary Language**: Python - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 1 - **Created**: 2020-12-03 - **Last Updated**: 2025-03-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 管廊数据中心使用说明 [TOC] ## 特性 * 支持web api进行数据操作 * 支持对查询数据进行筛选 * 支持`rabbitmq`数据推送 * 支持数据变化自动存储到历史 * 支持数据的模拟,并且可配置模拟参数 ## 已接入的数据 ### 环境监测系统 设备类型 | 设备编号 :---: | :---: 液位 | L002_101_001_2101 温度 | L002_101_001_2201 湿度 | L002_101_001_2301 氧气 | L002_101_001_2401 硫化氢 | L002_101_002_2501 ### 可燃气体泄漏报警系统 设备类型 | 设备编号 :---: | :---: 可燃气体传感器 | L009_101_002_9101 ### 入侵报警系统 设备类型 | 设备编号 :---: | :---: 入侵报警探测装置 | L005_101_001_5101 入侵报警探测装置 | L005_101_001_5102 ## 数据获取 ### 获取当前所有系统 http://118.26.73.70:19090 ```json C:\> curl -i http://118.26.73.70:19090 HTTP/1.1 200 OK Content-Length →786 Content-Type →application/json { "accesses": "/accesses{/serial}", "accesses_history": "/accesses_history{/serial}", "combustibles": "/combustibles{/serial}", "combustibles_history": "/combustibles_history{/serial}", "employees": "/employees{/serial}", "employees_history": "/employees_history{/serial}", "environments": "/environments{/serial}", "environments_history": "/environments_history{/serial}", "equipments": "/equipments{/serial}", "equipments_history": "/equipments_history{/serial}", "fires": "/fires{/serial}", "fires_history": "/fires_history{/serial}", "invades": "/invades{/serial}", "invades_history": "/invades_history{/serial}", "patrols": "/patrols{/serial}", "structures": "/structures{/serial}", "structures_history": "/structures_history{/serial}", "videos": "/videos{/serial}" } ``` ### 获取系统内的所有数据 http://118.26.73.70:19090/:system/ ```json C:\> curl -i http://118.26.73.70:19090/environments/ HTTP/1.1 200 OK Content-Length →60467 Content-Type →application/json ETag →"416de6708af63b2d16648b043ef9eca7" { "resources": [ { "alarm": "无报警", "area": "起点", "max_alarm": 1, "max_range": 5, "min_alarm": 0, "min_range": 0, "mock": "@float(0, 1, 2, 2)", "module": "综合舱1", "name": "液位传感器1号", "serial": "L002_100_001_2101", "state": "正常", "time": "2017-10-24T15:48:56", "type": "液位传感器", "unit": "m", "value": 1.11 }, { "alarm": "无报警", "area": "起点", "max_alarm": 1, "max_range": 5, "min_alarm": 0, "min_range": 0, "mock": "@float(0, 1, 2, 2)", "module": "综合舱2", "name": "液位传感器2号", "serial": "L002_100_002_2101", "state": "正常", "time": "2017-10-24T15:49:26", "type": "液位传感器", "unit": "m", "value": 0.49 } ... ] } ``` ### 获取系统内的指定数据 http://118.26.73.70:19090/:system/:serial ```json C:\> curl -i http://118.26.73.70:19090/environments/L002_100_001_2101 HTTP/1.1 200 OK Content-Length →455 Content-Type →application/json ETag →"07d918a13b374dbd68daad9b02305ed5" Link →; rel=self, ; rel=related { "alarm": "无报警", "area": "起点", "max_alarm": 1, "max_range": 5, "min_alarm": 0, "min_range": 0, "mock": "@float(0, 1, 2, 2)", "module": "综合舱1", "name": "液位传感器1号", "serial": "L002_100_001_2101", "state": "正常", "time": "2017-10-24T15:48:56", "type": "液位传感器", "unit": "m", "value": 1.11 } ``` ### 条件筛选参数 http://118.26.73.70:19090/:system?q=:query ```json C:\> curl http://118.26.73.70:19090/environments/?q= { "filters": { "type": "温度传感器", "state": ["正常", "断线", "掉电"], "time": ["2017-10-23", "2017-10-25"] }, "columns": ["name", "serial", "value"], "order_by": "serial", "page": 1, "page_size": 5, "remove_duplicate": "alarm" } { "total": 5 "resources": [ { "name": "温度传感器1号", "serial": "L002_101_001_2201", "value": 19.02 }, { "name": "温度传感器2号", "serial": "L002_101_002_2201", "value": 28.97 }, { "name": "温度传感器3号", "serial": "L002_101_003_2201", "value": 29.48 }, { "name": "温度传感器4号", "serial": "L002_102_001_2201", "value": 22.44 }, { "name": "温度传感器5号", "serial": "L002_102_002_2201", "value": 23.25 } ] } ``` > **filters:** 过滤条件,多个条件为`and`的关系。若条件值为`array`,则`array`内的元素为`or`的关系(若数组内有且只有**2个**元素且类型为`int`、`float`、`datetime`类型则视为`between`的关系)。 > **columns:** 返回的列, 类型可以为`string`或`array`。当为聚合查询时,可以为函数并且结合group_by条件。 > **group_by:** 分组条件, 类型同`columns`一致。 > **order_by:** 指定排序的列, 类型可以为`string` 或 `array`,若类型为`array`,则第二个元素必须是`asc` 或 `desc`其中的一个。默认为`asc`。 > **page:** 当前返回的页数。 > **page_size:** 返回每页的个数。 > **remove_duplicate:** 指定过滤的列,类型为`string`。过滤相邻记录的重复值 > **limit:** 返回数据的条数,类型为`int`。 > **offset:** 指定偏移量,类型为`int`。 > **注意:** page、page_size和limit、offset不能同时使用。 当条件中存在limit或offset时,page、page_size条件失效。page、page_size必须成对出现,而limit和offset可单独使用。 ## 订阅推送数据 开放的`amqp`协议端口为 `25675` 开放的`stomp`协议端口为 `25674` 开放的`web`协议端口为 `25672` 数据推送采用的是`rabbitmq`基于`amq.topic`的`exchange`。当有数据推送时,topic为系统名称, body为变化的数据。 数据格式参考`获取系统内的指定数据`。服务器端`rabbitmq`开启了`stomp`协议,前端可通过`websocket`直接订阅。具体示例参考 [官方文档](http://www.rabbitmq.com/web-stomp.html) ## 后台管理界面 后台管理界面的地址为: http://118.26.73.70:19090/admin 后台管理提供了对数据的增删改的操作,修改可触发数据推送。 ## 状态和报警 状态值:`正常`、`断线`、`掉电`、`故障`、`标校` 报警值: `无报警`、`一般报警`、`严重报警` ## 编号的规则 编号的规则为**L** + **3位系统编号**+**3位分区编号**+**3位舱室编号**+**4位类型编号**。若不存在舱室,则舱室节段省略 > **提示:** 4位类型编号 = 类型编号 + 当前类型设备个数 ### 系统编号 系统名称 | 系统编号 :---: | :---: structures | 1 environments | 2 equipments | 3 videos | 4 invades | 5 accesses | 6 patrols | 7 telephones | 8 combustibles | 9 fires | 10 ### 分区编号 分区名称 | 分区编号 :---: | :---: 起点 | 100 101分区 | 101 102分区 | 102 103分区 | 103 104分区 | 104 105分区 | 105 106分区 | 106 107分区 | 107 ### 舱室编号 分区名称 | 分区编号 :---: | :---: 起点 | 100 综合舱1 | 1 综合舱2 | 2 电力舱 | 3 供电所 | 4 设备间 | 5 ### 类型编号 类型名称 | 类型编号 :---: | :---: 管廊沉降检测仪 | 100 管廊扭转检测仪 | 200 接缝张开检测仪 | 300 液位传感器 | 100 温度传感器 | 200 湿度传感器 | 300 氧气传感器 | 400 硫化氢探测器 | 500 风机 | 100 照明灯开关 | 200 排水泵 | 300 摄像机 | 100 入侵报警探测装置 | 100 声光报警器 | 200 进门读卡器 | 100 人员定位分站 | 100 无线基站 | 200 防爆有线电话 | 100 可燃气体检测报警器 | 100 手动报警器 | 100 智能烟感传感器 | 200 火灾环境测温感温光缆 | 300 ## 系统说明 ### `fires`- 火灾报警系统 | 字段 | 类型| 说明 | 历史 | | :--: | :--:| :--: | :--:| | area | String | 分区 | √ | | module | String | 舱室 | √ | | serial | String | 设备编号 | √ | | name | String | 设备名称 | × | | type | String | 设备类型 | × | | value | String | 实时值| √ | | state | String | 状态 | √ | | alarm | String | 报警| √ | | time | DateTime | 时间 | √ | ### `structures`- 结构监测系统 | 字段 | 类型| 说明 | 历史 | | :--: | :--:| :--: | :--:| | area | String | 分区 | √ | | serial | String | 设备编号 | √ | | name | String | 设备名称 | × | | type | String | 设备类型 | √ | | unit | String | 单位 | × | | max_alarm | Float | 报警上限阈值 | × | | value | Float | 实时值| √ | | state | String | 状态 | √ | | alarm | String | 报警| √ | | time | DateTime | 时间 | √ | ### `environments`- 环境监测系统 | 字段 | 类型| 说明 | 历史 | | :--: | :--:| :--: | :--:| | area | String | 分区 | √ | | module | String | 舱室 | √ | | serial | String | 设备编号 | √ | | name | String | 设备名称 | × | | type | String | 设备类型 | √ | | unit | String | 单位 | × | | max_alarm | Float | 报警上限阈值 | × | | min_alarm | Float | 报警下限阈值 | × | | max_range | Float | 量程上限 | × | | min_range | Float | 量程下限 | × | | value | Float | 实时值| √ | | state | String | 状态 | √ | | alarm | String | 报警| √ | | time | DateTime | 时间 | √ | ### `equipments`- 设备监控系统 | 字段 | 类型| 说明 | 历史 | | :--: | :--:| :--: | :--:| | area | String | 分区 | √ | | module | String | 舱室 | √ | | serial | String | 设备编号 | √ | | name | String | 设备名称 | × | | type | String | 设备类型 | √ | | voltage | Float | 电压(V) | × | | electricity | Float | 电流(mA) | × | | value | String | 实时值| √ | | state | String | 状态 | √ | | alarm | String | 报警| √ | | time | DateTime | 时间 | √ | ### `invades`- 入侵报警系统 | 字段 | 类型| 说明 | 历史 | | :--: | :--:| :--: | :--:| | area | String | 分区 | √ | | module | String | 舱室 | √ | | serial | String | 设备编号 | √ | | name | String | 设备名称 | × | | type | String | 设备类型 | √ | | value | String | 实时值| √ | | state | String | 状态 | √ | | alarm | String | 报警| √ | | time | DateTime | 时间 | √ | ### `combustibles`- 可燃气体泄漏报警系统 | 字段 | 类型| 说明 | 历史 | | :--: | :--:| :--: | :--:| | area | String | 分区 | √ | | module | String | 舱室 | √ | | serial | String | 设备编号 | √ | | name | String | 设备名称 | × | | type | String | 设备类型 | √ | | unit | String | 单位 | × | | max_alarm | Float | 报警上限阈值 | × | | min_alarm | Float | 报警下限阈值 | × | | max_range | Float | 量程上限 | × | | min_range | Float | 量程下限 | × | | value | Float | 实时值| √ | | state | String | 状态 | √ | | alarm | String | 报警| √ | | time | DateTime | 时间 | √ | ### `accesses`- 出入口控制系统 | 字段 | 类型| 说明 | 历史 | | :--: | :--:| :--: | :--:| | area | String | 分区 | √ | | module | String | 舱室 | √ | | serial | String | 设备编号 | √ | | name | String | 设备名称 | × | | type | String | 设备类型 | √ | | staff_serial | String | 员工编号| √ | | staff_name | String | 员工姓名| √ | | state | String | 状态 | √ | | alarm | String | 报警| √ | | time | DateTime | 时间 | √ | ### `employees`- 出入口控制系统 | 字段 | 类型| 说明 | 历史 | | :--: | :--:| :--: | :--:| | serial | String | 员工编号 | √ | | dept | String | 部门名称 | × | | name | String | 员工姓名 | × | | patrol_id | Integer | 所在分站id | √ | | time | DateTime | 时间 | √ | > **提示:** `patrol_id`为电子巡查管理系统的自增id ### `patrols`- 电子巡查管理系统 | 字段 | 类型| 说明 | | :--: | :--:| :--: | | area | String | 分区 | | module | String | 舱室 | | serial | String | 设备编号 | | name | String | 设备名称 | | type | String | 设备类型 | | value | Integer | 实时值 | | state | String | 状态 | | alarm | String | 报警 | | time | DateTime | 时间 | > **提示:** 电子巡查管理系统的`value`表示当前分站人数 ### `videos`- 视频监控系统 | 字段 | 类型| 说明 | | :--: | :--:| :--: | | area | String | 分区 | | module | String | 舱室 | | serial | String | 设备编号 | | name | String | 设备名称 | | type | Integer | 设备类型 | | ip | String | ip地址 | | port | Integer | 端口号 | | user | String | 用户名 | | password | String | 密码 | | channel | Integer | 通道 | | code | String | 设变编码 | | state | String | 状态 | > 1. 类型记录了设备的厂商,例如:1-海康,2-大华 > 1. `code`表示当不直接连接摄像机前端时所采用的播放编码 ## 数据模拟 模拟数据使用了`redis`数据库。 在`db1`中的以`redbeat:`+`系统名称`的`key`对应的`definition`为模拟数据的定义。 ### 实时数据模拟 实时数据模拟仅包含了实时值`value`和时间`time`的改变,默认更新间隔为`60秒`。 包含的系统有: 1. 可燃气体数据模拟 1. 环境监测数据模拟 1. 设备监测数据模拟 1. 结构监测数据模拟 1. 防火系统数据模拟 1. 入侵系统数据模拟 ```json { "name" : ":system_name", // 任务名称:通常是系统名 "task" : "celery_app.tasks.mock_value", //任务:任务调用的方法,不可编辑 "enabled" : true, //状态:是否开启任务,可编辑 true/false "schedule": { "__type__": "interval", //任务类型 "every": 60, //任务周期,单位秒 "relative": false }, "args" : [ "XXXX" //对应的系统名称。 不可编辑 ], "kwargs" : { "min_count" : 100, // 模拟数据的最少数量 "max_count" : 100 // 模拟数据的最少数量 } } ``` > **schedule**中的`interval`字段都可以变为定时任务,格式如下: ```json "schedule": { "__type__": "crontab", "minute" : "60", "hour" : "2", "day_of_week" : "*", // 每周的第几天 "day_of_month" : "*", // 每月的第几天 "month_of_year" : "*" // 每年的第几月 } ``` ### 报警数据模拟 报警数据模拟会以下列表中更新数据库的`alarm`和`time`字段,默认的更新间隔为`5分钟` ```json { "name" : "alarm", "task" : "celery_app.tasks.mock_alarm", "enabled" : true, "schedule": { "__type__": "interval", "every": 300, "relative": false }, "args" : [ // 表示在下面列表中的系统报警,需要下列表必须有alarm字段 "access", "combustibles", "environments", "equipments", "fires", "invades", "structures" ], "kwargs" : { "min_system" : 1,// 报警系统最少数量, 可编辑 "max_system" : 2,// 报警系统最多数量, 可编辑 "sys_min_count" : 2, // 单个系统报警最少数量, 可编辑 "sys_max_count" : 2, // 单个系统报警最大数量, 可编辑 "alarm_desc" : [ // 报警字段的值在下面列表中选择, 可编辑 "一般报警", "严重报警" ], "normal_desc" : "无报警", // 消警是报警字段的值, 可编辑 "during_min" : 30, // 报警持续的最少时间, 可编辑 "during_max" : 120 // 报警持续的最大时间, 可编辑 } } ``` ### 人员定位数据模拟 人员定位数据模拟会更新`emp`表中的`patrol_id`字段以及`patrols`表中的`value`字段,默认更新时间为`3分钟`。 ```json { "name" : "employees", "task" : "celery_app.tasks.mock_alarm", "enabled" : true, "schedule": { "__type__": "interval", "every": 180, "relative": false }, "args" : [ // 人员将在编号为以下列表中的分站往返行走, 可编辑 "L007_101_001_7101", "L007_101_001_7102", "L007_102_001_7101", "L007_102_001_7102", "L007_103_001_7101", "L007_103_001_7102", "L007_104_001_7101", "L007_104_001_7102", "L007_105_001_7101", "L007_105_001_7102", "L007_106_001_7101", "L007_106_001_7102" ], "kwargs" : { "min_count" : 1, // 人数最少数量, 可编辑 "max_count" : 5 // 人数最多数量, 可编辑 } } ``` ### 门禁系统数据模拟 门禁系统数据模拟会更新`accesses`表中的`staff_serial`和`staff_name`字段,默认更新间隔为`60秒` ```json { "name" : "access", "task" : "celery_app.tasks.mock_access", "enabled" : true, "schedule": { "__type__": "interval", "every": 60, "relative": false }, "args" : [], "kwargs" : {} } ``` # 部署流程(add by wzg 2020-10-21) + 安装docker + 安装docker-compose + 复制软件目录到linux路径下 + 进入目录 + 执行docker-compose up -d启动部署服务 + 使用navicat 连接mysql数据库 默认root root (如果使用的虚拟机,请先将默认端口3306映射到宿主机上) + 执行mysql 下的unity_tunnel.sql脚本初始化数据库 + 连接 redis 数据库 默认无密码 + 执行redis下的beat.txt中的命令 初始化模拟服务任务定义,注意查看rebeat:mock_alarm下definition的 "alarm_desc","normal_desc"是否为中文,(因为如果使用redis-cli执行的命令,不支持中文)如果是乱码,请手动修改 + 回到linux下软件目录 执行docker-compose down 停止服务 再次执行docker-compose up -d重启服务 + 登录rabbitmq查看amq.topic下是否有数据# MAS-GLMNService