Search in sources :

Example 1 with StationUse

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");
    }
}
Also used : StationUse(im.tny.segvault.disturbances.model.StationUse) Trip(im.tny.segvault.disturbances.model.Trip) Date(java.util.Date)

Example 2 with StationUse

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();
}
Also used : StationUse(im.tny.segvault.disturbances.model.StationUse) Station(im.tny.segvault.subway.Station) Line(im.tny.segvault.subway.Line) Stop(im.tny.segvault.subway.Stop)

Example 3 with StationUse

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;
}
Also used : StationUse(im.tny.segvault.disturbances.model.StationUse)

Aggregations

StationUse (im.tny.segvault.disturbances.model.StationUse)3 Trip (im.tny.segvault.disturbances.model.Trip)1 Line (im.tny.segvault.subway.Line)1 Station (im.tny.segvault.subway.Station)1 Stop (im.tny.segvault.subway.Stop)1 Date (java.util.Date)1