pieceClassify.py 4.99 KB
Newer Older
lcn's avatar
lcn committed
1 2 3 4
import numpy as np
import re


wang.wenrong's avatar
wang.wenrong committed
5 6
def piececlassfy(current="eachnode_cur", power="eachnode_pow", timer="timer",
                 params="params"):
lcn's avatar
lcn committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
    month = timer[0].split(" ")[0].split("-")[1]
    day = timer[0].split(" ")[0].split("-")[2]
    hours = [each.split(" ")[1].split(":")[0] for each in timer]
    dataLen = len(current)
    his_p = []
    his_i = []
    now_p = []
    now_i = []
    operations = []
    runingEquip = []
    statesaircond = []
    statesrefrig = []
    stateselectro = []
    statesricecook = []
    statesheater = []
    timeaircond = []
    timerefrig = []
    timericecook = []
    timeelectro = []
    timeheater = []

    statesaircond_off = []
    statesrefrig_off = []
    stateselectro_off = []
    statesricecook_off = []
    statesheater_off = []
    timeaircond_off = []
    timerefrig_off = []
    timericecook_off = []
    timeelectro_off = []
    timeheater_off = []

wang.wenrong's avatar
wang.wenrong committed
39 40
    quannums = [.01, .03, .05, .1, .2, .3, .4, .5, .6, .7, .8, .9, .95, .98,
                .99]
lcn's avatar
lcn committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
    opernumstate = []
    for i in range(dataLen):
        if i == 0:
            now_p.append(power[i])
            now_i.append(current[i])
            timerefrig.append(timer[i])
            continue
        if i < 6:
            now_p.append(power[i])
            now_i.append(power[i])
            continue
        if i >= 6:
            now_p.append(power[i])
            now_i.append(power[i])

            his_i.append(now_i[0])
            his_p.append(now_p[0])
            now_p = now_p[-5:]
            now_i = now_i[-5:]
wang.wenrong's avatar
wang.wenrong committed
60 61
            if 1000 * (now_p[0] - his_p[-1]) > params[0] - 50 and 1000 * (
                    now_p[0] - his_p[-1]) < min(params[1:]) + 50:
lcn's avatar
lcn committed
62 63 64
                statesrefrig.append("电冰箱运行")
                timerefrig.append(timer[i])

wang.wenrong's avatar
wang.wenrong committed
65 66
            if 1000 * (now_p[0] - his_p[-1]) > params[1] - 50 and 1000 * (
                    now_p[0] - his_p[-1]) < min(params[2:]) + 50:
lcn's avatar
lcn committed
67 68 69
                statesaircond.append("空调运行")
                timeaircond.append(timer[i])
            if 1000 * (now_p[0] - his_p[-1]) > min(params[2:]) - 50 and (
wang.wenrong's avatar
wang.wenrong committed
70 71
                    int(hours[i]) >= 22 or int(hours[i]) < 5 or int(
                hours[i]) >= 19):
lcn's avatar
lcn committed
72 73
                statesheater.append("热水器启动")
                timeheater.append(timer[i])
wang.wenrong's avatar
wang.wenrong committed
74 75
            if 1000 * (now_p[0] - his_p[-1]) > min(
                    params[3:]) - 50 and 1000 * (now_p[0] - his_p[-1]) < max(
lcn's avatar
lcn committed
76
                    params[3:]) + 50 and (
wang.wenrong's avatar
wang.wenrong committed
77 78
                    int(hours[i]) >= 10 and int(hours[i]) < 14 or int(
                hours[i]) >= 17 and int(hours[i]) < 20 or int(
lcn's avatar
lcn committed
79 80 81 82
                hours[i]) >= 5 and int(hours[i]) < 10):
                statesricecook.append("电饭煲启动")
                timericecook.append(timer[i])
            if 1000 * (now_p[0] - his_p[-1]) > max(params[3:]) - 50 and (
wang.wenrong's avatar
wang.wenrong committed
83 84
                    int(hours[i]) >= 10 and int(hours[i]) < 14 or int(
                hours[i]) >= 17 and int(hours[i]) < 20 or int(
lcn's avatar
lcn committed
85 86 87 88
                hours[i]) >= 5 and int(hours[i]) < 10):
                stateselectro.append("电磁炉运行")
                timeelectro.append(timer[i])
            # return 0
wang.wenrong's avatar
wang.wenrong committed
89 90
            if 1000 * (his_p[-1] - now_p[0]) > params[0] - 50 and 1000 * (
                    his_p[-1] - now_p[0]) < min(params[1:]) + 50:
lcn's avatar
lcn committed
91 92 93
                statesrefrig_off.append("电冰箱关闭")
                timerefrig_off.append(timer[i])

wang.wenrong's avatar
wang.wenrong committed
94 95
            if 1000 * (his_p[-1] - now_p[0]) > params[1] - 50 and 1000 * (
                    his_p[-1] - now_p[0]) < min(params[2:]) + 50:
lcn's avatar
lcn committed
96 97 98
                statesaircond_off.append("空调关闭")
                timeaircond_off.append(timer[i])
            if 1000 * (his_p[-1] - now_p[0]) > min(params[2:]) - 50 and (
wang.wenrong's avatar
wang.wenrong committed
99 100
                    int(hours[i]) >= 22 or int(hours[i]) < 5 or int(
                hours[i]) >= 19):
lcn's avatar
lcn committed
101 102
                statesheater_off.append("热水器关闭")
                timeheater_off.append(timer[i])
wang.wenrong's avatar
wang.wenrong committed
103 104
            if 1000 * (his_p[-1] - now_p[0]) > min(
                    params[3:]) - 50 and 1000 * (his_p[-1] - now_p[0]) < max(
lcn's avatar
lcn committed
105
                    params[3:]) + 50 and (
wang.wenrong's avatar
wang.wenrong committed
106 107
                    int(hours[i]) >= 10 and int(hours[i]) < 14 or int(
                hours[i]) >= 17 and int(hours[i]) < 20 or int(
lcn's avatar
lcn committed
108 109 110 111
                hours[i]) >= 5 and int(hours[i]) < 10):
                statesricecook_off.append("电饭煲关闭")
                timericecook_off.append(timer[i])
            if 1000 * (his_p[-1] - now_p[0]) > max(params[3:]) - 50 and (
wang.wenrong's avatar
wang.wenrong committed
112 113
                    int(hours[i]) >= 10 and int(hours[i]) < 14 or int(
                hours[i]) >= 17 and int(hours[i]) < 20 or int(
lcn's avatar
lcn committed
114 115 116 117
                hours[i]) >= 5 and int(hours[i]) < 10):
                stateselectro_off.append("电磁炉关闭")
                timeelectro_off.append(timer[i])
    return statesaircond, statesrefrig, stateselectro, statesricecook, statesheater, timeaircond, timerefrig, timericecook, timeelectro, timeheater, statesaircond_off, statesrefrig_off, stateselectro_off, statesricecook_off, statesheater_off, timeaircond_off, timerefrig_off, timericecook_off, timeelectro_off, timeheater_off