Search in sources :

Example 16 with Match

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

the class MatchBreakdownView2019Test method getView.

private MatchBreakdownView2019 getView(String matchJsonFile) {
    Match match = ModelMaker.getModel(Match.class, matchJsonFile);
    LayoutInflater inflater = LayoutInflater.from(InstrumentationRegistry.getTargetContext());
    View view = inflater.inflate(R.layout.fragment_match_breakdown, null, false);
    FrameLayout matchView = view.findViewById(R.id.match_breakdown);
    assertEquals(1, matchView.getChildCount());
    assertTrue(matchView.getChildAt(0) instanceof MatchBreakdownView2019);
    MatchBreakdownView2019 view2019 = (MatchBreakdownView2019) matchView.getChildAt(0);
    MatchType matchType = MatchType.fromKey(match.getKey());
    view2019.initWithData(matchType, match.getWinningAlliance(), match.getAlliances(), mGson.fromJson(match.getScoreBreakdown(), JsonObject.class));
    view2019.setVisibility(View.VISIBLE);
    // hide progress bar
    view.findViewById(R.id.progress).setVisibility(View.GONE);
    return view2019;
}
Also used : MatchType(com.thebluealliance.androidclient.types.MatchType) LayoutInflater(android.view.LayoutInflater) FrameLayout(android.widget.FrameLayout) JsonObject(com.google.gson.JsonObject) View(android.view.View) Match(com.thebluealliance.androidclient.models.Match)

Example 17 with Match

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

the class TeamMatchVideoNotification method parseMessageData.

@Override
public void parseMessageData() throws JsonParseException {
    JsonObject jsonData = mGson.fromJson(messageData, JsonObject.class);
    if (!jsonData.has("match_key")) {
        throw new JsonParseException("TeamMatchVideoNotification has no match key");
    }
    mMatchKey = jsonData.get("match_key").getAsString();
    mEventKey = MatchHelper.getEventKeyFromMatchKey(mMatchKey);
    mEventName = jsonData.get("event_name").getAsString();
    mMatchTeamKeys = new ArrayList<>();
    mMatch = mGson.fromJson(jsonData.get("match"), Match.class);
    if (mMatch.getAlliances() != null) {
        mMatchTeamKeys.addAll(mMatch.getAlliances().getBlue().getTeamKeys());
        mMatchTeamKeys.addAll(mMatch.getAlliances().getRed().getTeamKeys());
    }
}
Also used : JsonObject(com.google.gson.JsonObject) JsonParseException(com.google.gson.JsonParseException) Match(com.thebluealliance.androidclient.models.Match)

Example 18 with Match

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

the class MatchHelperTest method testGetLastMatchPlayed.

@Test
public void testGetLastMatchPlayed() {
    List<Match> matches;
    Match lastMatch;
    // Empty cases
    assertNull(MatchHelper.getLastMatchPlayed(null));
    assertNull(MatchHelper.getLastMatchPlayed(new ArrayList<>()));
    // No matches played
    matches = mockMatchList(10);
    lastMatch = MatchHelper.getLastMatchPlayed(matches);
    assertNull(lastMatch);
    // One block of matches played
    markMatchesPlayed(matches, 0, 4);
    lastMatch = MatchHelper.getLastMatchPlayed(matches);
    assertEquals(lastMatch, matches.get(3));
    // Data gap
    markMatchesPlayed(matches, 6, 8);
    lastMatch = MatchHelper.getLastMatchPlayed(matches);
    assertEquals(lastMatch, matches.get(7));
    // All matches played
    markMatchesPlayed(matches, 0, 10);
    lastMatch = MatchHelper.getLastMatchPlayed(matches);
    assertEquals(lastMatch, matches.get(9));
}
Also used : ArrayList(java.util.ArrayList) Match(com.thebluealliance.androidclient.models.Match) Test(org.junit.Test)

Example 19 with Match

use of com.thebluealliance.androidclient.models.Match 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)));
    }
}
Also used : PitLocationHelper(com.thebluealliance.androidclient.helpers.PitLocationHelper) ITeamRecord(com.thebluealliance.api.model.ITeamRecord) ITeamAtEventPlayoff(com.thebluealliance.api.model.ITeamAtEventPlayoff) IRankingSortOrder(com.thebluealliance.api.model.IRankingSortOrder) RankingFormatter.buildRankingString(com.thebluealliance.androidclient.helpers.RankingFormatter.buildRankingString) LabeledMatchViewModel(com.thebluealliance.androidclient.viewmodels.LabeledMatchViewModel) ITeamAtEventAlliance(com.thebluealliance.api.model.ITeamAtEventAlliance) Date(java.util.Date) Match(com.thebluealliance.androidclient.models.Match) LabelValueViewModel(com.thebluealliance.androidclient.viewmodels.LabelValueViewModel) SimpleTeamViewModel(com.thebluealliance.androidclient.viewmodels.SimpleTeamViewModel) IRankingItem(com.thebluealliance.api.model.IRankingItem) TeamAtEventStatus(com.thebluealliance.androidclient.models.TeamAtEventStatus) ITeamAtEventQual(com.thebluealliance.api.model.ITeamAtEventQual) EventAwardsEvent(com.thebluealliance.androidclient.eventbus.EventAwardsEvent) Event(com.thebluealliance.androidclient.models.Event) EventMatchesEvent(com.thebluealliance.androidclient.eventbus.EventMatchesEvent) Team(com.thebluealliance.androidclient.models.Team) MatchSortByPlayOrderComparator(com.thebluealliance.androidclient.comparators.MatchSortByPlayOrderComparator) Nullable(javax.annotation.Nullable)

Example 20 with Match

use of com.thebluealliance.androidclient.models.Match 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)

Aggregations

Match (com.thebluealliance.androidclient.models.Match)23 JsonObject (com.google.gson.JsonObject)8 MatchType (com.thebluealliance.androidclient.types.MatchType)6 Test (org.junit.Test)6 LayoutInflater (android.view.LayoutInflater)5 View (android.view.View)5 FrameLayout (android.widget.FrameLayout)5 ArrayList (java.util.ArrayList)4 Event (com.thebluealliance.androidclient.models.Event)3 Nullable (androidx.annotation.Nullable)2 JsonParseException (com.google.gson.JsonParseException)2 MatchSortByPlayOrderComparator (com.thebluealliance.androidclient.comparators.MatchSortByPlayOrderComparator)2 EventMatchesEvent (com.thebluealliance.androidclient.eventbus.EventMatchesEvent)2 MatchAlliancesContainer (com.thebluealliance.androidclient.models.MatchAlliancesContainer)2 Team (com.thebluealliance.androidclient.models.Team)2 List (java.util.List)2 Cursor (android.database.Cursor)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 WorkerThread (androidx.annotation.WorkerThread)1 MatchSortByDisplayOrderComparator (com.thebluealliance.androidclient.comparators.MatchSortByDisplayOrderComparator)1