Search in sources :

Example 21 with RiderStageConnection

use of ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection 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

RiderStageConnection (ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection)21 Realm (io.realm.Realm)9 Test (org.junit.Test)7 RealmList (io.realm.RealmList)6 Rider (ch.hsr.sa.radiotour.dataaccess.models.Rider)5 RiderRanking (ch.hsr.sa.radiotour.dataaccess.models.RiderRanking)3 Judgement (ch.hsr.sa.radiotour.dataaccess.models.Judgement)2 RiderStageConnectionComparatorMountainPoints (ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorMountainPoints)2 RiderStageConnectionComparatorPoints (ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorPoints)2 RiderStageConnectionComparatorVirtualGap (ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorVirtualGap)2 Date (java.util.Date)2 JSONException (org.json.JSONException)2 JudgmentRiderConnection (ch.hsr.sa.radiotour.dataaccess.models.JudgmentRiderConnection)1 Reward (ch.hsr.sa.radiotour.dataaccess.models.Reward)1 RiderStageConnectionComparatorMoney (ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorMoney)1 RiderStageConnectionComparatorOfficalGap (ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorOfficalGap)1 RiderStageConnectionComparatorTimeInLead (ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorTimeInLead)1 Stage (ch.hsr.sa.radiotour.dataaccess.models.Stage)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1