def get_all_active_stations(self):
     """
     Gets all stations whose status is "normal"
     :return: list of SubwayStation nodes
     """
     with neo4j_driver.session() as s:
         transact = s.write_transaction(self._get_all_active_stations)
     return transact
 def get_distinct_lines(self):
     """
     Gets all of the unique lines in the graph
     :return:
     """
     with neo4j_driver.session() as s:
         transact = s.write_transaction(self._get_distinct_lines)
     return transact
 def all_stations(self) -> List[Node]:
     """
     Gets all of the SubwayStation nodes in the graph
     :return: the list of SubwayStation nodes
     """
     with neo4j_driver.session() as s:
         transact = s.write_transaction(self._all_stations)
     return transact
 def get_stations_by_line(self, line: str) -> List[Node]:
     """
     Gets all of the stations that have the given line in their list of lines
     :param line: the line
     :return: List of Node and Relationship objects
     """
     with neo4j_driver.session() as s:
         transact = s.write_transaction(self._get_stations_by_line, line)
     return transact
 def create_station(self, station: SubwayStation) -> Node:
     """
     Creates a station node in the graph based on 'station'
     :param station: SubwayStation object
     :return: the Node that was created
     """
     with neo4j_driver.session() as s:
         transact = s.write_transaction(self._create_station, station)
     return transact
 def clear_db():
     """
     Clears the graph
     :return:
     """
     with neo4j_driver.session() as s:
         s.run('''
             MATCH (n) DETACH DELETE n
         ''')
 def all_connections(self, station: SubwayStation):
     """
     Gets all connections to and from the given SubwayStation
     :param station: SubwayStation object
     :return: List of starting nodes, ending nodes, lines, and reroutes
     """
     with neo4j_driver.session() as s:
         transact = s.write_transaction(self._all_connections, station)
     return transact
 def remove_reroute(self, reroute: SubwayStation):
     """
     Removes all REROUTES relationships for the given SubwayStation. Sets that station's status to "normal"
     :param reroute:
     :return:
     """
     with neo4j_driver.session() as s:
         transact = s.write_transaction(self._remove_reroute, reroute)
     return transact
 def get_reroutes(self, reroute: str):
     """
     Returns all REROUTES relationships for the given node
     :param reroute: the reroute key for the SubwayStation
     :return: the starting nodes, ending nodes, and relationship for all of the relevant REROUTES
     """
     with neo4j_driver.session() as s:
         transact = s.write_transaction(self._get_reroutes, reroute)
     return transact
示例#10
0
 def detach_node(self, station):
     """
     Removes all connections to the given SubwayStation
     :param station: SubwayStation Object
     :return: None
     """
     with neo4j_driver.session() as s:
         transact = s.write_transaction(self._detach_node, station)
     return transact
示例#11
0
 def shortest_path(self, start_station: SubwayStation,
                   stop_station: SubwayStation):
     """
     Gets the shortest, unweighted paths between two nodes.
     :param start_station:
     :param stop_station:
     :return: a list of the shortest paths
     """
     with neo4j_driver.session() as s:
         transact = s.write_transaction(self._shortest_path, start_station,
                                        stop_station)
     return transact
示例#12
0
 def get_connections_between_stations(self, station_1,
                                      station_2) -> List[Relationship]:
     """
     Gets all of the connections between two SubwayStation nodes
     :param station_1: the first SubwayStation object
     :param station_2: the second subwayStation object
     :return: a list of Relationships corresponding to the given nodes
     """
     with neo4j_driver.session() as s:
         transact = s.write_transaction(
             self._get_connections_between_stations, station_1, station_2)
     return transact
示例#13
0
    def create_connection(
            self, train_line: TrainLine) -> List[Node, Node, Relationship]:
        """
        Create a connection between two stations for a given line
        :param train_line: TrainLine object
        :return: list containing the two Nodes and the Relationship that was created
        """
        if train_line is None:
            return None
        with neo4j_driver.session() as s:
            transact = s.write_transaction(self._create_connection, train_line)

        return transact
示例#14
0
 def get_station_by_name_and_entrance(self, station_name: str,
                                      entrance: str) -> List[Node]:
     """
     Gets a station by its station_name and entrances values. This combination of values is a unique
     identifier in the graph database
     :param station_name: the station name
     :param entrance: the entrance
     :return:
     """
     with neo4j_driver.session() as s:
         transact = s.write_transaction(
             self._get_station_by_name_and_entrance, station_name, entrance)
     return transact
示例#15
0
 def stations_with_line_without_relationship(line):
     """
     For debugging-Gets all stations that have a line in their lines property but don't have a connection for that line
     :param line: the line
     :return:
     """
     with neo4j_driver.session() as s:
         result = s.run('''
             MATCH (s:SubwayStation)-[r]-()
             WHERE r.line IN s.lines
             RETURN s
             ''',
                        line=line)
         return [x for x in result]
示例#16
0
 def create_reroute(self, train_line, reroute):
     """
     Creates a REROUTES relationships between two SubwayStations. REROUTES keep track of the stations that are
     being rerouted to ensure that the graph can be properly reconstructed.
     :param train_line:
     :param reroute:
     :return:
     """
     if train_line is None:
         return None
     with neo4j_driver.session() as s:
         transact = s.write_transaction(self._create_reroute, train_line,
                                        reroute)
     return transact