From 0350d762a7c08199e79dc401b6c6821d7e2a21bd Mon Sep 17 00:00:00 2001 From: amilasilva88 Date: Thu, 13 Aug 2015 20:28:58 +0800 Subject: Added ODOMeter and Modification to Mobile UI --- debug.xml | 7 +++-- src/org/traccar/BasePipelineFactory.java | 10 +++++++ src/org/traccar/ODOMeterHandler.java | 51 ++++++++++++++++++++++++++++++++ src/org/traccar/model/Position.java | 4 +++ web/app/store/DistanceUnits.js | 22 +++++++++++++- web/app/store/SpeedUnits.js | 6 ++-- web/app/view/main/MainMobile.js | 5 ++++ web/app/view/report/Report.js | 9 +++++- web/app/view/state/StateController.js | 13 +++++++- 9 files changed, 120 insertions(+), 7 deletions(-) create mode 100644 src/org/traccar/ODOMeterHandler.java diff --git a/debug.xml b/debug.xml index 85cdb46b8..2742356ca 100644 --- a/debug.xml +++ b/debug.xml @@ -25,6 +25,8 @@ true 50--> + true + @@ -97,6 +99,7 @@ altitude FLOAT NOT NULL, speed FLOAT NOT NULL, course FLOAT NOT NULL, + odoMeter FLOAT NOT NULL, address VARCHAR(512), other VARCHAR(4096) NOT NULL, FOREIGN KEY (deviceId) REFERENCES device (id) ON DELETE CASCADE); @@ -232,8 +235,8 @@ - INSERT INTO position (deviceId, protocol, serverTime, deviceTime, fixTime, valid, latitude, longitude, altitude, speed, course, address, other) - VALUES (:deviceId, :protocol, CURRENT_TIMESTAMP(), :time, :time, :valid, :latitude, :longitude, :altitude, :speed, :course, :address, :other); + INSERT INTO position (deviceId, protocol, serverTime, deviceTime, fixTime, valid, latitude, longitude, altitude, speed, course, odoMeter, address, other) + VALUES (:deviceId, :protocol, CURRENT_TIMESTAMP(), :time, :time, :valid, :latitude, :longitude, :altitude, :speed, :course, :odoMeter, :address, :other); diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java index 4d8b0ffc4..410b57318 100644 --- a/src/org/traccar/BasePipelineFactory.java +++ b/src/org/traccar/BasePipelineFactory.java @@ -38,6 +38,7 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory { private int resetDelay; private FilterHandler filterHandler; + private ODOMeterHandler odoMeterHandler; private ReverseGeocoderHandler reverseGeocoderHandler; protected class OpenChannelHandler extends SimpleChannelHandler { @@ -92,6 +93,10 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory { filterHandler = new FilterHandler(); } + if (Context.getConfig().getBoolean("system.odometer.enable")) { + odoMeterHandler = new ODOMeterHandler(); + } + if (Context.getReverseGeocoder() != null) { reverseGeocoderHandler = new ReverseGeocoderHandler( Context.getReverseGeocoder(), Context.getConfig().getBoolean("geocode.processInvalidPositions")); @@ -114,6 +119,11 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory { if (filterHandler != null) { pipeline.addLast("filter", filterHandler); } + + if (odoMeterHandler != null) { + pipeline.addLast("odoMeter", odoMeterHandler); + } + if (reverseGeocoderHandler != null) { pipeline.addLast("geocoder", reverseGeocoderHandler); } diff --git a/src/org/traccar/ODOMeterHandler.java b/src/org/traccar/ODOMeterHandler.java new file mode 100644 index 000000000..1dc3aed44 --- /dev/null +++ b/src/org/traccar/ODOMeterHandler.java @@ -0,0 +1,51 @@ +/** + * + */ +package org.traccar; + +import org.traccar.helper.DistanceCalculator; +import org.traccar.helper.Log; +import org.traccar.model.Position; + +/** + *

+ * ODO Meter handler + *

+ * + * @author Amila Silva + * + */ +public class ODOMeterHandler extends BaseDataHandler { + + public ODOMeterHandler() { + Log.debug("System based ODO meter calculation enabled for all devices"); + } + + private Position getLastPosition(long deviceId) { + if (Context.getConnectionManager() != null) { + return Context.getConnectionManager().getLastPosition(deviceId); + } + return null; + } + + private Position calculateDistance(Position position) { + Position last = getLastPosition(position.getDeviceId()); + if (last != null) { + double distance = DistanceCalculator.distance( + position.getLatitude(), position.getLongitude(), + last.getLatitude(), last.getLongitude()); + distance = Math.round((distance) * 100.0) / 100.0; + double odoMeter = distance + last.getOdoMeter(); + Log.info("::: Device Course : " + position.getDeviceId() + + ", Distance :" + distance + "m, ODO Meter :" + odoMeter + " m"); + position.setOdoMeter(odoMeter); + } + return position; + } + + @Override + protected Position handlePosition(Position position) { + return calculateDistance(position); + } + +} diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java index 62c999d94..8c3340d9c 100644 --- a/src/org/traccar/model/Position.java +++ b/src/org/traccar/model/Position.java @@ -56,6 +56,10 @@ public class Position extends Event implements Factory { private double course; public double getCourse() { return course; } public void setCourse(double course) { this.course = course; } + + private double odoMeter; // value in meters + public double getOdoMeter() { return odoMeter; } + public void setOdoMeter(double odoMeter) { this.odoMeter = odoMeter; } private String address; public String getAddress() { return address; } diff --git a/web/app/store/DistanceUnits.js b/web/app/store/DistanceUnits.js index 506f1077c..7f0f93b70 100644 --- a/web/app/store/DistanceUnits.js +++ b/web/app/store/DistanceUnits.js @@ -20,5 +20,25 @@ Ext.define('Traccar.store.DistanceUnits', { data: [ {'key': 'km', 'name': strings.sharedKm}, {'key': 'mi', 'name': strings.sharedMi} - ] + ], + + convert: function(value, unit) { + switch (unit) { + case 'km': + value = value * 0.001; + return Math.round(value * 100) / 100; + case 'mi': + value = value * 0.000621371; + return Math.round(value * 100) / 100; + } + return value; + }, + + getUnitName: function(unit) { + if (unit) { + return this.findRecord('key', unit).get('name'); + } else { + return ''; + } + }, }); diff --git a/web/app/store/SpeedUnits.js b/web/app/store/SpeedUnits.js index 78686fbb9..934d03717 100644 --- a/web/app/store/SpeedUnits.js +++ b/web/app/store/SpeedUnits.js @@ -25,9 +25,11 @@ Ext.define('Traccar.store.SpeedUnits', { convert: function(value, unit) { switch (unit) { case 'kmh': - return value * 1.852; + value = value * 1.852; + return Math.round(value * 10) / 10; case 'mph': - return value * 1.15078; + value = value * 1.15078; + return Math.round(value * 10) / 10; } return value; }, diff --git a/web/app/view/main/MainMobile.js b/web/app/view/main/MainMobile.js index f32ad9fb1..1cdd6f525 100644 --- a/web/app/view/main/MainMobile.js +++ b/web/app/view/main/MainMobile.js @@ -40,6 +40,11 @@ Ext.define('Traccar.view.main.MainMobile', { xtype: 'deviceView', header: false, flex: 1 + },{ + region: 'east', + xtype: 'stateView', + header: false, + flex: 1 }] }); diff --git a/web/app/view/report/Report.js b/web/app/view/report/Report.js index ff8cc7b3d..f081333d4 100644 --- a/web/app/view/report/Report.js +++ b/web/app/view/report/Report.js @@ -90,7 +90,14 @@ Ext.define('Traccar.view.report.Report', { return speedUnits.convert(value, unit) + ' ' + speedUnits.getUnitName(unit); } }, - { text: strings.positionCourse, dataIndex: 'course', flex: 1 }, + /* { text: strings.positionCourse, dataIndex: 'course', flex: 1 }, */ + { text: 'ODO Meter', dataIndex: 'odoMeter', flex: 1, + renderer: function(value) { + var distanceUnits = Ext.getStore('DistanceUnits'); + var unit = Traccar.getApplication().getUser().get('distanceUnit') || Traccar.getApplication().getServer().get('distanceUnit') || ''; + return distanceUnits.convert(value, unit) + ' ' + distanceUnits.getUnitName(unit); + } + }, { text: strings.positionAddress, dataIndex: 'address', flex: 1 } ] diff --git a/web/app/view/state/StateController.js b/web/app/view/state/StateController.js index 58b63120b..858feab52 100644 --- a/web/app/view/state/StateController.js +++ b/web/app/view/state/StateController.js @@ -59,9 +59,13 @@ Ext.define('Traccar.view.state.StateController', { priority: 6, name: strings.positionSpeed }, - 'course': { +/* 'course': { priority: 7, name: strings.positionCourse + },*/ + 'odoMeter': { + priority: 7, + name: 'ODO Meter' }, 'address': { priority: 8, @@ -87,6 +91,13 @@ Ext.define('Traccar.view.state.StateController', { var unit = Traccar.getApplication().getUser().get('speedUnit') || Traccar.getApplication().getServer().get('speedUnit') || ''; value = speedUnits.convert(value, unit) + ' ' + speedUnits.getUnitName(unit); } + + if (key === 'odoMeter') { + var distanceUnits = Ext.getStore('DistanceUnits'); + var unit = Traccar.getApplication().getUser().get('distanceUnit') || Traccar.getApplication().getServer().get('distanceUnit') || ''; + value = distanceUnits.convert(value, unit) + ' ' + distanceUnits.getUnitName(unit); + } + store.add(Ext.create('Traccar.model.Parameter', { priority: this.keys[key].priority, name: this.keys[key].name, -- cgit v1.2.3 From bb18dcd541642aad00ad3253940dc239a7c9681e Mon Sep 17 00:00:00 2001 From: amilasilva88 Date: Thu, 13 Aug 2015 22:13:18 +0800 Subject: my branding --- web/release.html | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/web/release.html b/web/release.html index bc4d902c0..fc2ff6e87 100644 --- a/web/release.html +++ b/web/release.html @@ -3,7 +3,7 @@ -Traccar +BlueSky