Search in sources :

Example 11 with RiderRanking

use of ch.hsr.sa.radiotour.dataaccess.models.RiderRanking 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 12 with RiderRanking

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

the class MaillotsAdapter method getActualLeader.

private void getActualLeader(String type, MaillotViewHolder holder) {
    Rider rider = null;
    RiderRanking riderRanking = null;
    switch(type) {
        case "leader":
            riderRanking = RiderRankingPresenter.getInstance().getFirstInRanking(RankingType.VIRTUAL);
            rider = riderRanking.getRiderStageConnection().getRiders();
            holder.leaderVirtInfo.setText(String.format("%s, %s, (%d)", rider.getName(), rider.getTeamName(), riderRanking.getRank()));
            break;
        case "mountain":
            riderRanking = RiderRankingPresenter.getInstance().getFirstInRanking(RankingType.MOUNTAIN);
            rider = riderRanking.getRiderStageConnection().getRiders();
            holder.leaderVirtInfo.setText(String.format("%s, %s, (%d)", rider.getName(), rider.getTeamName(), riderRanking.getRank()));
            break;
        case "points":
            riderRanking = RiderRankingPresenter.getInstance().getFirstInRanking(RankingType.POINTS);
            rider = riderRanking.getRiderStageConnection().getRiders();
            holder.leaderVirtInfo.setText(String.format("%s, %s, (%d)", rider.getName(), rider.getTeamName(), riderRanking.getRank()));
            break;
        case "bestSwiss":
            riderRanking = RiderRankingPresenter.getInstance().getFirstInRanking(RankingType.SWISS);
            rider = riderRanking.getRiderStageConnection().getRiders();
            holder.leaderVirtInfo.setText(String.format("%s, %s, (%d)", rider.getName(), rider.getTeamName(), riderRanking.getRank()));
            break;
        default:
            break;
    }
    if (rider != null) {
        holder.leaderVirtStart.setText(String.valueOf(rider.getStartNr()));
        holder.leaderVirtFlag.setImageResource(UIUtilitis.getCountryFlag(String.valueOf(rider.getCountry())));
        holder.leaderVirtFlag.setAdjustViewBounds(true);
    }
}
Also used : RiderRanking(ch.hsr.sa.radiotour.dataaccess.models.RiderRanking) Rider(ch.hsr.sa.radiotour.dataaccess.models.Rider)

Aggregations

RiderRanking (ch.hsr.sa.radiotour.dataaccess.models.RiderRanking)12 RiderStageConnection (ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection)10 JSONException (org.json.JSONException)8 RiderStageConnectionComparatorVirtualGap (ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorVirtualGap)3 Rider (ch.hsr.sa.radiotour.dataaccess.models.Rider)2 Realm (io.realm.Realm)2 RiderStageConnectionComparatorDistanceInLead (ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorDistanceInLead)1 RiderStageConnectionComparatorMoney (ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorMoney)1 RiderStageConnectionComparatorMountainPoints (ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorMountainPoints)1 RiderStageConnectionComparatorOfficalGap (ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorOfficalGap)1 RiderStageConnectionComparatorPoints (ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorPoints)1 RiderStageConnectionComparatorTimeInLead (ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorTimeInLead)1 Date (java.util.Date)1 Random (java.util.Random)1 Test (org.junit.Test)1