use of com.supercilex.robotscouter.data.model.Scout in project Robot-Scouter by SUPERCILEX.
the class SpreadsheetExporter method buildTeamSheet.
@AddTrace(name = "buildTeamSheet")
private void buildTeamSheet(TeamHelper teamHelper, Sheet teamSheet) {
List<Scout> scouts = mScouts.get(teamHelper);
if (scouts.isEmpty()) {
Workbook workbook = teamSheet.getWorkbook();
workbook.removeSheetAt(workbook.getSheetIndex(teamSheet));
return;
}
Row header = teamSheet.createRow(0);
// Create empty top left corner cell
header.createCell(0);
List<Metric<?>> orderedMetrics = scouts.get(scouts.size() - 1).getMetrics();
for (int i = 0; i < orderedMetrics.size(); i++) {
Metric metric = orderedMetrics.get(i);
Row row = teamSheet.createRow(i + 1);
setupRow(row, teamHelper, metric);
}
for (int i = 0, column = 1; i < scouts.size(); i++, column++) {
Scout scout = scouts.get(i);
List<Metric<?>> metrics = scout.getMetrics();
Cell cell = header.getCell(column, MissingCellPolicy.CREATE_NULL_AS_BLANK);
String name = scout.getName();
cell.setCellValue(TextUtils.isEmpty(name) ? "Scout " + column : name);
cell.setCellStyle(mCache.getColumnHeaderStyle());
columnIterator: for (int j = 0, rowNum = 1; j < metrics.size(); j++, rowNum++) {
Metric metric = metrics.get(j);
Row row = teamSheet.getRow(rowNum);
if (row == null) {
setupRowAndSetValue(teamSheet.createRow(rowNum), teamHelper, metric, column);
} else {
List<Row> rows = getAdjustedList(teamSheet);
for (Row row1 : rows) {
Cell cell1 = row1.getCell(0);
if (TextUtils.equals(mCache.getMetricKey(row1), metric.getRef().getKey())) {
setRowValue(column, metric, row1);
if (TextUtils.isEmpty(cell1.getStringCellValue())) {
cell1.setCellValue(metric.getName());
}
continue columnIterator;
}
}
setupRowAndSetValue(teamSheet.createRow(teamSheet.getLastRowNum() + 1), teamHelper, metric, column);
}
}
}
if (scouts.size() > SINGLE_ITEM) {
buildAverageColumn(teamSheet, teamHelper);
}
}
use of com.supercilex.robotscouter.data.model.Scout in project Robot-Scouter by SUPERCILEX.
the class Scouts method build.
public Task<Map<TeamHelper, List<Scout>>> build() {
List<Task<Pair<TeamHelper, List<String>>>> scoutIndicesTasks = new ArrayList<>();
for (TeamHelper helper : mTeamHelpers) {
TaskCompletionSource<Pair<TeamHelper, List<String>>> scoutIndicesTask = new TaskCompletionSource<>();
scoutIndicesTasks.add(scoutIndicesTask.getTask());
getScoutIndicesRef(helper.getTeam().getKey()).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
AsyncTaskExecutor.Companion.execute(() -> {
List<String> scoutKeys = new ArrayList<>();
for (DataSnapshot scoutKeyTemplate : snapshot.getChildren()) {
scoutKeys.add(scoutKeyTemplate.getKey());
}
return scoutKeys;
}).addOnSuccessListener(scoutKeys -> scoutIndicesTask.setResult(Pair.create(helper, scoutKeys)));
}
@Override
public void onCancelled(DatabaseError error) {
scoutIndicesTask.setException(error.toException());
FirebaseCrash.report(error.toException());
}
});
}
for (Task<Pair<TeamHelper, List<String>>> scoutKeysTask : scoutIndicesTasks) {
scoutKeysTask.addOnSuccessListener(this).addOnFailureListener(this);
}
Tasks.whenAll(scoutIndicesTasks).addOnSuccessListener(aVoid -> Tasks.whenAll(mScoutMetricsTasks).addOnSuccessListener(aVoid1 -> mScoutsTask.setResult(mScouts)).addOnFailureListener(this)).addOnFailureListener(this);
return mScoutsTask.getTask();
}
Aggregations