2019-12-18

2019-12-18  本文已影响0人  西章momo
from datetime import timedelta
from datetime import datetime
import math

def normalize_shipment(cnt_list, date_list):
    arrive_table = {}

    for i in range(len(cnt_list)):
        cnt = cnt_list[i]
        date = date_list[i]
        month_table = arrive_table.get(date.month, {})
        day_cnt = month_table.get(date.day, 0)
        month_table[date.day] = day_cnt + cnt
        arrive_table[date.month] = month_table

    return arrive_table 


def traversal(ave_sale, storage, arrive_table, tdelta=timedelta(days=1), days = 30):
    record = []

    cur_storage = storage
    saleout_days = 0
    saleout_start_date = None

    now = datetime.now()
    for i in range(days):
        print('-----------------')
        print(now)
        sto = sto - ave_sale

        # print("当前库存:{0}".format(sto))
        if arrive_table.__contains__(now.month):
            month_table = arrive_table[now.month]
            sto = sto + month_table.get(now.day, 0)
            # print("补货:{0}".format(month_table.get(now.day, 0)))
        if sto < 0:
            if saleout_days == 0:
                saleout_start_date = now
            saleout_days = saleout_days + 1
            sto = 0
        else:
            if saleout_days > 0:
                warning = "{0}/{1}/{2}起断货{3}天,需补货:{4}"
                record.append(warning)
                saleout_days = 0
        now = now + tdelta

    return record

    
上一篇下一篇

猜你喜欢

热点阅读