Search in sources :

Example 6 with RiderStageConnection

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

the class RiderStageConnectionRepository method getRiderStageConnections.

@Override
public void getRiderStageConnections(OnGetAllRiderStageConnectionsCallback callback) {
    Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
    RealmResults<RiderStageConnection> results = realm.where(RiderStageConnection.class).findAll();
    RealmList<RiderStageConnection> res = new RealmList<>();
    res.addAll(results);
    if (callback != null) {
        callback.onSuccess(res);
    }
}
Also used : RiderStageConnection(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection) RealmList(io.realm.RealmList) Realm(io.realm.Realm)

Example 7 with RiderStageConnection

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

the class RiderRepositoryInstrumentedTest method updateRiderStateConnection.

@Test
public void updateRiderStateConnection() {
    RiderStageConnection riderStageConnection = new RiderStageConnection();
    riderStageConnection.setOfficialTime(100);
    riderStageConnection.setOfficialGap(100);
    riderStageConnection.setVirtualGap(100);
    riderStageConnection.setBonusPoint(100);
    riderStageConnection.setBonusTime(200);
    riderStageConnection.setType(RiderStateType.AKTIVE);
    synchronized (this) {
        riderStageConnectionRepository.addRiderStageConnection(riderStageConnection, onSaveRiderStageConnectionCallbackCallback);
    }
    Rider rider = new Rider();
    rider.setCountry("swiss");
    rider.setName("testrider" + 1);
    rider.setStartNr(15);
    rider.setTeamName("Swiss");
    rider.setTeamShortName("CH");
    synchronized (this) {
        riderRepository.addRider(rider, onSaveRiderCallback);
    }
    RealmList<RiderStageConnection> connections = new RealmList<>();
    synchronized (this) {
        connections.add(riderStageConnectionRepository.getAllRiderStateConnections().first());
        riderRepository.updateRiderStageConnection(rider, connections, OnUpdateRiderStageCallback);
    }
    Rider realmRider = realm.where(Rider.class).equalTo("startNr", rider.getStartNr()).findFirst();
    RealmList<RiderStageConnection> riderStageConnections = realmRider.getRiderStages();
    assertEquals(100, riderStageConnections.get(0).getBonusPoint());
    assertEquals(200, riderStageConnections.get(0).getBonusTime());
}
Also used : RiderStageConnection(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection) RealmList(io.realm.RealmList) Rider(ch.hsr.sa.radiotour.dataaccess.models.Rider) Test(org.junit.Test)

Example 8 with RiderStageConnection

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

the class RiderStageConnectionRepositoryInstrumentedTest method updateRiderStageConnectionRank.

@Test
public void updateRiderStageConnectionRank() {
    Date date = new Date();
    RiderRanking virtRank = new RiderRanking();
    virtRank.setRank(1);
    virtRank.setType(RankingType.VIRTUAL);
    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 rSC = realm.where(RiderStageConnection.class).equalTo("virtualGap", riderStageConnection.getVirtualGap()).findFirst();
    synchronized (this) {
        riderStageConnectionRepository.updateRiderStageConnectionRanking(virtRank, rSC);
    }
    rSC = realm.where(RiderStageConnection.class).equalTo("id", rSC.getId()).findFirst();
    assertEquals(1, rSC.getRiderRanking(RankingType.VIRTUAL).getRank());
}
Also used : RiderRanking(ch.hsr.sa.radiotour.dataaccess.models.RiderRanking) RiderStageConnection(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection) Date(java.util.Date) Test(org.junit.Test)

Example 9 with RiderStageConnection

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

the class RiderStageConnectionRepositoryInstrumentedTest method updateRiderState.

@Test
public void updateRiderState() {
    RealmList<RiderStageConnection> riderStageConnections = new RealmList<>();
    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);
    }
    initalRider();
    Rider rider = realm.where(Rider.class).findAll().first();
    RiderStageConnection stageConnection = realm.where(RiderStageConnection.class).findAll().first();
    riderStageConnections.add(stageConnection);
    synchronized (this) {
        riderRepository.updateRiderStageConnection(rider, riderStageConnections, onUpdateRiderStageCallback);
    }
    synchronized (this) {
        riderStageConnectionRepository.updateRiderState(RiderStateType.DROP, rider, onUpdateRiderStateCallBack);
    }
    RiderStageConnection res = riderStageConnectionRepository.getAllRiderStateConnections().first();
    assertEquals(RiderStateType.DROP, res.getType());
}
Also used : RiderStageConnection(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection) RealmList(io.realm.RealmList) Rider(ch.hsr.sa.radiotour.dataaccess.models.Rider) Test(org.junit.Test)

Example 10 with RiderStageConnection

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

the class RiderStageConnectionRepositoryInstrumentedTest method getRiderByRank.

@Test
public void getRiderByRank() {
    initalData();
    RiderStageConnection rider = null;
    for (RiderStageConnection riderStageConnection : riderStageConnectionRepository.getAllRiderStateConnections()) {
        if (riderStageConnection.getBonusPoint() == 20) {
            rider = riderStageConnection;
        }
    }
    assertEquals(100, rider.getOfficialGap());
    assertEquals(100, rider.getVirtualGap());
    assertEquals(100, rider.getOfficialTime());
    assertEquals(20, rider.getBonusPoint());
    assertEquals(400, rider.getMountainBonusPoints());
    assertEquals(300, rider.getSprintBonusPoints());
    assertEquals(40, rider.getBonusTime());
    assertEquals(RiderStateType.DOCTOR, rider.getType());
}
Also used : RiderStageConnection(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection) Test(org.junit.Test)

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