コード例 #1
0
 def _get_st_arrival_dt(self, feed_estimated_call):
     try:
         arrival_time = feed_estimated_call.find(
             "./{{{siri}}}ExpectedArrivalTime".format(siri=SIRI_NS)).text
         return str_to_utc_naive_dt(arrival_time)
     except Exception:
         return None
コード例 #2
0
 def _get_st_departure_dt(self, feed_estimated_call):
     try:
         departure_time = feed_estimated_call.find(
             "./{{{siri}}}ExpectedDepartureTime".format(siri=SIRI_NS)).text
         return str_to_utc_naive_dt(departure_time)
     except Exception:
         return None
コード例 #3
0
 def _get_origin_dt(self, feed_vj):
     try:
         origin_dt = str_to_utc_naive_dt(
             feed_vj.find("./{{{siri}}}OriginAimedDepartureTime".format(
                 siri=SIRI_NS)).text)
         return origin_dt
     except Exception:
         return None
コード例 #4
0
 def _get_input_timestamp(self, feed):
     try:
         input_timestamp = feed.find(
             "./{{{soap}}}Body/{{{siri_wsdl}}}NotifyEstimatedTimetable/ServiceDeliveryInfo/{{{siri}}}ResponseTimestamp"
             .format(soap=SOAP_NS, siri_wsdl=SIRI_WSDL_NS,
                     siri=SIRI_NS)).text
         return str_to_utc_naive_dt(input_timestamp)
     except Exception:
         return None
コード例 #5
0
def _get_first_stop_base_datetime(list_ads,
                                  hour_obj_name,
                                  skip_fully_added_stops=True):
    if skip_fully_added_stops:
        s = next((s for s in list_ads if not _is_fully_added_stop(s)), None)
    else:
        s = next((s for s in list_ads), None)

    str_time = get_value(get_value(s, hour_obj_name),
                         "dateHeure") if s else None
    return str_to_utc_naive_dt(str_time) if str_time else None
コード例 #6
0
ファイル: model_maker.py プロジェクト: woshilapin/kirin
def _get_first_stop_datetime(list_pdps,
                             hour_obj_name,
                             skip_fully_added_stops=True):
    if skip_fully_added_stops:
        p = next((p for p in list_pdps if not _is_fully_added_pdp(p)), None)
    else:
        p = next((p for p in list_pdps), None)

    str_time = get_value(get_value(p, hour_obj_name),
                         "dateHeure") if p else None
    return str_to_utc_naive_dt(str_time) if str_time else None
コード例 #7
0
    def _make_trip_update(self, json_train, vj):
        trip_update = model.TripUpdate(vj=vj,
                                       contributor_id=self.contributor.id)
        trip_update.headsign = json_train.get("numero")
        company_id = json_train.get("operateur").get("codeOperateur")
        trip_update.company_id = self._get_navitia_company_id(company_id)
        physical_mode = json_train.get("modeTransport").get("typeMode")
        trip_update.physical_mode_id = self._get_navitia_physical_mode_id(
            physical_mode)
        trip_status_type = trip_piv_status_to_effect.get(
            json_train.get("evenement").get("type"), TripEffect.UNDEFINED)
        trip_update.message = json_train.get("evenement").get("texte")
        trip_update.effect = trip_status_type.name
        if trip_status_type == TripEffect.NO_SERVICE:
            # the whole trip is deleted
            trip_update.status = ModificationType.delete.name
            trip_update.stop_time_updates = []
            return trip_update
        elif trip_status_type == TripEffect.ADDITIONAL_SERVICE:
            trip_update.status = ModificationType.add.name
        else:
            trip_update.status = ModificationType.update.name

        highest_st_status = ModificationType.none.name
        ads = get_value(get_value(json_train, "listeArretsDesserte"), "arret")

        # this variable is used to store the last stop_time's departure in order to check the stop_time consistency
        # ex. stop_time[i].arrival/departure must be greater than stop_time[i-1].departure
        previous_rt_stop_event_time = datetime.datetime.utcfromtimestamp(0)
        for arret in ads:
            # retrieve navitia's stop_point corresponding to the current PIV ad
            nav_stop, log_dict = self._get_navitia_stop_point(
                arret, vj.navitia_vj)

            if log_dict:
                record_internal_failure(log_dict["log"],
                                        contributor=self.contributor.id)
                log_dict.update({"contributor": self.contributor.id})
                logging.getLogger(__name__).info("metrology", extra=log_dict)

            if nav_stop is None:
                continue  # simply skip stop_times at unknown stop areas

            st_update = model.StopTimeUpdate(nav_stop)
            trip_update.stop_time_updates.append(st_update)

            st_update.message = _get_message(arret)
            for event_toggle in ["arrivee", "depart"]:
                event = get_value(arret, event_toggle, nullable=True)
                if event is None:
                    continue

                piv_disruption = event.get("evenement", {})
                piv_event_status = event.get("statutModification",
                                             piv_disruption.get("type", None))

                if not piv_event_status or piv_event_status in MANAGED_STOP_EVENTS:
                    piv_event_datetime = get_value(event,
                                                   "dateHeureReelle",
                                                   nullable=True)
                    event_datetime = str_to_utc_naive_dt(
                        piv_event_datetime) if piv_event_datetime else None
                    if event_datetime:
                        setattr(st_update,
                                STOP_EVENT_DATETIME_MAP[event_toggle],
                                event_datetime)

                    if piv_event_status in ["SUPPRESSION_PARTIELLE"]:
                        setattr(st_update, STATUS_MAP[event_toggle],
                                ModificationType.delete.name)
                    elif piv_event_status in ["SUPPRESSION_DETOURNEMENT"]:
                        setattr(st_update, STATUS_MAP[event_toggle],
                                ModificationType.deleted_for_detour.name)
                    elif piv_event_status in ["CREATION"]:
                        setattr(st_update, STATUS_MAP[event_toggle],
                                ModificationType.add.name)
                    elif piv_event_status in ["CREATION_DETOURNEMENT"]:
                        setattr(st_update, STATUS_MAP[event_toggle],
                                ModificationType.added_for_detour.name)
                    elif trip_status_type == TripEffect.ADDITIONAL_SERVICE:
                        # In this case we want to create schedules taking into account the delay
                        # without adding the delay a second time
                        setattr(st_update, STATUS_MAP[event_toggle],
                                ModificationType.add.name)
                    elif piv_event_status in [
                            "RETARD_OBSERVE", "RETARD_PROJETE"
                    ]:
                        setattr(st_update, STATUS_MAP[event_toggle],
                                ModificationType.update.name)
                        if piv_disruption:
                            piv_event_delay = piv_disruption.get(
                                "retard", {}).get("duree", 0)
                            setattr(st_update, DELAY_MAP[event_toggle],
                                    as_duration(piv_event_delay *
                                                60))  # minutes
                    else:
                        setattr(st_update, STATUS_MAP[event_toggle],
                                ModificationType.none.name)
                    # otherwise let those be none

                else:
                    raise InvalidArguments(
                        "invalid value {s} for field {t}/statutModification or {t}/evenement/type"
                        .format(s=piv_event_status, t=event_toggle))

                event_status = getattr(st_update, STATUS_MAP[event_toggle],
                                       ModificationType.none.name)
                highest_st_status = get_higher_status(highest_st_status,
                                                      event_status)

                mdi = (arret[STOP_EVENT_MDI_MAP[event_toggle]] if arret.get(
                    STOP_EVENT_MDI_MAP[event_toggle]) else False)
                if _is_stop_event_served(event_datetime, event_status, mdi):
                    if previous_rt_stop_event_time > event_datetime:
                        raise InvalidArguments(
                            "invalid feed: stop_point's({}) time is not consistent"
                            .format(
                                get_value(get_value(arret, "emplacement"),
                                          "code")))
                    previous_rt_stop_event_time = event_datetime

        # Calculates effect from stop_time status list (this work is also done in kraken and has to be deleted there)
        if trip_update.effect == TripEffect.MODIFIED_SERVICE.name:
            trip_update.effect = get_effect_from_modification_type(
                highest_st_status)
        return trip_update
コード例 #8
0
ファイル: model_maker.py プロジェクト: woshilapin/kirin
def _retrieve_stop_event_datetime(cots_traveler_time):
    base_schedule_datetime = get_value(cots_traveler_time,
                                       "dateHeure",
                                       nullable=True)
    return str_to_utc_naive_dt(
        base_schedule_datetime) if base_schedule_datetime else None