Search in sources :

Example 31 with Event

use of com.thebluealliance.androidclient.models.Event in project the-blue-alliance-android by the-blue-alliance.

the class MatchListSubscriber method parseData.

@Override
public void parseData() {
    mDataToBind.clear();
    mQualMatches.clear();
    mOctoMatches.clear();
    mQuarterMatches.clear();
    mSemiMatches.clear();
    mFinalMatches.clear();
    // wins, losses, ties
    int[] record = { 0, 0, 0 };
    Match nextMatch = null;
    Match lastMatch = null;
    Event event = mDb.getEventsTable().get(mEventKey);
    if (event != null && event.isHappeningNow()) {
        Collections.sort(mAPIData, new MatchSortByPlayOrderComparator());
    } else {
        Collections.sort(mAPIData, new MatchSortByDisplayOrderComparator());
    }
    ListGroup currentGroup = mQualMatches;
    MatchType lastType = null;
    Match previousIteration = null;
    boolean lastMatchPlayed = false;
    int redFinalsWon = 0;
    int blueFinalsWon = 0;
    if (mAPIData.size() > 0) {
        nextMatch = mAPIData.get(0);
    }
    for (int i = 0; i < mAPIData.size(); i++) {
        Match match = mAPIData.get(i);
        MatchType currentType = MatchType.fromShortType(match.getCompLevel());
        if (lastType != currentType) {
            switch(currentType) {
                case QUAL:
                    currentGroup = mQualMatches;
                    break;
                case OCTO:
                    currentGroup = mOctoMatches;
                    break;
                case QUARTER:
                    currentGroup = mQuarterMatches;
                    break;
                case SEMI:
                    currentGroup = mSemiMatches;
                    break;
                case FINAL:
                    currentGroup = mFinalMatches;
                    break;
            }
        }
        currentGroup.children.add(match);
        if (lastMatchPlayed && !match.hasBeenPlayed()) {
            lastMatch = previousIteration;
            nextMatch = match;
        }
        /* Track alliance advancement, indexed by captain team key */
        if (currentType == MatchType.FINAL && match.hasBeenPlayed()) {
            // Need to ensure we can differentiate who won the finals
            if ("red".equals(match.getWinningAlliance())) {
                redFinalsWon++;
            } else if ("blue".equals(match.getWinningAlliance())) {
                blueFinalsWon++;
            }
        }
        /**
         * the only reason this isn't moved to PopulateTeamAtEvent is that if so,
         * we'd have to iterate through every match again to calculate the
         * record, and that's just wasteful
         */
        if (mTeamKey != null) {
            match.addToRecord(mTeamKey, record);
        }
        lastType = currentType;
        previousIteration = match;
        lastMatchPlayed = match.hasBeenPlayed();
    }
    if (lastMatch == null && !mAPIData.isEmpty()) {
        Match last = mAPIData.get(mAPIData.size() - 1);
        if (last.hasBeenPlayed()) {
            lastMatch = last;
        }
    }
    if (nextMatch != null && nextMatch.hasBeenPlayed()) {
        // Avoids bug where matches loop over when all played
        // Because nextMatch is initialized to the first qual match
        // So that it displayed before any have been played
        nextMatch = null;
    }
    if (!mQualMatches.children.isEmpty()) {
        mDataToBind.add(mQualMatches);
    }
    if (!mOctoMatches.children.isEmpty()) {
        mDataToBind.add(mOctoMatches);
    }
    if (!mQuarterMatches.children.isEmpty()) {
        mDataToBind.add(mQuarterMatches);
    }
    if (!mSemiMatches.children.isEmpty()) {
        mDataToBind.add(mSemiMatches);
    }
    if (!mFinalMatches.children.isEmpty()) {
        mDataToBind.add(mFinalMatches);
    }
    mEventBus.post(new LiveEventMatchUpdateEvent(lastMatch, nextMatch));
}
Also used : MatchType(com.thebluealliance.androidclient.types.MatchType) MatchSortByDisplayOrderComparator(com.thebluealliance.androidclient.comparators.MatchSortByDisplayOrderComparator) ListGroup(com.thebluealliance.androidclient.listitems.ListGroup) LiveEventMatchUpdateEvent(com.thebluealliance.androidclient.eventbus.LiveEventMatchUpdateEvent) EventMatchesEvent(com.thebluealliance.androidclient.eventbus.EventMatchesEvent) Event(com.thebluealliance.androidclient.models.Event) MatchSortByPlayOrderComparator(com.thebluealliance.androidclient.comparators.MatchSortByPlayOrderComparator) LiveEventMatchUpdateEvent(com.thebluealliance.androidclient.eventbus.LiveEventMatchUpdateEvent) Match(com.thebluealliance.androidclient.models.Match)

Example 32 with Event

use of com.thebluealliance.androidclient.models.Event in project the-blue-alliance-android by the-blue-alliance.

the class DistrictRenderer method renderFromKey.

/**
 * Only {@code showMyTba} is preserved from args param
 */
@WorkerThread
@Override
@Nullable
public DistrictListElement renderFromKey(String key, ModelType type, RenderArgs args) {
    District district = mDatafeed.fetchDistrict(key).toBlocking().first();
    if (district == null) {
        return null;
    }
    List<Event> events = mDatafeed.fetchDistrictEvents(key).toBlocking().first();
    RenderArgs newArgs = new RenderArgs(events != null ? events.size() : 0, args != null && args.showMyTba);
    return renderFromModel(district, newArgs);
}
Also used : Event(com.thebluealliance.androidclient.models.Event) District(com.thebluealliance.androidclient.models.District) WorkerThread(androidx.annotation.WorkerThread) Nullable(androidx.annotation.Nullable)

Example 33 with Event

use of com.thebluealliance.androidclient.models.Event in project the-blue-alliance-android by the-blue-alliance.

the class MyTbaModelRenderer method renderFromKey.

@WorkerThread
@Override
@Nullable
public ListElement renderFromKey(String key, ModelType type, Void args) {
    String text;
    switch(type) {
        case EVENT:
            Event event = mDatafeed.fetchEvent(key).toBlocking().first();
            if (event == null) {
                return new ModelListElement(key, key, type);
            }
            return mEventRenderer.renderFromModel(event, true);
        case TEAM:
            Team team = mDatafeed.fetchTeam(key).toBlocking().first();
            if (team == null) {
                return new ModelListElement(key, key, type);
            }
            return mTeamRenderer.renderFromModel(team, TeamRenderer.RENDER_MYTBA_DETAILS);
        case MATCH:
            Match match = mDatafeed.fetchMatch(key).toBlocking().first();
            if (match == null) {
                return new ModelListElement(key, key, type);
            }
            return mMatchRenderer.renderFromModel(match, MatchRenderer.RENDER_DEFAULT);
        case EVENTTEAM:
            String teamKey = EventTeamHelper.getTeamKey(key);
            String eventKey = EventTeamHelper.getEventKey(key);
            Team eTeam = mDatafeed.fetchTeam(teamKey).toBlocking().first();
            Event eEvent = mDatafeed.fetchEvent(eventKey).toBlocking().first();
            if (eTeam == null || eEvent == null) {
                text = String.format("%1$s @ %2$s", teamKey, eventKey);
                return new ModelListElement(text, key, type);
            }
            text = String.format("%1$s @ %2$d %3$s", eTeam.getNickname(), eEvent.getYear(), eEvent.getShortName());
            return new ModelListElement(text, key, type);
        case DISTRICT:
            DistrictListElement element = mDistrictRenderer.renderFromKey(key, ModelType.DISTRICT, new DistrictRenderer.RenderArgs(0, true));
            if (element == null) {
                return new ModelListElement(key, key, type);
            }
            return element;
        default:
            return null;
    }
}
Also used : Event(com.thebluealliance.androidclient.models.Event) ModelListElement(com.thebluealliance.androidclient.listitems.ModelListElement) Team(com.thebluealliance.androidclient.models.Team) DistrictListElement(com.thebluealliance.androidclient.listitems.DistrictListElement) Match(com.thebluealliance.androidclient.models.Match) WorkerThread(androidx.annotation.WorkerThread) Nullable(androidx.annotation.Nullable)

Example 34 with Event

use of com.thebluealliance.androidclient.models.Event in project the-blue-alliance-android by the-blue-alliance.

the class DistrictPointsListSubscriber method parseData.

@Override
public void parseData() {
    mDataToBind.clear();
    JsonObject rankingsData = mAPIData.getAsJsonObject();
    if (!rankingsData.has("points")) {
        return;
    }
    JsonObject points = rankingsData.get("points").getAsJsonObject();
    String districtKey = "";
    Event event = mDb.getEventsTable().get(mEventKey);
    if (event != null) {
        boolean isDistrict = (event.getDistrict() != null);
        ((Type) mDataToBind).isDistrict = isDistrict;
        if (isDistrict) {
            districtKey = event.getDistrict().getKey();
        }
    }
    ArrayList<DistrictPointBreakdown> pointBreakdowns = new ArrayList<>();
    for (Map.Entry<String, JsonElement> teamPoints : points.entrySet()) {
        Team team = mDb.getTeamsTable().get(teamPoints.getKey());
        DistrictPointBreakdown b = mGson.fromJson(teamPoints.getValue(), DistrictPointBreakdown.class);
        b.setTeamKey(teamPoints.getKey());
        b.setTeamName(team != null ? team.getNickname() : "Team " + teamPoints.getKey().substring(3));
        b.setDistrictKey(districtKey);
        pointBreakdowns.add(b);
    }
    Collections.sort(pointBreakdowns, new PointBreakdownComparater());
    for (int i = 0; i < pointBreakdowns.size(); i++) {
        pointBreakdowns.get(i).setRank(i + 1);
        mDataToBind.add(mRenderer.renderFromModel(pointBreakdowns.get(i), null));
    }
}
Also used : ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) JsonElement(com.google.gson.JsonElement) Event(com.thebluealliance.androidclient.models.Event) Team(com.thebluealliance.androidclient.models.Team) PointBreakdownComparater(com.thebluealliance.androidclient.comparators.PointBreakdownComparater) DistrictPointBreakdown(com.thebluealliance.androidclient.models.DistrictPointBreakdown) Map(java.util.Map)

Example 35 with Event

use of com.thebluealliance.androidclient.models.Event in project the-blue-alliance-android by the-blue-alliance.

the class EventsTable method inflate.

@Override
public Event inflate(Cursor cursor) {
    Event event = ModelInflater.inflateEvent(cursor);
    if (event.getDistrictKey() != null) {
        District district = mDistrictsTable.get(event.getDistrictKey());
        event.setDistrict(district);
    }
    return event;
}
Also used : Event(com.thebluealliance.androidclient.models.Event) District(com.thebluealliance.androidclient.models.District)

Aggregations

Event (com.thebluealliance.androidclient.models.Event)35 Test (org.junit.Test)8 Team (com.thebluealliance.androidclient.models.Team)6 ArrayList (java.util.ArrayList)5 District (com.thebluealliance.androidclient.models.District)4 Date (java.util.Date)4 JsonObject (com.google.gson.JsonObject)3 TeamAvatarUpdateEvent (com.thebluealliance.androidclient.eventbus.TeamAvatarUpdateEvent)3 Match (com.thebluealliance.androidclient.models.Match)3 EventRenderer (com.thebluealliance.androidclient.renderers.EventRenderer)3 Before (org.junit.Before)3 Cursor (android.database.Cursor)2 Nullable (androidx.annotation.Nullable)2 WorkerThread (androidx.annotation.WorkerThread)2 JsonElement (com.google.gson.JsonElement)2 MatchSortByPlayOrderComparator (com.thebluealliance.androidclient.comparators.MatchSortByPlayOrderComparator)2 EventMatchesEvent (com.thebluealliance.androidclient.eventbus.EventMatchesEvent)2 LiveEventUpdateEvent (com.thebluealliance.androidclient.eventbus.LiveEventUpdateEvent)2 ListGroup (com.thebluealliance.androidclient.listitems.ListGroup)2 DistrictPointBreakdown (com.thebluealliance.androidclient.models.DistrictPointBreakdown)2