Search in sources :

Example 1 with RiderStageConnectionComparatorVirtualGap

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

the class RiderStageConnectionRepository method updateRiderStageConnectionTime.

@Override
public void updateRiderStageConnectionTime(long timeBefore, long timeStamp, final RaceGroup res, OnUpdateRiderStageConnectionCallBack callback) {
    Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
    realm.beginTransaction();
    if (timeBefore > 0 && !res.getRiders().isEmpty()) {
        for (Rider r : res.getRiders()) {
            if (!r.getRiderStages().isEmpty()) {
                r.getRiderStages().first().setVirtualGap(r.getRiderStages().first().getVirtualGap() - timeBefore);
            }
        }
    }
    if (!res.getRiders().isEmpty()) {
        for (Rider r : res.getRiders()) {
            if (!r.getRiderStages().isEmpty()) {
                r.getRiderStages().first().setVirtualGap(r.getRiderStages().first().getVirtualGap() + timeStamp);
            }
        }
    }
    RealmResults<RiderStageConnection> connections = realm.where(RiderStageConnection.class).findAll();
    List<RiderStageConnection> cons = realm.copyFromRealm(connections);
    cons.sort(new RiderStageConnectionComparatorVirtualGap());
    for (int i = 0; i < cons.size(); i++) {
        RiderRanking riderRanking = realm.where(RiderStageConnection.class).equalTo("id", cons.get(i).getId()).findFirst().getRiderRanking(RankingType.VIRTUAL);
        if (riderRanking != null) {
            riderRanking.setRank(i + 1);
        }
    }
    realm.commitTransaction();
    if (callback != null) {
        callback.onSuccess();
    }
}
Also used : RiderStageConnectionComparatorVirtualGap(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorVirtualGap) RiderStageConnection(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection) RiderRanking(ch.hsr.sa.radiotour.dataaccess.models.RiderRanking) Realm(io.realm.Realm) Rider(ch.hsr.sa.radiotour.dataaccess.models.Rider)

Example 2 with RiderStageConnectionComparatorVirtualGap

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

the class Parser method updateRiderConnectionRankByOfficalGap.

private static void updateRiderConnectionRankByOfficalGap() throws InterruptedException {
    Runnable runnable = new Runnable() {

        public void run() {
            try {
                RealmList<RiderStageConnection> connections = Context.getAllRiderStageConnections();
                connections.sort(new RiderStageConnectionComparatorOfficalGap());
                for (int i = 0; i < connections.size(); i++) {
                    RiderRanking rankingOfficial = new RiderRanking();
                    rankingOfficial.setType(RankingType.OFFICAL);
                    rankingOfficial.setRank(i + 1);
                    synchronized (this) {
                        Context.addRiderRanking(rankingOfficial);
                    }
                    RiderRanking realmRiderRanking = Context.getRiderRanking(rankingOfficial);
                    Context.updateRiderStageConnectionRanking(realmRiderRanking, connections.get(i));
                }
                connections.sort(new RiderStageConnectionComparatorVirtualGap());
                for (int i = 0; i < connections.size(); i++) {
                    RiderRanking rankingVirtual = new RiderRanking();
                    rankingVirtual.setType(RankingType.VIRTUAL);
                    rankingVirtual.setRank(i + 1);
                    synchronized (this) {
                        Context.addRiderRanking(rankingVirtual);
                    }
                    RiderRanking realmRiderRanking = Context.getRiderRanking(rankingVirtual);
                    Context.updateRiderStageConnectionRanking(realmRiderRanking, connections.get(i));
                }
                connections.sort(new RiderStageConnectionComparatorMountainPoints());
                for (int i = 0; i < connections.size(); i++) {
                    RiderRanking rankingMountain = new RiderRanking();
                    rankingMountain.setType(RankingType.MOUNTAIN);
                    rankingMountain.setRank(i + 1);
                    synchronized (this) {
                        Context.addRiderRanking(rankingMountain);
                    }
                    RiderRanking realmRiderRanking = Context.getRiderRanking(rankingMountain);
                    Context.updateRiderStageConnectionRanking(realmRiderRanking, connections.get(i));
                }
                connections.sort(new RiderStageConnectionComparatorPoints());
                for (int i = 0; i < connections.size(); i++) {
                    RiderRanking rankingPoints = new RiderRanking();
                    rankingPoints.setType(RankingType.POINTS);
                    rankingPoints.setRank(i + 1);
                    synchronized (this) {
                        Context.addRiderRanking(rankingPoints);
                    }
                    RiderRanking realmRiderRanking = Context.getRiderRanking(rankingPoints);
                    Context.updateRiderStageConnectionRanking(realmRiderRanking, connections.get(i));
                }
                connections.sort(new RiderStageConnectionComparatorVirtualGap());
                int rank = 1;
                for (int i = 0; i < connections.size(); i++) {
                    if (connections.get(i).getRiders().getCountry().equals("SUI")) {
                        RiderRanking rankingSwiss = new RiderRanking();
                        rankingSwiss.setType(RankingType.SWISS);
                        rankingSwiss.setRank(rank);
                        rank++;
                        synchronized (this) {
                            Context.addRiderRanking(rankingSwiss);
                        }
                        RiderRanking realmRiderRanking = Context.getRiderRanking(rankingSwiss);
                        Context.updateRiderStageConnectionRanking(realmRiderRanking, connections.get(i));
                    }
                }
                for (int i = 0; i < connections.size(); i++) {
                    RiderRanking rankingMoney = new RiderRanking();
                    rankingMoney.setType(RankingType.MONEY);
                    rankingMoney.setRank(i + 1);
                    synchronized (this) {
                        Context.addRiderRanking(rankingMoney);
                    }
                    RiderRanking realmRiderRanking = Context.getRiderRanking(rankingMoney);
                    Context.updateRiderStageConnectionRanking(realmRiderRanking, connections.get(i));
                }
                for (int i = 0; i < connections.size(); i++) {
                    RiderRanking rankingTimeInLead = new RiderRanking();
                    rankingTimeInLead.setType(RankingType.TIME_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();
}
Also used : RiderStageConnectionComparatorOfficalGap(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorOfficalGap) RiderStageConnectionComparatorVirtualGap(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorVirtualGap) RiderStageConnection(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection) RiderRanking(ch.hsr.sa.radiotour.dataaccess.models.RiderRanking) RiderStageConnectionComparatorMountainPoints(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorMountainPoints) RiderStageConnectionComparatorPoints(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorPoints) JSONException(org.json.JSONException)

Aggregations

RiderRanking (ch.hsr.sa.radiotour.dataaccess.models.RiderRanking)2 RiderStageConnection (ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection)2 RiderStageConnectionComparatorVirtualGap (ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorVirtualGap)2 Rider (ch.hsr.sa.radiotour.dataaccess.models.Rider)1 RiderStageConnectionComparatorMountainPoints (ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorMountainPoints)1 RiderStageConnectionComparatorOfficalGap (ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorOfficalGap)1 RiderStageConnectionComparatorPoints (ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorPoints)1 Realm (io.realm.Realm)1 JSONException (org.json.JSONException)1