aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/reports
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2016-08-05 14:41:53 +0500
committerAbyss777 <abyss@fox5.ru>2016-08-05 14:41:53 +0500
commit5a6e7582a7978341f3a2de9a81cb63252bca0bb7 (patch)
tree585eab11bfd805b9de814324e5e892e854fc1c62 /src/org/traccar/reports
parent933247b3d2ec24d65203fae39dcafbe2c9afb87e (diff)
downloadtrackermap-server-5a6e7582a7978341f3a2de9a81cb63252bca0bb7.tar.gz
trackermap-server-5a6e7582a7978341f3a2de9a81cb63252bca0bb7.tar.bz2
trackermap-server-5a6e7582a7978341f3a2de9a81cb63252bca0bb7.zip
- Moved GeneralReport to separate file
- Removed unnecessary getOut function - Added methods sorting
Diffstat (limited to 'src/org/traccar/reports')
-rw-r--r--src/org/traccar/reports/Events.java2
-rw-r--r--src/org/traccar/reports/General.java50
-rw-r--r--src/org/traccar/reports/ReportUtils.java13
-rw-r--r--src/org/traccar/reports/Route.java2
-rw-r--r--src/org/traccar/reports/model/GeneralReport.java42
5 files changed, 49 insertions, 60 deletions
diff --git a/src/org/traccar/reports/Events.java b/src/org/traccar/reports/Events.java
index d3457e5a5..de4354371 100644
--- a/src/org/traccar/reports/Events.java
+++ b/src/org/traccar/reports/Events.java
@@ -30,7 +30,7 @@ public final class Events {
return json.build().toString();
}
- public static byte[] getCsv(long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
+ public static String getCsv(long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
Collection<String> types, Date from, Date to) throws SQLException {
CsvBuilder csv = new CsvBuilder();
csv.addHeaderLine(new Event());
diff --git a/src/org/traccar/reports/General.java b/src/org/traccar/reports/General.java
index 75194bc13..595dd49f9 100644
--- a/src/org/traccar/reports/General.java
+++ b/src/org/traccar/reports/General.java
@@ -12,6 +12,7 @@ import javax.json.JsonObjectBuilder;
import org.traccar.Context;
import org.traccar.helper.DistanceCalculator;
import org.traccar.model.Position;
+import org.traccar.reports.model.GeneralReport;
import org.traccar.web.CsvBuilder;
import org.traccar.web.JsonConverter;
@@ -20,49 +21,8 @@ public final class General {
private General() {
}
- public static class GeneralResult {
-
- private String deviceName;
- public String getDeviceName() {
- return deviceName;
- }
- public void setDeviceName(String deviceName) {
- this.deviceName = deviceName;
- }
-
- private double distance = 0;
- public double getDistance() {
- return distance;
- }
- public void setDistance(double distance) {
- this.distance = distance;
- }
-
- public void addDistance(double distance) {
- this.distance += distance;
- }
-
- private double averageSpeed = 0;
- public double getAverageSpeed() {
- return averageSpeed;
- }
- public void setAverageSpeed(double averageSpeed) {
- this.averageSpeed = averageSpeed;
- }
-
- private double maxSpeed = 0;
- public double getMaxSpeed() {
- return maxSpeed;
- }
- public void setMaxSpeed(double maxSpeed) {
- if (maxSpeed > this.maxSpeed) {
- this.maxSpeed = maxSpeed;
- }
- }
- }
-
- private static GeneralResult calculateGeneralResult(long deviceId, Date from, Date to) throws SQLException {
- GeneralResult result = new GeneralResult();
+ private static GeneralReport calculateGeneralResult(long deviceId, Date from, Date to) throws SQLException {
+ GeneralReport result = new GeneralReport();
Collection<Position> positions = Context.getDataManager().getPositions(deviceId, from, to);
if (positions != null && !positions.isEmpty()) {
result.setDeviceName(Context.getDeviceManager().getDeviceById(deviceId).getName());
@@ -93,12 +53,12 @@ public final class General {
return json.build().toString();
}
- public static byte[] getCsv(long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
+ public static String getCsv(long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
Date from, Date to) throws SQLException {
CsvBuilder csv = new CsvBuilder();
for (long deviceId: ReportUtils.getReportedDevices(deviceIds, groupIds)) {
Context.getPermissionsManager().checkDevice(userId, deviceId);
- csv.addHeaderLine(new GeneralResult());
+ csv.addHeaderLine(new GeneralReport());
csv.addLine(calculateGeneralResult(deviceId, from, to));
}
return csv.get();
diff --git a/src/org/traccar/reports/ReportUtils.java b/src/org/traccar/reports/ReportUtils.java
index e8048f1f2..c4c63e525 100644
--- a/src/org/traccar/reports/ReportUtils.java
+++ b/src/org/traccar/reports/ReportUtils.java
@@ -1,13 +1,8 @@
package org.traccar.reports;
-import java.io.IOException;
-import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collection;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.StreamingOutput;
-
import org.traccar.Context;
public final class ReportUtils {
@@ -24,12 +19,4 @@ public final class ReportUtils {
return result;
}
- public static StreamingOutput getOut(final byte[] csvBytes) {
- return new StreamingOutput() {
- @Override
- public void write(OutputStream out) throws IOException, WebApplicationException {
- out.write(csvBytes);
- }
- };
- }
}
diff --git a/src/org/traccar/reports/Route.java b/src/org/traccar/reports/Route.java
index 035526970..a77e3c5ff 100644
--- a/src/org/traccar/reports/Route.java
+++ b/src/org/traccar/reports/Route.java
@@ -28,7 +28,7 @@ public final class Route {
return json.build().toString();
}
- public static byte[] getCsv(long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
+ public static String getCsv(long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
Date from, Date to) throws SQLException {
CsvBuilder csv = new CsvBuilder();
csv.addHeaderLine(new Position());
diff --git a/src/org/traccar/reports/model/GeneralReport.java b/src/org/traccar/reports/model/GeneralReport.java
new file mode 100644
index 000000000..f60bb7238
--- /dev/null
+++ b/src/org/traccar/reports/model/GeneralReport.java
@@ -0,0 +1,42 @@
+package org.traccar.reports.model;
+
+public class GeneralReport {
+
+ private String deviceName;
+ public String getDeviceName() {
+ return deviceName;
+ }
+ public void setDeviceName(String deviceName) {
+ this.deviceName = deviceName;
+ }
+
+ private double distance = 0;
+ public double getDistance() {
+ return distance;
+ }
+ public void setDistance(double distance) {
+ this.distance = distance;
+ }
+
+ public void addDistance(double distance) {
+ this.distance += distance;
+ }
+
+ private double averageSpeed = 0;
+ public double getAverageSpeed() {
+ return averageSpeed;
+ }
+ public void setAverageSpeed(double averageSpeed) {
+ this.averageSpeed = averageSpeed;
+ }
+
+ private double maxSpeed = 0;
+ public double getMaxSpeed() {
+ return maxSpeed;
+ }
+ public void setMaxSpeed(double maxSpeed) {
+ if (maxSpeed > this.maxSpeed) {
+ this.maxSpeed = maxSpeed;
+ }
+ }
+}