In [15]:
%matplotlib inline

import matplotlib.pyplot as plt


def get_down_centre_last_low(p_list):
    zn_num = len(p_list) - 1
    available_num = min(9, (zn_num - 6))
    
    index = len(p_list) - 4
    for i in range(0, available_num // 2):
        if p_list[index - 2] < p_list[index]:
            index = index -2
        else:
            return index
    return index + 2

def get_down_centre_first_high(p_list):
    s = max(enumerate(p_list[3:]), key=lambda x: x[1])[0]
    return s + 3

def down_centre_expand_spliter(p_list):
    s1 = get_down_centre_last_low(p_list)
    s0 = get_down_centre_first_high(p_list[: s1 - 2])
    return [0, s0, s1, len(p_list) - 1], [p_list[0], p_list[s0], p_list[s1], p_list[-1]]

# y = [0, 100, 60, 130, 70, 120, 40, 90, 50, 140, 85, 105]
# y = [0, 100, 60, 110, 70, 72, 61, 143, 77, 91, 82, 100, 83, 124, 89, 99, 89, 105]

# x = list(range(0, len(y)))
# gg = [min(y[1], y[3])] * len(y)
# dd = [max(y[2], y[4])] * len(y)

# plt.figure(figsize=(len(y),4))
# plt.grid()
# plt.plot(x, y)
# plt.plot(x, gg, '--')
# plt.plot(x, dd, '--')
# sx, sy = down_centre_expand_spliter(y)
# plt.plot(sx, sy)
# plt.show()

In [ ]:
# Centre Expand Prototype
%matplotlib inline

import matplotlib.pyplot as plt


y_base = [0, 100, 60, 130, 70, 120, 40, 90, 50, 140, 85, 105, 55, 80]

for i in range(10, len(y_base)):
    y = y_base[:(i + 1)]
    x = list(range(0, len(y)))
    gg = [min(y[1], y[3])] * len(y)
    dd = [max(y[2], y[4])] * len(y)

    plt.figure(figsize=(i,4))
    plt.grid()
    plt.plot(x, y)
    plt.plot(x, gg, '--')
    plt.plot(x, dd, '--')
    if i % 2 == 1:
        sx, sy = down_centre_expand_spliter(y)
        plt.plot(sx, sy)
    plt.show()

In [ ]:
# Random Centre Generator
%matplotlib inline

import random
import matplotlib.pyplot as plt

y_max = 150
y_min = 50
num_max = 18

def generate_next(y_list, direction):
    if direction == 1:
        y_list.append(random.randint(max(y_list[2], y_list[4], y_list[-1]) + 1, y_max))
    elif direction == -1:
        y_list.append(random.randint(y_min, min(y_list[1], y_list[3], y_list[-1]) - 1))

y_base = [0, 100, 60, 110, 70]
# y_base = [0, 110, 70, 100, 60]
# y_base = [0, 100, 60, 90, 70]
# y_base = [0, 90, 70, 100, 60]

direction = 1
for i in range(5, num_max):
    generate_next(y_base, direction)
    direction = 0 - direction

print(y_base)
for i in range(11, len(y_base), 2):
    y = y_base[:(i + 1)]
    x = list(range(0, len(y)))
    gg = [min(y[1], y[3])] * len(y)
    dd = [max(y[2], y[4])] * len(y)

    plt.figure(figsize=(i,4))
    plt.title(y)
    plt.grid()
    plt.plot(x, y)
    plt.plot(x, gg, '--')
    plt.plot(x, dd, '--')
    sx, sy = down_centre_expand_spliter(y)
    plt.plot(sx, sy)
    plt.show()

In [ ]:
%matplotlib inline

import matplotlib.pyplot as plt

# Group 1
# y_base = [0, 100, 60, 110, 70, 99, 66, 121, 91, 141, 57, 111, 69, 111]
# y_base = [0, 100, 60, 110, 70, 105, 58, 102, 74, 137, 87, 142, 55, 128]
# y_base = [0, 90, 50, 100, 55, 110, 60, 120, 65, 130, 70, 140, 75, 150]
# y_base = [0, 100, 60, 110, 70, 115, 75, 120, 80, 125, 85, 130, 90, 135]
# y_base = [0, 100, 60, 110, 70, 120, 80, 130, 90, 140, 50, 120]
# y_base = [0, 100, 60, 110, 70, 114, 52, 75, 54, 77, 65, 100, 66, 87, 70, 116]
# y_base = [0, 100, 60, 110, 70, 72, 61, 143, 77, 91, 82, 100, 83, 124, 89, 99, 89, 105]

# Group 2
y_base = [0, 110, 70, 100, 60, 142, 51, 93, 78, 109, 60, 116, 50, 106]
# y_base = [0, 110, 70, 100, 60, 88, 70, 128, 82, 125, 72, 80, 63, 119]
# y_base = [0, 110, 70, 100, 60, 74, 66, 86, 57, 143, 50, 95, 70, 91]
# y_base = [0, 110, 70, 100, 60, 77, 73, 122, 96, 116, 82, 124, 69, 129]
# y_base = [0, 110, 70, 100, 60, 147, 53, 120, 77, 103, 56, 76, 74, 92]
# y_base =  [0, 110, 70, 100, 60, 95, 55, 90, 50, 85, 45, 80, 40, 75]

# Group 3
# y_base = [0, 100, 60, 90, 70, 107, 55, 123, 79, 112, 64, 85, 74, 110]
# y_base = [0, 100, 60, 90, 70, 77, 55, 107, 76, 141, 87, 91, 60, 83]
# y_base = [0, 100, 60, 90, 70, 114, 67, 93, 58, 134, 53, 138, 64, 107]
# y_base = [0, 100, 60, 90, 70, 77, 66, 84, 79, 108, 87, 107, 72, 89]
# y_base = [0, 100, 60, 90, 70, 88, 72, 86, 74, 84, 76, 82, 74, 80]

# Group 4
# y_base = [0, 90, 70, 100, 60, 131, 57, 144, 85, 109, 82, 124, 87, 101]
# y_base = [0, 90, 70, 100, 60, 150, 56, 112, 63, 95, 84, 118, 58, 110]
# y_base = [0, 90, 70, 100, 60, 145, 64, 112, 69, 86, 71, 119, 54, 95]
# y_base = [0, 90, 70, 100, 60, 105, 55, 110, 50, 115, 45, 120, 40, 125]

for i in range(11, len(y_base), 2):
    y = y_base[:(i + 1)]
    x = list(range(0, len(y)))
    gg = [min(y[1], y[3])] * len(y)
    dd = [max(y[2], y[4])] * len(y)

    plt.figure(figsize=(i,4))
    plt.title(y)
    plt.grid()
    plt.plot(x, y)
    plt.plot(x, gg, '--')
    plt.plot(x, dd, '--')
    sx, sy = down_centre_expand_spliter(y)
    plt.plot(sx, sy)
    plt.show()