2 Commits 80bbfb60e1 ... 4efb0e2b5c

Author SHA1 Message Date
  wdl 4efb0e2b5c Merge remote-tracking branch 'origin/master' 2 years ago
  wdl 5a93170ce9 添加照明记录导入 2 years ago
5 changed files with 405 additions and 0 deletions
  1. 37 0
      energy/date_for.sh
  2. 317 0
      energy/dayTask/bus_hive.sql
  3. 1 0
      energy/dayTask/energy_hive.sql
  4. BIN
      energy/dayTask/img.png
  5. 50 0
      energy/dayTask/remind.md

+ 37 - 0
energy/date_for.sh

@@ -0,0 +1,37 @@
+#!/bin/bash
+
+startDate=$1
+endDate=$2
+startSec=`date -d "$startDate" "+%s"`
+endSec=`date -d "$endDate" "+%s"`
+source /etc/profile.d/saga_env.sh
+for((i=$startSec;i<=$endSec;i+=86400))
+do
+    current_day=`date -d "@$i" "+%Y-%m-%d"`
+    one_day_ago=`date -d "$current_day yesterday" +%Y%m%d`
+
+    start_time=`date -d "0 day $current_day" +%Y%m%d`000000
+    end_time=`date -d "1 day $current_day" +%Y%m%d`000000
+
+    energy_start_time=`date -d "-1 day $current_day" +%Y%m%d`160000
+    energy_end_time=`date -d "-0 day $current_day" +%Y%m%d`160000
+
+    echo current_day:$current_day
+    echo start_time:${start_time}
+    echo end_time:${end_time}
+
+    echo "**************************************"
+    echo energy_start_time:${energy_start_time}
+    echo energy_end_time:${energy_end_time}
+
+    /usr/local/bin/python3 /opt/app/python_transfer/start_mysql.py 10101 --start_time $energy_start_time --end_time $energy_end_time
+
+    sh /opt/app/bi-app/energy/dayTask/mysql_to_hdfs.sh ods_energy_15_min $current_day
+
+    ssh hadoop01 sh /opt/app/bi-app/energy/dayTask/ods_to_dwd.sh all $current_day
+
+    ssh hadoop01 sh /opt/app/bi-app/energy/dayTask/clean_mysql.sh clean_energy_15 $current_day
+
+    sh /opt/app/bi-app/energy/dayTask/hdfs_to_mysql.sh app_energy_day $current_day
+
+done

+ 317 - 0
energy/dayTask/bus_hive.sql

@@ -1,3 +1,4 @@
+-- 空调操作记录表
 create table ods_bus_feedback
 (
     id             STRING comment '主键',
@@ -28,4 +29,320 @@ create table ods_bus_feedback
     LOCATION
         'hdfs://sagaCluster:8020/warehouse/saga_dw/ods/tmp/ods_bus_feedback'
     TBLPROPERTIES (
+        'orc.compress'='lzo');
+
+-- 照明操作记录
+create table saga_dw.ods_bus_light_switch
+(
+    id STRING comment '主键',
+    project_id  STRING  comment '项目ID',
+    object_id   STRING  comment '空间ID',
+    source_type STRING  comment '反馈来源分类',
+    user_id     STRING ,
+    user_phone  STRING ,
+    user_name   STRING ,
+    on_off      STRING comment '1开 0关',
+    result      STRING comment '1成功 0失败',
+    create_time STRING,
+    exe_result  integer comment '执行结果'
+) COMMENT '照明操作记录'
+    PARTITIONED BY (`dt` string)
+    ROW FORMAT DELIMITED FIELDS TERMINATED BY '\001'
+    STORED AS TEXTFILE
+    LOCATION
+        'hdfs://sagaCluster:8020/warehouse/saga_dw/ods/ods_bus_light_switch'
+    TBLPROPERTIES (
+        'orc.compress'='lzo');
+
+-- 项目信息
+create table saga_dw.ods_object_data_project
+(
+    id  STRING comment '项目id',
+    secret  STRING comment '',
+    `name`  STRING comment '',
+    local_id   STRING comment '',
+    local_name STRING comment '',
+    longitude  STRING comment '经度',
+    latitude   STRING comment '纬度',
+    distance   STRING comment '',
+    city_id    STRING comment '',
+    is_duoduo  STRING comment '',
+    `status` STRING comment '0:无效,1:有效'
+) COMMENT '项目信息'
+    PARTITIONED BY (`dt` string)
+    ROW FORMAT DELIMITED FIELDS TERMINATED BY '\001'
+    STORED AS TEXTFILE
+    LOCATION
+        'hdfs://sagaCluster:8020/warehouse/saga_dw/ods/ods_object_data_project'
+    TBLPROPERTIES (
+        'orc.compress'='lzo');
+
+-- 建筑信息
+create table saga_dw.ods_object_data_building
+(
+    id STRING,
+    name       STRING,
+    local_id   STRING,
+    local_name STRING,
+    project_id STRING,
+    `status`   STRING
+) COMMENT '建筑信息'
+    PARTITIONED BY (`dt` string)
+    ROW FORMAT DELIMITED FIELDS TERMINATED BY '\001'
+    STORED AS TEXTFILE
+    LOCATION
+        'hdfs://sagaCluster:8020/warehouse/saga_dw/ods/ods_object_data_building'
+    TBLPROPERTIES (
+        'orc.compress'='lzo');
+
+
+-- 空间
+create table saga_dw.ods_object_data_space
+(
+    id  STRING,
+    name                     STRING comment '',
+    local_id                 STRING comment '',
+    local_name               STRING comment '',
+    room_func_type           STRING comment '',
+    group_id                 STRING comment '',
+    bim_location             STRING comment '',
+    room_q_r_code            STRING comment '',
+    business_type            STRING comment '业务区域编码',
+    function_code            STRING comment '',
+    out_line                 STRING comment '',
+    pic                      STRING comment '',
+    position_img             STRING comment '',
+    position_img_upload_type STRING comment '',
+    position_img_create_time STRING comment '',
+    project_id               STRING comment '',
+    building_id              STRING comment '',
+    floor_id                 STRING comment '',
+    `status`                 STRING comment '',
+    is_controlled            STRING comment '是否为服务定制受控对象',
+    is_chiller_monitor       STRING comment '是否冷站智控监测 1:是 0:不是',
+    has_window               STRING comment '是否有窗户',
+    has_defect               STRING comment '是否有工程缺陷',
+    region                   STRING comment '内外区',
+    zone_orientation         STRING comment '朝向,东西南北',
+    remark                   STRING comment '备注',
+    tenant_id                STRING comment '租户id',
+    room_serial              STRING comment '空间序号',
+    monitor_remark           STRING comment '日常数据监控的空间备注',
+    light_group_id           STRING comment '照明分组ID'
+) COMMENT ''
+    PARTITIONED BY (`dt` string)
+    ROW FORMAT DELIMITED FIELDS TERMINATED BY '\001'
+    STORED AS TEXTFILE
+    LOCATION
+        'hdfs://sagaCluster:8020/warehouse/saga_dw/ods/ods_object_data_space'
+    TBLPROPERTIES (
+        'orc.compress'='lzo');
+
+-- 空间组
+create table saga_dw.ods_object_data_space_group
+(
+    id  STRING,
+    project_id  STRING comment '',
+    name        STRING comment '',
+    `status`      STRING comment '',
+    `readonly`    STRING comment '',
+    update_time STRING comment '',
+    type        STRING comment '组类型,默认0 空调;1照明;其它...',
+    update_user STRING comment '',
+    remark      STRING comment ''
+) COMMENT ''
+    PARTITIONED BY (`dt` string)
+    ROW FORMAT DELIMITED FIELDS TERMINATED BY '\001'
+    STORED AS TEXTFILE
+    LOCATION
+        'hdfs://sagaCluster:8020/warehouse/saga_dw/ods/ods_object_data_space_group'
+    TBLPROPERTIES (
+        'orc.compress'='lzo');
+
+-- 楼层
+create table saga_dw.ods_object_data_floor
+(
+    id STRING comment '',
+    name              STRING comment '',
+    local_id          STRING comment '',
+    local_name        STRING comment '',
+    floor_map         STRING comment '',
+    project_id        STRING comment '',
+    building_id       STRING comment '',
+    floor_sequence_id integer comment '',
+    `status`          STRING comment ''
+) COMMENT ''
+    PARTITIONED BY (`dt` string)
+    ROW FORMAT DELIMITED FIELDS TERMINATED BY '\001'
+    STORED AS TEXTFILE
+    LOCATION
+        'hdfs://sagaCluster:8020/warehouse/saga_dw/ods/ods_object_data_floor'
+    TBLPROPERTIES (
+        'orc.compress'='lzo');
+
+-- 设备
+create table saga_dw.ods_object_data_equipment
+(
+    id  STRING comment '',
+    name               STRING comment '',
+    local_id           STRING comment '',
+    local_name         STRING comment '',
+    major_category     STRING comment '',
+    system_category    STRING comment '',
+    equipment_category STRING comment '',
+    bim_location       STRING comment '',
+    run_status         STRING comment '',
+    equip_q_r_code     STRING comment '',
+    install_location   STRING comment '',
+    position_img       STRING comment '',
+    position_img_upload_type STRING comment '',
+    position_img_create_time STRING comment '',
+    project_id               STRING comment '',
+    building_id              STRING comment '',
+    `status`                   STRING comment ''
+) COMMENT ''
+    PARTITIONED BY (`dt` string)
+    ROW FORMAT DELIMITED FIELDS TERMINATED BY '\001'
+    STORED AS TEXTFILE
+    LOCATION
+        'hdfs://sagaCluster:8020/warehouse/saga_dw/ods/ods_object_data_equipment'
+    TBLPROPERTIES (
+        'orc.compress'='lzo');
+
+-- 设备信息
+create table saga_dw.ods_object_data_equipment_infos
+(
+    id STRING comment '',
+    project_id STRING comment '',
+    category   STRING comment '',
+    infos  STRING comment '',
+    body   STRING comment ''
+) COMMENT ''
+    PARTITIONED BY (`dt` string)
+    ROW FORMAT DELIMITED FIELDS TERMINATED BY '\001'
+    STORED AS TEXTFILE
+    LOCATION
+        'hdfs://sagaCluster:8020/warehouse/saga_dw/ods/ods_object_data_equipment_infos'
+    TBLPROPERTIES (
+        'orc.compress'='lzo');
+
+-- 关系表
+create table saga_dw.ods_object_data_relation
+(
+    id STRING comment '',
+    project_id STRING comment '',
+    graph_id   STRING comment '',
+    from_id    STRING comment '',
+    rel_type   STRING comment '',
+    to_id      STRING comment '',
+    infos      STRING comment ''
+) COMMENT ''
+    PARTITIONED BY (`dt` string)
+    ROW FORMAT DELIMITED FIELDS TERMINATED BY '\001'
+    STORED AS TEXTFILE
+    LOCATION
+        'hdfs://sagaCluster:8020/warehouse/saga_dw/ods/ods_object_data_relation'
+    TBLPROPERTIES (
+        'orc.compress'='lzo');
+
+-- 租户
+create table saga_dw.ods_object_data_tenant
+(
+    id  STRING comment '',
+    name       STRING comment '',
+    local_id   STRING comment '',
+    local_name STRING comment '',
+    project_id STRING comment '',
+    `status`   STRING comment ''
+) COMMENT ''
+    PARTITIONED BY (`dt` string)
+    ROW FORMAT DELIMITED FIELDS TERMINATED BY '\001'
+    STORED AS TEXTFILE
+    LOCATION
+        'hdfs://sagaCluster:8020/warehouse/saga_dw/ods/ods_object_data_tenant'
+    TBLPROPERTIES (
+        'orc.compress'='lzo');
+
+
+create table saga_dw.ods_custom_content_real
+(
+    id             STRING comment '',
+    project_id     STRING comment '',
+    space_id       STRING comment '',
+    group_id       STRING comment '',
+    `date`         STRING comment '',
+    `time`         STRING comment '',
+    item           STRING comment '',
+    time_point     STRING comment '',
+    fixed_value    double comment '',
+    max_value      double comment '',
+    min_value      double comment '',
+    create_user_id STRING comment '',
+    create_time    STRING comment '',
+    update_user_id STRING comment '',
+    update_time    STRING comment '',
+    update_source  STRING comment '更新来源  0 初始化配置  1、反馈算法调整季节  2、反馈算法调整日期 3、临时服务定制 4、提前开机  5、小程序捏曲线',
+    is_beforehand  STRING comment '提前开机1 不提前开机0',
+    custom_type    STRING comment '0 初始化 1 算法季节 2算法日期 3 app 4 临时 5灯加班    关机情况有初始服务定制默认0'
+) COMMENT ''
+    PARTITIONED BY (`dt` string)
+    ROW FORMAT DELIMITED FIELDS TERMINATED BY '\001'
+    STORED AS TEXTFILE
+    LOCATION
+        'hdfs://sagaCluster:8020/warehouse/saga_dw/ods/ods_custom_content_real'
+    TBLPROPERTIES (
+        'orc.compress'='lzo');
+
+
+create table saga_dw.ods_custom_persist_target
+(
+    id              STRING comment '',
+    project_id      STRING comment '',
+    space_id        STRING comment '',
+    `date`          STRING comment '',
+    `time`          STRING comment '',
+    temperature_max double comment '',
+    temperature_min double comment '',
+    humidity_max    double comment '',
+    humidity_min    double comment '',
+    co2_max         double comment '',
+    co2_min         double comment '',
+    hcho_max        double comment '',
+    hcho_min        double comment '',
+    pm25_max        double comment '',
+    pm25_min        double comment '',
+    sun_fixed       double comment '',
+    create_time     STRING comment '',
+    is_beforehand   STRING comment ''
+) COMMENT ''
+    PARTITIONED BY (`dt` string)
+    ROW FORMAT DELIMITED FIELDS TERMINATED BY '\001'
+    STORED AS TEXTFILE
+    LOCATION
+        'hdfs://sagaCluster:8020/warehouse/saga_dw/ods/ods_custom_persist_target'
+    TBLPROPERTIES (
+        'orc.compress'='lzo');
+
+-- 用户信息
+create table saga_dw.ods_user
+(
+    id STRING comment '',
+    name             STRING comment '用户名   游客用户没有名字',
+    company_id       STRING comment '所属企业ID',
+    type             STRING comment '类型:1,普通租户;2,租户行政;3,运营方;4,访客',
+    `status`         STRING comment '用户状态【0:未入驻/1:审核中/2:已入驻激活/3:已入驻待激活/4:已入驻冻结/5:已入驻作废】',
+    create_date      STRING comment '创建时间',
+    update_date      STRING comment '更新时间',
+    dep_name         STRING comment '',
+    job              STRING comment '职务',
+    phone            STRING comment '',
+    manage_user_type STRING comment '成员类型:1-正式成员, 2-临时成员',
+    first_use_time   STRING comment '首次使用时间(入住、激活时的时间)'
+) COMMENT ''
+    PARTITIONED BY (`dt` string)
+    ROW FORMAT DELIMITED FIELDS TERMINATED BY '\001'
+    STORED AS TEXTFILE
+    LOCATION
+        'hdfs://sagaCluster:8020/warehouse/saga_dw/ods/ods_user'
+    TBLPROPERTIES (
         'orc.compress'='lzo');

+ 1 - 0
energy/dayTask/energy_hive.sql

@@ -174,6 +174,7 @@ create table ods_temperature_15_min
     TBLPROPERTIES (
         'orc.compress'='lzo');
 
+drop table ods_humidity_15_min;
 /** 湿度 15 分钟分精度 */
 create table ods_humidity_15_min
 (

BIN
energy/dayTask/img.png


+ 50 - 0
energy/dayTask/remind.md

@@ -0,0 +1,50 @@
+## 博锐尚格能源数据
+
+### 总部
+
+```sql
+select branch_type,
+       use_range_type,
+       branch_type_name,
+       sum(value_sum),
+       sum(if(year_mouth = '2022-01', value_sum, 0)) '01',
+       sum(if(year_mouth = '2022-02', value_sum, 0)) '02',
+       sum(if(year_mouth = '2022-03', value_sum, 0)) '03',
+       sum(if(year_mouth = '2022-04', value_sum, 0)) '04',
+       sum(if(year_mouth = '2022-05', value_sum, 0)) '05',
+       sum(if(year_mouth = '2022-06', value_sum, 0)) '06',
+       sum(if(year_mouth = '2022-07', value_sum, 0)) '07',
+       sum(if(year_mouth = '2022-08', value_sum, 0)) '08',
+       sum(if(year_mouth = '2022-09', value_sum, 0)) '09',
+       sum(if(year_mouth = '2022-10', value_sum, 0)) '10',
+       sum(if(year_mouth = '2022-11', value_sum, 0)) '11',
+       sum(if(year_mouth = '2022-12', value_sum, 0)) '12'
+from ( select building, func_id, parent_code, branch_type, 
+              branch_type_name, use_range_type, value_sum, 
+              current_hour, substr(current_hour, 12) hour_, 
+              current_year, year_mouth, week_of_year, dt 
+       from app_energy_15_min  ) t1
+group by branch_type, use_range_type, branch_type_name;
+```
+
+### 成都 & 西安
+成都办公室1101080255 \
+西安办公室6101122004
+
+修改 192.168.100.142 的目录 /opt/app/python_tmp 下的配置文件 config.json \
+将 building 替换成都与西安的建筑id \
+![img.png](img.png) \
+
+
+执行脚本
+```shell
+python3 /opt/app/python_tmp/start_mysql.py 10101 --start_time 20221001000000 --end_time 20221031000000
+```
+
+```sql
+select building, func_id, meter, sum(data_value)
+from (select building, func_id, meter, data_time, data_value, substr(data_time, 12, 2) hour_ 
+      from energy_15_min_ot) t1
+where hour_ in ('21', '22', '23', '00', '01', '02', '03', '04', '05', '06')
+group by building, func_id, meter;
+```