Search in sources :

Example 1 with RiderStageConnection

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

the class JudgmentRiderConnectionRepository method removeOldJudgmentRiderConnections.

private void removeOldJudgmentRiderConnections(RealmResults<JudgmentRiderConnection> res) {
    for (JudgmentRiderConnection jRc : res) {
        int rank = jRc.getRank();
        Judgement judgement = jRc.getJudgements().first();
        Reward reward = judgement.getRewards();
        RiderStageConnection riderStageConnection = jRc.getRider().first().getRiderStages().first();
        if (reward.getType() == RewardType.POINTS) {
            if (judgement.getName().toLowerCase().contains("sprint")) {
                riderStageConnection.removeSprintBonusPoints(RiderStageConnectionUtilities.getPointsAtPosition(rank, reward));
                riderStageConnection.removeBonusPoint(RiderStageConnectionUtilities.getPointsAtPosition(rank, reward));
            } else if (judgement.getName().toLowerCase().contains("bergpreis")) {
                riderStageConnection.removeMountainBonusPoints(RiderStageConnectionUtilities.getPointsAtPosition(rank, reward));
            } else {
                riderStageConnection.removeBonusPoint(RiderStageConnectionUtilities.getPointsAtPosition(rank, reward));
            }
        }
        if (reward.getType() == RewardType.TIME) {
            riderStageConnection.removeBonusTime(RiderStageConnectionUtilities.getPointsAtPosition(rank, reward));
        }
        riderStageConnection.removeMoney(RiderStageConnectionUtilities.getMoneyAtPosition(rank, reward));
        jRc.deleteFromRealm();
    }
}
Also used : Judgement(ch.hsr.sa.radiotour.dataaccess.models.Judgement) RiderStageConnection(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection) Reward(ch.hsr.sa.radiotour.dataaccess.models.Reward) JudgmentRiderConnection(ch.hsr.sa.radiotour.dataaccess.models.JudgmentRiderConnection)

Example 2 with RiderStageConnection

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

the class RiderStageConnectionRepository method appendTimeInLeadGroup.

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

Example 3 with RiderStageConnection

use of ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection 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.executeTransaction((Realm db) -> {
        RiderStageConnection res = db.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.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);
            }
        }
    });
    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)

Example 4 with RiderStageConnection

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

the class RiderStageConnectionRepository method getAllRiderStateConnections.

@Override
public RealmList<RiderStageConnection> getAllRiderStateConnections() {
    Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
    RealmResults<RiderStageConnection> res = realm.where(RiderStageConnection.class).findAll();
    RealmList<RiderStageConnection> resList = new RealmList<>();
    resList.addAll(res);
    return resList;
}
Also used : RiderStageConnection(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection) RealmList(io.realm.RealmList) Realm(io.realm.Realm)

Example 5 with RiderStageConnection

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

the class RiderStageConnectionRepository method addRiderStageConnection.

@Override
public RiderStageConnection addRiderStageConnection(RiderStageConnection riderStageConnection, OnSaveRiderStageConnectionCallback callback) {
    Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
    final RiderStageConnection transferRiderStateConnection = riderStageConnection;
    RiderStageConnection returnValue;
    realm.beginTransaction();
    RiderStageConnection realmRiderStageConnection = realm.createObject(RiderStageConnection.class, UUID.randomUUID().toString());
    realmRiderStageConnection.setBonusPoint(transferRiderStateConnection.getBonusPoint());
    realmRiderStageConnection.setBonusTime(transferRiderStateConnection.getBonusTime());
    realmRiderStageConnection.setMountainBonusPoints(transferRiderStateConnection.getMountainBonusPoints());
    realmRiderStageConnection.setSprintBonusPoints(transferRiderStateConnection.getSprintBonusPoints());
    realmRiderStageConnection.setOfficialGap(transferRiderStateConnection.getOfficialGap());
    realmRiderStageConnection.setOfficialTime(transferRiderStateConnection.getOfficialTime());
    realmRiderStageConnection.setVirtualGap(transferRiderStateConnection.getVirtualGap());
    realmRiderStageConnection.setType(transferRiderStateConnection.getType());
    realmRiderStageConnection.setMoney(transferRiderStateConnection.getMoney());
    realm.commitTransaction();
    returnValue = realmRiderStageConnection;
    if (callback != null) {
        callback.onSuccess();
    }
    return returnValue;
}
Also used : RiderStageConnection(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection) Realm(io.realm.Realm)

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