# -*- coding: utf-8 -*-
"""
配置文件
珠海燃气保税监管系统
"""

# 系统配置
SYSTEM = {
    'name': '珠海燃气保税业务监管系统',
    'debug': False,
    'secret_key': 'your-secret-key-change-in-production',
    'host': '0.0.0.0',
    'port': 5001
}

# OPC服务器配置
OPC = {
    'server_url': 'opc.tcp://192.168.1.100:4840',  # 需要改成现场实际地址
    'update_interval': 5,  # 数据更新间隔（秒）
    'enable': False  # 是否启用OPC采集，开发测试可以关，用模拟数据
}

# 罐体配置
# 珠海LNG接收站 8个储罐 - 侧视图，竖直排列
# 每个储罐：进液管从顶部进，出液管从底部出
TANKS = [
    {
        'id': 1,
        'name': 'LNG储罐1',
        'node_id': 'ns=1;s=Level1',        # 液位节点ID
        'density_node': 'ns=1;s=Density1',  # 密度节点ID
        'temp_node': 'ns=1;s=Temperature1', # 温度节点ID
        'flow_in_node': 'ns=1;s=FlowIn',    # 输入流量
        'flow_out_node': 'ns=1;s=FlowOut',  # 输出流量
        'x': 80,    # 中心X
        'y': 200,  # 中心Y
        'width': 60,  # 宽度
        'height': 150 # 高度
    },
    {
        'id': 2,
        'name': 'LNG储罐2',
        'node_id': 'ns=1;s=Level2',
        'density_node': 'ns=1;s=Density2',
        'temp_node': 'ns=1;s=Temperature2',
        'flow_in_node': 'ns=1;s=FlowIn2',
        'flow_out_node': 'ns=1;s=FlowOut2',
        'x': 170,
        'y': 200,
        'width': 60,
        'height': 150
    },
    {
        'id': 3,
        'name': 'LNG储罐3',
        'node_id': 'ns=1;s=Level3',
        'density_node': 'ns=1;s=Density3',
        'temp_node': 'ns=1;s=Temperature3',
        'flow_in_node': 'ns=1;s=FlowIn3',
        'flow_out_node': 'ns=1;s=FlowOut3',
        'x': 260,
        'y': 200,
        'width': 60,
        'height': 150
    },
    {
        'id': 4,
        'name': 'LNG储罐4',
        'node_id': 'ns=1;s=Level4',
        'density_node': 'ns=1;s=Density4',
        'temp_node': 'ns=1;s=Temperature4',
        'flow_in_node': 'ns=1;s=FlowIn4',
        'flow_out_node': 'ns=1;s=FlowOut4',
        'x': 350,
        'y': 200,
        'width': 60,
        'height': 150
    },
    {
        'id': 5,
        'name': 'LNG储罐5',
        'node_id': 'ns=1;s=Level5',
        'density_node': 'ns=1;s=Density5',
        'temp_node': 'ns=1;s=Temperature5',
        'flow_in_node': 'ns=1;s=FlowIn5',
        'flow_out_node': 'ns=1;s=FlowOut5',
        'x': 440,
        'y': 200,
        'width': 60,
        'height': 150
    },
    {
        'id': 6,
        'name': 'LNG储罐6',
        'node_id': 'ns=1;s=Level6',
        'density_node': 'ns=1;s=Density6',
        'temp_node': 'ns=1;s=Temperature6',
        'flow_in_node': 'ns=1;s=FlowIn6',
        'flow_out_node': 'ns=1;s=FlowOut6',
        'x': 530,
        'y': 200,
        'width': 60,
        'height': 150
    },
    {
        'id': 7,
        'name': 'LNG储罐7',
        'node_id': 'ns=1;s=Level7',
        'density_node': 'ns=1;s=Density7',
        'temp_node': 'ns=1;s=Temperature7',
        'flow_in_node': 'ns=1;s=FlowIn7',
        'flow_out_node': 'ns=1;s=FlowOut7',
        'x': 620,
        'y': 200,
        'width': 60,
        'height': 150
    },
    {
        'id': 8,
        'name': 'LNG储罐8',
        'node_id': 'ns=1;s=Level8',
        'density_node': 'ns=1;s=Density8',
        'temp_node': 'ns=1;s=Temperature8',
        'flow_in_node': 'ns=1;s=FlowIn8',
        'flow_out_node': 'ns=1;s=FlowOut8',
        'x': 710,
        'y': 200,
        'width': 60,
        'height': 150
    }
]

# 管道配置（坐标连线画流程图）
# 侧视图：顶部进料总管，底部出料总管
PIPES = [
    # 进料总管（顶部水平）- 红色
    {'from': {'x': 0, 'y': 80}, 'to': {'x': 800, 'y': 80}, 'direction': 'right'},
    # 出料总管（底部水平）- 蓝色
    {'from': {'x': 0, 'y': 320}, 'to': {'x': 800, 'y': 320}, 'direction': 'right'},
    # 每个储罐：顶部进料管从总管进储罐，底部出料管出储罐到总管
    {'from': {'x': 80, 'y': 80}, 'to': {'x': 80, 'y': 125}, 'direction': 'down'},
    {'from': {'x': 80, 'y': 275}, 'to': {'x': 80, 'y': 320}, 'direction': 'down'},
    {'from': {'x': 170, 'y': 80}, 'to': {'x': 170, 'y': 125}, 'direction': 'down'},
    {'from': {'x': 170, 'y': 275}, 'to': {'x': 170, 'y': 320}, 'direction': 'down'},
    {'from': {'x': 260, 'y': 80}, 'to': {'x': 260, 'y': 125}, 'direction': 'down'},
    {'from': {'x': 260, 'y': 275}, 'to': {'x': 260, 'y': 320}, 'direction': 'down'},
    {'from': {'x': 350, 'y': 80}, 'to': {'x': 350, 'y': 125}, 'direction': 'down'},
    {'from': {'x': 350, 'y': 275}, 'to': {'x': 350, 'y': 320}, 'direction': 'down'},
    {'from': {'x': 440, 'y': 80}, 'to': {'x': 440, 'y': 125}, 'direction': 'down'},
    {'from': {'x': 440, 'y': 275}, 'to': {'x': 440, 'y': 320}, 'direction': 'down'},
    {'from': {'x': 530, 'y': 80}, 'to': {'x': 530, 'y': 125}, 'direction': 'down'},
    {'from': {'x': 530, 'y': 275}, 'to': {'x': 530, 'y': 320}, 'direction': 'down'},
    {'from': {'x': 620, 'y': 80}, 'to': {'x': 620, 'y': 125}, 'direction': 'down'},
    {'from': {'x': 620, 'y': 275}, 'to': {'x': 620, 'y': 320}, 'direction': 'down'},
    {'from': {'x': 710, 'y': 80}, 'to': {'x': 710, 'y': 125}, 'direction': 'down'},
    {'from': {'x': 710, 'y': 275}, 'to': {'x': 710, 'y': 320}, 'direction': 'down'},
]

# 报警配置
# 支持多种报警源：
# 1. 液位差异报警：储罐理论液位 vs 实际液位差异过大
#    - 支持全局默认阈值 + 每个罐体单独配置阈值
#    - 可设置阈值过低报警（液位太低）+ 阈值过高报警（液位太高）
# 2. 温度异常报警：温度超出正常范围
# 3. 密度异常报警：密度超出正常范围
# 4. 当日流量不平衡报警：当日总流入和总流出差异超过阈值，触发短信报警
# 支持多人分组报警：不同分组发给不同责任人
ALERT = {
    'enabled': True,
    'check_interval_minutes': 60,  # 报警检查间隔（分钟）
    
    # 液位报警 - 全局默认阈值
    'level': {
        'diff_threshold_default': 5.0,    # 液位差异默认阈值（单位根据现场调整）
        'low_threshold_default': 2.0,    # 默认最低液位报警阈值
        'high_threshold_default': 14.0,  # 默认最高液位报警阈值
        'enabled': True
    },
    
    # 温度报警 - 全局默认范围
    'temperature': {
        'low_threshold_default': 10.0,   # 最低温度报警
        'high_threshold_default': 20.0,  # 最高温度报警 → 调低触发报警看效果
        'enabled': True
    },
    
    # 密度报警 - 全局默认范围
    'density': {
        'low_threshold_default': 0.75,   # 最低密度
        'high_threshold_default': 0.95,  # 最高密度
        'enabled': True
    },
    
    # 流量不平衡报警
    'daily_flow': {
        'diff_threshold': 100.0,  # 当日流量不平衡阈值 (立方米)
        'enabled': True
    },
    
    # 报警分组：不同分组发给不同责任人
    'groups': [
        {
            'name': '操作值班组',
            'phones': ['138xxxxxxxx', '139xxxxxxxx'],
            'enabled': True,
            'alarm_types': ['level_diff', 'level_low', 'level_high', 'temperature', 'density', 'daily_flow']  # 接收哪些报警
        },
        {
            'name': '管理人员组',
            'phones': ['137xxxxxxxx', '136xxxxxxxx'],
            'enabled': True,
            'alarm_types': ['level_diff', 'daily_flow']  # 只接收差异和流量不平衡
        },
        {
            'name': '维修技术组',
            'phones': ['135xxxxxxxx'],
            'enabled': False,  # 暂时禁用
            'alarm_types': ['temperature', 'density']
        }
    ]
}

# 阿里云短信配置（需要改成实际配置）
SMS = {
    'access_key_id': 'your-access-key-id',
    'access_key_secret': 'your-access-key-secret',
    'sign_name': '珠海燃气监管',
    'template_code': 'SMS_12345678',
    'template_content': '【珠海燃气监管】报警类型: ${type}, 报警内容: ${content}, 时间: ${time}'
}

# 数据库配置
DATABASE = {
    'url': 'sqlite:///gas_monitor.db'
}
