예제 #1
0
파일: train_ccs.py 프로젝트: uxmar/indra
def main():

    class_master_data = master_data()
    class_train_ccs = train_ccs()

    a = class_train_ccs.get_options("La Rinconada", "Agua Salud")

    for i in a:
        print ""
        for j in i["path"]:
            print j["text"]
예제 #2
0
파일: train_ccs.py 프로젝트: uxmar/indra
    def get_options(self, start, end):

        cl_mdata, l_sta_trans, l_sta_part = master_data(), [], []
        l_path = self.find_all_paths(cl_mdata.graph, start, end)
        l_path = sorted(l_path, key=len)  # Se ordena l_path por longitud
        print start, end
        print "PATHS", l_path
        print ""
        print ""

        if start in cl_mdata.direction["21"].keys():
            d_del = {}
            if end == "Silencio" or end in cl_mdata.direction["4"].keys():
                [d_del.update({len(path): l_path.index(path)}) for path in l_path]
                l_path.pop(d_del[max(d_del.keys())])

        # ~ l_path.pop(1)

        for path in l_path:
            qty_trans, d_sta_trans, l_trans = 0, {}, []
            l_path_end, l_sta_part = [], []
            d_connec = deepcopy(cl_mdata.connec)

            if cl_mdata.line[path[0]] in ["21", "20"]:
                line = "2"
            else:
                line = cl_mdata.line[path[0]]

            l_path_end.append({"text": "Aborde la estacion " + path[0] + " de la Linea " + line, "stations": []})

            for i, j in zip(path, path[1::]):
                l_sta_part.append(i)
                d_connec = self.line_2(i, cl_mdata, path, d_connec)
                l_trans, qty_trans = self.get_trans(path, cl_mdata, d_connec)

                if (i, j) in l_trans and len(l_sta_part) > 0:

                    direction = self.get_direction(l_sta_part, cl_mdata)
                    # ~ print 'DIRECTION', direction

                    if cl_mdata.line[j] in ["21", "20"]:
                        line = "2"
                    else:
                        line = cl_mdata.line[j]

                    if start == i:
                        if cl_mdata.connec3[1] in ",".join(path):
                            l_path_end.append(
                                {
                                    "text": "Realice Transferencia de la estacion "
                                    + i
                                    + " a la Linea "
                                    + cl_mdata.line[path[path.index(j) + 1]],
                                    "stations": [],
                                }
                            )
                        else:
                            l_path_end.append(
                                {
                                    "text": "Realice Transferencia de la estacion "
                                    + i
                                    + " a la Linea "
                                    + line
                                    + " hasta la estacion "
                                    + j,
                                    "stations": [],
                                }
                            )
                    elif d_connec[i][j] == 1:
                        direction and l_path_end.append(
                            {"text": "IIngrese al tren con direccion " + direction, "stations": []}
                        )
                        l_path_end.append(
                            {
                                "text": "Contiiinue "
                                + str(len(l_sta_part))
                                + " estaciones en esta linea hasta la estacion "
                                + l_sta_part[-1]
                                + " ->",
                                "stations": l_sta_part,
                            }
                        )
                        l_path_end.append(
                            {
                                "text": "Realice Transferencia de tren en la estacion "
                                + l_sta_part[len(l_sta_part) - 1],
                                "stations": [],
                            }
                        )
                    elif d_connec[i][j] == 2 and cl_mdata.connec3[1] in ",".join(path):
                        direction and l_path_end.append(
                            {"text": "Ingre al tren con direccion " + direction, "stations": []}
                        )
                        l_path_end.append(
                            {
                                "text": "Continueee "
                                + str(len(l_sta_part))
                                + " estaciones en esta linea hasta la estacion "
                                + i
                                + " ->",
                                "stations": l_sta_part,
                            }
                        )
                        l_path_end.append(
                            {
                                "text": "RRealicee Transferencia en la estacion "
                                + i
                                + " a la Linea "
                                + cl_mdata.line[path[path.index(j) + 1]],
                                "stations": [],
                            }
                        )
                    elif d_connec[i][j] in [2, 3]:
                        direction and l_path_end.append(
                            {"text": "Ingressse al tren con direccion " + direction, "stations": []}
                        )
                        l_path_end.append(
                            {
                                "text": "Continueee "
                                + str(len(l_sta_part))
                                + " estaciones en esta linea hasta la estacion "
                                + i
                                + " ->",
                                "stations": l_sta_part,
                            }
                        )
                        l_path_end.append(
                            {
                                "text": "Realicee Transferencia en la estacion "
                                + i
                                + " a la Linea "
                                + line
                                + " hasta la estacion "
                                + j,
                                "stations": [],
                            }
                        )
                    elif d_connec[i][j] == 4:
                        direction and l_path_end.append(
                            {"text": "Ingrese al tren con direccion " + direction, "stations": []}
                        )
                        l_path_end.append(
                            {
                                "text": "Continueee "
                                + str(len(l_sta_part))
                                + " estaciones en esta linea hasta la estacion "
                                + i
                                + " ->",
                                "stations": l_sta_part,
                            }
                        )
                        l_path_end.append(
                            {
                                "text": "RRealicee Transferencia en la estacion " + i + " a la Linea " + line,
                                "stations": [],
                            }
                        )
                    elif d_connec[i][j] == 5:
                        direction and l_path_end.append(
                            {"text": "Ingrese al tren con direccion " + direction, "stations": []}
                        )
                        l_path_end.append(
                            {
                                "text": "Continueee "
                                + str(len(l_sta_part) + 1)
                                + " estaciones en esta linea hasta la estacion "
                                + j
                                + " ->",
                                "stations": l_sta_part,
                            }
                        )
                        if cl_mdata.connec3[2] in ",".join(path):
                            l_path_end.append(
                                {
                                    "text": "Realicee Transferencia en la estacion "
                                    + j
                                    + " a la Linea "
                                    + cl_mdata.line[path[path.index(j) + 1]],
                                    "stations": [],
                                }
                            )
                        else:
                            l_path_end.append(
                                {
                                    "text": "Realicee Transferencia en la estacion " + j + " a la Linea " + line,
                                    "stations": [],
                                }
                            )
                    elif d_connec[i][j] == 6:
                        direction and l_path_end.append(
                            {"text": "Ingrese al tren con direccion " + direction, "stations": []}
                        )
                        l_path_end.append(
                            {
                                "text": "Continueee "
                                + str(len(l_sta_part) + 1)
                                + " estaciones en esta linea hasta la estacion "
                                + j
                                + " ->",
                                "stations": l_sta_part,
                            }
                        )
                        l_path_end.append({"text": "Realice Transferencia de tren en la estacion " + j, "stations": []})
                    l_sta_part = []
                # ~ if j==end or (l_sta_part and l_sta_part[-1] ==end):
                # ~ l_sta_part=[]

            # ~ print 'I %s J %s' % (i,j)
            [l_sta_part.append(i) for i, j in zip(path, path[1::]) if qty_trans == 0]

            if not any(j in s for s in l_sta_part):
                l_sta_part.append(j)

            if (
                (d_connec.get(i) and d_connec[i].get(j))
                and d_connec[i][j] == 3
                or ((l_trans and l_trans[-1][1] == end) and d_connec[i][j] != 4 and d_connec[i][j] != 1)
            ):
                # 3: Para el caso en que luego de la transferencia no hay que rodar una estacion mas
                # para Llegar.Con solo hacer la transferencia ya se llego al destino.
                # Si es de tipo 1 o 4 no debe entrar aqui porque necesito que continue las
                # estaciones que hace falta. TEST 44.
                pass
            else:
                if len(l_sta_part) > 1:
                    sta1 = l_sta_part[0]
                    sta2 = l_sta_part[1]
                    if (d_connec.get(sta1) and d_connec[sta1].get(sta2)) == 4 and (
                        cl_mdata.connec3[1] in ",".join(path)
                    ):
                        l_sta_part.pop(0)
                        # Para el caso en que la transferencia es la 4 me sobra
                        # la estacion Plaza Venezuela, me da una estacion de mas.
                if len(l_sta_part) >= 1:

                    direction = self.get_direction(l_sta_part, cl_mdata)
                    # ~ print 'direction', direction
                    direction and l_path_end.append(
                        {"text": "Innnngrese al tren con direccion " + direction, "stations": []}
                    )
                    l_path_end.append(
                        {
                            "text": "CContinue "
                            + str(len(l_sta_part))
                            + " estaciones en esta linea hasta la estacion "
                            + j
                            + " ->",
                            "stations": l_sta_part,
                        }
                    )

            l_path_end.append({"text": "Usted ha llegado a su destino", "stations": []})
            d_sta_trans.update({"stations": len(path)})
            d_sta_trans.update({"transfers": qty_trans})
            d_sta_trans.update({"path": l_path_end})
            l_sta_trans.append(d_sta_trans)
        return l_sta_trans