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;
}
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());
}
Aggregations