Ejemplo n.º 1
0
 def _get_journeys(self, sections: List[SectionStr]):
     connection: Connection = self._db.open()
     db_sections: DBSection = connection.root().sections
     journeys: DBJourney = connection.root().journeys
     times: DBTime = connection.root().times
     complex_string: List[str] = construct_complex_xpath('StopEvent', False, False, 'line_trias_id', 'journey_ref',
                                                         'timetable_times', 'estimated_times', **self._kwargs)
     complex_dict: List[Dict[str, str]] = complex_xpath_to_dict_list(complex_string, 'line_trias_id',
                                                                     'journey_ref', 'timetable_times',
                                                                     'estimated_times', **self._kwargs)
     for i in complex_dict:
         line: [LineStr, None] = None
         for j in self._lines:
             if i['line_trias_id'] == j:
                 line = j
                 break
         if line:
             section_trias_id: SectionStr = SectionStr('')
             for j in sections:
                 if j.split('=|=')[0] == str(self._stop):
                     section_trias_id = j
             if section_trias_id != '':
                 journey: JourneyStr = JourneyStr(i['journey_ref'])
                 time: TimeStr = TimeStr(times.calculate_id(section_trias_id, journey))
                 if i['estimated_times'] and time not in times.keys():
                     if journey not in journeys.keys():
                         journeys[journey] = Journey(line, journey)
                         self._journeys.append(journey)
                     timetable_time: ISOTimeStr = ISOTimeStr(i['timetable_times'])
                     estimate_time: ISOTimeStr = ISOTimeStr(i['estimated_times'])
                     times[time] = Time(self._stop, journey, estimate_time, timetable_time, section_trias_id)
Ejemplo n.º 2
0
 def _get_lines(self):
     connection: Connection = self._db.open()
     complex_string: List[str] = construct_complex_xpath('StopEvent', False, False, 'line_trias_id', 'line_number',
                                                         'line_string', 'line_start', 'line_start_name', 'line_end',
                                                         'line_end_name', **self._kwargs)
     # TODO use complex_string_to_dict
     lines: DBLine = connection.root().lines
     stops: DBStopWithoutLine = connection.root().stops_without_line
     self._lines: List[LineStr] = []
     for i in complex_string:
         list: List[str] = i.split(' # ')
         trias_id: LineStr = LineStr(list[0])
         if trias_id not in lines.keys():
             number: int = int(list[1])
             string: str = list[2]
             line: Line = Line(number, string, trias_id)
             # TODO doesn't work
             lines[trias_id] = line
         if lines[trias_id].get_len_stops() < 2:
             lines[trias_id].delete_stops()
             start_stop: StopWithoutLineStr = StopWithoutLineStr(list[3])
             lines[trias_id].add_stop(start_stop)
             if start_stop not in stops.keys():
                 stops[start_stop] = StopWithoutLine(start_stop, list[4])
             end_stop: StopWithoutLineStr = StopWithoutLineStr(list[5])
             lines[trias_id].add_stop(end_stop)
             if end_stop not in stops.keys():
                 stops[end_stop] = StopWithoutLine(end_stop, list[6])
         self._lines.append(trias_id)
     connection.close()
Ejemplo n.º 3
0
 def _get_stops(self):
     is_lineref = True if self._predefined_line_trias_id else False
     complex_string: List[str] = construct_complex_xpath(
         'Trip', is_lineref, True, 'stops', 'stop_names', **self._kwargs)
     complex_dict: List[Dict[str, str]] = complex_xpath_to_dict_list(
         complex_string, 'stops', 'stop_names', **self._kwargs)
     self._stops: List[StopStr] = []
     self._stop_names: List[str] = []
     for i in complex_dict:
         self._stops.append(StopStr(i['stops']))
         self._stop_names.append(i['stop_names'])
Ejemplo n.º 4
0
 def _get_stop(self):
     connection: Connection = self._db.open()
     stops: DBStopWithoutLine = connection.root().stops_without_line
     complex_string: List[str] = construct_complex_xpath('StopEvent', False, False, 'stops', 'stop_names',
                                                         **self._kwargs)
     if len(complex_string) >= 1:
         separate = complex_string[0].split(' # ')
         trias_id: StopWithoutLineStr = StopWithoutLineStr(separate[0])
         name: str = separate[1]
         if trias_id not in stops.keys():
             stops[trias_id] = StopWithoutLine(trias_id, name)
         self._stop: StopWithoutLineStr = stops[trias_id]
     connection.close()
Ejemplo n.º 5
0
 def _get_cords(self):
     is_lineref = True if self._predefined_line_trias_id else False
     complex_string: List[str] = construct_complex_xpath(
         'Trip', is_lineref, True, 'lats', 'lons', **self._kwargs)
     complex_dict: List[Dict[str, str]] = complex_xpath_to_dict_list(
         complex_string, 'lats', 'lons', **self._kwargs)
     self._locations: List[Location] = []
     for i in complex_dict:
         self._locations.append({
             'latitude': float(i['lats']),
             'longitude': float(i['lons'])
         })
     for i in range(len(self._locations) - 1, 1, -1):
         if self._locations.count(self._locations[i]) > 1:
             self._locations.pop(i)
Ejemplo n.º 6
0
 def _get_line(self):
     is_lineref = True if self._predefined_line_trias_id else False
     complex_string: List[str] = construct_complex_xpath(
         'Trip', is_lineref, True, 'line_number', 'line_string',
         'line_trias_id', **self._kwargs)
     complex_dict: List[Dict[str, str]] = complex_xpath_to_dict_list(
         complex_string, 'line_number', 'line_string', 'line_trias_id',
         **self._kwargs)
     if len(complex_dict) >= 1:
         line_details: Dict[str, str] = complex_dict[0]
         line_number: int = int(line_details['line_number'])
         line_name: str = line_details['line_string']
         self._line: LineStr = LineStr(line_details['line_trias_id'])
     else:
         logger.warning('Empty TripResponse')
         return
     connection: Connection = self._db.open()
     lines: DBLine = connection.root.lines
     if self._line not in lines.keys():
         lines[self._line] = Line(line_number, line_name, self._line)
     commit()
     connection.close()