Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <chrono>
- #include "auxiliaires.h"
- #include "arret.h"
- #include "ligne.h"
- using namespace std::chrono;
- int main(int argc, char *argv[]) {
- high_resolution_clock::time_point t1 = high_resolution_clock::now();
- //Redirect stdout to file
- std::ofstream out("out.txt");
- std::streambuf *coutOrigBuf = std::cout.rdbuf();
- std::cout.rdbuf(out.rdbuf());
- std::vector<std::vector<std::string>> stops;
- std::vector<std::vector<std::string>> stopsStation;
- std::vector<std::vector<std::string>> lines;
- std::vector<std::vector<std::string>> travels;
- std::vector<std::vector<std::string>> calendar_dates;
- std::vector<Arret> arrets;
- std::vector<Ligne> lignes;
- std::vector<Voyage> voyages;
- std::vector<Station> stations;
- //stop_times.txt takes a while to read and parse. (Big File)
- lireFichier("RTC/stop_times.txt", stops, ',', true);
- lireFichier("RTC/routes.txt", lines, ',', true);
- lireFichier("RTC/trips.txt", travels, ',', true);
- lireFichier("RTC/stops.txt", stopsStation, ',', true);
- lireFichier("RTC/calendar_dates.txt", calendar_dates, ',', true);
- for (std::vector<std::string> arret : stops) {
- arrets.push_back(Arret(arret));
- }
- std::sort(arrets.begin(), arrets.end(), [](const Arret &a, const Arret &b) {
- return a.getVoyageId() < b.getVoyageId(); //Loop faster
- });
- for (std::vector<std::string> ligne : lines) {
- lignes.push_back(Ligne(ligne));
- }
- std::sort(lignes.begin(), lignes.end(), [](const Ligne &a, const Ligne &b) {
- return a.getNumero() < b.getNumero();
- });
- for (std::vector<std::string> voyage : travels) {
- for (Ligne &ligne : lignes) {
- if (ligne.getId() == stoi(voyage[0])) {
- voyages.push_back(Voyage(voyage, &ligne));
- ligne.addVoyage(&voyages.back());
- break;
- }
- }
- }
- std::sort(voyages.begin(), voyages.end(), [](const Voyage &a, const Voyage &b) {
- return a.getId() < b.getId();
- });
- for (std::vector<std::string> stopStation : stopsStation) {
- Station station(stopStation);
- stations.push_back(station);
- }
- std::sort(stations.begin(), stations.end(), [](Station a, Station b){
- return a.getId() < b.getId();
- });
- int compteurPrecedent = 0;
- for(Voyage &voyage : voyages) {
- bool firstArretFound = false;
- std::vector<Arret> arretsForVoyage;
- for(int i = compteurPrecedent; i < arrets.size(); i++) {
- if(voyage.getId() == arrets[i].getVoyageId()) {
- firstArretFound = true;
- arretsForVoyage.push_back(arrets[i]);
- } else if(firstArretFound) {
- compteurPrecedent = i;
- break;
- }
- }
- voyage.setArrets(arretsForVoyage);
- }
- high_resolution_clock::time_point t2 = high_resolution_clock::now();
- double duration = (double)duration_cast<microseconds>(t2 - t1).count() / 1000 / 1000;
- std::cout << std::endl;
- std::cout << "Chargement des données terminé en " << duration << " secondes" << std::endl;
- std::cout << "======================" << std::endl;
- std::cout << " LIGNE DE LA RTC" << std::endl;
- std::cout << " COMPTE : " << lignes.size() << std::endl;
- std::cout << "======================" << std::endl;
- for (Ligne &ligne : lignes) {
- std::cout << ligne << std::endl;
- }
- std::cout << std::endl;
- std::cout << "======================" << std::endl;
- std::cout << " STATION DE LA RTC" << std::endl;
- std::cout << " COMPTE : " << stations.size() << std::endl;
- std::cout << "======================" << std::endl;
- for (Station &station : stations) {
- std::cout << station << std::endl;
- }
- std::string service_id_otd_1;
- std::string service_id_otd_2;
- Date currentDate;
- Heure currentTime;
- for (int i = 0; i < calendar_dates.size(); i++) {
- if(currentDate == calendar_dates[i][1]) {
- service_id_otd_1 = calendar_dates[i][0];
- service_id_otd_2 = calendar_dates[i+1][0];
- break;
- }
- }
- std::vector<Voyage*> voyagesProchaineHeure;
- for(Voyage &voyage: voyages) {
- if(voyage.getServiceId() == service_id_otd_1 || voyage.getServiceId() == service_id_otd_2) {
- if (voyage.getHeureDepart() - currentTime > 0 && voyage.getHeureFin() - currentTime < 3600){
- voyagesProchaineHeure.push_back(&voyage);
- }
- }
- }
- std::sort(voyagesProchaineHeure.begin(), voyagesProchaineHeure.end(), [](Voyage &a, Voyage &b){
- return a.getHeureDepart() <b.getHeureDepart();
- });
- for(Voyage *voyage: voyagesProchaineHeure) {
- std::cout << std::endl;
- std::cout << "======================" << std::endl;
- std::cout << " VOYAGES DE LA JOURNÉE DU " << currentDate << std::endl;
- std::cout << " " << voyage->getHeureDepart() << " - " << voyage->getHeureFin() << std::endl;
- std::cout << " COMPTE : " << voyage->getArrets().size() << std::endl;
- std::cout << "======================" << std::endl;
- std::cout << voyage->getLigne()->getNumero() << " : " << voyage->getDestination() << std::endl;
- for(Arret &arret : voyage->getArrets()) {
- std::cout << arret.getHeureDepart() << " - " << arret.getStationId() << std::endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement