Skip to content

Commit

Permalink
Merge branch 'dev' into opg_cached
Browse files Browse the repository at this point in the history
  • Loading branch information
azime authored Jan 15, 2024
2 parents 57395e3 + aa1d08e commit a6bb1f6
Show file tree
Hide file tree
Showing 45 changed files with 641 additions and 138 deletions.
3 changes: 2 additions & 1 deletion docker/debian8/Dockerfile-eitri
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ COPY source/ /navitia/source/
RUN dpkg -i ./navitia-ed_*.deb || exit 0
RUN apt-get install -f -y --force-yes

RUN rm navitia-ed_*.deb

# install eitri requirements
RUN pip install --no-cache-dir -r /navitia/source/eitri/requirements.txt

6 changes: 4 additions & 2 deletions docker/debian8/Dockerfile-kraken
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ FROM navitia/master
COPY navitia-kraken_*.deb navitia-monitor-kraken_*.deb ./

# install navitia-kraken package
RUN dpkg -i ./navitia-kraken_*.deb
RUN dpkg -i ./navitia-monitor-kraken_*.deb
RUN dpkg -i ./navitia-kraken_*.deb ./navitia-monitor-kraken_*.deb
RUN apt-get install -f -y --force-yes

RUN rm navitia-kraken_*.deb \
navitia-monitor-kraken_*.deb

# put the binary in /srv/kraken
RUN mkdir -p /srv/kraken
RUN cp /usr/bin/kraken /srv/kraken/kraken
Expand Down
2 changes: 2 additions & 0 deletions docker/debian8/Dockerfile-mock-kraken
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ COPY mock-kraken_*.deb ./
RUN dpkg -i ./mock-kraken_*.deb
RUN apt-get install -f -y --force-yes

RUN rm mock-kraken_*.deb

RUN mkdir -p /srv/kraken
RUN cp /usr/bin/main_routing_test /srv/kraken/
RUN cp /usr/bin/departure_board_test /srv/kraken/
Expand Down
8 changes: 5 additions & 3 deletions docker/debian8/Dockerfile-tyr-beat
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
FROM navitia/master

COPY navitia-common_*.deb ./
COPY navitia-tyr_*.deb ./
COPY navitia-common_*.deb navitia-tyr_*.deb ./

RUN apt-get update \
&& apt install -y --force-yes jq
Expand All @@ -14,12 +13,15 @@ COPY docker/templates/* /templates/

# install navitia-common package
RUN dpkg -i ./navitia-common_*.deb || exit 0
RUN apt-get install -f -y --force-yes

# install navitia-tyr package
RUN dpkg -i ./navitia-tyr_*.deb || exit 0

RUN apt-get install -f -y --force-yes

RUN rm navitia-common_*.deb \
navitia-tyr_*.deb

# install ed migrations requirements
RUN pip install -r /tmp/requirements.txt

Expand Down
8 changes: 5 additions & 3 deletions docker/debian8/Dockerfile-tyr-web
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
FROM navitia/master

COPY navitia-common_*.deb ./
COPY navitia-tyr_*.deb ./
COPY navitia-common_*.deb navitia-tyr_*.deb ./

# install navitia-common package
RUN dpkg -i ./navitia-common_*.deb || exit 0
RUN apt-get install -f -y --force-yes

# install navitia-tyr package
RUN dpkg -i ./navitia-tyr_*.deb || exit 0

RUN apt-get install -f -y --force-yes

RUN rm navitia-common_*.deb \
navitia-tyr_*.deb

# install postgresql-client
RUN apt-get install -y --force-yes postgresql-client

Expand Down
35 changes: 15 additions & 20 deletions docker/debian8/Dockerfile-tyr-worker
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,39 @@ RUN git clone -b ${TARTARE_TOOLS_VERSION} --depth 1 https://x-access-token:${GIT
RUN cd tartare-tools \
&& cargo build --release -p enrich-ntfs-with-addresses \
&& cp target/release/enrich-ntfs-with-addresses /usr/bin/ \
&& rm -rf tartare-tools \
&& cd ..
&& cd .. \
&& rm -rf tartare-tools

COPY navitia-common_*deb ./
COPY navitia-tyr_*.deb ./
COPY navitia-ed_*.deb ./
COPY navitia-cities_*.deb ./
COPY mimirsbrunn7_*.deb ./
COPY cosmogony2cities_*.deb ./
COPY mimirsbrunn-config-*.deb ./
COPY navitia-common_*deb navitia-tyr_*.deb navitia-ed_*.deb navitia-cities_*.deb mimirsbrunn7_jessie-*.deb cosmogony2cities_*.deb mimirsbrunn-config-*.deb ./

# install navitia-common package
RUN dpkg -i ./navitia-common_*.deb || exit 0
RUN apt-get install -f -y --force-yes

# install navitia-tyr package
RUN dpkg -i ./navitia-tyr_*.deb || exit 0
RUN apt-get install -f -y --force-yes

# install navitia-ed package
RUN dpkg -i ./navitia-ed_*.deb || exit 0
RUN apt-get install -f -y --force-yes

# install navitia-cities package
RUN dpkg -i ./navitia-cities_*.deb || exit 0
RUN apt-get install -f -y --force-yes

# install navitia-mimirsbrunn package
RUN dpkg -i ./mimirsbrunn7_jessie-*.deb
RUN apt-get install -f -y --force-yes
RUN dpkg -i ./mimirsbrunn7_jessie-*.deb \
# install cosmogony2cities package
./cosmogony2cities*.deb \
# install conf mimir package
./mimirsbrunn-config-*.deb

# install cosmogony2cities package
RUN dpkg -i ./cosmogony2cities*.deb
RUN apt-get install -f -y --force-yes

# install conf mimir package
RUN dpkg -i ./mimirsbrunn-config-*.deb
RUN apt-get install -f -y --force-yes
RUN rm navitia-common_*deb \
navitia-tyr_*.deb \
navitia-cities_*.deb \
navitia-ed_*.deb \
mimirsbrunn-config-*.deb \
mimirsbrunn7_jessie-*.deb \
cosmogony2cities_*.deb

# install tyr requirements
RUN pip install --no-cache-dir -r /usr/share/tyr/requirements.txt
Expand Down
2 changes: 1 addition & 1 deletion source/chaos-proto
Submodule chaos-proto updated 1 files
+21 −39 chaos.proto
13 changes: 11 additions & 2 deletions source/ed/build_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,16 +544,25 @@ Impacter& Impacter::msg(dis::Message m) {
return *this;
}

Impacter& Impacter::msg(const std::string& text, nt::disruption::ChannelType c) {
Impacter& Impacter::msg(const std::string& text,
nt::disruption::ChannelType c,
const std::string& translated_text,
const std::string& language) {
dis::Message m;
auto str = to_string(c);
m.text = text;
m.channel_id = str;
m.channel_id = str;
m.channel_name = str + " channel";
m.channel_content_type = "content type";
m.created_at = boost::posix_time::ptime(b.data->meta->production_date.begin(), boost::posix_time::minutes(0));

if (!translated_text.empty()) {
dis::Translation t;
t.text = translated_text;
t.language = language;
m.translations.push_back(std::move(t));
}

m.channel_types.insert(c);
return msg(std::move(m));
}
Expand Down
5 changes: 4 additions & 1 deletion source/ed/build_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,10 @@ struct Impacter {
const std::vector<std::string>& route_uris,
nt::PT_Data& pt_data);
Impacter& msg(nt::disruption::Message);
Impacter& msg(const std::string& text, nt::disruption::ChannelType = nt::disruption::ChannelType::email);
Impacter& msg(const std::string& text,
nt::disruption::ChannelType = nt::disruption::ChannelType::email,
const std::string& translated_text = "",
const std::string& language = "");
Impacter& publish(const boost::posix_time::time_period& p);
};

Expand Down
16 changes: 14 additions & 2 deletions source/fare/fare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,20 @@ results Fare::compute_fare(const pbnavitia::PtFaresRequest::PtJourney& pt_journe
for (const auto& s : pt_journey.pt_sections()) {
const auto& first_sp_uri = s.first_stop_point_uri();
const auto& last_sp_uri = s.last_stop_point_uri();
const auto* first_stop_point = data.pt_data->stop_points_map.find(first_sp_uri)->second;
const auto* last_stop_point = data.pt_data->stop_points_map.find(last_sp_uri)->second;

const auto first_it = data.pt_data->stop_points_map.find(first_sp_uri);
if (first_it == data.pt_data->stop_points_map.cend()) {
LOG4CPLUS_ERROR(logger, "stop point uri cannot be found %s" << first_sp_uri);
return {};
}
const auto last_it = data.pt_data->stop_points_map.find(last_sp_uri);
if (last_it == data.pt_data->stop_points_map.cend()) {
LOG4CPLUS_ERROR(logger, "stop point uri cannot be found %s" << last_sp_uri);
return {};
}

const auto* first_stop_point = first_it->second;
const auto* last_stop_point = last_it->second;
SectionKey section_key{s, *first_stop_point, *last_stop_point};

labels = compute_labels(nb_nodes, labels, section_key);
Expand Down
5 changes: 4 additions & 1 deletion source/fare/fare_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ namespace fare {

void fill_fares(PbCreator& pb_creator, const pbnavitia::PtFaresRequest& fares) {
for (const pbnavitia::PtFaresRequest::PtJourney& pt_journey : fares.pt_journeys()) {
auto tickets = pb_creator.data->fare->compute_fare(pt_journey, *pb_creator.data);
if (tickets.not_found) {
continue;
}
pbnavitia::PtJourneyFare* pb_journey_fare = pb_creator.add_pt_journey_fares();
pb_journey_fare->set_journey_id(pt_journey.id());

auto tickets = pb_creator.data->fare->compute_fare(pt_journey, *pb_creator.data);
pb_creator.fill_fare(pb_journey_fare->mutable_fare(), nullptr, tickets);
}
}
Expand Down
93 changes: 93 additions & 0 deletions source/fare/tests/fare_integration_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,96 @@ BOOST_AUTO_TEST_CASE(test_fare_api) {
BOOST_CHECK_EQUAL(ticket[pb_fare.ticket_id(1)].cost().currency(), "euro");
BOOST_CHECK_EQUAL(ticket[pb_fare.ticket_id(1)].section_id(0), "section_3");
}

BOOST_AUTO_TEST_CASE(test_fare_api_with_invalid_stop_point) {
ed::builder b("20120614");
b.vj_with_network("RATP", "A", "11111111", "", true, "")("stop1", 8000, 8050)("stop2", 8100, 8150)("stop3", 8200,
8250);
b.vj_with_network("RATP", "B", "11111111", "", true, "")("stop4", 8000, 8050)("stop2", 8300, 8350)("stop5", 8400,
8450);
b.connection("stop1", "stop1", 120);
b.connection("stop2", "stop2", 120);
b.connection("stop3", "stop3", 120);
b.connection("stop4", "stop4", 120);
b.connection("stop5", "stop5", 120);
b.make();
b.data->compute_labels();
b.data->meta->production_date =
boost::gregorian::date_period(boost::gregorian::date(2012, 06, 14), boost::gregorian::days(7));

RAPTOR raptor(*b.data);

// fare data initialization
boost::gregorian::date start_date(boost::gregorian::from_undelimited_string("20110101"));
boost::gregorian::date end_date(boost::gregorian::from_undelimited_string("20350101"));
b.data->fare->fare_map["price1"].add(start_date, end_date, fare::Ticket("price1", "Ticket vj 1", 100, "125"));
b.data->fare->fare_map["price2"].add(start_date, end_date, fare::Ticket("price2", "Ticket vj 2", 200, "175"));

// dummy transition
fare::Transition transitionA;
fare::State endA;
endA.line = "A";
transitionA.ticket_key = "price1";
auto endA_v = boost::add_vertex(endA, b.data->fare->g);
boost::add_edge(b.data->fare->begin_v, endA_v, transitionA, b.data->fare->g);

fare::Transition transitionB;
fare::State endB;
endB.line = "B";
transitionB.ticket_key = "price2";
auto endB_v = boost::add_vertex(endB, b.data->fare->g);
boost::add_edge(b.data->fare->begin_v, endB_v, transitionB, b.data->fare->g);

// call to raptor
type::EntryPoint origin(type::Type_e::StopArea, "stop1");
type::EntryPoint destination(type::Type_e::StopArea, "stop5");

georef::StreetNetwork sn_worker(*b.data->geo_ref);
const auto* data_ptr = b.data.get();
navitia::PbCreator pb_creator(data_ptr, boost::gregorian::not_a_date_time, null_time_period);
make_response(pb_creator, raptor, origin, destination, {test::to_posix_timestamp("20120614T080000")}, true,
type::AccessibiliteParams(), {}, {}, sn_worker, type::RTLevel::Base, 2_min);
pbnavitia::Response resp = pb_creator.get_response();
BOOST_REQUIRE_EQUAL(resp.response_type(), pbnavitia::ITINERARY_FOUND);
BOOST_REQUIRE_EQUAL(resp.journeys_size(), 1);

const pbnavitia::Journey& journey = resp.journeys(0);

// from journey we create the PrJourneyReuqest:
pbnavitia::PtFaresRequest pt_fare_request{};

auto* pt_fare_journey = pt_fare_request.add_pt_journeys();
pt_fare_journey->set_id("pt_jourey_1");

for (const auto& section : journey.sections()) {
if (section.type() != pbnavitia::PUBLIC_TRANSPORT) {
continue;
}

auto* pt_fare_section = pt_fare_journey->add_pt_sections();

pt_fare_section->set_id(section.id());
pt_fare_section->set_network_uri(section.pt_display_informations().uris().network());
pt_fare_section->set_start_stop_area_uri(section.origin().uri());
pt_fare_section->set_end_stop_area_uri(section.destination().uri());
pt_fare_section->set_line_uri(section.pt_display_informations().uris().line());
pt_fare_section->set_begin_date_time(section.begin_date_time());
pt_fare_section->set_end_date_time(section.end_date_time());

pt_fare_section->set_first_stop_point_uri("INVALID_STOP_POINT_URI");

auto last_stop_point = section.stop_date_times().rbegin()->stop_point();
pt_fare_section->set_last_stop_point_uri(last_stop_point.uri());

pt_fare_section->set_physical_mode(section.pt_display_informations().physical_mode());
}

navitia::PbCreator pb_creator_fare(data_ptr, boost::gregorian::not_a_date_time, null_time_period);

fare::fill_fares(pb_creator_fare, pt_fare_request);

const auto& fare_response = pb_creator_fare.get_response();
const auto& pt_journey_fares = fare_response.pt_journey_fares();

BOOST_REQUIRE_EQUAL(pt_journey_fares.size(), 0);
}
25 changes: 17 additions & 8 deletions source/jormungandr/jormungandr/georef.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,21 +158,30 @@ def get_crow_fly(
logger.error("feed publisher not empty: expect performance regression!")
return res.places_nearby

def get_stop_points_for_stop_area(self, uri, request_id):
def get_stop_points_uris_for_stop_area(self, stop_area_uri, request_id):
req = request_pb2.Request()
req.requested_api = type_pb2.PTREFERENTIAL
req.ptref.requested_type = type_pb2.STOP_POINT
req.ptref.count = 100
req.ptref.start_page = 0
req.ptref.depth = 0
req.ptref.filter = 'stop_area.uri = {uri}'.format(uri=uri)
req.ptref.filter = 'stop_area.uri = {uri}'.format(uri=stop_area_uri)
return self.instance.send_and_receive(req, request_id=request_id)

result = self.instance.send_and_receive(req, request_id=request_id)
if not result.stop_points:
logging.getLogger(__name__).info(
'PtRef, Unable to find stop_point with filter {}'.format(req.ptref.filter)
)
return result.stop_points
def get_stop_points_for_stop_area(self, uri, request_id):
@memory_cache.memoize(
current_app.config[str('MEMORY_CACHE_CONFIGURATION')].get(str('TIMEOUT_PTOBJECTS'), 30)
)
@cache.memoize(current_app.config[str('CACHE_CONFIGURATION')].get(str('TIMEOUT_PTOBJECTS'), 300))
def inner(stop_area_uri, instance_publication_date):
result = self.get_stop_points_uris_for_stop_area(stop_area_uri, request_id)
if not result:
logging.getLogger(__name__).info(
'PtRef, Unable to find stop_point with filter {}'.format(stop_area_uri)
)
return {sp.uri for sp in result.stop_points}

return inner(uri, self.instance.publication_date)

def get_stop_points_from_uri(self, uri, request_id, depth=0):
req = request_pb2.Request()
Expand Down
3 changes: 2 additions & 1 deletion source/jormungandr/jormungandr/instance_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ def dispatch(self, arguments, api, instance_name=None):
raise RegionNotFound(instance_name)

instance = self.instances[instance_name]

if not arguments.get('language'):
arguments['language'] = instance.language
scenario = instance.scenario(arguments.get('_override_scenario'))
if not hasattr(scenario, api) or not callable(getattr(scenario, api)):
raise ApiNotFound(api)
Expand Down
8 changes: 7 additions & 1 deletion source/jormungandr/jormungandr/interfaces/v1/Disruptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@
from jormungandr.interfaces.v1.ResourceUri import ResourceUri
from jormungandr.interfaces.v1.serializer import api
from jormungandr.interfaces.common import split_uri
from navitiacommon.parser_args_type import BooleanType, DateTimeFormat, DepthArgument
from navitiacommon.parser_args_type import BooleanType, DateTimeFormat, DepthArgument, OptionValue
from jormungandr.utils import date_to_timestamp
from jormungandr.resources_utils import ResourceUtc
from navitiacommon.constants import ENUM_LANGUAGE
from flask.globals import g
from flask_restful import abort
from datetime import datetime
Expand Down Expand Up @@ -102,6 +103,11 @@ def __init__(self):
action="append",
help="If filled, will restrain the search within the given disruption tags",
)
parser_get.add_argument(
"language",
type=OptionValue(ENUM_LANGUAGE),
help="Here, select a specific language for disruption message",
)

parser_get.add_argument("since", type=DateTimeFormat(), help="use disruptions valid after this date")
parser_get.add_argument("until", type=DateTimeFormat(), help="use disruptions valid before this date")
Expand Down
Loading

0 comments on commit a6bb1f6

Please sign in to comment.