Search in sources :

Example 6 with AddTrace

use of com.google.firebase.perf.metrics.AddTrace in project Robot-Scouter by SUPERCILEX.

the class SpreadsheetExporter method getWorkbook.

@AddTrace(name = "getWorkbook")
private Workbook getWorkbook() {
    Workbook workbook;
    if (isUnsupportedDevice()) {
        workbook = new HSSFWorkbook();
        showToast(this, getString(R.string.unsupported_device));
    } else {
        workbook = new XSSFWorkbook();
    }
    mCache.setWorkbook(workbook);
    Sheet averageSheet = null;
    if (mCache.getTeamHelpers().size() > SINGLE_ITEM) {
        averageSheet = workbook.createSheet("Team Averages");
        averageSheet.createFreezePane(1, 1);
    }
    List<TeamHelper> teamHelpers = mCache.getTeamHelpers();
    for (TeamHelper teamHelper : teamHelpers) {
        mCache.updateNotification(getString(R.string.exporting_spreadsheet_team, teamHelper));
        Sheet teamSheet = workbook.createSheet(getSafeSheetName(workbook, teamHelper));
        teamSheet.createFreezePane(1, 1);
        buildTeamSheet(teamHelper, teamSheet);
    }
    mCache.updateNotification(getString(R.string.exporting_spreadsheet_average));
    if (averageSheet != null)
        buildTeamAveragesSheet(averageSheet);
    mCache.updateNotification(getString(R.string.exporting_spreadsheet_cleanup));
    autoFitColumnWidths(workbook);
    return workbook;
}
Also used : XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) TeamHelper(com.supercilex.robotscouter.data.util.TeamHelper) Sheet(org.apache.poi.ss.usermodel.Sheet) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) AddTrace(com.google.firebase.perf.metrics.AddTrace)

Example 7 with AddTrace

use of com.google.firebase.perf.metrics.AddTrace in project Robot-Scouter by SUPERCILEX.

the class SpreadsheetExporter method buildTeamChart.

@AddTrace(name = "buildTeamChart")
private void buildTeamChart(Row row, TeamHelper teamHelper, Map<Chart, Pair<LineChartData, List<ChartAxis>>> chartData, Map<Metric<Void>, Chart> chartPool) {
    if (isUnsupportedDevice())
        return;
    Sheet sheet = row.getSheet();
    int rowNum = row.getRowNum();
    int lastDataCellNum = row.getSheet().getRow(0).getLastCellNum() - 2;
    Chart chart = null;
    Pair<Integer, Metric<Void>> nearestHeader = null;
    List<Row> rows = getAdjustedList(row.getSheet());
    for (int i = row.getRowNum() - 1; i >= 0; i--) {
        Metric metric = getMetricForScouts(mScouts.get(teamHelper), mCache.getMetricKey(rows.get(i)));
        if (metric.getType() == HEADER) {
            nearestHeader = Pair.create(i, metric);
            Chart cachedChart = chartPool.get(metric);
            if (cachedChart != null)
                chart = cachedChart;
            break;
        }
    }
    chartFinder: if (nearestHeader == null) {
        for (Chart possibleChart : chartData.keySet()) {
            if (possibleChart instanceof XSSFChart) {
                XSSFChart xChart = (XSSFChart) possibleChart;
                if (xChart.getGraphicFrame().getAnchor().getRow1() == SINGLE_ITEM) {
                    nearestHeader = Pair.create(0, getMetricForChart(xChart, chartPool));
                    chart = xChart;
                    break chartFinder;
                }
            }
        }
        nearestHeader = Pair.create(0, new Metric.Header("", null));
    }
    LineChartData data;
    if (chart == null) {
        Drawing drawing = sheet.createDrawingPatriarch();
        Integer headerIndex = nearestHeader.first + 1;
        int startChartIndex = lastDataCellNum + 3;
        chart = drawing.createChart(createChartAnchor(drawing, getChartRowIndex(headerIndex, new ArrayList<>(chartData.keySet())), startChartIndex, startChartIndex + 10));
        LineChartData lineChartData = chart.getChartDataFactory().createLineChartData();
        data = lineChartData;
        ChartAxis bottomAxis = chart.getChartAxisFactory().createCategoryAxis(AxisPosition.BOTTOM);
        ValueAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT);
        leftAxis.setCrosses(AxisCrosses.AUTO_ZERO);
        ChartLegend legend = chart.getOrCreateLegend();
        legend.setPosition(LegendPosition.RIGHT);
        chartData.put(chart, Pair.create(lineChartData, Arrays.asList(bottomAxis, leftAxis)));
        chartPool.put(nearestHeader.second, chart);
    } else {
        data = chartData.get(chart).first;
    }
    ChartDataSource<String> categorySource = DataSources.fromStringCellRange(sheet, new CellRangeAddress(0, 0, 1, lastDataCellNum));
    data.addSeries(categorySource, DataSources.fromNumericCellRange(sheet, new CellRangeAddress(rowNum, rowNum, 1, lastDataCellNum))).setTitle(row.getCell(0).getStringCellValue());
}
Also used : Drawing(org.apache.poi.ss.usermodel.Drawing) ArrayList(java.util.ArrayList) RichTextString(org.apache.poi.ss.usermodel.RichTextString) ChartLegend(org.apache.poi.ss.usermodel.charts.ChartLegend) PreferencesUtilsKt.setShouldShowExportHint(com.supercilex.robotscouter.util.PreferencesUtilsKt.setShouldShowExportHint) PreferencesUtilsKt.shouldShowExportHint(com.supercilex.robotscouter.util.PreferencesUtilsKt.shouldShowExportHint) XSSFChart(org.apache.poi.xssf.usermodel.XSSFChart) ChartAxis(org.apache.poi.ss.usermodel.charts.ChartAxis) ValueAxis(org.apache.poi.ss.usermodel.charts.ValueAxis) LineChartData(org.apache.poi.ss.usermodel.charts.LineChartData) Metric(com.supercilex.robotscouter.data.model.Metric) Row(org.apache.poi.ss.usermodel.Row) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) SpreadsheetUtils.getCellRangeAddress(com.supercilex.robotscouter.data.client.spreadsheet.SpreadsheetUtils.getCellRangeAddress) Sheet(org.apache.poi.ss.usermodel.Sheet) XSSFChart(org.apache.poi.xssf.usermodel.XSSFChart) Chart(org.apache.poi.ss.usermodel.Chart) CTChart(org.openxmlformats.schemas.drawingml.x2006.chart.CTChart) SpreadsheetUtils.getMetricForChart(com.supercilex.robotscouter.data.client.spreadsheet.SpreadsheetUtils.getMetricForChart) AddTrace(com.google.firebase.perf.metrics.AddTrace)

Aggregations

AddTrace (com.google.firebase.perf.metrics.AddTrace)7 PreferencesUtilsKt.setShouldShowExportHint (com.supercilex.robotscouter.util.PreferencesUtilsKt.setShouldShowExportHint)6 PreferencesUtilsKt.shouldShowExportHint (com.supercilex.robotscouter.util.PreferencesUtilsKt.shouldShowExportHint)6 Row (org.apache.poi.ss.usermodel.Row)5 SpreadsheetUtils.getStringForCell (com.supercilex.robotscouter.data.client.spreadsheet.SpreadsheetUtils.getStringForCell)4 Metric (com.supercilex.robotscouter.data.model.Metric)4 Cell (org.apache.poi.ss.usermodel.Cell)4 RichTextString (org.apache.poi.ss.usermodel.RichTextString)4 SpreadsheetUtils.getCellRangeAddress (com.supercilex.robotscouter.data.client.spreadsheet.SpreadsheetUtils.getCellRangeAddress)3 SpreadsheetUtils.getMetricForChart (com.supercilex.robotscouter.data.client.spreadsheet.SpreadsheetUtils.getMetricForChart)3 ArrayList (java.util.ArrayList)3 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)3 Chart (org.apache.poi.ss.usermodel.Chart)3 Sheet (org.apache.poi.ss.usermodel.Sheet)3 Workbook (org.apache.poi.ss.usermodel.Workbook)3 ChartAxis (org.apache.poi.ss.usermodel.charts.ChartAxis)3 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)3 XSSFChart (org.apache.poi.xssf.usermodel.XSSFChart)3 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)3 CTChart (org.openxmlformats.schemas.drawingml.x2006.chart.CTChart)3