Search in sources :

Example 11 with RiderStageConnection

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

the class RiderStageConnectionRepositoryInstrumentedTest method initalData.

private void initalData() {
    RiderStageConnection riderStageConnection = new RiderStageConnection();
    riderStageConnection.setBonusPoint(10);
    riderStageConnection.setBonusTime(20);
    riderStageConnection.setSprintBonusPoints(100);
    riderStageConnection.setMountainBonusPoints(200);
    riderStageConnection.setOfficialGap(100);
    riderStageConnection.setOfficialTime(100);
    riderStageConnection.setType(RiderStateType.DNC);
    riderStageConnection.setVirtualGap(100);
    RiderStageConnection riderStageConnectionTwo = new RiderStageConnection();
    riderStageConnectionTwo.setBonusPoint(20);
    riderStageConnectionTwo.setSprintBonusPoints(300);
    riderStageConnectionTwo.setMountainBonusPoints(400);
    riderStageConnectionTwo.setBonusTime(40);
    riderStageConnectionTwo.setOfficialGap(100);
    riderStageConnectionTwo.setOfficialTime(100);
    riderStageConnectionTwo.setType(RiderStateType.DOCTOR);
    riderStageConnectionTwo.setVirtualGap(100);
    synchronized (this) {
        riderStageConnectionRepository.addRiderStageConnection(riderStageConnection, onSaveRiderStageConnectionCallback);
        riderStageConnectionRepository.addRiderStageConnection(riderStageConnectionTwo, onSaveRiderStageConnectionCallback);
    }
}
Also used : RiderStageConnection(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection)

Example 12 with RiderStageConnection

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

the class StageRepositoryInstrumentedTest method addStage.

@Test
public void addStage() {
    RiderStageConnection riderStageConnection = new RiderStageConnection();
    riderStageConnection.setBonusPoint(10);
    riderStageConnection.setBonusTime(20);
    riderStageConnection.setOfficialGap(100);
    riderStageConnection.setOfficialTime(100);
    riderStageConnection.setType(RiderStateType.DNC);
    riderStageConnection.setVirtualGap(100);
    synchronized (this) {
        riderStageConnectionRepository.addRiderStageConnection(riderStageConnection, onSaveRiderStageConnectionCallback);
        riderStageConnection.setBonusPoint(100);
        riderStageConnectionRepository.addRiderStageConnection(riderStageConnection, onSaveRiderStageConnectionCallback);
    }
    RealmList<RiderStageConnection> connections = new RealmList<>();
    RealmResults<RiderStageConnection> realmConnections = realm.where(RiderStageConnection.class).findAll();
    connections.addAll(realmConnections);
    Stage stage = new Stage();
    stage.setStageId(1);
    stage.setDistance(100);
    stage.setStartTime(new Date());
    stage.setEndTime(new Date());
    stage.setFrom("bern");
    stage.setTo("zuerich");
    stage.setName("Etappe 1");
    stage.setType(StageType.FLATSTAGE);
    stage.setStageConnections(connections);
    synchronized (this) {
        stageRepository.addStage(stage, onSaveStageCallback);
    }
    Assert.assertEquals(100, realm.where(Stage.class).findAll().first().getDistance());
    Assert.assertEquals("bern", realm.where(Stage.class).findAll().first().getFrom());
    Assert.assertEquals("Etappe 1", realm.where(Stage.class).findAll().first().getName());
    Assert.assertEquals(2, realm.where(Stage.class).findAll().first().getStageConnections().size());
    Assert.assertEquals(20, realm.where(Stage.class).findAll().first().getStageConnections().first().getBonusTime());
}
Also used : RiderStageConnection(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection) RealmList(io.realm.RealmList) Stage(ch.hsr.sa.radiotour.dataaccess.models.Stage) Date(java.util.Date) Test(org.junit.Test)

Example 13 with RiderStageConnection

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

the class JudgmentDetailFragment method updateRiderStateConnectionWithPerformance.

private void updateRiderStateConnectionWithPerformance(Rider rider, int rank) {
    int r = rider.getStartNr();
    new Thread(() -> {
        Judgement judgement = JudgmentPresenter.getInstance().getJudgmentByObjectIdReturned(judgementID);
        rewardM = RewardPresenter.getInstance().getRewardReturnedByJudgment(judgement);
        RiderStageConnection riderStageConnection = new RiderStageConnection();
        riderStageConnection.setId(RiderPresenter.getInstance().getRiderByStartNr(r).getRiderStages().first().getId());
        if (rewardM.getType() == RewardType.TIME) {
            riderStageConnection.setBonusTime(RiderStageConnectionUtilities.getPointsAtPosition(rank, rewardM));
        } else if (rewardM.getType() == RewardType.POINTS) {
            int points = RiderStageConnectionUtilities.getPointsAtPosition(rank, rewardM);
            if (judgement.getName().toLowerCase().contains("sprint")) {
                riderStageConnection.setSprintBonusPoints(points);
                riderStageConnection.setBonusPoint(points);
            } else if (judgement.getName().toLowerCase().contains("bergpreis")) {
                riderStageConnection.setMountainBonusPoints(points);
            } else {
                riderStageConnection.setBonusPoint(points);
            }
        } else {
            Log.d(JudgmentDetailFragment.class.getSimpleName(), "APP - CALCULATE - UNSUPPORTED TYPE");
        }
        riderStageConnection.setMoney(RiderStageConnectionUtilities.getMoneyAtPosition(rank, rewardM));
        RiderStageConnectionPresenter.getInstance().updateRiderStageConnectionReward(riderStageConnection);
    }).start();
}
Also used : Judgement(ch.hsr.sa.radiotour.dataaccess.models.Judgement) RiderStageConnection(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection)

Example 14 with RiderStageConnection

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

the class RiderStageConnectionRepository method updateRiderStageConnectionRanking.

@Override
public void updateRiderStageConnectionRanking(final RiderRanking riderRanking, final RiderStageConnection connection) {
    Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
    realm.executeTransaction((Realm db) -> {
        RiderStageConnection res = db.where(RiderStageConnection.class).equalTo("id", connection.getId()).findFirst();
        res.addRiderRanking(riderRanking);
    });
}
Also used : RiderStageConnection(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection) Realm(io.realm.Realm)

Example 15 with RiderStageConnection

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

the class RiderStageConnectionRepository method updateRiderState.

@Override
public void updateRiderState(final RiderStateType type, final Rider rider, OnUpdateRiderStateCallBack callback) {
    Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
    realm.beginTransaction();
    Rider res = realm.where(Rider.class).equalTo("id", rider.getId()).findFirst();
    for (RiderStageConnection sC : res.getRiderStages()) {
        if (sC.getType() == type) {
            sC.setType(RiderStateType.AKTIVE);
        } else {
            sC.setType(type);
        }
    }
    realm.commitTransaction();
    RiderStageConnection state = realm.where(RiderStageConnection.class).equalTo("riders.id", rider.getId()).findFirst();
    if (callback != null)
        callback.onSuccess(state);
}
Also used : RiderStageConnection(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection) Realm(io.realm.Realm) Rider(ch.hsr.sa.radiotour.dataaccess.models.Rider)

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