use of com.opencsv.CSVWriterBuilder in project zachtronics-leaderboard-bot by F43nd1r.
the class SzManualTest method bootstrapPsv.
@Test
public void bootstrapPsv() throws IOException {
Path repoPath = Paths.get("../shenzhenIO/leaderboard");
for (SzPuzzle puzzle : SzPuzzle.values()) {
if (puzzle.getType() != SzType.STANDARD)
continue;
Path indexPath = repoPath.resolve(puzzle.getGroup().getRepoFolder()).resolve(puzzle.getId()).resolve("solutions.psv");
try (ICSVWriter writer = new CSVWriterBuilder(Files.newBufferedWriter(indexPath)).withSeparator('|').build()) {
Map<SzScore, CategoryRecord<SzRecord, SzCategory>> scoreMap = repository.findCategoryHolders(puzzle, true).stream().collect(Collectors.toMap(cr -> cr.getRecord().getScore(), Function.identity(), (cr1, cr2) -> {
cr1.getCategories().addAll(cr2.getCategories());
return cr1;
}, () -> new TreeMap<>(SzCategory.CP.getScoreComparator())));
for (CategoryRecord<SzRecord, SzCategory> cr : scoreMap.values()) {
SzRecord record = cr.getRecord();
String author = record.getAuthor();
String categories = cr.getCategories().stream().map(SzCategory::name).sorted().collect(Collectors.joining(","));
String[] csvRecord = new String[] { record.getScore().toDisplayString(), author, categories };
writer.writeNext(csvRecord, false);
}
}
}
}
Aggregations