Search in sources :

Example 6 with RTextfield

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

the class RTeam method verify.

/**
 * verify() makes sure that the form and team are synchronized. Here's what it does:
 * <p>
 * PIT:
 * -If the user modified the form and ADDED elements, then we'll make sure to add them to this team's form copy
 * -If the user modified the form and REMOVED elements, then we'll make sure to remove them from this team's form copy
 * -If the user changed any item titles, change them right away
 * -If the user changed any default values, reset all the values on all elements that have NOT been modified
 * -If the user changed the order of any elements, change the order
 * <p>
 * MATCH:
 * -If the user modified the match form and ADDED elements, then we'll add those to EVERY match profile
 * -If the user modified the match form and REMOVED elements, then we'll remove those from EVERY match profile
 * -If the user changed any item titles, change them on ALL match profiles
 * -If the user changed any default values, reset all the values of EVERY match that have NOT been modified
 * -If the user changed the order of any elements, change the order
 * <p>
 * PREMISE:
 * -PIT and MATCH form arrays may NOT be null, only empty
 * <p>
 * NULLS to check for:
 * -If the team has never been opened before, set the PIT values, matches don't need to be set until creation.
 */
public void verify(RForm form) {
    // Check for null or missing Pit & Predictions tabs
    if (this.tabs == null || this.tabs.size() == 0) {
        this.tabs = new ArrayList<>();
        addTab(new RTab(number, "Pit", Utils.duplicateRMetricArray(form.getPit()), false, false, 0));
        addTab(new RTab(number, "Predictions", Utils.duplicateRMetricArray(form.getMatch()), false, false, 0));
        // Check to make sure the team name and number have been inserted into the form
        for (RMetric m : this.getTabs().get(0).getMetrics()) {
            if (// team name
            m.getID() == 0)
                // team name
                ((RTextfield) m).setText(name);
            else // team number
            if (m.getID() == 1)
                ((RTextfield) m).setText(String.valueOf(number));
        }
        return;
    }
    // Remove elements that aren't on the form
    // less if statements, just switches between PIT or MATCH depending on what needs to be verified
    ArrayList<RMetric> temp = form.getPit();
    for (int i = 0; i < tabs.size(); i++) {
        if (!tabs.get(i).getTitle().equalsIgnoreCase("Pit"))
            temp = form.getMatch();
        for (int j = 0; j < tabs.get(i).getMetrics().size(); j++) {
            boolean found = false;
            if (temp.size() == 0) {
                tabs.get(i).getMetrics().clear();
                break;
            }
            for (int k = 0; k < temp.size(); k++) {
                if (tabs.get(i).getMetrics().get(j).getID() == temp.get(k).getID())
                    found = true;
                if (k == temp.size() - 1 && !found) {
                    tabs.get(i).getMetrics().remove(j);
                    j = 0;
                    break;
                }
            }
        }
    }
    /*
         * Alright, so we removed old elements, but we're still very suspicious. For example,
         * let's say the user edited the form (by removing an element), didn't re-verify any teams (by not opening them),
         * and then added a new element in the position of the old one. What will happen is that the above method will
         * NOT remove the old metric instance, and instead below the metrics name will not get updated. So, here we will
         * make sure that both the ID and INSTANCE TYPE of each metric (in the form and team) match, otherwise, the metric
         * gets booted.
         */
    temp = form.getPit();
    for (int i = 0; i < tabs.size(); i++) {
        if (!tabs.get(i).getTitle().equalsIgnoreCase("Pit"))
            temp = form.getMatch();
        for (int j = 0; j < temp.size(); j++) {
            for (int k = 0; k < tabs.get(i).getMetrics().size(); k++) {
                if (tabs.get(i).getMetrics().get(k).getID() == temp.get(j).getID()) {
                    if (!temp.get(j).getClass().equals(tabs.get(i).getMetrics().get(k).getClass())) {
                        tabs.get(i).getMetrics().remove(k);
                        j = 0;
                        k = 0;
                    }
                }
            }
        }
    }
    // Add elements that are on the form, but not in this team
    temp = form.getPit();
    for (int i = 0; i < tabs.size(); i++) {
        if (!tabs.get(i).getTitle().equalsIgnoreCase("Pit"))
            temp = form.getMatch();
        for (int j = 0; j < temp.size(); j++) {
            boolean found = false;
            if (tabs.get(i).getMetrics().size() == 0) {
                tabs.get(i).getMetrics().add(temp.get(j).clone());
                continue;
            }
            for (int k = 0; k < tabs.get(i).getMetrics().size(); k++) {
                if (tabs.get(i).getMetrics().get(k).getID() == temp.get(j).getID())
                    found = true;
                if (k == tabs.get(i).getMetrics().size() - 1 && !found) {
                    tabs.get(i).getMetrics().add(temp.get(j).clone());
                    j = 0;
                    break;
                }
            }
        }
    }
    // Update item names
    temp = form.getPit();
    for (int i = 0; i < tabs.size(); i++) {
        if (!tabs.get(i).getTitle().equalsIgnoreCase("PIT"))
            temp = form.getMatch();
        for (int j = 0; j < temp.size(); j++) {
            for (int k = 0; k < tabs.get(i).getMetrics().size(); k++) {
                if (temp.get(j).getID() == tabs.get(i).getMetrics().get(k).getID()) {
                    tabs.get(i).getMetrics().get(k).setTitle(temp.get(j).getTitle());
                    break;
                }
            }
        }
    }
    // Update default values for non-modified values, also check for some weird scenario
    temp = form.getPit();
    for (int i = 0; i < tabs.size(); i++) {
        if (!tabs.get(i).getTitle().equalsIgnoreCase("PIT"))
            temp = form.getMatch();
        for (int j = 0; j < temp.size(); j++) {
            for (int k = 0; k < tabs.get(i).getMetrics().size(); k++) {
                if (temp.get(j).getID() == tabs.get(i).getMetrics().get(k).getID()) {
                    RMetric e = temp.get(j);
                    RMetric s = tabs.get(i).getMetrics().get(k);
                    if (e instanceof RBoolean && !s.isModified() && s instanceof RBoolean)
                        ((RBoolean) s).setValue(((RBoolean) e).isValue());
                    else if (e instanceof RCounter && !s.isModified() && s instanceof RCounter) {
                        ((RCounter) s).setValue(((RCounter) e).getValue());
                    } else if (e instanceof RCalculation && s instanceof RCalculation) {
                        ((RCalculation) s).setCalculation(((RCalculation) e).getCalculation());
                    } else if (e instanceof RCheckbox && s instanceof RCheckbox) {
                        // update the titles always, rely on position for this one
                        LinkedHashMap<String, Boolean> newHash = new LinkedHashMap<>();
                        // get old values
                        ArrayList<Boolean> values = new ArrayList<>();
                        // put values from team checkbox into this array
                        for (String oKey : ((RCheckbox) s).getValues().keySet()) {
                            values.add(((RCheckbox) s).getValues().get(oKey));
                        }
                        // copy values to new linked hash map, replacing the new keys
                        int index = 0;
                        for (String oKey : ((RCheckbox) e).getValues().keySet()) {
                            newHash.put(oKey, values.get(index));
                            index++;
                        }
                        // set new array back to team metric
                        ((RCheckbox) s).setValues(newHash);
                        // if the checkbox is not modified, reset the boolean values
                        if (!s.isModified()) {
                            for (String key : ((RCheckbox) e).getValues().keySet()) ((RCheckbox) s).getValues().put(key, ((RCheckbox) e).getValues().get(key));
                        }
                    } else // if one line is true, it means its the team name or number metric and its value shouldn't be overrided
                    if (e instanceof RTextfield && !s.isModified() && !((RTextfield) e).isOneLine())
                        ((RTextfield) s).setText(((RTextfield) e).getText());
                    else if (e instanceof RChooser && s instanceof RChooser) {
                        // Always update the title
                        if (!Arrays.equals(((RChooser) s).getValues(), ((RChooser) e).getValues())) {
                            ((RChooser) s).setValues(((RChooser) e).getValues());
                        }
                        // if the chooser is not modified, reset the chooser values
                        if (!s.isModified())
                            ((RChooser) s).setSelectedIndex(((RChooser) e).getSelectedIndex());
                    } else if (e instanceof RStopwatch && !s.isModified() && s instanceof RStopwatch)
                        ((RStopwatch) s).setTime(((RStopwatch) e).getTime());
                    else if (e instanceof RSlider && !s.isModified() && s instanceof RSlider) {
                        ((RSlider) s).setMax(((RSlider) e).getMax());
                        ((RSlider) s).setMin(((RSlider) e).getMin());
                        ((RSlider) s).setValue(((RSlider) e).getValue());
                    } else if (e instanceof RCounter && s instanceof RCounter) {
                        ((RCounter) s).setIncrement(((RCounter) e).getIncrement());
                        ((RCounter) s).setVerboseInput(((RCounter) e).isVerboseInput());
                        if (!s.isModified())
                            ((RCounter) s).setValue(((RCounter) e).getValue());
                    }
                    break;
                }
            }
        }
    }
}
Also used : RBoolean(com.cpjd.roblu.models.metrics.RBoolean) RChooser(com.cpjd.roblu.models.metrics.RChooser) RTextfield(com.cpjd.roblu.models.metrics.RTextfield) ArrayList(java.util.ArrayList) RMetric(com.cpjd.roblu.models.metrics.RMetric) RCalculation(com.cpjd.roblu.models.metrics.RCalculation) LinkedHashMap(java.util.LinkedHashMap) 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)

Example 7 with RTextfield

use of com.cpjd.roblu.models.metrics.RTextfield 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 8 with RTextfield

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

the class PredefinedFormSelector method processForm.

/**
 * Converst the form into an RForm reference
 * @param name the file name
 * @return an RForm instance
 */
private RForm processForm(int index, String name) {
    RForm form = new RForm(null, null);
    ArrayList<RMetric> metrics = new ArrayList<>();
    try {
        AssetManager am = getAssets();
        InputStream is = am.open("predefinedForms" + File.separator + name);
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String line;
        int ID = 0;
        while ((line = br.readLine()) != null) {
            if (line.startsWith("Title")) {
                items[index] = line.split(":")[1];
                continue;
            } else if (line.startsWith("Description")) {
                sub_items[index] = line.split(":")[1];
                continue;
            }
            switch(line) {
                case "PIT":
                    continue;
                case "MATCH":
                    form.setPit(new ArrayList<>(metrics));
                    metrics.clear();
                    continue;
                case "DEFAULTS":
                    metrics.add(new RTextfield(0, "Team name", false, true, ""));
                    metrics.add(new RTextfield(1, "Team number", true, true, ""));
                    ID = 2;
                    break;
            }
            /*
                 * Process file
                 */
            String regex = "(?<!\\\\)" + Pattern.quote(",");
            String[] tokens = line.split(regex);
            for (int i = 0; i < tokens.length; i++) {
                tokens[i] = tokens[i].replaceAll("\\\\,", ",");
            }
            switch(tokens[0]) {
                case "counter":
                    metrics.add(new RCounter(ID, tokens[1], Integer.parseInt(tokens[2]), Integer.parseInt(tokens[3])));
                    ID++;
                    break;
                case "divider":
                    metrics.add(new RDivider(ID, tokens[1]));
                    ID++;
                    break;
                case "chooser":
                    metrics.add(new RChooser(ID, tokens[1], tokens[2].split(":"), Integer.parseInt(tokens[3])));
                    ID++;
                    break;
                case "slider":
                    metrics.add(new RSlider(ID, tokens[1], Integer.parseInt(tokens[2]), Integer.parseInt(tokens[3]), Integer.parseInt(tokens[4])));
                    ID++;
                    break;
                case "checkbox":
                    LinkedHashMap<String, Boolean> temp = new LinkedHashMap<>();
                    for (String s : tokens[2].split(":")) temp.put(s, false);
                    metrics.add(new RCheckbox(ID, tokens[1], temp));
                    ID++;
                    break;
                case "textfield":
                    metrics.add(new RTextfield(ID, tokens[1], ""));
                    ID++;
                    break;
                case "stopwatch":
                    metrics.add(new RStopwatch(ID, tokens[1], Double.parseDouble(tokens[2])));
                    ID++;
                    break;
                case "boolean":
                    metrics.add(new RBoolean(ID, tokens[1], Boolean.parseBoolean(tokens[2])));
                    ID++;
                    break;
                case "gallery":
                    metrics.add(new RGallery(ID, tokens[1]));
                    ID++;
                    break;
            }
        }
        form.setMatch(metrics);
        Log.d("RBS", "Form created successfully with " + form.getPit().size() + " pit metrics and " + form.getMatch().size() + " match metrics");
        return form;
    } catch (IOException e) {
        Log.d("RBS", "Failed to process form: " + e.getMessage());
        return null;
    }
}
Also used : RDivider(com.cpjd.roblu.models.metrics.RDivider) RBoolean(com.cpjd.roblu.models.metrics.RBoolean) RGallery(com.cpjd.roblu.models.metrics.RGallery) RTextfield(com.cpjd.roblu.models.metrics.RTextfield) ArrayList(java.util.ArrayList) RMetric(com.cpjd.roblu.models.metrics.RMetric) LinkedHashMap(java.util.LinkedHashMap) RForm(com.cpjd.roblu.models.RForm) RCheckbox(com.cpjd.roblu.models.metrics.RCheckbox) RSlider(com.cpjd.roblu.models.metrics.RSlider) RBoolean(com.cpjd.roblu.models.metrics.RBoolean) AssetManager(android.content.res.AssetManager) RChooser(com.cpjd.roblu.models.metrics.RChooser) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) IOException(java.io.IOException) RStopwatch(com.cpjd.roblu.models.metrics.RStopwatch) BufferedReader(java.io.BufferedReader) RCounter(com.cpjd.roblu.models.metrics.RCounter)

Example 9 with RTextfield

use of com.cpjd.roblu.models.metrics.RTextfield 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)

Example 10 with RTextfield

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

the class FormViewer method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_create_form);
    /*
		 * Load dependencies
		 */
    /*
         Stores the user's UI preferences
        */
    RUI rui = new IO(getApplicationContext()).loadSettings().getRui();
    /*
		 * Setup UI
		 */
    // Toolbar
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle("Form editor");
        if (getIntent().getBooleanExtra("master", false))
            getSupportActionBar().setSubtitle("Master form");
    }
    // Bottom bar - selector that lets the user switch between PIT and MATCH forms
    BottomBar bBar = findViewById(R.id.bottomBar);
    bBar.setOnTabSelectListener(this);
    BottomBarTab tab = bBar.getTabAtPosition(0);
    BottomBarTab tab2 = bBar.getTabAtPosition(1);
    tab.setBarColorWhenSelected(rui.getPrimaryColor());
    tab2.setBarColorWhenSelected(rui.getPrimaryColor());
    bBar.selectTabAtPosition(0);
    // Add the "New metric" button
    FloatingActionButton fab = findViewById(R.id.fab);
    fab.setOnClickListener(this);
    // Recycler view setup
    RecyclerView rv = findViewById(R.id.movie_recycler_view);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
    linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    rv.setLayoutManager(linearLayoutManager);
    ((SimpleItemAnimator) rv.getItemAnimator()).setSupportsChangeAnimations(false);
    metricsAdapter = new FormRecyclerAdapter(this, this);
    rv.setAdapter(metricsAdapter);
    // Gesture helper
    ItemTouchHelper.Callback callback = new FormRecyclerTouchHelper(metricsAdapter);
    ItemTouchHelper helper = new ItemTouchHelper(callback);
    helper.attachToRecyclerView(rv);
    /*
         * Check to see if we received a form from a different class or
         * if we need to create a new one
         */
    if (getIntent().getSerializableExtra("form") != null) {
        form = (RForm) getIntent().getSerializableExtra("form");
    } else {
        RTextfield name = new RTextfield(0, "Team name", false, true, "");
        RTextfield number = new RTextfield(1, "Team number", true, true, "");
        ArrayList<RMetric> pit = new ArrayList<>();
        pit.add(name);
        pit.add(number);
        form = new RForm(pit, new ArrayList<RMetric>());
    }
    loadViews(true, 0);
    new UIHandler(this, toolbar, fab).update();
}
Also used : SimpleItemAnimator(android.support.v7.widget.SimpleItemAnimator) UIHandler(com.cpjd.roblu.ui.UIHandler) IO(com.cpjd.roblu.io.IO) RTextfield(com.cpjd.roblu.models.metrics.RTextfield) RUI(com.cpjd.roblu.models.RUI) ArrayList(java.util.ArrayList) RMetric(com.cpjd.roblu.models.metrics.RMetric) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) BottomBar(com.roughike.bottombar.BottomBar) RForm(com.cpjd.roblu.models.RForm) BottomBarTab(com.roughike.bottombar.BottomBarTab) FloatingActionButton(android.support.design.widget.FloatingActionButton) RecyclerView(android.support.v7.widget.RecyclerView) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

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