Beispiel #1
0
    def parse_line(self, idx, line):
        is_2013 = False
        m = LINE_RE_2013.match(line)
        if m:
            is_2013 = True
        else:
            m = LINE_RE_2014.match(line)
        if m:
            gd = m.groupdict()
            stop_id = int(gd['raw_stop_id'])
            is_real = stops_utils.is_real(stop_id)

            sl = StopLine()
            if is_2013:
                date_str = gd['date']
                train_num = gd['train_num']
            else:
                date_str = gd['date_train_num'][0:8]
                train_num = gd['date_train_num'][8:]
            sl.date = self._parse_date(date_str)
            sl.train_num = train_num
            sl.stop_id = stop_id
            sl.stop_name = stops_utils.get_stop_name(sl.stop_id)
            sl.line = idx + 1  # make it base 1 now, like file editors
            sl.is_real = is_real
            sl.build_times(gd)

            self.stop_lines.append(sl)
        else:
            raise Exception('Illegal line %d at %s' % (idx, self.ifile))
Beispiel #2
0
    def parse_line(self, idx, line):
        is_2013 = False
        m = LINE_RE_2013.match(line)
        if m:
            is_2013 = True
        else:
            m = LINE_RE_2014.match(line)
        if m:
            gd = m.groupdict()
            stop_id = int(gd['raw_stop_id'])
            is_real = stops_utils.is_real(stop_id)

            sl = StopLine()
            if is_2013:
                date_str = gd['date']
                train_num = gd['train_num']
            else:
                date_str = gd['date_train_num'][0:8]
                train_num = gd['date_train_num'][8:]
            sl.date = self._parse_date(date_str)
            sl.train_num = train_num
            sl.stop_id = stop_id
            sl.stop_name = stops_utils.get_stop_name(sl.stop_id)
            sl.line = idx + 1  # make it base 1 now, like file editors
            sl.is_real = is_real
            sl.build_times(gd)

            self.stop_lines.append(sl)
        else:
            raise Exception('Illegal line %d at %s' % (idx, self.ifile))
Beispiel #3
0
    def get_csv_row(self, idx, parser, stop):
        result = {'train_num': self.train_num,
                  'start_date': self.get_start_date().isoformat(),
                  'index': idx,
                  'valid': 1 if self.is_valid else 0,
                  'is_first': 1 if idx == 0 else 0,
                  'is_last': 1 if 1 + idx == len(self.stops) else 0,
                  'stop_id': stop.stop_id,
                  'stop_name': stops_utils.get_stop_name(stop.stop_id),
                  'is_real_stop': 1 if stops_utils.is_real(stop.stop_id) else 0,
                  'data_file': os.path.basename(parser.ifile),
                  'data_file_line': stop.line,
        }
        result['data_file_link'] = 'http://localhost:8000/raw-data/?file={0}&line={1}'.format(result['data_file'],
                                                                                              result['data_file_line'])
        result['trip_id'] = '%s_%s' % (result['train_num'],self.get_start_date().strftime('%Y%m%d'))
        attrs = ['actual_arrival', 'exp_arrival', 'actual_departure', 'exp_departure']
        for attr in attrs:
            val = getattr(stop, attr)
            result[attr] = val.isoformat() if val else ''
        da = stop.get_delay_arrival()
        dd = stop.get_delay_departure()
        result['delay_arrival'] = da if da is not None else ''
        result['delay_departure'] = dd if dd is not None else ''

        return result
Beispiel #4
0
    def get_csv_row(self, idx, parser, stop):
        result = {
            'train_num': self.train_num,
            'start_date': self.get_start_date().isoformat(),
            'index': idx,
            'valid': 1 if self.is_valid else 0,
            'is_first': 1 if idx == 0 else 0,
            'is_last': 1 if 1 + idx == len(self.stops) else 0,
            'stop_id': stop.stop_id,
            'stop_name': stops_utils.get_stop_name(stop.stop_id),
            'is_real_stop': 1 if stops_utils.is_real(stop.stop_id) else 0,
            'data_file': os.path.basename(parser.ifile),
            'data_file_line': stop.line,
        }
        result[
            'data_file_link'] = 'http://localhost:8000/raw-data/?file={0}&line={1}'.format(
                result['data_file'], result['data_file_line'])
        result['trip_name'] = '%s_%s' % (
            result['train_num'], self.get_start_date().strftime('%Y%m%d'))
        attrs = [
            'actual_arrival', 'exp_arrival', 'actual_departure',
            'exp_departure'
        ]
        for attr in attrs:
            val = getattr(stop, attr)
            result[attr] = val.isoformat() if val else ''
        da = stop.get_delay_arrival()
        dd = stop.get_delay_departure()
        result['delay_arrival'] = da if da is not None else ''
        result['delay_departure'] = dd if dd is not None else ''

        return result