many-to-many multi-modal routing aggregator
1
2#include "scan-times.h"
3
4//' rcpp_scan_times
5//'
6//' @noRd
7// [[Rcpp::export]]
8void rcpp_scan_time_files (const Rcpp::DataFrame tt,
9 Rcpp::NumericVector ×,
10 const std::string &path)
11{
12 const std::vector <std::string> osm_id = tt ["osm_id"];
13 const std::vector <int> duration = tt ["duration"];
14
15 const size_t n = static_cast <size_t> (tt.nrow ());
16
17 for (size_t i = 0; i < n; i++)
18 {
19 const std::string f_base = "m4ra_from_" + osm_id [i];
20 const std::string f_name = path + f_base;
21
22 std::ifstream in_file;
23 in_file.open (f_name.c_str (), std::ifstream::in);
24 if (in_file.fail ())
25 {
26 Rcpp::Rcout << "File: [" << f_name << "]" << std::endl;
27 Rcpp::stop ("Scanning time files failed."); // # nocov
28 }
29 std::string linetxt;
30
31 in_file.clear ();
32 in_file.seekg (0);
33
34 R_xlen_t index = 0;
35 while (getline (in_file, linetxt, '\n'))
36 {
37 const double t_i = duration [i] + std::atof (linetxt.c_str ());
38 if (t_i < times [index])
39 {
40 times [index] = t_i;
41 }
42 index++;
43 }
44 in_file.close ();
45 }
46}