Search in sources :

Example 1 with RiderStageConnectionComparatorDistanceInLead

use of ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorDistanceInLead in project app by TourLive.

the class RiderStageConnectionRepository method appendDistanceInLeadGroup.

@Override
public void appendDistanceInLeadGroup(final RiderStageConnection riderStageConnection, double value) {
    Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
    realm.executeTransaction((Realm db) -> {
        RiderStageConnection res = db.where(RiderStageConnection.class).equalTo("id", riderStageConnection.getId()).findFirst();
        res.appendDistanceInLeadGroup(value);
        List<RiderStageConnection> cons = realm.copyFromRealm(db.where(RiderStageConnection.class).findAll());
        cons.sort(new RiderStageConnectionComparatorDistanceInLead());
        for (int i = 0; i < cons.size(); i++) {
            db.where(RiderStageConnection.class).equalTo("id", cons.get(i).getId()).findFirst().getRiderRanking(RankingType.DISTANCE_IN_LEAD).setRank(i + 1);
        }
        PostHandler.makeMessage("UpdateRiderStageConnection", realm.copyFromRealm(res));
    });
}
Also used : RiderStageConnection(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection) RiderStageConnectionComparatorDistanceInLead(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorDistanceInLead) Realm(io.realm.Realm)

Example 2 with RiderStageConnectionComparatorDistanceInLead

use of ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorDistanceInLead in project app by TourLive.

the class Parser method updateRiderConnectionRankByDistanceInLead.

public static String updateRiderConnectionRankByDistanceInLead() throws InterruptedException {
    Runnable runnable = new Runnable() {

        public void run() {
            try {
                RealmList<RiderStageConnection> connections = Context.getAllRiderStageConnections();
                connections.sort(new RiderStageConnectionComparatorDistanceInLead());
                for (int i = 0; i < connections.size(); i++) {
                    RiderRanking rankingTimeInLead = new RiderRanking();
                    rankingTimeInLead.setType(RankingType.DISTANCE_IN_LEAD);
                    rankingTimeInLead.setRank(i + 1);
                    synchronized (this) {
                        Context.addRiderRanking(rankingTimeInLead);
                    }
                    RiderRanking realmRiderRanking = Context.getRiderRanking(rankingTimeInLead);
                    Context.updateRiderStageConnectionRanking(realmRiderRanking, connections.get(i));
                }
            } catch (Exception e) {
                Log.d(Parser.class.getSimpleName(), "APP - PARSER - RIDERCONNECTION - " + e.getMessage());
            }
        }
    };
    Thread threadRanking = new Thread(runnable);
    threadRanking.start();
    threadRanking.join();
    return "success";
}
Also used : RiderStageConnection(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection) RiderRanking(ch.hsr.sa.radiotour.dataaccess.models.RiderRanking) RiderStageConnectionComparatorDistanceInLead(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorDistanceInLead) JSONException(org.json.JSONException)

Aggregations

RiderStageConnection (ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection)2 RiderStageConnectionComparatorDistanceInLead (ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorDistanceInLead)2 RiderRanking (ch.hsr.sa.radiotour.dataaccess.models.RiderRanking)1 Realm (io.realm.Realm)1 JSONException (org.json.JSONException)1