Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ A pitcher directory consists of the following files:
```
.
├── count.txt
├── pitchcount.txt
├── era.txt
├── firstname.txt
├── flag.png
Expand All @@ -106,6 +107,7 @@ The complete output directory is structured as follows:
├── away_score.txt
├── away_team.txt
├── balls.txt
├── balls.png
├── bases
│   ├── ooo.png
│   ├── oox.png
Expand Down Expand Up @@ -219,6 +221,7 @@ The complete output directory is structured as follows:
│   └── 2.png
├── outs.png
├── strikes.txt
├── strikes.png
└── team_resources
├── colors
│   ├── ALB.png
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ public void initResources() throws IOException {
filesClient.copyFileFromResource("/outs/1.png", "outs/1.png");
filesClient.copyFileFromResource("/outs/2.png", "outs/2.png");

filesClient.copyFileFromResource("/balls/0.png", "balls/0.png");
filesClient.copyFileFromResource("/balls/1.png", "balls/1.png");
filesClient.copyFileFromResource("/balls/2.png", "balls/2.png");
filesClient.copyFileFromResource("/balls/3.png", "balls/3.png");

filesClient.copyFileFromResource("/strikes/0.png", "strikes/0.png");
filesClient.copyFileFromResource("/strikes/1.png", "strikes/1.png");
filesClient.copyFileFromResource("/strikes/2.png", "strikes/2.png");

filesClient.copyFileFromResource(
"/images/player-image-default.png", "team_resources/player_images/default.png");
filesClient.copyFileFromResource(
Expand Down Expand Up @@ -162,14 +171,40 @@ private void updateScoreBoard() throws IOException {
situation.put("balls", s.balls().orElse("0"));
situation.put("strikes", s.strikes().orElse("0"));
});

updateCount(situation);
}

private void updateCount(Map<String, String> situation) throws IOException {
String balls = situation.getOrDefault("balls", "0");
String strikes = situation.getOrDefault("strikes", "0");

filesClient.writeStringToFile(
"count.txt",
String.format(
"%s - %s",
situation.getOrDefault("balls", "0"), situation.getOrDefault("strikes", "0")));
filesClient.writeStringToFile("balls.txt", situation.getOrDefault("balls", "0"));
filesClient.writeStringToFile("strikes.txt", situation.getOrDefault("strikes", "0"));
String.format("%s - %s", balls, strikes));

filesClient.writeStringToFile("balls.txt", balls);
filesClient.writeStringToFile("strikes.txt", strikes);

String ballsTarget = "balls.png";
if ("1".equals(balls)) {
filesClient.copyFile("balls/1.png", ballsTarget);
} else if ("2".equals(balls)) {
filesClient.copyFile("balls/2.png", ballsTarget);
} else if ("3".equals(balls)) {
filesClient.copyFile("balls/3.png", ballsTarget);
} else {
filesClient.copyFile("balls/0.png", ballsTarget);
}

String strikesTarget = "strikes.png";
if ("1".equals(strikes)) {
filesClient.copyFile("strikes/1.png", strikesTarget);
} else if ("2".equals(strikes)) {
filesClient.copyFile("strikes/2.png", strikesTarget);
} else {
filesClient.copyFile("strikes/0.png", strikesTarget);
}
}

private void updateBases() throws IOException {
Expand Down Expand Up @@ -225,6 +260,9 @@ private void updatePitcher(final Player pitcher, final String subdir) throws IOE
filesClient.writeStringToFile(
subdir + "/count.txt", String.format("P: %s", pitcher.pitches().orElse("0")));

filesClient.writeStringToFile(
subdir + "/pitchcount.txt", pitcher.pitches().orElse("0"));

filesClient.writeStringToFile(subdir + "/firstname.txt", pitcher.firstName().orElse(""));
filesClient.writeStringToFile(subdir + "/fullname.txt", pitcher.fullName().orElse(""));
filesClient.writeStringToFile(subdir + "/lastname.txt", pitcher.lastName().orElse(""));
Expand Down
Binary file added src/main/resources/balls/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/balls/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/balls/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/balls/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/strikes/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/strikes/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/strikes/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,19 @@ void willInitializeResources(@TempDir File tempDir) throws IOException {
Stream.of(tempDir.listFiles((f) -> f.isDirectory() && f.getName().equals("outs")))
.findFirst();

Optional<File> ballsDir =
Stream.of(tempDir.listFiles((f) -> f.isDirectory() && f.getName().equals("balls")))
.findFirst();

Optional<File> strikesDir =
Stream.of(tempDir.listFiles((f) -> f.isDirectory() && f.getName().equals("strikes")))
.findFirst();


assertTrue(basesDir.isPresent());
assertTrue(outsDir.isPresent());
assertTrue(ballsDir.isPresent());
assertTrue(strikesDir.isPresent());
assertTrue(teamResourcesDir.isPresent());

assertTrue(fileExistAndIsNonEmpty(basesDir.get(), "ooo.png"));
Expand All @@ -64,6 +75,15 @@ void willInitializeResources(@TempDir File tempDir) throws IOException {
assertTrue(fileExistAndIsNonEmpty(outsDir.get(), "1.png"));
assertTrue(fileExistAndIsNonEmpty(outsDir.get(), "2.png"));

assertTrue(fileExistAndIsNonEmpty(ballsDir.get(), "0.png"));
assertTrue(fileExistAndIsNonEmpty(ballsDir.get(), "1.png"));
assertTrue(fileExistAndIsNonEmpty(ballsDir.get(), "2.png"));
assertTrue(fileExistAndIsNonEmpty(ballsDir.get(), "3.png"));

assertTrue(fileExistAndIsNonEmpty(strikesDir.get(), "0.png"));
assertTrue(fileExistAndIsNonEmpty(strikesDir.get(), "1.png"));
assertTrue(fileExistAndIsNonEmpty(strikesDir.get(), "2.png"));

Optional<File> playerImagesDir =
Stream.of(
teamResourcesDir
Expand Down Expand Up @@ -166,6 +186,7 @@ void shouldUpdatePlay(String playJsonFile, @TempDir File tempDir) throws IOExcep
client.copyFileFromResource(
"/wbsc/default-player.jpg", "team_resources/player_images/default.png");
FilesService service = new FilesService(client);
service.initResources();
Play play = JsonMapper.fromJson(playJson, Play.class);
service.updatePlay(play);

Expand All @@ -184,6 +205,7 @@ void shouldUpdatePlay(String playJsonFile, @TempDir File tempDir) throws IOExcep
assertTrue(fileExistAndIsNonEmpty(currentPitcherDir.get(), "image.png"));
assertTrue(fileExistAndIsNonEmpty(currentPitcherDir.get(), "walks.txt"));
assertTrue(fileExistAndIsNonEmpty(currentPitcherDir.get(), "count.txt"));
assertTrue(fileExistAndIsNonEmpty(currentPitcherDir.get(), "pitchcount.txt"));
assertTrue(fileExistAndIsNonEmpty(currentPitcherDir.get(), "fullname.txt"));
assertTrue(fileExistAndIsNonEmpty(currentPitcherDir.get(), "pitching.txt"));
assertTrue(fileExistAndIsNonEmpty(currentPitcherDir.get(), "lastname.txt"));
Expand Down Expand Up @@ -235,7 +257,9 @@ void shouldUpdatePlay(String playJsonFile, @TempDir File tempDir) throws IOExcep

assertTrue(fileExistAndIsNonEmpty(tempDir, "count.txt"));
assertTrue(fileExistAndIsNonEmpty(tempDir, "balls.txt"));
assertTrue(fileExistAndIsNonEmpty(tempDir, "balls.png"));
assertTrue(fileExistAndIsNonEmpty(tempDir, "strikes.txt"));
assertTrue(fileExistAndIsNonEmpty(tempDir, "strikes.png"));

assertTrue(fileExistAndIsNonEmpty(tempDir, "inning_text.txt"));

Expand Down