Beispiel #1
0
def process_the_info(c_i, c_o, r_n, t_r):
    # This program is for my school for the class of AI

    # We take all the data and assing them to a varibles
    colors = [
        'Azul', 'Verde', 'Rojo', 'Negro', 'Morado', 'Amarillo', 'Blanco',
        'Cafe', 'Gris', 'Naranja', 'Rosa', 'Dorado', 'Plateado'
    ]

    cities_number = int(c_i)
    color_number = int(c_o)

    # We assert tha this varibles aprove the first rule
    if cities_number < 2 or color_number < 2:
        result = 'Deben existir por lo menos dos ciudades y dos colores'
        flash('Cambia los valores')
        return result

    relationships_number = int(r_n)

    while True:
        r_max = 0
        for r in range(cities_number):
            r_max = r_max + r
        if relationships_number > r_max:
            result = 'El numero de relaciones seleccionadas supera el numero de las posibles relaciones, es decir coloca un numero menor de relaciones para continuar o incrementa el numero de ciudades.'
            flash('Cambia los valores')
            return result
        else:
            print('numero maximo de relaciones:\t', r_max)
            break

    relations_incomplete = str(t_r).split()
    relations_complete = []
    nodes = []
    nodes_4 = []

    for relation in relations_incomplete:
        relations_complete.append({})
        for node in relation:
            try:
                nodes.append(int(node))
                nodes_4.append(int(node))
                for dic in relations_complete:
                    if len(dic) < 2:
                        dic[int(node)] = 'default'
            except:
                node

    print nodes

    # mn = int(most_common(nodes)) [WIP: Find a solution in the logic]
    # if int(nodes.count(mn)) > color_number:
    #
    #     flash('Cambia los valores')
    #     result = 'Uno de los nodos posee mas relaciones que los colores posibles a elegir. Tienes que cambiar las relaciones o incrementar el numero de colores.'
    #     return result

    colors_t_ch = random.sample(colors, color_number)

    colors_1 = []
    colors_2 = []
    colors_3 = []
    colors_4 = []
    for color in colors_t_ch:
        colors_1.append(color)
        colors_2.append(color)
        colors_3.append(color)

    for i in range(color_number):

        colors_t_ch_2 = colors_1
        print colors_t_ch_2
        colors_t_ch_3 = colors_2
        print colors_t_ch_3

        # Here we select the main color and the main node
        mn = int(most_common(nodes))
        minor_n = int(less_common(nodes_4))
        print(mn, 'nodo principal')
        print(minor_n, 'nodo menor')

        if len(colors_t_ch_2) > 1:
            mc = colors_t_ch_2[1]
        elif len(colors_t_ch_2) == 1:
            mc = colors_t_ch_2[0]

        minor_c = colors_t_ch_3[0]

        print(mc, 'color principal')
        print(minor_c, 'color menor')

        # Here we assing the main color to the main node
        for dic in relations_complete:
            for node, colors in dic.items():
                if node == mn and colors == 'default':
                    dic[mn] = mc
                elif node == minor_n and colors == 'default':
                    dic[minor_n] = minor_c

        for i in range(len(nodes)):
            if mn in nodes:
                nodes.remove(mn)
        for i in range(len(nodes_4)):
            if minor_n in nodes_4:
                nodes_4.remove(minor_n)

        if len(colors_t_ch_2) >= 1:
            colors_t_ch_2.remove(mc)
        if len(colors_t_ch_3) >= 1:
            colors_t_ch_3.remove(minor_c)

        print relations_complete

    print relations_complete

    nodes_2 = []
    nodes_3 = []
    result = []

    for relation in relations_incomplete:
        for node in relation:
            try:
                nodes_2.append(int(node))
            except:
                pass

    for node in nodes_2:
        if node not in nodes_3:
            nodes_3.append(int(node))
    print nodes_3

    for relation in relations_complete:
        for node in relation:
            if node in nodes_3:
                result.append({})
                for dic in result:
                    if len(dic) < 1:
                        dic[node] = relation[node]

                if nodes_3 != 0:
                    nodes_3.remove(node)
    return result
                    coords = [
                        finger_point_pos[0][0], finger_point_pos[0][1],
                        finger_point_pos[1][0], finger_point_pos[1][1],
                        finger_point_pos[2][0], finger_point_pos[2][1],
                        finger_point_pos[3][0], finger_point_pos[3][1],
                        finger_point_pos[4][0], finger_point_pos[4][1],
                        finger_point_pos[5][0], finger_point_pos[5][1],
                        finger_point_pos[6][0], finger_point_pos[6][1],
                        finger_angle_pos[0][0], finger_angle_pos[0][1],
                        finger_angle_pos[1][0], finger_angle_pos[1][1],
                        finger_angle_pos[2][0], finger_angle_pos[2][1],
                        finger_angle_pos[3][0], finger_angle_pos[3][1]
                    ]
                    last_predict.popleft()
                    last_predict.append(data.clf.predict([coords]))
                    pred = func.most_common(last_predict)
                    font = cv2.FONT_HERSHEY_SIMPLEX
                    cv2.putText(drawing, str(pred), (10, 40), font, 1,
                                (255, 255, 255), 2, cv2.LINE_AA)
                    # print(pred)
                    if prev != pred:
                        if prev == 0 and pred == 5 and status_dino:
                            pyautogui.press('space')
                        prev = pred
                        print(pred)
                    # print(clf.predict([coords]))
                    # print(neigh.predict([coords]))
                    # print(neigh.predict_proba([coords]))
            cv2.imshow('output', drawing)

    k = cv2.waitKey(5)
Beispiel #3
0
def re_check_numbers(input_text,firstwrite,matchID,c,fV,n_iter, possession):
    all_numbers = []

    # If time is missing

    for i in range(0, n_iter):
        all_numbers.append(get_all_numbers(input_text[i]))

    if firstwrite == 0 and fV[0] == -1:
        c.execute("SELECT timeMin as mins FROM footballdata where ID = ?", [str(matchID)])
        mins = c.fetchall()
        c.execute("SELECT timeSec as secs FROM footballdata where ID = ?", [str(matchID)])
        secs = c.fetchall()

        last_time = max(mins)
        last_secs = max(secs)

        last_match = 0
        last_within_one = 0

        for i in range(0, n_iter):

            if len(all_numbers) > 0 and len(last_time) > 0:

                if all_numbers[i][0] == last_time[0]:
                    last_match += 1
                    last_within_one += 1
                elif all_numbers[i][0] - last_time[0] < 2:
                    last_within_one += 1

                if last_match > 1:
                    fV[0] = all_numbers[i][0]
                    fV[1] = min(59, last_secs + 7)
                elif last_within_one > 2:
                    fV[0] = all_numbers[i][0]
                    fV[1] = 0

    anums = []

    # if attacks/possesion is missing

    if fV[2] == -1 or fV[3] == -1 or fV[4] == -1 or fV[5] == -1 or fV[6] == -1 or fV[7] == -1:
        tot_cells = 0
        n = 0
        for i in range(0, n_iter):
            text_list = input_text[i].splitlines()

            for j in range(0, len(text_list)):
                if "Attacks" in text_list[j] or "Danger" in text_list[j]:

                    if len(text_list[j + 1]) > 10:
                        anums.append(get_all_numbers(text_list[j + 1]))
                    elif len(text_list[j + 2]) > 10:
                        anums.append(get_all_numbers(text_list[j + 2]))
                    elif len(text_list[j + 3]) > 10:
                        anums.append(get_all_numbers(text_list[j + 3]))
                    elif len(text_list[j + 4]) > 10:
                        anums.append(get_all_numbers(text_list[j + 4]))


        obs1 = []
        obs2 = []
        obs3 = []
        obs4 = []
        obs5 = []
        obs6 = []

        # print(ave_cells)

        if possession == 0:
            for i in range(0, len(anums)):
                if len(anums[i]) == 4:
                    obs1.append(anums[i][0])
                    obs2.append(anums[i][1])
                    obs3.append(anums[i][2])
                    obs4.append(anums[i][3])

            if len(obs1) > 0:
                fV[2] = most_common(obs1)
                fV[3] = most_common(obs2)
                fV[4] = most_common(obs3)
                fV[5] = most_common(obs4)

                pos1 = float(fV[2]) * 1.5
                pos2 = float(fV[3]) * 1.5
                pos3 = float(fV[4])
                pos4 = float(fV[5])

                ep1 = 100 * (pos1 + pos3) / (pos1 + pos2 + pos3 + pos4)
                ep2 = 100 - ep1

                est_pos1 = str(round(ep1))
                est_pos2 = str(round(ep2))

                fV[6] = int(est_pos1)
                fV[7] = int(est_pos2)


        else:
            for i in range(0, len(anums)):
                if len(anums[i]) == 6:
                    obs1.append(anums[i][0])
                    obs2.append(anums[i][1])
                    obs3.append(anums[i][2])
                    obs4.append(anums[i][3])
                    obs5.append(anums[i][4])
                    obs6.append(anums[i][5])

            if len(obs1) > 0:
                fV[2] = most_common(obs1)
                fV[3] = most_common(obs2)
                fV[4] = most_common(obs3)
                fV[5] = most_common(obs4)
                fV[6] = most_common(obs5)
                fV[7] = most_common(obs6)

    # if shots on target is missing

    anums = []

    obs1 = []
    obs2 = []

    if fV[8] == -1 or fV[9] == -1:
        for i in range(0, n_iter):
            text_list = input_text[i].splitlines()

            for j in range(0, len(text_list)):
                if "On T" in text_list[j] or "n Ta" in text_list[j]:

                    if len(get_all_numbers(text_list[j])) == 2:
                        anums.append(get_all_numbers(text_list[j]))
                    elif len(get_all_numbers(text_list[j])) > 2:
                        pass
                    else:
                        pass

        if len(anums) > 0:
            for i in range(0, len(anums)):
                obs1.append(anums[i][0])
                obs2.append(anums[i][1])

            fV[8] = most_common(obs1)
            fV[9] = most_common(obs2)

    # if shots off target is missing

    if fV[10] == -1 or fV[11] == -1 or fV[12] == -1 or fV[13] == -1 or fV[14] == -1 or fV[15] == -1 or fV[16] == -1 or fV[
        17] == -1:
        for i in range(0, n_iter):
            text_list = input_text[i].splitlines()

            for j in range(0, len(text_list)):
                if "Off " in text_list[j] or "f Ta" in text_list[j]:
                    pass

    # If goals are missing

    if fV[18] == -1 or fV[19] == -1:
        for i in range(0, n_iter):
            text_list = input_text[i].splitlines()


    return fV
Beispiel #4
0
    pV = [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [],
          [], []]
    fV = [
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
        -1, -1
    ]

    for t in range(0, n_iter):
        pV = import_base_data(pV, input_text, t)
        #print(input_text[t])

    ### Create final suggested vector based on the five versions ###

    if pV[0]:
        if isnumber(most_common(pV[0][:])[0:2]) and isnumber(
                most_common(pV[0][:])[3:5]):
            fV[0] = int(most_common(pV[0][:])[0:2])
            fV[1] = int(most_common(pV[0][:])[3:5])

    for i in range(1, 19):
        if len(pV[i][:]) > 1:
            if isnumber(most_common(pV[i][:])):
                fV[i + 1] = int(most_common(pV[i][:]))
            else:
                fV[i + 1] = -1

        elif len(pV[i][:]) == 1:
            if isnumber((pV[i][0])):
                fV[i + 1] = int(pV[i][0])
            else:
Beispiel #5
0
def process_the_info(c_i, c_o, r_n, t_r):
    # This program is for my school for the class of AI

    # We take all the data and assing them to a varibles
    colors = [
        'Azul', 'Verde', 'Rojo', 'Negro', 'Morado', 'Amarillo', 'Blanco',
        'Cafe', 'Gris', 'Naranja', 'Rosa', 'Dorado', 'Plateado'
    ]

    cities_number = int(c_i)
    color_number = int(c_o)

    # We assert tha this varibles aprove the first rule
    while cities_number < 2 or color_number < 2:
        print('Deben existir por lo menos dos ciudades y dos colores \n')
        cities_number = int(c_i)
        color_number = int(c_o)

    relationships_number = int(r_n)

    while True:
        r_max = 0
        for r in range(cities_number):
            r_max = r_max + r
        if relationships_number > r_max:
            print(
                '\nEl numero de relaciones seleccionadas supera el numero de las posibles relaciones, es decir coloca un numero menor de relaciones para continuar o incrementa el numero de ciudades. \n'
            )
            cities_number = int(c_i)
            relationships_number = int(c_o)
        else:
            print('numero maximo de relaciones:\t', r_max)
            break

    relations_incomplete = str(t_r).split()
    relations_complete = []
    nodes = []
    nodes_4 = []

    for relation in relations_incomplete:
        relations_complete.append({})
        for node in relation:
            try:
                nodes.append(int(node))
                nodes_4.append(int(node))
                for dic in relations_complete:
                    if len(dic) < 2:
                        dic[int(node)] = 'default'
            except:
                node
    print 'the nodes are %s' % nodes

    colors_t_ch = random.sample(colors, color_number)

    colors_1 = []
    colors_2 = []
    colors_3 = []
    colors_4 = []
    for color in colors_t_ch:
        colors_1.append(color)
        colors_2.append(color)
        colors_3.append(color)

    for i in range(color_number):

        colors_t_ch_2 = colors_1
        print colors_t_ch_2
        colors_t_ch_3 = colors_2
        print colors_t_ch_3
        colors_t_ch_4 = colors_3
        print colors_t_ch_4

        # Here we select the main color and the main node
        mn = int(most_common(nodes))
        minor_n = int(less_common(nodes))
        print(mn, 'nodo principal')
        print(minor_n, 'nodo menor')

        mc = random.choice(colors_t_ch_2)
        minor_c = random.choice(colors_t_ch_3)

        the_time = clock()
        while mc == minor_c:
            mc = random.choice(colors_t_ch_2)
            minor_c = random.choice(colors_t_ch_3)
            if (the_time + .005 < clock()):
                break

        print(mc, 'color principal')
        print(minor_c, 'color menor')

        if color_number > 2:
            second_color_a = random.choice(colors_t_ch_4)
            while second_color_a == mc:
                second_color_a = random.choice(colors_t_ch_4)
            if color_number > 3:
                second_color_b = random.choice(colors_t_ch_4)
                while second_color_b == minor_n:
                    second_color_b = random.choice(colors_t_ch_4)

            print(
                second_color_a,
                'segundo color diferente del color principal y el color menor')

        # Here we assing the main color to the main node
        for dic in relations_complete:
            if dic.has_key(mn):
                dic[mn] = mc
            elif dic.has_key(minor_n):
                dic[minor_n] = minor_c

            print(dic, 'diccionario con los valores')

            for node, colors in dic.items():
                if dic.has_key(mn) and colors == 'default':
                    if node != mn:
                        dic[node] = second_color_a
                        print 'in mn'
                elif dic.has_key(minor_n) and colors == 'default':
                    if color_number > 3:
                        if node != minor_n:
                            dic[node] = second_color_b
                            print 'in minor_nc'
                    else:
                        if node != minor_n:
                            dic[node] = mc
                            print 'in minor_nc'

        for node in nodes:
            if node == mn:
                nodes.remove(mn)
            elif node == minor_n:
                nodes.remove(minor_n)

        if len(colors_t_ch_2) >= 1:
            colors_t_ch_2.remove(mc)
        if len(colors_t_ch_3) >= 1:
            colors_t_ch_3.remove(minor_c)

    print relations_complete

    nodes_2 = []
    nodes_3 = []
    result = []

    for relation in relations_incomplete:
        for node in relation:
            try:
                nodes_2.append(int(node))
            except:
                pass

    for node in nodes_2:
        if node not in nodes_3:
            nodes_3.append(int(node))
    print nodes_3

    for relation in relations_complete:
        for node in relation:
            if node in nodes_3:
                result.append({})
                for dic in result:
                    if len(dic) < 1:
                        dic[node] = relation[node]

                if nodes_3 != 0:
                    nodes_3.remove(node)
    return result
Beispiel #6
0
            if len(dic) < 2:
                dic[node] = 'default'

colors_t_ch = random.sample(colors, color_number)

a_test = []
for color in colors_t_ch:
    a_test.append(color)

for i in range(color_number):

    colors_t_ch_2 = colors_t_ch
    colors_t_ch_3 = colors_t_ch

    # Here we select the main color and the main node
    mn = int(most_common(nodes))
    minor_n = int(less_common(nodes_4))
    print mn
    print minor_n

    mc = random.choice(colors_t_ch_2)
    minor_c = random.choice(colors_t_ch_2)

    while mc == minor_c:
            mc = random.choice(colors_t_ch_2)
            minor_c = random.choice(colors_t_ch_2)

    print mc
    print minor_c

    second_color = []