use of ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection in project app by TourLive.
the class Parser method updateRiderConnectionRankByOfficalGap.
private static void updateRiderConnectionRankByOfficalGap() throws InterruptedException {
Runnable runnable = new Runnable() {
public void run() {
try {
RealmList<RiderStageConnection> connections = Context.getAllRiderStageConnections();
connections.sort(new RiderStageConnectionComparatorOfficalGap());
for (int i = 0; i < connections.size(); i++) {
RiderRanking rankingOfficial = new RiderRanking();
rankingOfficial.setType(RankingType.OFFICAL);
rankingOfficial.setRank(i + 1);
synchronized (this) {
Context.addRiderRanking(rankingOfficial);
}
RiderRanking realmRiderRanking = Context.getRiderRanking(rankingOfficial);
Context.updateRiderStageConnectionRanking(realmRiderRanking, connections.get(i));
}
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));
}
connections.sort(new RiderStageConnectionComparatorMountainPoints());
for (int i = 0; i < connections.size(); i++) {
RiderRanking rankingMountain = new RiderRanking();
rankingMountain.setType(RankingType.MOUNTAIN);
rankingMountain.setRank(i + 1);
synchronized (this) {
Context.addRiderRanking(rankingMountain);
}
RiderRanking realmRiderRanking = Context.getRiderRanking(rankingMountain);
Context.updateRiderStageConnectionRanking(realmRiderRanking, connections.get(i));
}
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));
}
connections.sort(new RiderStageConnectionComparatorVirtualGap());
int rank = 1;
for (int i = 0; i < connections.size(); i++) {
if (connections.get(i).getRiders().getCountry().equals("SUI")) {
RiderRanking rankingSwiss = new RiderRanking();
rankingSwiss.setType(RankingType.SWISS);
rankingSwiss.setRank(rank);
rank++;
synchronized (this) {
Context.addRiderRanking(rankingSwiss);
}
RiderRanking realmRiderRanking = Context.getRiderRanking(rankingSwiss);
Context.updateRiderStageConnectionRanking(realmRiderRanking, connections.get(i));
}
}
for (int i = 0; i < connections.size(); i++) {
RiderRanking rankingMoney = new RiderRanking();
rankingMoney.setType(RankingType.MONEY);
rankingMoney.setRank(i + 1);
synchronized (this) {
Context.addRiderRanking(rankingMoney);
}
RiderRanking realmRiderRanking = Context.getRiderRanking(rankingMoney);
Context.updateRiderStageConnectionRanking(realmRiderRanking, connections.get(i));
}
for (int i = 0; i < connections.size(); i++) {
RiderRanking rankingTimeInLead = new RiderRanking();
rankingTimeInLead.setType(RankingType.TIME_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();
}
Aggregations