Search in sources :

Example 1 with RiderStageConnectionComparatorPoints

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

the class Parser method updateRiderConnectionRankByPoints.

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

        public void run() {
            try {
                RealmList<RiderStageConnection> connections = Context.getAllRiderStageConnections();
                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));
                }
            } 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) RiderStageConnectionComparatorPoints(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorPoints) JSONException(org.json.JSONException)

Example 2 with RiderStageConnectionComparatorPoints

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

the class RiderStageConnectionRepository method updateRiderStageConnectionReward.

@Override
public void updateRiderStageConnectionReward(final RiderStageConnection riderStageConnection, OnUpdateRiderStageConnectionCallBack callback) {
    Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
    realm.beginTransaction();
    RiderStageConnection res = realm.where(RiderStageConnection.class).equalTo("id", riderStageConnection.getId()).findFirst();
    res.appendBonusPoint(riderStageConnection.getBonusPoint());
    res.appendBonusTime(riderStageConnection.getBonusTime());
    res.appendMoney(riderStageConnection.getMoney());
    res.appendMountainBonusPoints(riderStageConnection.getMountainBonusPoints());
    res.appendSprintBonusPoints(riderStageConnection.getSprintBonusPoints());
    realm.commitTransaction();
    // Neu Berechnung der Rankings für die API, wird auf der API ebenfalls ausgeführt.
    realm.executeTransaction((Realm db) -> {
        RealmResults<RiderStageConnection> connections = db.where(RiderStageConnection.class).findAll();
        List<RiderStageConnection> cons = realm.copyFromRealm(connections);
        cons.sort(new RiderStageConnectionComparatorPoints());
        for (int i = 0; i < cons.size(); i++) {
            db.where(RiderStageConnection.class).equalTo("id", cons.get(i).getId()).findFirst().getRiderRanking(RankingType.POINTS).setRank(i + 1);
        }
        if (riderStageConnection.getMountainBonusPoints() != 0) {
            cons.sort(new RiderStageConnectionComparatorMountainPoints());
            for (int i = 0; i < cons.size(); i++) {
                db.where(RiderStageConnection.class).equalTo("id", cons.get(i).getId()).findFirst().getRiderRanking(RankingType.MOUNTAIN).setRank(i + 1);
            }
        }
        if (riderStageConnection.getMoney() != 0) {
            cons.sort(new RiderStageConnectionComparatorMoney());
            for (int i = 0; i < cons.size(); i++) {
                db.where(RiderStageConnection.class).equalTo("id", cons.get(i).getId()).findFirst().getRiderRanking(RankingType.MONEY).setRank(i + 1);
            }
        }
    });
    PostHandler.makeMessage("UpdateRiderStageConnection", realm.copyFromRealm(res));
    if (callback != null) {
        callback.onSuccess();
    }
}
Also used : RiderStageConnectionComparatorMoney(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorMoney) RiderStageConnection(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection) RiderStageConnectionComparatorPoints(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorPoints) RiderStageConnectionComparatorMountainPoints(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorMountainPoints) Realm(io.realm.Realm)

Aggregations

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