| 1 | package edu.ucsb.cs156.happiercows.services; | |
| 2 | ||
| 3 | import org.springframework.beans.factory.annotation.Autowired; | |
| 4 | import org.springframework.stereotype.Service; | |
| 5 | ||
| 6 | import edu.ucsb.cs156.happiercows.entities.Game; | |
| 7 | import edu.ucsb.cs156.happiercows.entities.GameStats; | |
| 8 | import edu.ucsb.cs156.happiercows.repositories.GameRepository; | |
| 9 | import edu.ucsb.cs156.happiercows.repositories.GameStatsRepository; | |
| 10 | import edu.ucsb.cs156.happiercows.repositories.FarmerRepository; | |
| 11 | ||
| 12 | @Service("GameStatsService") | |
| 13 | public class GameStatsService { | |
| 14 | ||
| 15 | @Autowired | |
| 16 | GameStatsRepository gameStatsRepository; | |
| 17 | ||
| 18 | @Autowired | |
| 19 | GameRepository gameRepository; | |
| 20 | ||
| 21 | @Autowired | |
| 22 | FarmerRepository farmerRepository; | |
| 23 | ||
| 24 | @Autowired | |
| 25 | private AverageCowHealthService averageCowHealthService; | |
| 26 | ||
| 27 | public GameStats createGameStats(Long gameId) { | |
| 28 | ||
| 29 | Game game = gameRepository.findById(gameId) | |
| 30 |
1
1. lambda$createGameStats$0 : replaced return value with null for edu/ucsb/cs156/happiercows/services/GameStatsService::lambda$createGameStats$0 → KILLED |
.orElseThrow(() -> new IllegalArgumentException(String.format("Game with id %d not found", gameId))); |
| 31 | ||
| 32 | double avgHealth = averageCowHealthService.getAverageCowHealth(gameId); | |
| 33 | int totalNumCows = averageCowHealthService.getTotalNumCows(gameId); | |
| 34 | int numUsers = gameRepository.getNumUsers(gameId).orElse(0); | |
| 35 |
1
1. createGameStats : Replaced integer multiplication with division → KILLED |
int effectiveCapacity = Math.max(game.getCapacityPerUser() * numUsers, game.getCarryingCapacity()); |
| 36 | ||
| 37 | GameStats stats = GameStats.builder() | |
| 38 | .gameId(gameId) | |
| 39 | .numCows(totalNumCows) | |
| 40 | .avgHealth(avgHealth) | |
| 41 | .effectiveCapacity(effectiveCapacity) | |
| 42 | .numFarmers(numUsers) | |
| 43 | .capacityPerUser(game.getCapacityPerUser()) | |
| 44 | .carryingCapacity(game.getCarryingCapacity()) | |
| 45 | .build(); | |
| 46 | ||
| 47 |
1
1. createGameStats : replaced return value with null for edu/ucsb/cs156/happiercows/services/GameStatsService::createGameStats → KILLED |
return stats; |
| 48 | } | |
| 49 | ||
| 50 | public GameStats createAndSaveGameStats(Long gameId) { | |
| 51 | | |
| 52 | GameStats stats = createGameStats(gameId); | |
| 53 | gameStatsRepository.save(stats); | |
| 54 | ||
| 55 |
1
1. createAndSaveGameStats : replaced return value with null for edu/ucsb/cs156/happiercows/services/GameStatsService::createAndSaveGameStats → KILLED |
return stats; |
| 56 | } | |
| 57 | ||
| 58 | } | |
Mutations | ||
| 30 |
1.1 |
|
| 35 |
1.1 |
|
| 47 |
1.1 |
|
| 55 |
1.1 |