Search in sources :

Example 26 with Rider

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

the class RiderStageConnectionRepository method updateRiderStageConnectionTime.

@Override
public void updateRiderStageConnectionTime(long timeBefore, long timeStamp, final RaceGroup res, OnUpdateRiderStageConnectionCallBack callback) {
    Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
    realm.beginTransaction();
    if (timeBefore > 0 && !res.getRiders().isEmpty()) {
        for (Rider r : res.getRiders()) {
            if (!r.getRiderStages().isEmpty()) {
                r.getRiderStages().first().setVirtualGap(r.getRiderStages().first().getVirtualGap() - timeBefore);
            }
        }
    }
    if (!res.getRiders().isEmpty()) {
        for (Rider r : res.getRiders()) {
            if (!r.getRiderStages().isEmpty()) {
                r.getRiderStages().first().setVirtualGap(r.getRiderStages().first().getVirtualGap() + timeStamp);
            }
        }
    }
    RealmResults<RiderStageConnection> connections = realm.where(RiderStageConnection.class).findAll();
    List<RiderStageConnection> cons = realm.copyFromRealm(connections);
    cons.sort(new RiderStageConnectionComparatorVirtualGap());
    for (int i = 0; i < cons.size(); i++) {
        RiderRanking riderRanking = realm.where(RiderStageConnection.class).equalTo("id", cons.get(i).getId()).findFirst().getRiderRanking(RankingType.VIRTUAL);
        if (riderRanking != null) {
            riderRanking.setRank(i + 1);
        }
    }
    realm.commitTransaction();
    if (callback != null) {
        callback.onSuccess();
    }
}
Also used : RiderStageConnectionComparatorVirtualGap(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorVirtualGap) RiderStageConnection(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection) RiderRanking(ch.hsr.sa.radiotour.dataaccess.models.RiderRanking) Realm(io.realm.Realm) Rider(ch.hsr.sa.radiotour.dataaccess.models.Rider)

Example 27 with Rider

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

the class UIUtilitis method getCountsPerLine.

public static HashMap<Integer, Integer> getCountsPerLine(RealmList<Rider> riders) {
    HashMap<Integer, Integer> number = new HashMap<>();
    if (!riders.isEmpty()) {
        for (Rider r : riders) {
            int startnr = r.getStartNr();
            int firstNumber = UIUtilitis.getFirstDigit(startnr);
            int temp = 1;
            if (number.containsKey(firstNumber)) {
                temp = number.get(firstNumber) + 1;
            }
            number.put(firstNumber, temp);
        }
    }
    number.put(30, 1);
    return number;
}
Also used : HashMap(java.util.HashMap) Rider(ch.hsr.sa.radiotour.dataaccess.models.Rider)

Example 28 with Rider

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

the class JudgmentRiderConnectionInstrumentedTest method addRewardRiderConnection.

@Test
public void addRewardRiderConnection() {
    addRider();
    addJudgment();
    RealmList<Rider> riderList = new RealmList<>();
    RealmList<Judgement> judgementList = new RealmList<>();
    riderList.add(RiderPresenter.getInstance().getRiderByStartNr(15));
    judgementList.add(JudgmentPresenter.getInstance().getJudgmentsById(93).first());
    JudgmentRiderConnection judgmentRiderConnection = new JudgmentRiderConnection();
    judgmentRiderConnection.setRank(1);
    judgmentRiderConnection.setJudgements(judgementList);
    judgmentRiderConnection.setRider(riderList);
    synchronized (this) {
        judgmentRiderConnectionRepository.addJudgmentRiderConnection(judgmentRiderConnection, onSaveJudgmentRiderConnectionCallback);
    }
    Assert.assertEquals(1, realm.where(JudgmentRiderConnection.class).findAll().first().getRank());
}
Also used : RealmList(io.realm.RealmList) Judgement(ch.hsr.sa.radiotour.dataaccess.models.Judgement) Rider(ch.hsr.sa.radiotour.dataaccess.models.Rider) JudgmentRiderConnection(ch.hsr.sa.radiotour.dataaccess.models.JudgmentRiderConnection) Test(org.junit.Test)

Example 29 with Rider

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

the class JudgmentRiderConnectionInstrumentedTest method clearAllRewardRiderConnections.

@Test
public void clearAllRewardRiderConnections() {
    addRider();
    addJudgment();
    RealmList<Rider> riderList = new RealmList<>();
    RealmList<Judgement> judgementList = new RealmList<>();
    riderList.add(RiderPresenter.getInstance().getRiderByStartNr(15));
    judgementList.add(JudgmentPresenter.getInstance().getJudgmentsById(93).first());
    JudgmentRiderConnection judgmentRiderConnection = new JudgmentRiderConnection();
    judgmentRiderConnection.setRank(1);
    judgmentRiderConnection.setJudgements(judgementList);
    judgmentRiderConnection.setRider(riderList);
    synchronized (this) {
        judgmentRiderConnectionRepository.addJudgmentRiderConnection(judgmentRiderConnection, onSaveJudgmentRiderConnectionCallback);
    }
    synchronized (this) {
        judgmentRiderConnectionRepository.clearAllJudgmentRiderConnections();
    }
    Assert.assertEquals(0, realm.where(JudgmentRiderConnection.class).findAll().size());
}
Also used : RealmList(io.realm.RealmList) Judgement(ch.hsr.sa.radiotour.dataaccess.models.Judgement) Rider(ch.hsr.sa.radiotour.dataaccess.models.Rider) JudgmentRiderConnection(ch.hsr.sa.radiotour.dataaccess.models.JudgmentRiderConnection) Test(org.junit.Test)

Example 30 with Rider

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

the class JudgmentRiderConnectionInstrumentedTest method addRider.

private void addRider() {
    Rider rider = new Rider();
    rider.setCountry("swiss");
    rider.setName("testrider");
    rider.setStartNr(15);
    rider.setTeamName("Swiss");
    rider.setTeamShortName("CH");
    synchronized (this) {
        riderRepository.addRider(rider, onSaveRiderCallback);
    }
}
Also used : Rider(ch.hsr.sa.radiotour.dataaccess.models.Rider)

Aggregations

Rider (ch.hsr.sa.radiotour.dataaccess.models.Rider)46 RealmList (io.realm.RealmList)17 Realm (io.realm.Realm)13 RaceGroup (ch.hsr.sa.radiotour.dataaccess.models.RaceGroup)9 Test (org.junit.Test)9 RiderStageConnection (ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection)5 TextView (android.widget.TextView)3 Judgement (ch.hsr.sa.radiotour.dataaccess.models.Judgement)3 JSONException (org.json.JSONException)3 Fragment (android.support.v4.app.Fragment)2 View (android.view.View)2 JudgmentRiderConnection (ch.hsr.sa.radiotour.dataaccess.models.JudgmentRiderConnection)2 RiderRanking (ch.hsr.sa.radiotour.dataaccess.models.RiderRanking)2 Manifest (android.Manifest)1 AlertDialog (android.app.AlertDialog)1 TimePickerDialog (android.app.TimePickerDialog)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 PackageManager (android.content.pm.PackageManager)1 Location (android.location.Location)1