Search in sources :

Example 1 with RFieldData

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

the class MetricEditor method onItemSelected.

/**
 * Called when the user selects a metric type
 * @param adapterView the adapter containing all the choices
 * @param view the view that was tapped
 * @param i the position of the view
 * @param l id of the view
 */
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
    ((TextView) adapterView.getChildAt(0)).setTextColor(rui.getText());
    /*
         * User selected a new metric, let's create it
         */
    String stringOfSelected = METRIC_TYPES[i];
    if (stringOfSelected.equals(METRIC_TYPES[0])) {
        metric = new RBoolean(0, "Boolean", false);
    } else if (stringOfSelected.equals(METRIC_TYPES[1])) {
        metric = new RCounter(0, "Counter", 1, 0);
    } else if (stringOfSelected.equals(METRIC_TYPES[2])) {
        metric = new RSlider(0, "Slider", 0, 100, 0);
    } else if (stringOfSelected.equals(METRIC_TYPES[3])) {
        metric = new RChooser(0, "Chooser", null, 0);
    } else if (stringOfSelected.equals(METRIC_TYPES[4])) {
        metric = new RCheckbox(0, "Checkbox", null);
    } else if (stringOfSelected.equals(METRIC_TYPES[5])) {
        metric = new RStopwatch(0, "Stopwatch", 0);
    } else if (stringOfSelected.equals(METRIC_TYPES[6])) {
        metric = new RTextfield(0, "Text field", "");
    } else if (stringOfSelected.equals(METRIC_TYPES[7])) {
        metric = new RGallery(0, "Gallery");
    } else if (stringOfSelected.equalsIgnoreCase(METRIC_TYPES[8])) {
        metric = new RDivider(0, "Divider");
    } else if (stringOfSelected.equals(METRIC_TYPES[9])) {
        metric = new RFieldDiagram(0, R.drawable.field2018, null);
    } else if (stringOfSelected.equals(METRIC_TYPES[10])) {
        metric = new RCalculation(0, "Custom calculation");
    } else if (stringOfSelected.equals(METRIC_TYPES[11])) {
        metric = new RFieldData(0, "Match data");
    }
    metric.setModified(true);
    addMetricPreviewToToolbar();
    buildConfigLayout();
}
Also used : RBoolean(com.cpjd.roblu.models.metrics.RBoolean) RDivider(com.cpjd.roblu.models.metrics.RDivider) RChooser(com.cpjd.roblu.models.metrics.RChooser) RGallery(com.cpjd.roblu.models.metrics.RGallery) RTextfield(com.cpjd.roblu.models.metrics.RTextfield) RFieldData(com.cpjd.roblu.models.metrics.RFieldData) RFieldDiagram(com.cpjd.roblu.models.metrics.RFieldDiagram) RCalculation(com.cpjd.roblu.models.metrics.RCalculation) RStopwatch(com.cpjd.roblu.models.metrics.RStopwatch) RCheckbox(com.cpjd.roblu.models.metrics.RCheckbox) RSlider(com.cpjd.roblu.models.metrics.RSlider) TextView(android.widget.TextView) RCounter(com.cpjd.roblu.models.metrics.RCounter)

Example 2 with RFieldData

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

the class UnpackTBAEvent method doInBackground.

protected Void doInBackground(Void... params) {
    /*
         * No teams were contained within the event, so exit, nothing here is relevant
         * to a TBA event that doesn't contain any team models
         */
    if (event.teams == null || event.teams.length == 0)
        return null;
    /*
         * Create an array of team models from the ones contained in the event
         */
    ArrayList<RTeam> teams = new ArrayList<>();
    for (int i = 0; i < event.teams.length; i++) {
        // i can be used as the ID because we are creating a fresh event, io.getNewTeamID is irrelevant
        teams.add(new RTeam(event.teams[i].nickname, (int) event.teams[i].team_number, i));
    }
    /*
         * Sort the matches in the event
         */
    Collections.sort(Arrays.asList(event.matches));
    /*
         * Add the matches to the respective team models
         */
    IO io = new IO(activityWeakReference.get());
    RForm form = io.loadForm(eventID);
    int result;
    for (RTeam t : teams) {
        t.verify(form);
        for (int j = 0; j < event.matches.length; j++) {
            result = event.matches[j].doesMatchContainTeam(t.getNumber());
            if (result > 0) {
                String name = "Match";
                // process the correct match name
                switch(event.matches[j].comp_level) {
                    case "qm":
                        name = "Quals " + event.matches[j].match_number;
                        break;
                    case "qf":
                        name = "Quarters " + event.matches[j].set_number + " Match " + event.matches[j].match_number;
                        break;
                    case "sf":
                        name = "Semis " + event.matches[j].set_number + " Match " + event.matches[j].match_number;
                        break;
                    case "f":
                        name = "Finals " + event.matches[j].match_number;
                }
                boolean isRed = result == com.cpjd.main.Constants.CONTAINS_TEAM_RED;
                // add the match to the team, make sure to multiple the Event model's matches times by 1000 (seconds to milliseconds, Roblu works with milliseconds!)
                RTab tab = new RTab(t.getNumber(), name, Utils.duplicateRMetricArray(form.getMatch()), isRed, event.matches[j].isOnWinningAlliance(t.getNumber()), event.matches[j].time * 1000);
                // set the match position, if possible
                tab.setAlliancePosition(event.matches[j].getTeamPosition(t.getNumber()));
                // Check for FieldData metrics
                if (tab.getMetrics() != null) {
                    for (RMetric metric : tab.getMetrics()) {
                        if (metric instanceof RFieldData) {
                            if (((RFieldData) metric).getData() == null)
                                ((RFieldData) metric).setData(new LinkedHashMap<String, ArrayList<RMetric>>());
                            for (int i = 0; i < event.matches[j].scorableItems.length; i++) {
                                Log.d("RBS", "Metric name: " + event.matches[j].scorableItems[i] + ", " + "Red value: " + event.matches[j].redValues[i] + ", Blue value: " + event.matches[j].blueValues[i]);
                                ArrayList<RMetric> metrics = new ArrayList<>();
                                try {
                                    metrics.add(new RCounter(0, "", 0, Double.parseDouble(event.matches[j].redValues[i])));
                                } catch (Exception e) {
                                    metrics.add(new RTextfield(0, "", (event.matches[j].redValues[i])));
                                }
                                try {
                                    metrics.add(new RCounter(0, "", 0, Double.parseDouble(event.matches[j].blueValues[i])));
                                } catch (Exception e) {
                                    metrics.add(new RTextfield(0, "", (event.matches[j].blueValues[i])));
                                }
                                if (event.matches[j].scorableItems[i] != null && metrics.size() > 0)
                                    ((RFieldData) metric).getData().put(event.matches[j].scorableItems[i], metrics);
                            }
                        }
                    }
                }
                t.addTab(tab);
            }
        }
        /*
             * This is where the merge decision comes into play
             */
        if (randomize) {
            t.setLastEdit(System.currentTimeMillis());
            Utils.randomizeTeamMetrics(t.getTabs());
        }
        io.saveTeam(eventID, t);
    }
    return null;
}
Also used : RTeam(com.cpjd.roblu.models.RTeam) RTab(com.cpjd.roblu.models.RTab) IO(com.cpjd.roblu.io.IO) RTextfield(com.cpjd.roblu.models.metrics.RTextfield) ArrayList(java.util.ArrayList) RFieldData(com.cpjd.roblu.models.metrics.RFieldData) RMetric(com.cpjd.roblu.models.metrics.RMetric) LinkedHashMap(java.util.LinkedHashMap) RForm(com.cpjd.roblu.models.RForm) RCounter(com.cpjd.roblu.models.metrics.RCounter)

Example 3 with RFieldData

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

the class MetricEditor method addMetricPreviewToToolbar.

/**
 * Adds the metric preview to the Toolbar
 */
private void addMetricPreviewToToolbar() {
    Toolbar toolbar = findViewById(R.id.toolbar);
    toolbar.setBackgroundColor(rui.getPrimaryColor());
    toolbar.removeAllViews();
    if (metric instanceof RBoolean)
        toolbar.addView(rMetricToUI.getBoolean((RBoolean) metric));
    else if (metric instanceof RCounter)
        toolbar.addView(rMetricToUI.getCounter((RCounter) metric));
    else if (metric instanceof RSlider)
        toolbar.addView(rMetricToUI.getSlider((RSlider) metric));
    else if (metric instanceof RChooser)
        toolbar.addView(rMetricToUI.getChooser((RChooser) metric));
    else if (metric instanceof RCheckbox)
        toolbar.addView(rMetricToUI.getCheckbox((RCheckbox) metric));
    else if (metric instanceof RStopwatch)
        toolbar.addView(rMetricToUI.getStopwatch((RStopwatch) metric, true));
    else if (metric instanceof RTextfield)
        toolbar.addView(rMetricToUI.getTextfield((RTextfield) metric));
    else if (metric instanceof RGallery)
        toolbar.addView(rMetricToUI.getGallery(true, 0, 0, ((RGallery) metric)));
    else if (metric instanceof RDivider)
        toolbar.addView(rMetricToUI.getDivider((RDivider) metric));
    else if (metric instanceof RFieldDiagram)
        toolbar.addView(rMetricToUI.getFieldDiagram(-1, (RFieldDiagram) metric));
    else if (metric instanceof RCalculation)
        toolbar.addView(rMetricToUI.getCalculationMetric(null, ((RCalculation) metric)));
    else if (metric instanceof RFieldData)
        toolbar.addView(rMetricToUI.getFieldData((RFieldData) metric));
}
Also used : RBoolean(com.cpjd.roblu.models.metrics.RBoolean) RDivider(com.cpjd.roblu.models.metrics.RDivider) RChooser(com.cpjd.roblu.models.metrics.RChooser) RGallery(com.cpjd.roblu.models.metrics.RGallery) RTextfield(com.cpjd.roblu.models.metrics.RTextfield) RFieldData(com.cpjd.roblu.models.metrics.RFieldData) RFieldDiagram(com.cpjd.roblu.models.metrics.RFieldDiagram) RCalculation(com.cpjd.roblu.models.metrics.RCalculation) RStopwatch(com.cpjd.roblu.models.metrics.RStopwatch) RCheckbox(com.cpjd.roblu.models.metrics.RCheckbox) RSlider(com.cpjd.roblu.models.metrics.RSlider) RCounter(com.cpjd.roblu.models.metrics.RCounter) Toolbar(android.support.v7.widget.Toolbar)

Example 4 with RFieldData

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

the class MetricSortFragment method metricSelected.

/**
 * This method is called when the user taps on a metric
 *
 * @param v the View that the user tapped on (used for inferring the RMetric object)
 */
@Override
public void metricSelected(View v) {
    final int position = rv.getChildLayoutPosition(v);
    if (metrics.get(position) instanceof RFieldData) {
        final Dialog d = new Dialog(getActivity());
        d.setTitle("Select sub metric");
        d.setContentView(R.layout.submetric_import);
        final Spinner spinner = d.findViewById(R.id.type);
        // Attempt to load a team to get a list of values
        int id = 0;
        IO io = new IO(getActivity());
        RTeam team;
        do {
            team = io.loadTeam(eventID, id);
            id++;
        } while (team == null && id < 100);
        RFieldData fieldData = null;
        try {
            mainLoop: for (RTab tab : team.getTabs()) {
                if (tab.getTitle().equalsIgnoreCase("PIT") || tab.getTitle().equalsIgnoreCase("PREDICTIONS"))
                    continue;
                for (RMetric metric2 : tab.getMetrics()) {
                    if (metric2 instanceof RFieldData && metrics.get(position).getID() == metric2.getID() && ((RFieldData) metric2).getData() != null && ((RFieldData) metric2).getData().size() >= 1) {
                        fieldData = (RFieldData) metric2;
                        break mainLoop;
                    }
                }
            }
        } catch (Exception e) {
        // }
        }
        if (fieldData == null)
            return;
        final String[] values = Utils.depackFieldData(fieldData);
        if (values == null) {
            Toast.makeText(getActivity(), "Error occurred while loading metrics.", Toast.LENGTH_LONG).show();
            return;
        }
        ArrayAdapter<String> adp = new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1, values);
        adp.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adp);
        Button button = d.findViewById(R.id.button7);
        button.setText(R.string.select);
        button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent result = new Intent();
                result.putExtra("sortToken", TeamMetricProcessor.PROCESS_METHOD.MATCHES + ":" + metrics.get(position).getID() + ":" + values[spinner.getSelectedItemPosition()]);
                getActivity().setResult(Constants.CUSTOM_SORT_CONFIRMED, result);
                getActivity().finish();
                d.dismiss();
            }
        });
        if (d.getWindow() != null)
            d.getWindow().getAttributes().windowAnimations = new IO(getActivity()).loadSettings().getRui().getAnimation();
        d.show();
        return;
    } else // User selected the "In Match" option, now we have to display a list of all the matches within the event
    if (processMethod == TeamMetricProcessor.PROCESS_METHOD.OTHER && metrics.get(position).getID() == TeamMetricProcessor.PROCESS_METHOD.OTHER_METHOD.IN_MATCH) {
        final Dialog d = new Dialog(getActivity());
        d.setTitle("Select match");
        d.setContentView(R.layout.event_import_dialog);
        final Spinner spinner = d.findViewById(R.id.type);
        TextView t = d.findViewById(R.id.spinner_tip);
        t.setText(R.string.match);
        final String[] values = Utils.getMatchTitlesWithinEvent(getContext(), eventID);
        if (values == null) {
            Toast.makeText(getActivity(), "Error occurred while loading matches. Do any matches exist?", Toast.LENGTH_LONG).show();
            return;
        }
        ArrayAdapter<String> adp = new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1, values);
        adp.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adp);
        Button button = d.findViewById(R.id.button7);
        button.setText(R.string.select);
        button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent result = new Intent();
                result.putExtra("sortToken", TeamMetricProcessor.PROCESS_METHOD.OTHER + ":" + TeamMetricProcessor.PROCESS_METHOD.OTHER_METHOD.IN_MATCH + ":" + values[spinner.getSelectedItemPosition()]);
                getActivity().setResult(Constants.CUSTOM_SORT_CONFIRMED, result);
                getActivity().finish();
                d.dismiss();
            }
        });
        if (d.getWindow() != null)
            d.getWindow().getAttributes().windowAnimations = new IO(getActivity()).loadSettings().getRui().getAnimation();
        d.show();
        return;
    }
    String sortToken = processMethod + ":" + metrics.get(position).getID();
    Intent result = new Intent();
    result.putExtra("sortToken", sortToken);
    if (getActivity() != null) {
        getActivity().setResult(Constants.CUSTOM_SORT_CONFIRMED, result);
        getActivity().finish();
    }
}
Also used : RTeam(com.cpjd.roblu.models.RTeam) RTab(com.cpjd.roblu.models.RTab) Spinner(android.widget.Spinner) IO(com.cpjd.roblu.io.IO) RFieldData(com.cpjd.roblu.models.metrics.RFieldData) Intent(android.content.Intent) RMetric(com.cpjd.roblu.models.metrics.RMetric) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) Button(android.widget.Button) Dialog(android.app.Dialog) TextView(android.widget.TextView) ArrayAdapter(android.widget.ArrayAdapter)

Example 5 with RFieldData

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

the class TeamMetricProcessor method process.

/**
 * Processes an RTeam object and sets its filterTag and relevance variables.
 * -filterTag is a string representing a certain metric as defined by param method and param ID
 * -relevance is used for sorting (relevance is assigned differently for the type of RMetric, but for example,
 * counters with the highest value with cause that team to be sorted at the top)
 *
 * @param team the team to process
 * @param method an int from PROCESS_METHOD that defines how an team should be processed
 * @param ID the id of the metric to process, this value will be ignored if method is PIT, PREDICTIONS, or MATCHES
 */
public void process(RTeam team, int method, int ID) {
    team.setCustomRelevance(0);
    /*
         * Helper variables
         */
    StringBuilder rawData = new StringBuilder();
    int occurrences = 0;
    double relevance = 0;
    double average = 0.0, min = 0.0, max = 0.0;
    /*
         * If the request method is PIT or PREDICTIONS, use the following code to
         * sort the team. Note, each team will only have one value that needs to be
         * analyzed, so statistics are essentially invalid
         */
    if (method == PROCESS_METHOD.PIT || method == PROCESS_METHOD.PREDICTIONS) {
        for (RMetric metric : team.getTabs().get(method).getMetrics()) {
            if (metric.getID() != ID)
                continue;
            if (metric instanceof RBoolean) {
                rawData.append("Boolean: ").append(metric.getTitle()).append(" is ").append(friendlyBoolean((RBoolean) metric));
                if (metric.isModified() && ((RBoolean) metric).isValue())
                    relevance++;
            } else if (metric instanceof RCounter) {
                rawData.append("Counter: ").append(metric.getTitle()).append(" is ").append(friendlyCounter((RCounter) metric));
                relevance += ((RCounter) metric).getValue();
            } else if (metric instanceof RSlider) {
                rawData.append("Slider: ").append(metric.getTitle()).append(" is ").append(friendlySlider((RSlider) metric));
                relevance += ((RSlider) metric).getValue();
            } else if (metric instanceof RStopwatch) {
                rawData.append("Stopwatch: ").append(metric.getTitle()).append(" is ").append(friendlyStopwatch((RStopwatch) metric));
                relevance += ((RStopwatch) metric).getTime();
            } else if (metric instanceof RTextfield) {
                rawData.append("Textfield: ").append(metric.getTitle()).append(" has  ").append(((RTextfield) metric).getText().length()).append(" characters");
                relevance += ((RTextfield) metric).getText().length();
            } else if (metric instanceof RGallery) {
                rawData.append("Gallery: ").append(metric.getTitle()).append(" contains  ").append(((RGallery) metric).getImages().size()).append(" images");
                relevance += ((RGallery) metric).getImages().size();
            } else if (metric instanceof RCheckbox) {
                rawData.append("Checkbox: ").append(metric.getTitle()).append(" values:  ").append(friendlyCheckbox((RCheckbox) metric));
                relevance += getCheckedAmount((RCheckbox) metric);
            } else if (metric instanceof RChooser) {
                rawData.append("Chooser: ").append(metric.getTitle()).append(" has value  ").append(((RChooser) metric).getValues()[((RChooser) metric).getSelectedIndex()]);
            }
            rawData.append(" in ").append(friendlyMode(method));
            team.setFilterTag("\n" + rawData.toString());
            team.setCustomRelevance(relevance);
            break;
        }
    } else /*
         * If the request method is MATCHES, then the following code has to be used
         * to look at each particular RTab object within the team object
         */
    if (method == PROCESS_METHOD.MATCHES) {
        if (team.getTabs() == null || team.getTabs().size() == 0) {
            team.setFilterTag("\nThis team does not contain any matches that can be sorted.");
            return;
        }
        /*
             * This nested for loop will go through every team tab and every metric within each team tab.
             * This loop should only process the RAW DATA for each metric, the overview stuff will be added at the end.
             * Use StringBuilder rawData to store raw data
             */
        rawData.append("\nRaw data: ");
        for (int i = 2; i < team.getTabs().size(); i++) {
            for (RMetric metric : team.getTabs().get(i).getMetrics()) {
                // Make sure that the metric that is being processed is equal to the inputted value
                if (metric.getID() != ID)
                    continue;
                // RBoolean type
                if (metric instanceof RBoolean) {
                    RBoolean rBoolean = (RBoolean) metric;
                    // if the value is modified and true, add some relevance info
                    if (rBoolean.isModified() && rBoolean.isValue()) {
                        occurrences++;
                        relevance++;
                    }
                    // add raw data
                    rawData.append(friendlyBoolean((RBoolean) metric)).append(ending(i, team.getTabs()));
                } else // RCounter type
                if (metric instanceof RCounter) {
                    double value = ((RCounter) metric).getValue();
                    if (i == 2)
                        min = value;
                    // Overview stats will only consider modified items
                    if (metric.isModified()) {
                        /*
                             * Progressively calculate the min, max, and average values
                             */
                        if (value < min)
                            min = value;
                        if (value > max)
                            max = value;
                        average += value / (double) numModified(team.getTabs(), ID);
                        relevance = average;
                    }
                    // add raw data
                    rawData.append(friendlyCounter((RCounter) metric)).append(ending(i, team.getTabs()));
                } else if (metric instanceof RCalculation) {
                    try {
                        double value = Double.parseDouble(((RCalculation) metric).getValue(team.getTabs().get(i).getMetrics()));
                        if (i == 2)
                            min = value;
                        // Overview stats will only consider modified items
                        if (metric.isModified()) {
                            /*
                             * Progressively calculate the min, max, and average values
                             */
                            if (value < min)
                                min = value;
                            if (value > max)
                                max = value;
                            average += value / (double) numModified(team.getTabs(), ID);
                            relevance = average;
                        }
                        // add raw data
                        rawData.append(friendlyCounter((RCounter) metric)).append(ending(i, team.getTabs()));
                    } catch (Exception e) {
                    // eat it
                    }
                } else // RSlider type
                if (metric instanceof RSlider) {
                    int value = ((RSlider) metric).getValue();
                    if (i == 2)
                        min = value;
                    // Overview stats will only consider modified sliders
                    if (metric.isModified()) {
                        if (value < min)
                            min = value;
                        if (value > max)
                            max = value;
                        average += (double) value / (double) numModified(team.getTabs(), ID);
                        relevance = average;
                    }
                    // add raw data
                    rawData.append(friendlySlider((RSlider) metric)).append(ending(i, team.getTabs()));
                } else // RStopwatch type
                if (metric instanceof RStopwatch) {
                    double value = ((RStopwatch) metric).getTime();
                    if (i == 2)
                        min = value;
                    // Overview stats will only consider modified stopwatches
                    if (metric.isModified()) {
                        /*
                             * Progressively calculate the min, max, and average values
                             */
                        if (value < min)
                            min = value;
                        if (value > max)
                            max = value;
                        average += value / (double) numModified(team.getTabs(), ID);
                        relevance = average;
                    }
                    // add raw data
                    rawData.append(friendlyStopwatch((RStopwatch) metric)).append(ending(i, team.getTabs()));
                } else // RTextfield type
                if (metric instanceof RTextfield) {
                    int value = ((RTextfield) metric).getText().length();
                    // Overview stats will only consider modified textfields
                    if (metric.isModified()) {
                        /*
                             * Progressively calculate the min, max, and average values
                             */
                        if (value < min)
                            min = value;
                        if (value > max)
                            max = value;
                        average += (double) value / (double) numModified(team.getTabs(), ID);
                        relevance = average;
                    }
                    // add raw data
                    rawData.append(value).append(" chars").append(ending(i, team.getTabs()));
                } else // RGallery type
                if (metric instanceof RGallery) {
                    int value = ((RGallery) metric).getImages().size();
                    // Overview stats will only consider modified textfields
                    if (metric.isModified()) {
                        /*
                             * Progressively calculate the min, max, and average values
                             */
                        if (value < min)
                            min = value;
                        if (value > max)
                            max = value;
                        average += (double) value / (double) numModified(team.getTabs(), ID);
                        relevance = average;
                    }
                    // add raw data
                    rawData.append(value).append(" images ").append(ending(i, team.getTabs()));
                } else // RCheckbox type
                if (metric instanceof RCheckbox) {
                    // add raw data
                    rawData.append(friendlyCheckbox((RCheckbox) metric)).append(ending(i, team.getTabs()));
                    relevance += getCheckedAmount((RCheckbox) metric);
                } else // RChooser type
                if (metric instanceof RChooser) {
                    if (metric.isModified())
                        relevance++;
                    // add raw data
                    rawData.append(((RChooser) metric).getValues()[((RChooser) metric).getSelectedIndex()]).append(ending(i, team.getTabs()));
                } else // Field data
                if (metric instanceof RFieldData) {
                    // Find the sub metric
                    if (((RFieldData) metric).getData() != null && ((RFieldData) metric).getData().get(inMatchTitle) != null)
                        rawData.append(((RFieldData) metric).getData().get(inMatchTitle).get(team.getTabs().get(i).isRedAlliance() ? 0 : 1).toString()).append(ending(i, team.getTabs()));
                    // Overview stats will only consider modified textfields
                    if (metric.isModified()) {
                        /*
                             * Progressively calculate the min, max, and average values
                             */
                        try {
                            double value = Double.parseDouble(((RFieldData) metric).getData().get(inMatchTitle).get(team.getTabs().get(i).isRedAlliance() ? 0 : 1).toString());
                            if (i == 2)
                                min = value;
                            if (value < min)
                                min = value;
                            if (value > max)
                                max = value;
                            average += value / (double) numModified(team.getTabs(), ID);
                            relevance = average;
                        } catch (Exception e) {
                        // eat it
                        }
                    }
                }
                /*
                     * Now, add the overview statistics to the team if the metric has overview statistics
                     * available
                    */
                max = Utils.round(max, 2);
                min = Utils.round(min, 2);
                average = Utils.round(average, 2);
                StringBuilder overview = new StringBuilder();
                if (metric instanceof RBoolean)
                    overview.append("Boolean: ").append(metric.getTitle()).append(" is true in ").append(occurrences).append(" / ").append(team.getTabs().size() - 2).append(" matches");
                else if (metric instanceof RCounter)
                    overview.append("Counter: ").append(metric.getTitle()).append(" Average: ").append(Utils.round(average, 2)).append(" Min: ").append(min).append(" Max: ").append(max);
                else if (metric instanceof RCalculation)
                    overview.append("Calculation: ").append(metric.getTitle()).append(" Average: ").append(Utils.round(average, 2)).append(" Min: ").append(min).append(" Max: ").append(max);
                else if (metric instanceof RSlider)
                    overview.append("Slider: ").append(metric.getTitle()).append(" Average: ").append(Utils.round(average, 2)).append(" Min: ").append(min).append(" Max: ").append(max);
                else if (metric instanceof RStopwatch)
                    overview.append("Stopwatch: ").append(metric.getTitle()).append(" Average: ").append(Utils.round(average, 2)).append(" Min: ").append(min).append(" Max: ").append(max);
                else if (metric instanceof RTextfield)
                    overview.append("Textfield: ").append(metric.getTitle()).append(" Average chars: ").append(Utils.round(average, 2)).append(" Min: ").append(min).append(" Max: ").append(max);
                else if (metric instanceof RGallery)
                    overview.append("Gallery: ").append(metric.getTitle()).append(" Average images: ").append(Utils.round(average, 2)).append(" Min: ").append(min).append(" Max: ").append(max);
                else if (metric instanceof RChooser)
                    overview.append("Chooser: ").append(metric.getTitle());
                else if (metric instanceof RCheckbox)
                    overview.append("Checkbox: ").append(metric.getTitle());
                else if (metric instanceof RFieldData) {
                    overview.append("Field data: ").append(inMatchTitle);
                    try {
                        // this will fail if the value isn't a number
                        if (average != 0 || min != 0 || max != 0)
                            overview.append("\nAverage: ").append(Utils.round(average, 2)).append(" Min: ").append(min).append(" Max: ").append(max);
                    } catch (Exception e) {
                    // eat it
                    }
                }
                /*
                     * Now append the raw data as processed above
                     */
                team.setFilterTag("\n" + overview.append(rawData).toString());
                team.setCustomRelevance(relevance);
                // exit the loop, the metric has been fully processed
                break;
            }
        }
    } else /*
         * The user requested MATCH_WINS
         */
    if (method == PROCESS_METHOD.OTHER && ID == PROCESS_METHOD.OTHER_METHOD.MATCH_WINS) {
        for (int i = 2; i < team.getTabs().size(); i++) {
            if (team.getTabs().get(i).isWon()) {
                occurrences++;
                relevance++;
                rawData.append("W");
            } else
                rawData.append("L");
            rawData.append(ending(i, team.getTabs()));
        }
        /*
             * Setup overview rawData and add raw data
             */
        team.setCustomRelevance(relevance);
        team.setFilterTag("\n" + String.valueOf(occurrences) + " match wins\n" + rawData.toString());
    } else /*
         * The user requested IN_MATCH
         */
    if (method == PROCESS_METHOD.OTHER && ID == PROCESS_METHOD.OTHER_METHOD.IN_MATCH) {
        team.setFilter(TeamsView.SORT_TYPE.NUMERICAL);
        for (int i = 2; i < team.getTabs().size(); i++) {
            if (team.getTabs().get(i).getTitle().equalsIgnoreCase(inMatchTitle)) {
                team.setFilterTag("\n" + rawData.append("In ").append(inMatchTitle).toString());
                team.setCustomRelevance(1);
            }
        }
    } else /*
         * The user request a reset
         */
    if (method == PROCESS_METHOD.OTHER && ID == PROCESS_METHOD.OTHER_METHOD.RESET) {
        team.setFilterTag("");
        team.setCustomRelevance(0);
    }
}
Also used : RBoolean(com.cpjd.roblu.models.metrics.RBoolean) RChooser(com.cpjd.roblu.models.metrics.RChooser) RGallery(com.cpjd.roblu.models.metrics.RGallery) RTextfield(com.cpjd.roblu.models.metrics.RTextfield) RFieldData(com.cpjd.roblu.models.metrics.RFieldData) RMetric(com.cpjd.roblu.models.metrics.RMetric) RCalculation(com.cpjd.roblu.models.metrics.RCalculation) RStopwatch(com.cpjd.roblu.models.metrics.RStopwatch) RCheckbox(com.cpjd.roblu.models.metrics.RCheckbox) RSlider(com.cpjd.roblu.models.metrics.RSlider) RCounter(com.cpjd.roblu.models.metrics.RCounter)

Aggregations

RFieldData (com.cpjd.roblu.models.metrics.RFieldData)10 RMetric (com.cpjd.roblu.models.metrics.RMetric)8 RTab (com.cpjd.roblu.models.RTab)5 RCalculation (com.cpjd.roblu.models.metrics.RCalculation)5 RGallery (com.cpjd.roblu.models.metrics.RGallery)5 RTeam (com.cpjd.roblu.models.RTeam)4 RCounter (com.cpjd.roblu.models.metrics.RCounter)4 RStopwatch (com.cpjd.roblu.models.metrics.RStopwatch)4 RTextfield (com.cpjd.roblu.models.metrics.RTextfield)4 IO (com.cpjd.roblu.io.IO)3 RCheckout (com.cpjd.roblu.models.RCheckout)3 RBoolean (com.cpjd.roblu.models.metrics.RBoolean)3 RCheckbox (com.cpjd.roblu.models.metrics.RCheckbox)3 RChooser (com.cpjd.roblu.models.metrics.RChooser)3 RSlider (com.cpjd.roblu.models.metrics.RSlider)3 TextView (android.widget.TextView)2 RForm (com.cpjd.roblu.models.RForm)2 RDivider (com.cpjd.roblu.models.metrics.RDivider)2 RFieldDiagram (com.cpjd.roblu.models.metrics.RFieldDiagram)2 ArrayList (java.util.ArrayList)2