use of com.thebluealliance.api.model.IRankingSortOrder in project the-blue-alliance-android by the-blue-alliance.
the class RankingsListSubscriber method parseData.
@Override
public void parseData() {
mDataToBind.clear();
if (mAPIData == null || mAPIData.getRankings() == null || mAPIData.getRankings().isEmpty()) {
return;
}
List<IRankingItem> rankings = mAPIData.getRankings();
List<IRankingSortOrder> sortOrders = mAPIData.getSortOrderInfo();
List<IRankingSortOrder> extraStats = mAPIData.getExtraStatsInfo();
IRankingSortOrder firstSortInfo = sortOrders.remove(0);
for (int i = 0; i < rankings.size(); i++) {
IRankingItem row = rankings.get(i);
/* Assume that the list of lists has rank first and team # second, always */
String teamKey = row.getTeamKey();
String rankingString;
String rankingSummary;
String record;
@Nullable ITeamRecord teamRecord = row.getRecord();
if (teamRecord != null) {
record = "(" + RankingItem.TeamRecord.buildRecordString(teamRecord) + ")";
} else {
record = "";
}
// Remove the first sort item so we don't show duplicates
Double firstSort = row.getSortOrders().remove(0);
rankingSummary = mResources.getString(R.string.rank_item_summary, firstSortInfo.getName(), formatSortOrder(firstSortInfo, firstSort));
rankingString = buildRankingString(row, sortOrders, extraStats, mResources, BOLD_TITLES | LINE_BREAKS);
Team team = mDb.getTeamsTable().get(teamKey);
String nickname;
if (team != null) {
nickname = team.getNickname();
} else {
nickname = "Team " + teamKey.substring(3);
}
mDataToBind.add(new TeamRankingViewModel(teamKey, nickname, // team number
teamKey.substring(3), // rank
row.getRank(), record, rankingSummary, rankingString));
}
mEventBus.post(new EventRankingsEvent(generateTopRanksString(mAPIData)));
}
use of com.thebluealliance.api.model.IRankingSortOrder in project the-blue-alliance-android by the-blue-alliance.
the class RankingsResponseDeserializer method deserialize.
@Override
public RankingResponseObject deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject rankingsObject = json.getAsJsonObject();
RankingResponseObject rankingResponse = new RankingResponseObject();
List<IRankingItem> teamRanks = new ArrayList<>();
List<IRankingSortOrder> sortOrders;
List<IRankingSortOrder> extraStats;
if (!isNull(rankingsObject.get("rankings"))) {
JsonArray rankJson = rankingsObject.get("rankings").getAsJsonArray();
for (int i = 0; i < rankJson.size(); i++) {
teamRanks.add(context.deserialize(rankJson.get(i), RankingItem.class));
}
}
if (!isNull(rankingsObject.get("sort_order_info"))) {
JsonArray sortOrderJson = rankingsObject.get("sort_order_info").getAsJsonArray();
sortOrders = context.deserialize(sortOrderJson, new TypeToken<List<RankingSortOrder>>() {
}.getType());
} else {
sortOrders = new ArrayList<>();
}
if (!isNull(rankingsObject.get("extra_stats_info"))) {
JsonArray extraStatsJson = rankingsObject.get("extra_stats_info").getAsJsonArray();
extraStats = context.deserialize(extraStatsJson, new TypeToken<List<RankingSortOrder>>() {
}.getType());
} else {
extraStats = new ArrayList<>();
}
rankingResponse.setRankings(teamRanks);
rankingResponse.setSortOrderInfo(sortOrders);
rankingResponse.setExtraStatsInfo(extraStats);
return rankingResponse;
}
use of com.thebluealliance.api.model.IRankingSortOrder in project the-blue-alliance-android by the-blue-alliance.
the class TeamAtEventStatusDeserializer method deserialize.
@Override
public TeamAtEventStatus deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject data = json.getAsJsonObject();
TeamAtEventStatus status = new TeamAtEventStatus();
if (!isNull(data.get("alliance"))) {
JsonObject allianceJson = data.getAsJsonObject("alliance");
TeamAtEventStatus.TeamAtEventAlliance alliance = new TeamAtEventStatus.TeamAtEventAlliance();
alliance.setName(allianceJson.get("name").getAsString());
alliance.setNumber(allianceJson.get("number").getAsInt());
alliance.setPick(allianceJson.get("pick").getAsInt());
if (!isNull(allianceJson.get("backup"))) {
alliance.setBackup(context.deserialize(allianceJson.get("backup"), IAllianceBackup.class));
}
status.setAlliance(alliance);
}
if (!isNull(data.get("alliance_status_str"))) {
status.setAllianceStatusStr(data.get("alliance_status_str").getAsString());
}
if (!isNull(data.get("overall_status_str"))) {
status.setOverallStatusStr(data.get("overall_status_str").getAsString());
}
if (!isNull(data.get("playoff_status_str"))) {
status.setPlayoffStatusStr(data.get("playoff_status_str").getAsString());
}
if (!isNull(data.get("playoff"))) {
JsonObject playoffJson = data.getAsJsonObject("playoff");
TeamAtEventPlayoff playoff = context.deserialize(playoffJson, TeamAtEventPlayoff.class);
status.setPlayoff(playoff);
}
if (!isNull(data.get("qual"))) {
JsonObject qualJson = data.getAsJsonObject("qual");
TeamAtEventStatus.TeamAtEventQual qual = new TeamAtEventStatus.TeamAtEventQual();
RankingItem teamRank = context.deserialize(qualJson.get("ranking"), RankingItem.class);
List<IRankingSortOrder> sortOrders = context.deserialize(qualJson.get("sort_order_info"), new TypeToken<List<IRankingSortOrder>>() {
}.getType());
qual.setRanking(teamRank);
qual.setSortOrderInfo(sortOrders);
qual.setNumTeams(qualJson.get("num_teams").getAsInt());
qual.setStatus(qualJson.get("status").getAsString());
status.setQual(qual);
}
return status;
}
use of com.thebluealliance.api.model.IRankingSortOrder in project the-blue-alliance-android by the-blue-alliance.
the class RankingFormatter method buildRankingString.
public static String buildRankingString(IRankingItem rankData, List<IRankingSortOrder> sortOrders, @Nullable List<IRankingSortOrder> extraStats, Resources resources, @RankingStringOptions int flags) {
Map<String, String> rankingElements = new LinkedHashMap<>();
if (rankData.getQualAverage() != null) {
rankingElements.put(resources.getString(R.string.rank_qual_average), ThreadSafeFormatters.formatDoubleOnePlace(rankData.getQualAverage()));
}
for (int j = 0; j < Math.min(sortOrders.size(), rankData.getSortOrders().size()); j++) {
String rankString;
Double rankValue = rankData.getSortOrders().get(j);
IRankingSortOrder sort = sortOrders.get(j);
rankString = formatSortOrder(sort, rankValue);
rankingElements.put(sort.getName(), rankString);
}
for (int j = 0; extraStats != null && j < Math.min(extraStats.size(), rankData.getExtraStats().size()); j++) {
String rankString;
Double rankValue = rankData.getExtraStats().get(j);
IRankingSortOrder sort = extraStats.get(j);
rankString = formatSortOrder(sort, rankValue);
rankingElements.put(sort.getName(), rankString);
}
rankingElements.put(resources.getString(R.string.rank_played), Integer.toString(rankData.getMatchesPlayed()));
rankingElements.put(resources.getString(R.string.rank_dq), Integer.toString(rankData.getDq()));
return createRankingBreakdown(rankingElements, flags);
}
use of com.thebluealliance.api.model.IRankingSortOrder in project the-blue-alliance-android by the-blue-alliance.
the class TeamAtEventSummarySubscriber method parseData.
@Override
public synchronized void parseData() {
mDataToBind.clear();
Match nextMatch = null, lastMatch = null;
@Nullable TeamAtEventStatus status = mAPIData.status;
@Nullable ITeamAtEventAlliance allianceData = status != null ? status.getAlliance() : null;
@Nullable ITeamAtEventQual qualData = status != null ? status.getQual() : null;
@Nullable ITeamAtEventPlayoff playoffData = status != null ? status.getPlayoff() : null;
Event event = mAPIData.event;
Date now = new Date();
if (event == null) {
return;
}
Team team = mAPIData.team;
if (team == null) {
return;
}
int year = event.getYear();
boolean activeEvent = event.isHappeningNow();
String playoffStatusString = status != null ? status.getPlayoffStatusStr() : "";
String allianceStatusString = status != null ? status.getAllianceStatusStr() : "";
String overallStatusString;
if (status != null) {
overallStatusString = status.getOverallStatusStr();
} else if (now.before(event.getStartDate())) {
overallStatusString = mResources.getString(R.string.team_at_event_future_event);
} else {
overallStatusString = "";
}
String qualRecordString;
@Nullable ITeamRecord qualRecord = null;
if (qualData != null && qualData.getRanking() != null && qualData.getRanking().getRecord() != null) {
qualRecord = qualData.getRanking().getRecord();
}
if (qualRecord != null) {
qualRecordString = RankingItem.TeamRecord.buildRecordString(qualRecord);
} else {
qualRecordString = "";
}
if (activeEvent && mIsMatchListLoaded) {
Collections.sort(mMatches, new MatchSortByPlayOrderComparator());
nextMatch = MatchHelper.getNextMatchPlayed(mMatches);
lastMatch = MatchHelper.getLastMatchPlayed(mMatches);
}
int rank = 0;
String rankingString = "";
LabelValueViewModel rankBreakdownItem = null;
@Nullable IRankingItem rankData = qualData != null ? qualData.getRanking() : null;
@Nullable List<IRankingSortOrder> sortOrders = qualData != null ? qualData.getSortOrderInfo() : null;
if (rankData != null && sortOrders != null) {
rank = rankData.getRank();
rankingString = buildRankingString(rankData, sortOrders, null, mResources, NONE);
rankBreakdownItem = new LabelValueViewModel(mResources.getString(R.string.team_at_event_rank_breakdown), rankingString);
}
// Basic information about the team
mDataToBind.add(new SimpleTeamViewModel(team.getKey(), team.getNickname(), team.getLocation(), year));
// Rank
if (rank > 0) {
mDataToBind.add(new LabelValueViewModel(mResources.getString(R.string.team_at_event_rank), rank + Utilities.getOrdinalFor(rank)));
}
// Number of awards, only if nonzero
if (mIsAwardListLoaded && mAwards.size() > 0) {
String awardsString;
if (mAwards.size() == 1) {
awardsString = mResources.getString(R.string.team_at_event_awards_format_one);
} else {
awardsString = mResources.getString(R.string.team_at_event_awards_format, mAwards.size());
}
mDataToBind.add(new LabelValueViewModel(mResources.getString(R.string.awards_header), awardsString));
}
// Pit Location Stuff
if (PitLocationHelper.shouldShowPitLocationAtEvent(mAppConfig, mEventKey)) {
PitLocationHelper.TeamPitLocation location = PitLocationHelper.getPitLocation(mContext, mTeamKey);
if (location != null) {
mDataToBind.add(new LabelValueViewModel(mResources.getString(R.string.pit_location), location.getAddressString()));
}
}
/* Team Qual Record
* Don't show for 2015 events, because no wins and such */
if (year != 2015 && !RankingItem.TeamRecord.isEmpty(qualRecord)) {
mDataToBind.add(new LabelValueViewModel(mResources.getString(R.string.team_at_event_qual_record), qualRecordString));
}
// Alliance
if (allianceData != null) {
mDataToBind.add(new LabelValueViewModel(mResources.getString(R.string.team_at_event_alliance), Html.fromHtml(allianceStatusString)));
}
// Alliance Status
mDataToBind.add(new LabelValueViewModel(mResources.getString(R.string.team_at_event_status), Html.fromHtml(playoffData != null ? playoffStatusString : overallStatusString)));
// Ranking Breakdown
if (rankingString != null && !rankingString.isEmpty()) {
mDataToBind.add(rankBreakdownItem);
}
if (lastMatch != null) {
mDataToBind.add(new LabeledMatchViewModel(mResources.getString(R.string.title_last_match), mMatchRenderer.renderFromModel(lastMatch, MatchRenderer.RENDER_DEFAULT)));
}
if (nextMatch != null) {
mDataToBind.add(new LabeledMatchViewModel(mResources.getString(R.string.title_next_match), mMatchRenderer.renderFromModel(nextMatch, MatchRenderer.RENDER_DEFAULT)));
}
}
Aggregations