Search in sources :

Example 1 with Scout

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);
    }
}
Also used : Metric(com.supercilex.robotscouter.data.model.Metric) ArrayList(java.util.ArrayList) SpreadsheetUtils.getAdjustedList(com.supercilex.robotscouter.data.client.spreadsheet.SpreadsheetUtils.getAdjustedList) List(java.util.List) Row(org.apache.poi.ss.usermodel.Row) RichTextString(org.apache.poi.ss.usermodel.RichTextString) Cell(org.apache.poi.ss.usermodel.Cell) SpreadsheetUtils.getStringForCell(com.supercilex.robotscouter.data.client.spreadsheet.SpreadsheetUtils.getStringForCell) Scout(com.supercilex.robotscouter.data.model.Scout) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) PreferencesUtilsKt.setShouldShowExportHint(com.supercilex.robotscouter.util.PreferencesUtilsKt.setShouldShowExportHint) PreferencesUtilsKt.shouldShowExportHint(com.supercilex.robotscouter.util.PreferencesUtilsKt.shouldShowExportHint) AddTrace(com.google.firebase.perf.metrics.AddTrace)

Example 2 with Scout

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();
}
Also used : Context(android.content.Context) Query(com.google.firebase.database.Query) Metric(com.supercilex.robotscouter.data.model.Metric) DataSnapshot(com.google.firebase.database.DataSnapshot) Pair(android.util.Pair) DatabaseReference(com.google.firebase.database.DatabaseReference) Timer(java.util.Timer) FIREBASE_NAME(com.supercilex.robotscouter.util.ConstantsKt.FIREBASE_NAME) NonNull(android.support.annotation.NonNull) Task(com.google.android.gms.tasks.Task) ChildEventListener(com.google.firebase.database.ChildEventListener) ArrayList(java.util.ArrayList) ValueEventListener(com.google.firebase.database.ValueEventListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener) Map(java.util.Map) TimerTask(java.util.TimerTask) ConnectivityUtilsKt.isOffline(com.supercilex.robotscouter.util.ConnectivityUtilsKt.isOffline) AsyncTaskExecutor(com.supercilex.robotscouter.util.AsyncTaskExecutor) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) METRIC_PARSER(com.supercilex.robotscouter.data.util.ScoutUtilsKt.METRIC_PARSER) FIREBASE_METRICS(com.supercilex.robotscouter.util.ConstantsKt.FIREBASE_METRICS) FirebaseCrash(com.google.firebase.crash.FirebaseCrash) FIREBASE_SCOUTS(com.supercilex.robotscouter.util.ConstantsKt.FIREBASE_SCOUTS) Size(android.support.annotation.Size) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Tasks(com.google.android.gms.tasks.Tasks) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) TaskCompletionSource(com.google.android.gms.tasks.TaskCompletionSource) Scout(com.supercilex.robotscouter.data.model.Scout) ScoutUtilsKt.getScoutIndicesRef(com.supercilex.robotscouter.data.util.ScoutUtilsKt.getScoutIndicesRef) DatabaseError(com.google.firebase.database.DatabaseError) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Task(com.google.android.gms.tasks.Task) TimerTask(java.util.TimerTask) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) DataSnapshot(com.google.firebase.database.DataSnapshot) TaskCompletionSource(com.google.android.gms.tasks.TaskCompletionSource) DatabaseError(com.google.firebase.database.DatabaseError) ArrayList(java.util.ArrayList) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ValueEventListener(com.google.firebase.database.ValueEventListener) Pair(android.util.Pair)

Aggregations

Metric (com.supercilex.robotscouter.data.model.Metric)2 Scout (com.supercilex.robotscouter.data.model.Scout)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Context (android.content.Context)1 NonNull (android.support.annotation.NonNull)1 Size (android.support.annotation.Size)1 Pair (android.util.Pair)1 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)1 OnSuccessListener (com.google.android.gms.tasks.OnSuccessListener)1 Task (com.google.android.gms.tasks.Task)1 TaskCompletionSource (com.google.android.gms.tasks.TaskCompletionSource)1 Tasks (com.google.android.gms.tasks.Tasks)1 FirebaseCrash (com.google.firebase.crash.FirebaseCrash)1 ChildEventListener (com.google.firebase.database.ChildEventListener)1 DataSnapshot (com.google.firebase.database.DataSnapshot)1 DatabaseError (com.google.firebase.database.DatabaseError)1 DatabaseReference (com.google.firebase.database.DatabaseReference)1 Query (com.google.firebase.database.Query)1 ValueEventListener (com.google.firebase.database.ValueEventListener)1