Skip to content

Commit

Permalink
Correct the Departure time with 1st leg walking.
Browse files Browse the repository at this point in the history
Corect setting of Departure Station for ALL legs.
  • Loading branch information
poetaster committed Nov 3, 2022
1 parent 045be82 commit 9100396
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion rpm/harbour-fahrplan2.spec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Name: harbour-fahrplan2
%{!?qtc_make:%define qtc_make make}
%{?qtc_builddir:%define _builddir %qtc_builddir}
Summary: Public transportation application
Version: 2.0.43
Version: 2.0.44
Release: 1
Group: Location/Location Adaptation
License: GPLv2
Expand Down
45 changes: 23 additions & 22 deletions src/parser/parser_ninetwo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ JourneyResultItem * ParserNinetwo::parseJourneyJson(const QString& jsonData)

// using this to add last walking times
int walkingTime = 0;
int firstWalkingTime = 0;

// evil chaning scope to keep 'last value'
QDateTime arrivalTime;
Expand Down Expand Up @@ -506,8 +507,10 @@ JourneyResultItem * ParserNinetwo::parseJourneyJson(const QString& jsonData)

QDateTime departureTime = QDateTime::fromString(calls[0].toMap()["Departure"].toString(), Qt::ISODate);

qWarning() << "dtype: " << calls[0].toMap()["CallType"].toString();
qWarning() << "atype: " << calls[lastCall].toMap()["CallType"].toString();
qWarning() << "arrivalStation: " << arrivalStation;
qWarning() << "departureStation: " << departureStation;



// only set Arrival if we have it. not set for walk
if (calls[lastCall-1].toMap()["Arrival"].toString() != "")
Expand Down Expand Up @@ -546,8 +549,6 @@ JourneyResultItem * ParserNinetwo::parseJourneyJson(const QString& jsonData)
item->setArrivalDateTime(arrivalTimeWalk);
} else {
item->setArrivalDateTime(arrivalTime);
qWarning() << "dep: " << departureTime.toString("hh:mm");
qWarning() << "arr: " << arrivalTime.toString("hh:mm");
}

item->setArrivalStation(arrivalStation);
Expand All @@ -564,11 +565,15 @@ JourneyResultItem * ParserNinetwo::parseJourneyJson(const QString& jsonData)
if (detailCount == 0) {
detail->setDepartureStation(item->departureStation());
detail->setDepartureDateTime(item->departureDateTime());
// we need to record first walking to set it later and use if for departure.
firstWalkingTime = walkingTime;
} else if (detailCount == legs.count()-1){
detail->setArrivalDateTime(item->arrivalDateTime());
detail->setArrivalStation(item->arrivalStation());
}

// no ALWAYS set arrival :)
detail->setArrivalDateTime(item->arrivalDateTime());
detail->setArrivalStation(item->arrivalStation());
detail->appendItem(item);
detailCount ++;
}
Expand Down Expand Up @@ -597,30 +602,26 @@ JourneyResultItem * ParserNinetwo::parseJourneyJson(const QString& jsonData)
}
QDateTime minutesBegin;
QDateTime minutesEnd;
// we must calculate duration without first or final leg being a walk.
if (detail->getItem(detail->itemcount()-1)->train().startsWith("walk") ) {
// this is fixed above
minutesEnd = detail->getItem(detail->itemcount()-1)->arrivalDateTime();
response->setArrivalTime(detail->getItem(detail->itemcount()-1)->arrivalDateTime().toString("hh:mm"));
// add walking time at end.
//minutesEnd = detail->getItem(detail->itemcount()-2)->arrivalDateTime().addMSecs(walkingTime*60);
//response->setArrivalTime(minutesEnd.toString("hh:mm"));
} else {
minutesEnd = detail->getItem(detail->itemcount()-1)->arrivalDateTime();
response->setArrivalTime(detail->getItem(detail->itemcount()-1)->arrivalDateTime().toString("hh:mm"));
//qWarning() << "arrivalDetail: " << detail->getItem(detail->itemcount()-1)->arrivalDateTime().toString("hh:mm") ;
}

minutesEnd = detail->getItem(detail->itemcount()-1)->arrivalDateTime();

if (detail->getItem(0)->train().startsWith("walk") ) {
minutesBegin = detail->getItem(1)->departureDateTime();
// this gets us around not having a start time for walk legs.
// anolog to how we set arrival date time above
QDateTime walkDepart = detail->getItem(1)->departureDateTime().addSecs( - firstWalkingTime * 60) ;
detail->getItem(0)->setDepartureDateTime(walkDepart);

response->setDepartureTime(walkDepart.toString("hh:mm"));
minutesBegin = detail->getItem(0)->departureDateTime();
response->setDate(detail->getItem(1)->departureDateTime().date());
response->setDepartureTime(detail->getItem(1)->departureDateTime().toString("hh:mm"));
//qWarning() << "wOne-dDetail: " << detail->getItem(1)->departureDateTime().toString("hh:mm") ;

} else {
minutesBegin = detail->getItem(0)->departureDateTime();
response->setDepartureTime(detail->getItem(0)->departureDateTime().toString("hh:mm"));
//qWarning() << "departureDetail: " << detail->getItem(0)->departureDateTime().toString("hh:mm") ;
}

response->setArrivalTime(detail->getItem(detail->itemcount()-1)->arrivalDateTime().toString("hh:mm"));

int minutes = minutesBegin.secsTo(minutesEnd) / 60;
int hours = minutes / 60;
minutes = minutes % 60;
Expand Down

0 comments on commit 9100396

Please sign in to comment.