예제 #1
0
def predict_dbd(target_day=date.today()):
    names = ["f", "z", "other"]
    wd = target_day.weekday()
    target_monday = target_day - dt.timedelta(days=wd)

    preds = []
    for name in names:
        #1 該当週の合計量の予測(by NNと相関、土曜日だけは確定値を算出)
        if wd == 5:
            col_name = name + "_ship"
            dbcur.execute(
                "SELECT SUM(" + col_name + ") FROM amounts WHERE "
                "date>=%s AND date<=%s", (target_monday, target_day))
            num_pred = dbcur.fetchone()[0]
            if num_pred is None:
                num_pred = 0
        else:
            num_pred = predict_week.pred_week(target_day, name)
        #2 残り発送量の算出
        col_name = name + "_ship"
        dbcur.execute(
            "SELECT SUM(" + col_name + ") FROM amounts WHERE "
            "date>=%s AND date<=%s", (target_monday, target_day))
        num = dbcur.fetchone()[0]
        if num is None:
            num = 0
        pred = [0 for col in range(wd + 1)]
        pred.extend(func.weeksum_day(target_day, num_pred - num, name))
        pred.append(0)
        preds.append(pred)
        print(preds[-1])
    #全種sum(今日の発送量とpredsの発送量の合計 - 作り置き量)
    return preds
예제 #2
0
def predict_n(target_day=date.today()):
    names = ["f", "z", "other"]
    wd = target_day.weekday()
    if wd >= 5:
        target_monday = target_day + dt.timedelta(days=7 - wd)
    else:
        target_monday = target_day - dt.timedelta(days=wd)
    next_pred = []
    #NNの更新と予測値の取得
    for name in names:
        next_pred.append(
            nn_model.online_train(target_monday, True, predict_week_num,
                                  name)[2])
    preds = []  #axis0:n週後、axis1:fzo、axis2:月~土
    for i in range(predict_week_num):
        pred = []
        max_day = target_monday - dt.timedelta(days=1) + dt.timedelta(days=i *
                                                                      7)
        for j in range(3):
            we = list(func.weeksum_day(max_day, next_pred[j][i], name))
            we.append(0)
            pred.append(we)
        preds.append(pred)
    #week_dataの更新
    target_monday = target_day - dt.timedelta(days=wd)
    weight_each = [0, target_monday]
    names = ["f", "z", "other"]
    for name in names:
        for wd in range(6):
            target_day_t = target_monday + dt.timedelta(days=wd)
            col_name = name + "_ship"
            dbcur.execute(
                "SELECT SUM(" + col_name +
                ") FROM amounts WHERE date>=%s AND date<%s",
                (target_monday, target_day_t))
            wd_weight_1 = dbcur.fetchone()[0]
            if wd_weight_1 is None:
                wd_weight_1 = 0
            col_name = name + "_morn"
            dbcur.execute(
                "SELECT SUM(" + col_name + ") FROM amounts WHERE date=%s",
                (target_day_t, ))
            wd_weight_2 = dbcur.fetchone()[0]
            if wd_weight_2 is None:
                wd_weight_2 = 0
            weight_each.append(wd_weight_1 + wd_weight_2)
        col_name = name + "_ship"
        dbcur.execute(
            "SELECT SUM(" + col_name +
            ") FROM amounts WHERE date>=%s AND date<%s",
            (target_monday, target_monday + dt.timedelta(days=7)))
        total_weight = dbcur.fetchone()[0]
        if total_weight is None:
            total_weight = 0
        weight_each.append(total_weight)
    dbcur.execute(
        "INSERT INTO week_data VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,"
        "%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)", weight_each)

    return preds
예제 #3
0
def predict_n(target_day=date.today()):
    names=["f","z","other"]
    wd=target_day.weekday()
    if wd>=5:
        target_monday=target_day+dt.timedelta(days=7-wd)
    else:
        target_monday=target_day-dt.timedelta(days=wd)
    next_pred=[]
    #NNの更新と予測値の取得
    for name in names:
        next_pred.append(nn_model.online_train(target_monday, True, predict_week_num, name)[2])
    preds=[]#axis0:n週後、axis1:fzo、axis2:月~土
    for i in range(predict_week_num):
        pred=[]
        max_day=target_monday-dt.timedelta(days=1)+dt.timedelta(days=i*7)
        for j in range(3):
            we = list(func.weeksum_day(max_day, next_pred[j][i], name))
            we.append(0)
            pred.append(we)
        preds.append(pred)
    return preds