<commit_before>#include "departure_boards.h"
#include "request_handle.h"
#include "get_stop_times.h"
#include "type/pb_converter.h"
#include "boost/lexical_cast.hpp"
#include "boost/date_time/posix_time/posix_time.hpp"
#include "utils/paginate.h"

namespace pt = boost::posix_time;

namespace navitia { namespace timetables {

std::vector<vector_datetime> make_columuns(const vector_dt_st &stop_times) {
    std::vector<vector_datetime> result;
    DateTime prev_date = DateTimeUtils::inf;

    for(auto & item : stop_times) {
        if(prev_date == DateTimeUtils::inf ||
                (DateTimeUtils::hour(prev_date)/3600) != (DateTimeUtils::hour(item.first)/3600)) {
            //On supprime les doublons
            if(result.size() > 0) {
                auto last = result.back();
                auto it = std::unique(last.begin(), last.end());
                last.resize(std::distance(last.begin(), it));
            }
            result.push_back(vector_datetime());
        }

        result.back().push_back(item.first);
        prev_date = item.first;
    }

    if(result.size() > 0) {
        auto it = std::unique(result.back().begin(), result.back().end());
        result.back().resize(std::distance(result.back().begin(), it));
    }

    return result;
}


pbnavitia::Response
render_v0(const std::map<stop_point_line, vector_dt_st> &map_route_stop_point,
          DateTime datetime, DateTime max_datetime,
          const type::Data &data) {
    pbnavitia::Response response;
    auto current_time = pt::second_clock::local_time();
    pt::time_period action_period(to_posix_time(datetime, data),
                                  to_posix_time(max_datetime, data));

    auto sort_predicate =
        [&](datetime_stop_time d1, datetime_stop_time d2)->bool {
            auto hour1 = DateTimeUtils::hour(d1.first) % DateTimeUtils::SECONDS_PER_DAY;
            auto hour2 = DateTimeUtils::hour(d2.first) % DateTimeUtils::SECONDS_PER_DAY;
            return std::abs(hour1 - DateTimeUtils::hour(datetime)) <
                   std::abs(hour2 - DateTimeUtils::hour(datetime));
        };

    for(auto id_vec : map_route_stop_point) {

        auto board = response.add_departure_boards();
        fill_pb_object(data.pt_data.stop_points[id_vec.first.first], data,
                       board->mutable_stop_point(), 1,
                       current_time, action_period);
        fill_pb_object(data.pt_data.routes[id_vec.first.second], data,
                       board->mutable_route(), 2, current_time, action_period);

        auto vec_st = id_vec.second;
        std::sort(vec_st.begin(), vec_st.end(), sort_predicate);

        for(auto vec : make_columuns(vec_st)) {
            pbnavitia::BoardItem *item = board->add_board_items();

            for(DateTime dt : vec) {
                if(!item->has_hour()) {
                    auto hours = DateTimeUtils::hour(dt)/3600;
                    item->set_hour(boost::lexical_cast<std::string>(hours));
                }
                auto minutes = (DateTimeUtils::hour(dt)%3600)/60;
                item->add_minutes(boost::lexical_cast<std::string>(minutes));
            }
        }
    }
    return response;
}


pbnavitia::Response
render_v1(const std::map<uint32_t, pbnavitia::ResponseStatus> &response_status,
          const std::map<stop_point_line, vector_dt_st> &map_route_stop_point,
          DateTime datetime, DateTime max_datetime,
          const type::Data &data) {
    pbnavitia::Response response;
    auto current_time = pt::second_clock::local_time();
    auto now = pt::second_clock::local_time();
    pt::time_period action_period(to_posix_time(datetime, data),
                                  to_posix_time(max_datetime, data));

    for(auto id_vec : map_route_stop_point) {
        auto schedule = response.add_stop_schedules();
        //Each schedule has a stop_point and a route
        fill_pb_object(data.pt_data.stop_points[id_vec.first.first], data,
                       schedule->mutable_stop_point(), 0,
                       current_time, action_period);

        auto m_route = schedule->mutable_route();
        fill_pb_object(data.pt_data.routes[id_vec.first.second], data,
                               m_route, 0, current_time, action_period);
        if (data.pt_data.routes[id_vec.first.second]->line != nullptr){
            auto m_line = m_route->mutable_line();
            fill_pb_object(data.pt_data.routes[id_vec.first.second]->line, data,
                                   m_line, 0, current_time, action_period);
        }
        auto pt_display_information = schedule->mutable_pt_display_informations();
        fill_pb_object(data.pt_data.routes[id_vec.first.second], data,
                               pt_display_information, 0, current_time, action_period);
        //Now we fill the date_times
        for(auto dt_st : id_vec.second) {
            auto date_time = schedule->add_date_times();
            fill_pb_object(dt_st.second, data, date_time, 0,
                           now, action_period, dt_st.first);
        }
        auto it = response_status.at(id_vec.first.second);
        if(it != pbnavitia::ResponseStatus::default_status){
            schedule->set_status(it);
        }
    }
    return response;
}


pbnavitia::Response
departure_board(const std::string& request, const std::vector<std::string>& forbidden_uris,
                const std::string& date,
                uint32_t duration, int32_t max_date_times,
                int interface_version,
                int count, int start_page, const type::Data &data) {

    RequestHandle handler("DEPARTURE_BOARD", request, forbidden_uris, date,  duration, data);

    if(handler.pb_response.has_error())
        return handler.pb_response;

    if(handler.journey_pattern_points.size() == 0)
        return handler.pb_response;

    if (max_date_times < 0) {<commit_msg>Departureboards: Added default status<commit_after>#include "departure_boards.h"
#include "request_handle.h"
#include "get_stop_times.h"
#include "type/pb_converter.h"
#include "boost/lexical_cast.hpp"
#include "boost/date_time/posix_time/posix_time.hpp"
#include "utils/paginate.h"

namespace pt = boost::posix_time;

namespace navitia { namespace timetables {

std::vector<vector_datetime> make_columuns(const vector_dt_st &stop_times) {
    std::vector<vector_datetime> result;
    DateTime prev_date = DateTimeUtils::inf;

    for(auto & item : stop_times) {
        if(prev_date == DateTimeUtils::inf ||
                (DateTimeUtils::hour(prev_date)/3600) != (DateTimeUtils::hour(item.first)/3600)) {
            //On supprime les doublons
            if(result.size() > 0) {
                auto last = result.back();
                auto it = std::unique(last.begin(), last.end());
                last.resize(std::distance(last.begin(), it));
            }
            result.push_back(vector_datetime());
        }

        result.back().push_back(item.first);
        prev_date = item.first;
    }

    if(result.size() > 0) {
        auto it = std::unique(result.back().begin(), result.back().end());
        result.back().resize(std::distance(result.back().begin(), it));
    }

    return result;
}


pbnavitia::Response
render_v0(const std::map<stop_point_line, vector_dt_st> &map_route_stop_point,
          DateTime datetime, DateTime max_datetime,
          const type::Data &data) {
    pbnavitia::Response response;
    auto current_time = pt::second_clock::local_time();
    pt::time_period action_period(to_posix_time(datetime, data),
                                  to_posix_time(max_datetime, data));

    auto sort_predicate =
        [&](datetime_stop_time d1, datetime_stop_time d2)->bool {
            auto hour1 = DateTimeUtils::hour(d1.first) % DateTimeUtils::SECONDS_PER_DAY;
            auto hour2 = DateTimeUtils::hour(d2.first) % DateTimeUtils::SECONDS_PER_DAY;
            return std::abs(hour1 - DateTimeUtils::hour(datetime)) <
                   std::abs(hour2 - DateTimeUtils::hour(datetime));
        };

    for(auto id_vec : map_route_stop_point) {

        auto board = response.add_departure_boards();
        fill_pb_object(data.pt_data.stop_points[id_vec.first.first], data,
                       board->mutable_stop_point(), 1,
                       current_time, action_period);
        fill_pb_object(data.pt_data.routes[id_vec.first.second], data,
                       board->mutable_route(), 2, current_time, action_period);

        auto vec_st = id_vec.second;
        std::sort(vec_st.begin(), vec_st.end(), sort_predicate);

        for(auto vec : make_columuns(vec_st)) {
            pbnavitia::BoardItem *item = board->add_board_items();

            for(DateTime dt : vec) {
                if(!item->has_hour()) {
                    auto hours = DateTimeUtils::hour(dt)/3600;
                    item->set_hour(boost::lexical_cast<std::string>(hours));
                }
                auto minutes = (DateTimeUtils::hour(dt)%3600)/60;
                item->add_minutes(boost::lexical_cast<std::string>(minutes));
            }
        }
    }
    return response;
}


pbnavitia::Response
render_v1(const std::map<uint32_t, pbnavitia::ResponseStatus> &response_status,
          const std::map<stop_point_line, vector_dt_st> &map_route_stop_point,
          DateTime datetime, DateTime max_datetime,
          const type::Data &data) {
    pbnavitia::Response response;
    auto current_time = pt::second_clock::local_time();
    auto now = pt::second_clock::local_time();
    pt::time_period action_period(to_posix_time(datetime, data),
                                  to_posix_time(max_datetime, data));

    for(auto id_vec : map_route_stop_point) {
        auto schedule = response.add_stop_schedules();
        //Each schedule has a stop_point and a route
        fill_pb_object(data.pt_data.stop_points[id_vec.first.first], data,
                       schedule->mutable_stop_point(), 0,
                       current_time, action_period);

        auto m_route = schedule->mutable_route();
        fill_pb_object(data.pt_data.routes[id_vec.first.second], data,
                               m_route, 0, current_time, action_period);
        if (data.pt_data.routes[id_vec.first.second]->line != nullptr){
            auto m_line = m_route->mutable_line();
            fill_pb_object(data.pt_data.routes[id_vec.first.second]->line, data,
                                   m_line, 0, current_time, action_period);
        }
        auto pt_display_information = schedule->mutable_pt_display_informations();
        fill_pb_object(data.pt_data.routes[id_vec.first.second], data,
                               pt_display_information, 0, current_time, action_period);
        //Now we fill the date_times
        for(auto dt_st : id_vec.second) {
            auto date_time = schedule->add_date_times();
            fill_pb_object(dt_st.second, data, date_time, 0,
                           now, action_period, dt_st.first);
        }
        auto it = response_status.at(id_vec.first.second);
        schedule->set_status(it);
    }
    return response;
}


pbnavitia::Response
departure_board(const std::string& request, const std::vector<std::string>& forbidden_uris,
                const std::string& date,
                uint32_t duration, int32_t max_date_times,
                int interface_version,
                int count, int start_page, const type::Data &data) {

    RequestHandle handler("DEPARTURE_BOARD", request, forbidden_uris, date,  duration, data);

    if(handler.pb_response.has_error())
        return handler.pb_response;

    if(handler.journey_pattern_points.size() == 0)
        return handler.pb_response;

    if (max_date_times < 0) {
{'fraction_non_alphanumeric': 0.11828323256408073, 'fraction_numerical': 0.007664140338925317, 'mean_word_length': 2.57830591102986, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5094084', 'n_tokens_mistral': 3646, 'n_tokens_neox': 3527, 'n_words': 593}