Beispiel #1
0
def main():
    month = input("please input month1 01 ~ 12:  ")

    l = []
    name_list_hc = []
    name_list_rb = []
    for (k, v) in config.YearToColor.items():
        a = "HC" + k + month
        b = "RB" + k + month
        l.append([a, b, a + " - " + b, v])
        name_list_hc.append(a)
        name_list_rb.append(b)

    datas_hc = contract_hc.load()
    datas_rb = contract_rb.load()

    m_hc = contract_hc.filter1(datas_hc, name_list_hc, False)
    m_rb = contract_rb.filter1(datas_rb, name_list_rb, False)

    ax = plt.gca()
    ax.xaxis.set_major_formatter(mdates.DateFormatter('%m-%d'))
    ax.xaxis.set_major_locator(mdates.MonthLocator())

    y_major_locator = MultipleLocator(config.y_diff_major_locator)
    ax.yaxis.set_major_locator(y_major_locator)

    diff_l = []
    for pair in l:
        diff_x = []
        diff_y = []
        if pair[0] not in m_hc or pair[1] not in m_rb:
            continue
        ma = m_hc[pair[0]]
        mb = m_rb[pair[1]]
        year = int("20" + pair[0][2:4])
        for (date, v) in ma.items():
            if date not in mb:
                continue
            diff_y.append(v - mb[date])
            diff_x.append(
                datetime.date(2019 + date.year - year, date.month, date.day))

        diff_l.append([pair[2], diff_x, diff_y, pair[3]])

    plt.xlabel(" price diff " + month)
    plt.ylabel("")
    ls = []
    labels = []
    for i, v in enumerate(diff_l):
        plt.plot(v[1],
                 v[2],
                 color=v[3],
                 linestyle='-',
                 linewidth=1,
                 label=v[0])
        labels.append(v[0])

    plt.legend(labels=labels, loc='best', shadow=True)
    plt.grid(axis="y", linestyle="--")
    plt.show()
Beispiel #2
0
def gen_diff(year, month1, month2):
    year = config.Name + year
    name_list = []
    a = year + month1
    b = year + month2
    name_list.append(a)
    name_list.append(b)

    m = contract.filter1(datas, name_list, False)

    diff_x = []
    diff_y = []
    if a not in m or b not in m:
        return
    ma = m[a]
    mb = m[b]
    max = -10000
    min = 10000
    for (date, v) in ma.items():
        if date not in mb:
            continue
        diff = v - mb[date]
        if diff > max:
            max = diff
        if diff < min:
            min = diff
    return (max, min)
Beispiel #3
0
def get_cur_diff(a, b):
    a = config.Name + a
    b = config.Name + b
    name_list = [a, b]
    m = contract.filter1(datas, name_list, False)

    diff_x = []
    diff_y = []
    if a not in m or b not in m:
        return
    ma = m[a]
    mb = m[b]
    date_2_diff = {}
    max_date = datetime.date(2019, 1, 1)
    for (date, v) in ma.items():
        if date not in mb:
            continue
        diff = v - mb[date]
        date_2_diff[date] = diff
        if date > max_date:
            max_date = date

    return date_2_diff[max_date]
Beispiel #4
0
def main():
    month1 = ""
    month2 = ""
    if len(sys.argv) >= 3:
        month1 = sys.argv[1]
        month2 = sys.argv[2]
    else:
        month1 = input("please input month1 01 ~ 12:  ")
        month2 = input("please input month2 01 ~ 12:  ")

    l = []
    name_list = []
    for k, v in config.YearToColor.items():
        a = config.Name + k + month1
        b = config.Name + k + month2
        if month2 < month1:
            b = config.Name + config.NextYear(k) + month2
        l.append([a, b, a + " - " + b, v])
        name_list.append(a)
        name_list.append(b)

    datas = contract.load()
    m = contract.filter1(datas, name_list, False)

    ax = plt.gca()
    #指定X轴的以日期格式(带小时)显示
    ax.xaxis.set_major_formatter(mdates.DateFormatter('%m-%d'))
    #X轴的间隔为小时
    ax.xaxis.set_major_locator(mdates.MonthLocator())

    y_major_locator = MultipleLocator(100)
    ax.yaxis.set_major_locator(y_major_locator)

    diff_l = []
    for pair in l:
        diff_x = []
        diff_y = []
        if pair[0] not in m or pair[1] not in m:
            continue
        ma = m[pair[0]]
        mb = m[pair[1]]
        year = int("20" + pair[0][2:4])
        for (date, v) in ma.items():
            if date not in mb:
                continue
            diff_y.append(v - mb[date])
            diff_x.append(
                datetime.date(2019 + date.year - year, date.month, date.day))

        diff_l.append([pair[2], diff_x, diff_y, pair[3]])

    plt.xlabel("jd price diff " + month1 + " " + month2)
    plt.ylabel("")
    ls = []
    labels = []
    for i, v in enumerate(diff_l):
        plt.plot(v[1],
                 v[2],
                 color=v[3],
                 linestyle='-',
                 linewidth=1,
                 label=v[0])
        labels.append(v[0])

    plt.legend(labels=labels, loc='best', shadow=True)
    plt.grid(axis="y", linestyle="--")
    plt.show()
Beispiel #5
0
def gen_pic(prefix, month1, month2):
    l = []
    name_list = []
    for i, val in enumerate(cs):
        a = val[0] + month1
        b = val[0] + month2
        if month2 < month1:
            if i >= len(cs) - 1:
                continue
            b = cs[i + 1][0] + month2
        l.append([a, b, a + " - " + b])
        name_list.append(a)
        name_list.append(b)

    m = contract.filter1(datas, name_list, False)

    plt.figure(figsize=(20, 10))

    ax = plt.gca()
    #指定X轴的以日期格式(带小时)显示
    ax.xaxis.set_major_formatter(mdates.DateFormatter('%m-%d'))
    #X轴的间隔为小时
    ax.xaxis.set_major_locator(mdates.MonthLocator())

    y_major_locator = MultipleLocator(100)
    ax.yaxis.set_major_locator(y_major_locator)

    diff_l = []
    for pair in l:
        diff_x = []
        diff_y = []
        if pair[0] not in m or pair[1] not in m:
            continue
        ma = m[pair[0]]
        mb = m[pair[1]]
        year = int("20" + pair[0][2:4])
        for (date, v) in ma.items():
            if date not in mb:
                continue
            diff_y.append(v - mb[date])
            diff_x.append(
                datetime.date(2019 + date.year - year, date.month, date.day))

        diff_l.append([pair[2], diff_x, diff_y])

    plt.xlabel("jd price diff " + month1 + " " + month2)
    plt.ylabel("")
    ls = []
    labels = []
    for i, v in enumerate(diff_l):
        linewidth = 1
        if v[0][0:4] == "JD20":
            linewidth = 2
        plt.plot(v[1],
                 v[2],
                 color=cs[i][1],
                 linestyle='-',
                 linewidth=linewidth,
                 label=v[0])
        labels.append(v[0])

    plt.legend(labels=labels, loc='best', shadow=True)
    plt.grid(axis="y", linestyle="--")
    plt.savefig("pictures/" + prefix + "/" + month1 + "_" + month2 + ".png")
    plt.clf()
    plt.close('all')
Beispiel #6
0
def main():
    month1 = input("please input month1 01 ~ 12:  ")
    month2 = input("please input month2 01 ~ 12:  ")

    cs = [["m11", "gold"], ["m12", "plum"], ["m13", "purple"], ["m14", "gray"],
          ["m15", "pink"], ["m16", "green"], ["m17", "brown"], ["m18", "blue"],
          ["m19", "red"], ["m20", "black"], ["m21", "yellow"]]

    l = []
    name_list = []
    for i, val in enumerate(cs):
        a = val[0] + month1
        b = val[0] + month2
        if month2 < month1:
            if i >= len(cs) - 1:
                continue
            b = cs[i + 1][0] + month2
        l.append([a, b, a + " - " + b])
        name_list.append(a)
        name_list.append(b)

    datas = contract.load()
    m = contract.filter1(datas, name_list, False)
    print(m)
    ax = plt.gca()
    #指定X轴的以日期格式(带小时)显示
    ax.xaxis.set_major_formatter(mdates.DateFormatter('%m-%d'))
    #X轴的间隔为小时
    ax.xaxis.set_major_locator(mdates.MonthLocator())

    y_major_locator = MultipleLocator(100)
    ax.yaxis.set_major_locator(y_major_locator)

    diff_l = []
    for pair in l:
        diff_x = []
        diff_y = []
        if pair[0] not in m or pair[1] not in m:
            print(pair)
            continue
        ma = m[pair[0]]
        mb = m[pair[1]]
        year = int("20" + pair[0][1:3])
        for (date, v) in ma.items():
            if date not in mb:
                continue
            diff_y.append(v - mb[date])
            diff_x.append(
                datetime.date(2019 + date.year - year, date.month, date.day))

        diff_l.append([pair[2], diff_x, diff_y])

    plt.xlabel("m price diff " + month1 + " " + month2)
    plt.ylabel("")
    ls = []
    labels = []
    for i, v in enumerate(diff_l):
        plt.plot(v[1],
                 v[2],
                 color=cs[i][1],
                 linestyle='-',
                 linewidth=1,
                 label=v[0])
        labels.append(v[0])

    plt.legend(labels=labels, loc='best', shadow=True)
    plt.grid(axis="y", linestyle="--")
    plt.show()