From 26db3ccc2ed5d43a0e791a29d5cc4afca192e4b7 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Fri, 11 Aug 2017 15:26:11 +0500 Subject: Initialize tripsConfig ones in Context --- src/org/traccar/Context.java | 21 +++++++++++++++++++-- src/org/traccar/reports/ReportUtils.java | 9 --------- src/org/traccar/reports/Stops.java | 7 ++----- src/org/traccar/reports/Trips.java | 7 ++----- 4 files changed, 23 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/org/traccar/Context.java b/src/org/traccar/Context.java index 4bcc1468b..a69b1786d 100644 --- a/src/org/traccar/Context.java +++ b/src/org/traccar/Context.java @@ -67,7 +67,7 @@ import org.traccar.geolocation.GeolocationProvider; import org.traccar.geolocation.MozillaGeolocationProvider; import org.traccar.geolocation.OpenCellIdGeolocationProvider; import org.traccar.notification.EventForwarder; -import org.traccar.reports.ReportUtils; +import org.traccar.reports.model.TripsConfig; import org.traccar.smpp.SmppClient; import org.traccar.web.WebServer; @@ -244,6 +244,21 @@ public final class Context { return overspeedEventHandler; } + private static TripsConfig tripsConfig; + + public static TripsConfig getTripsConfig() { + return tripsConfig; + } + + public static TripsConfig initTripsConfig() { + return new TripsConfig( + config.getLong("report.trip.minimalTripDistance", 500), + config.getLong("report.trip.minimalTripDuration", 300) * 1000, + config.getLong("report.trip.minimalParkingDuration", 300) * 1000, + config.getBoolean("report.trip.greedyParking"), + config.getLong("report.trip.minimalNoDataDuration", 3600) * 1000); + } + public static void init(String[] arguments) throws Exception { config = new Config(); @@ -342,6 +357,8 @@ public final class Context { connectionManager = new ConnectionManager(); + tripsConfig = initTripsConfig(); + if (config.getBoolean("event.enable")) { geofenceManager = new GeofenceManager(dataManager); calendarManager = new CalendarManager(dataManager); @@ -366,7 +383,7 @@ public final class Context { velocityEngine = new VelocityEngine(); velocityEngine.init(velocityProperties); - motionEventHandler = new MotionEventHandler(ReportUtils.initTripsConfig()); + motionEventHandler = new MotionEventHandler(tripsConfig); overspeedEventHandler = new OverspeedEventHandler( Context.getConfig().getLong("event.overspeed.minimalDuration") * 1000, Context.getConfig().getBoolean("event.overspeed.notRepeat")); diff --git a/src/org/traccar/reports/ReportUtils.java b/src/org/traccar/reports/ReportUtils.java index e8db7e3b5..8c39bb9dc 100644 --- a/src/org/traccar/reports/ReportUtils.java +++ b/src/org/traccar/reports/ReportUtils.java @@ -155,15 +155,6 @@ public final class ReportUtils { transformer.write(); } - public static TripsConfig initTripsConfig() { - return new TripsConfig( - Context.getConfig().getLong("report.trip.minimalTripDistance", 500), - Context.getConfig().getLong("report.trip.minimalTripDuration", 300) * 1000, - Context.getConfig().getLong("report.trip.minimalParkingDuration", 300) * 1000, - Context.getConfig().getBoolean("report.trip.greedyParking"), - Context.getConfig().getLong("report.trip.minimalNoDataDuration", 3600) * 1000); - } - private static TripReport calculateTrip( ArrayList positions, int startIndex, int endIndex, boolean ignoreOdometer) { Position startTrip = positions.get(startIndex); diff --git a/src/org/traccar/reports/Stops.java b/src/org/traccar/reports/Stops.java index ee6746e4e..3f7f674b5 100644 --- a/src/org/traccar/reports/Stops.java +++ b/src/org/traccar/reports/Stops.java @@ -33,7 +33,6 @@ import org.traccar.model.Group; import org.traccar.reports.model.BaseReport; import org.traccar.reports.model.DeviceReport; import org.traccar.reports.model.StopReport; -import org.traccar.reports.model.TripsConfig; public final class Stops { @@ -43,13 +42,11 @@ public final class Stops { private static Collection detectStops(long deviceId, Date from, Date to) throws SQLException { double speedThreshold = Context.getConfig().getDouble("event.motion.speedThreshold", 0.01); - TripsConfig tripsConfig = ReportUtils.initTripsConfig(); - boolean ignoreOdometer = Context.getDeviceManager() .lookupAttributeBoolean(deviceId, "report.ignoreOdometer", false, true); - Collection result = ReportUtils.detectTripsAndStops(tripsConfig, - ignoreOdometer, speedThreshold, + Collection result = ReportUtils.detectTripsAndStops( + Context.getTripsConfig(), ignoreOdometer, speedThreshold, Context.getDataManager().getPositions(deviceId, from, to), false); return (Collection) result; diff --git a/src/org/traccar/reports/Trips.java b/src/org/traccar/reports/Trips.java index 6b97507f4..a4dcf00f1 100644 --- a/src/org/traccar/reports/Trips.java +++ b/src/org/traccar/reports/Trips.java @@ -32,7 +32,6 @@ import org.traccar.model.Group; import org.traccar.reports.model.BaseReport; import org.traccar.reports.model.DeviceReport; import org.traccar.reports.model.TripReport; -import org.traccar.reports.model.TripsConfig; public final class Trips { @@ -42,13 +41,11 @@ public final class Trips { private static Collection detectTrips(long deviceId, Date from, Date to) throws SQLException { double speedThreshold = Context.getConfig().getDouble("event.motion.speedThreshold", 0.01); - TripsConfig tripsConfig = ReportUtils.initTripsConfig(); - boolean ignoreOdometer = Context.getDeviceManager() .lookupAttributeBoolean(deviceId, "report.ignoreOdometer", false, true); - Collection result = ReportUtils.detectTripsAndStops(tripsConfig, - ignoreOdometer, speedThreshold, + Collection result = ReportUtils.detectTripsAndStops( + Context.getTripsConfig(), ignoreOdometer, speedThreshold, Context.getDataManager().getPositions(deviceId, from, to), true); return (Collection) result; -- cgit v1.2.3