Search in sources :

Example 6 with RTeam

use of com.cpjd.roblu.models.RTeam in project Roblu by wdavies973.

the class ManualScheduleImporter method run.

@Override
public void run() {
    RForm form = io.loadForm(eventID);
    RTeam[] teams = io.loadTeams(eventID);
    // Load the schedule
    ArrayList<String> lines = new ArrayList<>();
    try {
        InputStream fis = context.getContentResolver().openInputStream(uri);
        BufferedReader br = new BufferedReader(new InputStreamReader(fis));
        String line;
        while ((line = br.readLine()) != null) {
            Log.d("RBS", "Line: " + line);
            lines.add(line);
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        listener.error("File was not found on the system.");
        return;
    } catch (IOException e) {
        e.printStackTrace();
        listener.error("File contains syntax errors. Please double check it for accurate syntax.");
        return;
    }
    if (lines.size() == 0) {
        listener.error("File contains no readable data. Please double check syntax.");
        return;
    }
    for (int i = 0; i < lines.size(); i++) {
        try {
            String[] tokens = lines.get(i).split(",");
            RTeam team = new RTeam(tokens[0], Integer.parseInt(tokens[1]), io.getNewTeamID(eventID));
            /*
                 * Only add the team if it hasn't been found already
                 */
            if (teams != null) {
                for (RTeam local : teams) {
                    // Compare name and number, since IDs will be different
                    if (local.getName().equalsIgnoreCase(team.getName()) && local.getNumber() == team.getNumber()) {
                        team = local;
                        break;
                    }
                }
            }
            // Verify the team against the form
            team.verify(form);
            // The team has been added (or found locally), start processing matches
            for (int j = 2; j < tokens.length; j++) {
                // use j = 2 to ignore name and number
                String name = expandMatchName(tokens[j]);
                boolean isRedAlliance = name.contains("R");
                name = name.replaceAll("B", "").replaceAll("R", "");
                RTab tab = new RTab(team.getNumber(), name, form.getMatch(), isRedAlliance, false, 0);
                // Search for it
                if (team.getTabs() != null) {
                    boolean found = false;
                    for (RTab local : team.getTabs()) {
                        if (local.getTitle().equalsIgnoreCase(tab.getTitle())) {
                            tab = local;
                            found = true;
                            break;
                        }
                    }
                    if (!found) {
                        team.addTab(tab);
                        Collections.sort(team.getTabs());
                    }
                }
            }
            io.saveTeam(eventID, team);
        } catch (Exception e) {
            listener.error("A syntax error occurred one line #" + (i + 1) + ". Please double check syntax.");
            return;
        }
    }
    listener.success();
}
Also used : RTeam(com.cpjd.roblu.models.RTeam) InputStreamReader(java.io.InputStreamReader) RTab(com.cpjd.roblu.models.RTab) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) RForm(com.cpjd.roblu.models.RForm) BufferedReader(java.io.BufferedReader)

Example 7 with RTeam

use of com.cpjd.roblu.models.RTeam in project Roblu by wdavies973.

the class SyncTBAEvent method run.

@Override
public void run() {
    // Load all the teams locally
    RTeam[] teams = io.loadTeams(eventID);
    form = io.loadForm(eventID);
    /*
         * Start processing!
         */
    for (int i = 0; i < event.teams.length; i++) {
        // Check if the team already exists
        boolean found = false;
        if (teams != null) {
            for (RTeam team : teams) {
                if (team.getName().equals(event.teams[i].nickname) && team.getNumber() == event.teams[i].team_number) {
                    syncTeam(team);
                    found = true;
                    break;
                }
            }
        }
        if (!found) {
            RTeam newTeam = new RTeam(event.teams[i].nickname, (int) event.teams[i].team_number, io.getNewTeamID(eventID));
            syncTeam(newTeam);
        }
    }
    listener.done();
}
Also used : RTeam(com.cpjd.roblu.models.RTeam)

Example 8 with RTeam

use of com.cpjd.roblu.models.RTeam in project Roblu by wdavies973.

the class Utils method getMatchTitlesWithinEvent.

/**
 * Returns the match titles within an REvent
 * @return a String[] containing ALL match titles within an REvent, may be null
 */
public static String[] getMatchTitlesWithinEvent(Context context, int eventID) {
    RTeam[] local = new IO(context).loadTeams(eventID);
    // no teams found
    if (local == null || local.length == 0)
        return null;
    ArrayList<RTab> tabs = new ArrayList<>();
    RForm form = new IO(context).loadForm(eventID);
    for (RTeam team : local) {
        team.verify(form);
        // check if the match already exists
        if (team.getTabs() == null || team.getTabs().size() == 0)
            continue;
        for (RTab tab : team.getTabs()) {
            if (tab.getTitle().equalsIgnoreCase("pit") || tab.getTitle().equalsIgnoreCase("predictions"))
                continue;
            boolean found = false;
            for (RTab temp : tabs) {
                if (temp.getTitle().equalsIgnoreCase(tab.getTitle())) {
                    found = true;
                    break;
                }
            }
            if (!found)
                tabs.add(tab);
        }
    }
    if (tabs.size() == 0)
        return null;
    Collections.sort(tabs);
    // Convert to String[]
    String[] values = new String[tabs.size()];
    for (int i = 0; i < tabs.size(); i++) {
        values[i] = tabs.get(i).getTitle();
    }
    return values;
}
Also used : RForm(com.cpjd.roblu.models.RForm) RTeam(com.cpjd.roblu.models.RTeam) RTab(com.cpjd.roblu.models.RTab) IO(com.cpjd.roblu.io.IO) ArrayList(java.util.ArrayList) Point(android.graphics.Point)

Example 9 with RTeam

use of com.cpjd.roblu.models.RTeam in project Roblu by wdavies973.

the class LoadTeamsTask method run.

/**
 * Performs loading, sorting, searching, etc.
 */
@Override
public void run() {
    /*
         * Verify that the event actually exists
         */
    if (ioWeakReference.get() == null || !ioWeakReference.get().doesEventExist(eventID)) {
        quit();
        return;
    }
    /*
         * Next, take care of "reload", if reload is true, teams must be reloaded from the file system
         */
    if (teams == null || teams.size() == 0) {
        RTeam[] local = ioWeakReference.get().loadTeams(eventID);
        // no teams were found locally
        if (local == null || local.length == 0) {
            Log.d("RBS", "LoadTeamsTask found no teams locally stored.");
            teams = null;
            listener.teamsListLoaded(null, false);
            quit();
            return;
        }
        // teams were found locally, so attach them to the teams array
        teams = new ArrayList<>(Arrays.asList(local));
        Log.d("RBS", "LoadTeamsTask loaded " + teams.size() + " teams");
    }
    // threads) finish.
    for (RTeam team : teams) {
        if (team == null) {
            quit();
            return;
        }
    }
    /*
         * Next, each RTeam contains a variable named filter, it's a sort of "helper" variable.
         * Each RTeam has a compareTo method that will allow it to easily be sorted, the filter variable within
         * the team will let the team now how it's to behave when compareTo() is called in it
         */
    for (RTeam team : teams) team.setFilter(filter);
    /*
         * If filter is ANYTHING but SORT_TYPE.SEARCH or SORT_TYPE.CUSTOM_SORT, just run a standard sort.
         * And actually, that also means that we're done with this method, return the teams!
         */
    if (filter == TeamsView.SORT_TYPE.LAST_EDIT || filter == TeamsView.SORT_TYPE.NUMERICAL || filter == TeamsView.SORT_TYPE.ALPHABETICAL) {
        // reset the filter tag
        for (RTeam team : this.teams) team.setFilterTag("");
        try {
            Collections.sort(teams);
            if (filter == TeamsView.SORT_TYPE.LAST_EDIT)
                Collections.reverse(teams);
            listener.teamsListLoaded(this.teams, false);
            quit();
        } catch (Exception e) {
            Log.d("RBS", "A problem occurred while attempting to sort teams with SORT_TYPE = " + filter);
        }
    } else /*
         * Okay, the user actually wants to search, possibly.
         * Let's handle PURE searching next (no custom sort)
         */
    if (filter == TeamsView.SORT_TYPE.SEARCH) {
        for (RTeam team : teams) {
            team.setCustomRelevance(0);
            team.setFilterTag("");
            // assign search relevance to the team
            processTeamForSearch(team);
        }
        try {
            Collections.sort(this.teams);
            Collections.reverse(this.teams);
            listener.teamsListLoaded(this.teams, true);
            quit();
        } catch (Exception e) {
            Log.d("RBS", "A problem occurred while attempting to sort teams with SORT_TYPE = " + filter);
        }
    } else /*
         * Alright, the user actually wants to custom sort, so, let's custom sort, also
         * check to see if query is not null, because searching is also allowing during custom sorting
         */
    if (filter == TeamsView.SORT_TYPE.CUSTOM_SORT) {
        /*
             * Elements Processor is a powerful helper utility. How it works is the following:
             * -Elements Processor will be passed an input (int method defined by TeamMetricProcessor.PROCESS_METHOD, and ID of the metric to analyze
             * -Elements Processor will attach a string to filterTag and a relevance to customRelevance and return the team object, then just sort
             */
        TeamMetricProcessor teamMetricProcessor = new TeamMetricProcessor();
        /*
             * TeamMetricProcessor requires all inputted teams to be synced with the form, so let's do that
             */
        RForm form = ioWeakReference.get().loadForm(eventID);
        for (RTeam team : teams) {
            team.verify(form);
            ioWeakReference.get().saveTeam(eventID, team);
        }
        /*
             * Decode the method process and metric ID from the customSortToken string
             */
        int methodID = Integer.parseInt(customSortToken.split(":")[0]);
        int metricID = Integer.parseInt(customSortToken.split(":")[1]);
        Log.d("RBS", "Custom sorting with methodID: " + methodID + ", metricID: " + metricID);
        /*
             * Make sure to set the extra "matchTitle" parameter if processMethod==PROCESS_METHOD.IN_MATCH
             */
        // for the "In match" option, zero relevance items should be hidden
        boolean shouldHideZeroRelevance = false;
        if (methodID == TeamMetricProcessor.PROCESS_METHOD.OTHER && metricID == TeamMetricProcessor.PROCESS_METHOD.OTHER_METHOD.IN_MATCH && customSortToken.split(":").length == 3) {
            teamMetricProcessor.setInMatchTitle(customSortToken.split(":")[2]);
            Log.d("RBS", "In match title: " + teamMetricProcessor.getInMatchTitle());
            shouldHideZeroRelevance = true;
        } else if (methodID == TeamMetricProcessor.PROCESS_METHOD.MATCHES && customSortToken.split(":").length == 3) {
            teamMetricProcessor.setInMatchTitle(customSortToken.split(":")[2]);
            Log.d("RBS", "In match title: " + teamMetricProcessor.getInMatchTitle());
        }
        /*
             * Next, perform the operation
             */
        for (RTeam team : teams) {
            team.setFilter(filter);
            // reset old filter tags
            team.setFilterTag("");
            // reset any old relevance
            team.setCustomRelevance(0);
            teamMetricProcessor.process(team, methodID, metricID);
        }
        /*
             * Finally, check to see if the user also wants to sort through the array
             */
        for (RTeam team : teams) processTeamForSearch(team);
        try {
            Collections.sort(teams);
            // don't reverse array if sorting by "In matches" since in matches uses numerical sub sort
            if (!(methodID == TeamMetricProcessor.PROCESS_METHOD.OTHER && metricID == TeamMetricProcessor.PROCESS_METHOD.OTHER_METHOD.IN_MATCH))
                Collections.reverse(teams);
            listener.teamsListLoaded(this.teams, shouldHideZeroRelevance);
            quit();
        } catch (Exception e) {
            Log.d("RBS", "A problem occurred while attempting to sort teams with SORT_TYPE = " + filter);
        }
    }
}
Also used : RForm(com.cpjd.roblu.models.RForm) RTeam(com.cpjd.roblu.models.RTeam) TeamMetricProcessor(com.cpjd.roblu.ui.teamsSorting.TeamMetricProcessor)

Example 10 with RTeam

use of com.cpjd.roblu.models.RTeam in project Roblu by wdavies973.

the class PitData method generateSheet.

@Override
public void generateSheet(XSSFSheet sheet, REvent event, RForm form, RTeam[] teams, ArrayList<RCheckout> checkouts) {
    /*
         * Create some styles
         */
    XSSFCellStyle[] styles = { setCellStyle(BorderStyle.THIN, IndexedColors.CORAL, IndexedColors.BLACK, false), setCellStyle(BorderStyle.THIN, IndexedColors.LIGHT_GREEN, IndexedColors.BLACK, false), setCellStyle(BorderStyle.THIN, IndexedColors.GREY_50_PERCENT, IndexedColors.BLACK, false), setCellStyle(BorderStyle.THIN, IndexedColors.CORNFLOWER_BLUE, IndexedColors.BLACK, false) };
    /*
         * Create row 1 (predictions metric names)
         */
    Row metricNames = createRow(sheet, 60);
    setCellStyle(BorderStyle.THIN, IndexedColors.BLACK, IndexedColors.WHITE, true);
    createCell(metricNames, 0, "Team#");
    int styleCounter = 0;
    for (int i = 0; i < form.getMatch().size(); i++) {
        // decide the which style to use
        if (styleCounter == 4)
            styleCounter = 0;
        setStyle(styles[styleCounter]);
        styleCounter++;
        createCell(metricNames, i + 1, form.getMatch().get(i).getTitle() + getPossibleValuesForMetric(form.getMatch().get(i)));
    }
    /*
         * Add divider
         */
    setCellStyle(BorderStyle.THIN, IndexedColors.BLACK, IndexedColors.WHITE, true);
    createCell(metricNames, form.getMatch().size() + 1, "<--PREDICTIONS\nPIT-->");
    /*
         * Add pit metric names
         */
    styleCounter = 0;
    for (int i = 0; i < form.getPit().size(); i++) {
        // decide the which style to use
        if (styleCounter == 4)
            styleCounter = 0;
        setStyle(styles[styleCounter]);
        styleCounter++;
        createCell(metricNames, i + form.getMatch().size() + 2, form.getPit().get(i).getTitle() + getPossibleValuesForMetric(form.getPit().get(i)));
    }
    /*
         * Start adding scouting data
         */
    for (RTeam team : teams) {
        Row row = createRow(sheet);
        // Team number column
        setCellStyle(BorderStyle.THIN, IndexedColors.BLACK, IndexedColors.WHITE, true);
        getStyle().setAlignment(HorizontalAlignment.RIGHT);
        createCell(row, 0, String.valueOf(team.getNumber()));
        // Loop through the form metrics array
        for (int i = 0; i < form.getMatch().size(); i++) {
            // Set style
            setStyle(styles[i % styles.length]);
            // If the team contains the match and the metric is modified, add it to the excel sheet
            // We found the match, let's quickly find the metric
            RMetric teamMetric = null;
            for (RMetric metric : team.getTabs().get(1).getMetrics()) {
                if (metric.getID() == form.getMatch().get(i).getID()) {
                    teamMetric = metric;
                    break;
                }
            }
            if (shouldWriteMetric(team, teamMetric)) {
                if (teamMetric instanceof RStopwatch)
                    createCell(row, 1 + i, ((RStopwatch) teamMetric).getLapsString());
                else
                    createCell(row, 1 + i, teamMetric.toString());
            } else
                createCell(row, 1 + i, "");
        }
        // Add divider column
        setCellStyle(BorderStyle.THIN, IndexedColors.BLACK, IndexedColors.WHITE, true);
        getStyle().setAlignment(HorizontalAlignment.RIGHT);
        createCell(row, 1 + form.getMatch().size(), "");
        // Loop through the pit metrics array
        for (int i = 0; i < form.getPit().size(); i++) {
            // Set style
            setStyle(styles[i % styles.length]);
            RMetric teamMetric = null;
            for (RMetric metric : team.getTabs().get(0).getMetrics()) {
                if (metric.getID() == form.getPit().get(i).getID()) {
                    teamMetric = metric;
                    break;
                }
            }
            // always add the team name and number fields, even if they aren't modified
            if (teamMetric.getID() == 0) {
                createCell(row, 2 + form.getMatch().size() + i, team.getName());
                continue;
            }
            if (teamMetric.getID() == 1) {
                createCell(row, 2 + form.getMatch().size() + i, String.valueOf(team.getNumber()));
                continue;
            }
            if (shouldWriteMetric(team, teamMetric)) {
                if (teamMetric instanceof RStopwatch)
                    createCell(row, 2 + i + form.getMatch().size(), ((RStopwatch) teamMetric).getLapsString());
                else
                    createCell(row, 2 + i + form.getMatch().size(), teamMetric.toString());
            } else
                createCell(row, 2 + i + form.getMatch().size(), "");
        }
    }
}
Also used : RStopwatch(com.cpjd.roblu.models.metrics.RStopwatch) XSSFCellStyle(org.apache.poi.xssf.usermodel.XSSFCellStyle) RTeam(com.cpjd.roblu.models.RTeam) Row(org.apache.poi.ss.usermodel.Row) RMetric(com.cpjd.roblu.models.metrics.RMetric)

Aggregations

RTeam (com.cpjd.roblu.models.RTeam)25 RTab (com.cpjd.roblu.models.RTab)13 IO (com.cpjd.roblu.io.IO)10 RMetric (com.cpjd.roblu.models.metrics.RMetric)10 ArrayList (java.util.ArrayList)10 RForm (com.cpjd.roblu.models.RForm)9 RCheckout (com.cpjd.roblu.models.RCheckout)8 RGallery (com.cpjd.roblu.models.metrics.RGallery)6 REvent (com.cpjd.roblu.models.REvent)5 Bundle (android.os.Bundle)4 RFieldData (com.cpjd.roblu.models.metrics.RFieldData)4 Intent (android.content.Intent)3 RCounter (com.cpjd.roblu.models.metrics.RCounter)3 RStopwatch (com.cpjd.roblu.models.metrics.RStopwatch)3 IOException (java.io.IOException)3 LinkedHashMap (java.util.LinkedHashMap)3 StrictMode (android.os.StrictMode)2 View (android.view.View)2 TextView (android.widget.TextView)2 Request (com.cpjd.http.Request)2