Search in sources :

Example 6 with CSVWriterBuilder

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);
            }
        }
    }
}
Also used : Path(java.nio.file.Path) DisplayContext(com.faendir.zachtronics.bot.model.DisplayContext) Subreddit(com.faendir.zachtronics.bot.reddit.Subreddit) Files(java.nio.file.Files) BotTest(com.faendir.zachtronics.bot.BotTest) Autowired(org.springframework.beans.factory.annotation.Autowired) IOException(java.io.IOException) Disabled(org.junit.jupiter.api.Disabled) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) com.faendir.zachtronics.bot.sz.model(com.faendir.zachtronics.bot.sz.model) Test(org.junit.jupiter.api.Test) UncheckedIOException(java.io.UncheckedIOException) TreeMap(java.util.TreeMap) CategoryRecord(com.faendir.zachtronics.bot.repository.CategoryRecord) Paths(java.nio.file.Paths) Map(java.util.Map) RedditService(com.faendir.zachtronics.bot.reddit.RedditService) ICSVWriter(com.opencsv.ICSVWriter) Path(java.nio.file.Path) CSVWriterBuilder(com.opencsv.CSVWriterBuilder) CSVWriterBuilder(com.opencsv.CSVWriterBuilder) CategoryRecord(com.faendir.zachtronics.bot.repository.CategoryRecord) TreeMap(java.util.TreeMap) ICSVWriter(com.opencsv.ICSVWriter) BotTest(com.faendir.zachtronics.bot.BotTest) Test(org.junit.jupiter.api.Test)

Aggregations

CSVWriterBuilder (com.opencsv.CSVWriterBuilder)6 ICSVWriter (com.opencsv.ICSVWriter)5 BotTest (com.faendir.zachtronics.bot.BotTest)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 OutputStreamWriter (java.io.OutputStreamWriter)2 StringWriter (java.io.StringWriter)2 Writer (java.io.Writer)2 Path (java.nio.file.Path)2 Test (org.junit.jupiter.api.Test)2 DisplayContext (com.faendir.zachtronics.bot.model.DisplayContext)1 RedditService (com.faendir.zachtronics.bot.reddit.RedditService)1 Subreddit (com.faendir.zachtronics.bot.reddit.Subreddit)1 CategoryRecord (com.faendir.zachtronics.bot.repository.CategoryRecord)1 com.faendir.zachtronics.bot.sz.model (com.faendir.zachtronics.bot.sz.model)1 CSVWriter (com.opencsv.CSVWriter)1 ArchiveUnitCsv (fr.gouv.vitamui.archives.search.common.dto.ArchiveUnitCsv)1 BadRequestException (fr.gouv.vitamui.commons.api.exception.BadRequestException)1 UncheckedIOException (java.io.UncheckedIOException)1 Files (java.nio.file.Files)1