use of im.tny.segvault.disturbances.model.StationUse in project underlx by underlx.
the class StatsActivity method getTripsFor.
private static RealmQuery<Trip> getTripsFor(Realm realm, int days) {
if (days == 0) {
return realm.where(Trip.class);
} else {
RealmResults<StationUse> uses = realm.where(StationUse.class).greaterThan("entryDate", new Date(new Date().getTime() - TimeUnit.DAYS.toMillis(days))).findAll().where().equalTo("type", "NETWORK_ENTRY").or().equalTo("type", "VISIT").findAll();
// now we have all station uses that **might** be part of editable trips
// get all trips that contain these uses and which are yet to be confirmed
RealmQuery<Trip> tripsQuery = realm.where(Trip.class);
if (uses.size() > 0) {
// first item detached from the others because otherwise "Missing left-hand side of OR" might happen
// https://github.com/realm/realm-java/issues/1014#issuecomment-107235374
tripsQuery = tripsQuery.equalTo("path.station.id", uses.get(0).getStation().getId()).equalTo("path.entryDate", uses.get(0).getEntryDate());
for (int i = 1; i < uses.size(); i++) {
tripsQuery = tripsQuery.or().equalTo("path.station.id", uses.get(i).getStation().getId()).equalTo("path.entryDate", uses.get(i).getEntryDate());
}
return tripsQuery;
}
// https://github.com/realm/realm-java/issues/4011
return tripsQuery.equalTo("id", "NEVER_BE_TRUE");
}
}
use of im.tny.segvault.disturbances.model.StationUse in project underlx by underlx.
the class TripCorrectionActivity method removeVertex.
private void removeVertex(int i) {
if (!canRemoveVertex(i)) {
return;
}
List<StationUse> uses = trip.getPath();
uses.get(i - 1).setLeaveDate(trip.getPath().get(i + 1).getLeaveDate());
uses.remove(i);
// the next one to remove might be an interchange, if yes, save its src/dest line as it may be needed later
String srcLineId = uses.get(i).getSourceLine();
String dstLineId = uses.get(i).getTargetLine();
uses.remove(i);
if (uses.size() == 1) {
uses.get(0).setType(StationUse.UseType.VISIT);
} else {
uses.get(0).setType(StationUse.UseType.NETWORK_ENTRY);
uses.get(trip.getPath().size() - 1).setType(StationUse.UseType.NETWORK_EXIT);
if (i < uses.size() && i > 1) {
Station src = network.getStation(uses.get(i - 2).getStation().getId());
Station dst = network.getStation(uses.get(i).getStation().getId());
boolean foundSameLine = false;
for (Stop srcStop : src.getStops()) {
for (Line dstLine : dst.getLines()) {
if (dstLine.containsVertex(srcStop)) {
foundSameLine = true;
}
}
}
if (!foundSameLine) {
if (uses.get(i - 1).getType() != StationUse.UseType.INTERCHANGE) {
uses.get(i - 1).setType(StationUse.UseType.INTERCHANGE);
uses.get(i - 1).setSourceLine(srcLineId);
uses.get(i - 1).setTargetLine(dstLineId);
}
} else {
uses.get(i - 1).setType(StationUse.UseType.GONE_THROUGH);
}
}
}
originalPath = trip.toConnectionPath(network);
partsDeleted = true;
redrawPath();
}
use of im.tny.segvault.disturbances.model.StationUse in project underlx by underlx.
the class Synchronizer method tripToAPIRequest.
private API.TripRequest tripToAPIRequest(Trip t) {
API.TripRequest request = new API.TripRequest();
request.id = t.getId();
request.userConfirmed = t.isUserConfirmed();
request.uses = new ArrayList<>(t.getPath().size());
for (StationUse use : t.getPath()) {
request.uses.add(stationUseToAPI(use));
}
return request;
}