| | |
| | | import com.trafficaudit.common.util.RegionUtil; |
| | | |
| | | /** Selects one complete mileage record for an above-scale enterprise. */ |
| | | final class TrackMileageSelector { |
| | | static final String XIAOGAN_CITY = "孝感市"; |
| | | public final class TrackMileageSelector { |
| | | private static final double MAX_ANOMALY_RATE = 1.0; |
| | | private static final double MAX_ANOMALY_PER_VEHICLE = 10000.0; |
| | | private TrackMileageSelector() { |
| | | } |
| | | |
| | | static VehicleTrackMileage choose(VehicleTrackMileage current, VehicleTrackMileage candidate) { |
| | | return choose(current, candidate, false); |
| | | public static VehicleTrackMileage choose(VehicleTrackMileage current, VehicleTrackMileage candidate) { |
| | | return choose(current, candidate, (String) null); |
| | | } |
| | | |
| | | static VehicleTrackMileage choose(VehicleTrackMileage current, VehicleTrackMileage candidate, |
| | | boolean citySourceRequired) { |
| | | if (citySourceRequired) { |
| | | // Xiaogan above-scale enterprises must never fall back to provincial data. |
| | | if (isMandatoryCitySource(current)) return current; |
| | | if (isMandatoryCitySource(candidate)) return candidate; |
| | | public static VehicleTrackMileage choose(VehicleTrackMileage current, VehicleTrackMileage candidate, |
| | | String requiredCitySource) { |
| | | if (requiredCitySource != null) { |
| | | if (isCityThirdParty(current, requiredCitySource)) return current; |
| | | if (isCityThirdParty(candidate, requiredCitySource)) return candidate; |
| | | return null; |
| | | } |
| | | if (candidate == null) return current; |
| | |
| | | return isProvincial(candidate) && !isProvincial(current) ? candidate : current; |
| | | } |
| | | |
| | | static boolean isMandatoryCitySource(VehicleTrackMileage row) { |
| | | public static boolean isCityThirdParty(VehicleTrackMileage row, String city) { |
| | | return row != null |
| | | && VehicleTrackMileage.SOURCE_CITY_THIRD_PARTY.equals(row.getDataSource()) |
| | | && XIAOGAN_CITY.equals(RegionUtil.normalizeCityName(row.getCityName())); |
| | | && city != null |
| | | && city.equals(RegionUtil.normalizeCityName(row.getCityName())); |
| | | } |
| | | |
| | | static boolean isXiaoganRegionCode(String regionCode) { |
| | | return regionCode != null && regionCode.trim().startsWith("4209"); |
| | | } |
| | | |
| | | static boolean isProvincial(VehicleTrackMileage row) { |
| | | public static boolean isProvincial(VehicleTrackMileage row) { |
| | | return row == null || row.getDataSource() == null |
| | | || VehicleTrackMileage.SOURCE_PROVINCIAL.equals(row.getDataSource()); |
| | | } |
| | |
| | | * Mirrors the established workbook formula: monthly mileage plus anomaly mileage |
| | | * unless anomaly rate exceeds 100% or anomaly mileage per tracked vehicle exceeds 10,000 km. |
| | | */ |
| | | static double effectiveMonthlyMileage(VehicleTrackMileage row) { |
| | | public static double effectiveMonthlyMileage(VehicleTrackMileage row) { |
| | | double mileage = row.getMonthlyMileage() == null ? 0.0 : row.getMonthlyMileage(); |
| | | if (VehicleTrackMileage.SOURCE_CITY_THIRD_PARTY.equals(row.getDataSource())) { |
| | | // City third-party files do not split normal and abnormal mileage. |
| | | return mileage; |
| | | } |
| | | double anomaly = row.getAnomalyMileage() == null ? 0.0 : row.getAnomalyMileage(); |
| | | int trackedVehicles = row.getTrackedVehicles() == null ? 0 : row.getTrackedVehicles(); |
| | | |