Search in sources :

Example 1 with RiderRanking

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

the class Parser method updateRiderConnectionRankByVirtualGap.

public static String updateRiderConnectionRankByVirtualGap() throws InterruptedException {
    Runnable runnable = new Runnable() {

        public void run() {
            try {
                RealmList<RiderStageConnection> connections = Context.getAllRiderStageConnections();
                connections.sort(new RiderStageConnectionComparatorVirtualGap());
                for (int i = 0; i < connections.size(); i++) {
                    RiderRanking rankingVirtual = new RiderRanking();
                    rankingVirtual.setType(RankingType.VIRTUAL);
                    rankingVirtual.setRank(i + 1);
                    synchronized (this) {
                        Context.addRiderRanking(rankingVirtual);
                    }
                    RiderRanking realmRiderRanking = Context.getRiderRanking(rankingVirtual);
                    Context.updateRiderStageConnectionRanking(realmRiderRanking, connections.get(i));
                }
            } catch (Exception e) {
                Log.d(Parser.class.getSimpleName(), "APP - PARSER - RIDERCONNECTION - " + e.getMessage());
            }
        }
    };
    Thread threadRanking = new Thread(runnable);
    threadRanking.start();
    threadRanking.join();
    return "success";
}
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) JSONException(org.json.JSONException)

Example 2 with RiderRanking

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

the class Parser method updateRiderConnectionRankByPoints.

public static String updateRiderConnectionRankByPoints() throws InterruptedException {
    Runnable runnable = new Runnable() {

        public void run() {
            try {
                RealmList<RiderStageConnection> connections = Context.getAllRiderStageConnections();
                connections.sort(new RiderStageConnectionComparatorPoints());
                for (int i = 0; i < connections.size(); i++) {
                    RiderRanking rankingPoints = new RiderRanking();
                    rankingPoints.setType(RankingType.POINTS);
                    rankingPoints.setRank(i + 1);
                    synchronized (this) {
                        Context.addRiderRanking(rankingPoints);
                    }
                    RiderRanking realmRiderRanking = Context.getRiderRanking(rankingPoints);
                    Context.updateRiderStageConnectionRanking(realmRiderRanking, connections.get(i));
                }
            } catch (Exception e) {
                Log.d(Parser.class.getSimpleName(), "APP - PARSER - RIDERCONNECTION - " + e.getMessage());
            }
        }
    };
    Thread threadRanking = new Thread(runnable);
    threadRanking.start();
    threadRanking.join();
    return "success";
}
Also used : RiderStageConnection(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection) RiderRanking(ch.hsr.sa.radiotour.dataaccess.models.RiderRanking) RiderStageConnectionComparatorPoints(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorPoints) JSONException(org.json.JSONException)

Example 3 with RiderRanking

use of ch.hsr.sa.radiotour.dataaccess.models.RiderRanking 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.setId(new Random().nextLong());
    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) Random(java.util.Random) Date(java.util.Date) Test(org.junit.Test)

Example 4 with RiderRanking

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

the class RiderRankingRepository method addRiderRanking.

@Override
public void addRiderRanking(RiderRanking riderRanking, OnSaveRiderRankingCallback callback) {
    Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
    realm.executeTransaction((Realm db) -> {
        RiderRanking realmRiderRanking = db.createObject(RiderRanking.class, UUID.randomUUID().toString());
        realmRiderRanking.setType(riderRanking.getType());
        realmRiderRanking.setRank(riderRanking.getRank());
    });
    if (callback != null)
        callback.onSuccess();
}
Also used : RiderRanking(ch.hsr.sa.radiotour.dataaccess.models.RiderRanking) Realm(io.realm.Realm)

Example 5 with RiderRanking

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

the class Parser method updateRiderConnectionRankByDistanceInLead.

public static String updateRiderConnectionRankByDistanceInLead() throws InterruptedException {
    Runnable runnable = new Runnable() {

        public void run() {
            try {
                RealmList<RiderStageConnection> connections = Context.getAllRiderStageConnections();
                connections.sort(new RiderStageConnectionComparatorDistanceInLead());
                for (int i = 0; i < connections.size(); i++) {
                    RiderRanking rankingTimeInLead = new RiderRanking();
                    rankingTimeInLead.setType(RankingType.DISTANCE_IN_LEAD);
                    rankingTimeInLead.setRank(i + 1);
                    synchronized (this) {
                        Context.addRiderRanking(rankingTimeInLead);
                    }
                    RiderRanking realmRiderRanking = Context.getRiderRanking(rankingTimeInLead);
                    Context.updateRiderStageConnectionRanking(realmRiderRanking, connections.get(i));
                }
            } catch (Exception e) {
                Log.d(Parser.class.getSimpleName(), "APP - PARSER - RIDERCONNECTION - " + e.getMessage());
            }
        }
    };
    Thread threadRanking = new Thread(runnable);
    threadRanking.start();
    threadRanking.join();
    return "success";
}
Also used : RiderStageConnection(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection) RiderRanking(ch.hsr.sa.radiotour.dataaccess.models.RiderRanking) RiderStageConnectionComparatorDistanceInLead(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorDistanceInLead) JSONException(org.json.JSONException)

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