Search in sources :

Example 11 with RStopwatch

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

the class CheckoutEncoder method encodeCheckout.

/**
 * This method will encode a checkout with as little overhead as possible (as opposed to JSON
 * serialization). This method is used for QR serialization to minimize the data transfer, since
 * compression isn't supported well by QR. This could be expanded for the whole project, but isn't really versatile enough yet.
 * @return The encoded string
 */
public String encodeCheckout(String nameTag, RCheckout checkout) {
    StringBuilder builder = new StringBuilder();
    // Checkout components
    builder.append(checkout.getID()).append("\n");
    builder.append(nameTag).append("\n");
    // Team meta
    builder.append(checkout.getTeam().getID()).append("\n");
    builder.append(checkout.getTeam().getLastEdit()).append("\n");
    // Tabs!
    for (RTab tab : checkout.getTeam().getTabs()) {
        builder.append("TAB").append(tab.getTitle()).append("\n");
        builder.append(tab.isWon()).append("\n");
        // Edits
        builder.append("EDITS");
        if (tab.getEdits() != null) {
            for (Object o : tab.getEdits().keySet()) {
                builder.append(",");
                if (o.toString().equals(""))
                    builder.append("Unknown");
                else
                    builder.append(o.toString());
                // EDITS,will:120391823,john,12039123
                builder.append(",").append(tab.getEdits().get(o.toString()));
            }
        }
        builder.append("\n");
        // -RDivider and RCalculation don't need to be encoded since they don't contain any user information
        for (RMetric metric : tab.getMetrics()) {
            builder.append(getMetricType(metric)).append(DELIMITER).append(metric.getID()).append(DELIMITER).append(metric.getTitle()).append(DELIMITER).append(metric.isModified()).append(DELIMITER);
            if (metric instanceof RBoolean)
                builder.append(((RBoolean) metric).isValue());
            else if (metric instanceof RCheckbox) {
                if (((RCheckbox) metric).getValues() != null) {
                    for (Object o : ((RCheckbox) metric).getValues().keySet()) {
                        // :(title,value):(title,value):
                        builder.append("(").append(o.toString()).append(",").append(((RCheckbox) metric).getValues().get(o.toString())).append(")").append(DELIMITER);
                    }
                }
            } else if (metric instanceof RChooser) {
                builder.append(((RChooser) metric).getSelectedIndex()).append(DELIMITER);
                if (((RChooser) metric).getValues() != null) {
                    for (String s : ((RChooser) metric).getValues()) {
                        // :1:option:option:option:
                        builder.append(s).append(DELIMITER);
                    }
                }
            } else if (metric instanceof RCounter)
                builder.append(((RCounter) metric).isVerboseInput()).append(DELIMITER).append(((RCounter) metric).getValue()).append(DELIMITER).append(((RCounter) metric).getIncrement());
            else if (metric instanceof RSlider)
                builder.append(((RSlider) metric).getValue()).append(DELIMITER).append(((RSlider) metric).getMin()).append(DELIMITER).append(((RSlider) metric).getMax());
            else if (metric instanceof RStopwatch) {
                builder.append(((RStopwatch) metric).getTime()).append(DELIMITER);
                if (((RStopwatch) metric).getTimes() != null) {
                    for (Double t : ((RStopwatch) metric).getTimes()) {
                        // :curr:1:2:3:
                        builder.append(t).append(DELIMITER);
                    }
                }
            } else if (metric instanceof RTextfield)
                builder.append(((RTextfield) metric).getText());
            builder.append("\n");
        }
    }
    return builder.toString();
}
Also used : RBoolean(com.cpjd.roblu.models.metrics.RBoolean) RChooser(com.cpjd.roblu.models.metrics.RChooser) RTab(com.cpjd.roblu.models.RTab) RTextfield(com.cpjd.roblu.models.metrics.RTextfield) RMetric(com.cpjd.roblu.models.metrics.RMetric) 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 12 with RStopwatch

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

the class MatchData method generateSheet.

@Override
public void generateSheet(XSSFSheet sheet, REvent event, RForm form, RTeam[] teams, ArrayList<RCheckout> checkouts) {
    /*
         * Output the headers
         */
    Row row = createRow(sheet);
    createCell(row, 0, "Team Number");
    createCell(row, 1, "Match number");
    for (int i = 0; i < form.getMatch().size(); i++) {
        createCell(row, i + 2, form.getMatch().get(i).getTitle());
    }
    /*
         * Output the data
         */
    for (RCheckout checkout : checkouts) {
        if (checkout.getTeam().getTabs().get(0).getTitle().equalsIgnoreCase("PIT") || checkout.getTeam().getTabs().get(0).getTitle().equalsIgnoreCase("PREDICTIONS"))
            continue;
        Row data = createRow(sheet);
        Cell cs = data.createCell(0);
        cs.setCellValue(checkout.getTeam().getNumber());
        cs.setCellStyle(getStyle());
        createCell(data, 1, checkout.getTeam().getTabs().get(0).getTitle().replace("Quals ", ""));
        int index = 0;
        for (RMetric metric : checkout.getTeam().getTabs().get(0).getMetrics()) {
            if (shouldWriteMetric(checkout.getTeam(), metric)) {
                if (metric instanceof RStopwatch)
                    createCell(data, index + 2, ((RStopwatch) metric).getLapsString());
                else if (metric instanceof RCalculation)
                    createCell(data, index + 2, ((RCalculation) metric).getValue(checkout.getTeam().getTabs().get(0).getMetrics()));
                else if (metric instanceof RFieldData)
                    continue;
                else
                    createCell(data, index + 2, metric.toString());
            } else
                createCell(data, index + 2, "");
            index++;
        }
    }
}
Also used : RStopwatch(com.cpjd.roblu.models.metrics.RStopwatch) RFieldData(com.cpjd.roblu.models.metrics.RFieldData) RCheckout(com.cpjd.roblu.models.RCheckout) Row(org.apache.poi.ss.usermodel.Row) RMetric(com.cpjd.roblu.models.metrics.RMetric) Cell(org.apache.poi.ss.usermodel.Cell) RCalculation(com.cpjd.roblu.models.metrics.RCalculation)

Aggregations

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