コード例 #1
0
 /**
  * Sorts inventories by rating and returns these ratings.
  *
  * @param inventories inventories.
  * @return ratings.
  */
 public Map<String, Double> sortInventoriesByRelativity(
     int pathId, List<InventoryDto> inventories) {
   Map<RoadType, Double> pathMap = pathService.getRoadTypesWithPcts(pathId);
   final double averageSpeedCoeff =
       speedLimitsAnalyzer.getSpeedLimitsAverageCoeff(
           pathMap.get(RoadType.HIGHWAY_RURAL),
           pathMap.get(RoadType.HIGHWAY_URBAN),
           pathMap.get(RoadType.RESIDENTIAL));
   fillEngineHorsePowerMap(inventories);
   Map<String, Double> ratingMap = new HashMap<>();
   for (InventoryDto inventoryDto : inventories) {
     double delta = Math.abs(getInventoryHorsePowerCoeff(inventoryDto) - averageSpeedCoeff);
     ratingMap.put(inventoryDto.getId(), (1 - delta) * MAX_RATING);
   }
   Collections.sort(
       inventories,
       new Comparator<InventoryDto>() {
         @Override
         public int compare(InventoryDto o1, InventoryDto o2) {
           Double rating1 = ratingMap.get(o1.getId());
           Double rating2 = ratingMap.get(o2.getId());
           return rating2.compareTo(rating1);
         }
       });
   return ratingMap;
 }
コード例 #2
0
 public double getAverageSpeed(int pathId) {
   Map<RoadType, Double> pathMap = pathService.getRoadTypesWithPcts(pathId);
   double averageSpeedLimit =
       SpeedLimitsAnalyzer.FREEWAY_RURAL_MAX * pathMap.get(RoadType.HIGHWAY_RURAL) / 100
           + SpeedLimitsAnalyzer.FREEWAY_URBAN_MAX * pathMap.get(RoadType.HIGHWAY_URBAN) / 100
           + SpeedLimitsAnalyzer.RESIDENTIAL_MAX * pathMap.get(RoadType.RESIDENTIAL) / 100;
   return averageSpeedLimit;
 }