From 41d0c830fc2089fd018bd32146ecb6117194ce06 Mon Sep 17 00:00:00 2001 From: kowatsch Date: Fri, 12 Apr 2019 10:57:11 +0200 Subject: [PATCH] =?UTF-8?q?implementing=20=E2=80=98total=E2=80=99=20catego?= =?UTF-8?q?ry=20for=20/users/count/groupBy/tag|key?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit which gives value for all active users based on filters (excluding groupBy filters) --- .../executor/UsersRequestExecutor.java | 20 +++++++++++-------- .../controller/GetControllerTest.java | 10 ++++------ 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/heigit/bigspatialdata/ohsome/ohsomeapi/executor/UsersRequestExecutor.java b/src/main/java/org/heigit/bigspatialdata/ohsome/ohsomeapi/executor/UsersRequestExecutor.java index 804d1d0c..8cd19314 100644 --- a/src/main/java/org/heigit/bigspatialdata/ohsome/ohsomeapi/executor/UsersRequestExecutor.java +++ b/src/main/java/org/heigit/bigspatialdata/ohsome/ohsomeapi/executor/UsersRequestExecutor.java @@ -164,6 +164,7 @@ public static Response executeCountGroupByTag(HttpServletRequest servletRequest, if (res.isEmpty()) { res.add(new ImmutablePair<>(new ImmutablePair(-1, -1), f)); } + res.add(new ImmutablePair<>(new ImmutablePair(-2, -2), f)); return res; }).aggregateByTimestamp().aggregateBy(Pair::getKey, zeroFill).map(Pair::getValue) .map(OSMContribution::getContributorUserId).countUniq(); @@ -176,11 +177,12 @@ public static Response executeCountGroupByTag(HttpServletRequest servletRequest, .entrySet()) { UsersResult[] results = exeUtils.fillUsersResult(entry.getValue(), requestParameters.isDensity(), inputProcessor, df); - // check for non-remainder objects (which do have the defined key and value) - if (entry.getKey().getKey() != -1 && entry.getKey().getValue() != -1) { - groupByName = tt.getOSMTagOf(keysInt, entry.getKey().getValue()).toString(); - } else { + if (entry.getKey().getKey() == -2 && entry.getKey().getValue() == -2) { + groupByName = "total"; + } else if (entry.getKey().getKey() == -1 && entry.getKey().getValue() == -1) { groupByName = "remainder"; + } else { + groupByName = tt.getOSMTagOf(keysInt, entry.getKey().getValue()).toString(); } resultSet[count] = new GroupByResult(groupByName, results); count++; @@ -235,6 +237,7 @@ public static Response executeCountGroupByKey(HttpServletRequest servletRequest, if (res.isEmpty()) { res.add(new ImmutablePair<>(-1, f)); } + res.add(new ImmutablePair<>(-2, f)); return res; }).aggregateByTimestamp().aggregateBy(Pair::getKey, Arrays.asList(keysInt)).map(Pair::getValue) .map(OSMContribution::getContributorUserId).countUniq(); @@ -246,11 +249,12 @@ public static Response executeCountGroupByKey(HttpServletRequest servletRequest, for (Entry> entry : groupByResult.entrySet()) { UsersResult[] results = exeUtils.fillUsersResult(entry.getValue(), requestParameters.isDensity(), inputProcessor, df); - // check for non-remainder objects (which do have the defined key) - if (entry.getKey() != -1) { - groupByName = tt.getOSMTagKeyOf(entry.getKey().intValue()).toString(); - } else { + if (entry.getKey() == -2) { + groupByName = "total"; + } else if (entry.getKey() == -1) { groupByName = "remainder"; + } else { + groupByName = tt.getOSMTagKeyOf(entry.getKey().intValue()).toString(); } resultSet[count] = new GroupByResult(groupByName, results); count++; diff --git a/src/test/java/org/heigit/bigspatialdata/ohsome/ohsomeapi/controller/GetControllerTest.java b/src/test/java/org/heigit/bigspatialdata/ohsome/ohsomeapi/controller/GetControllerTest.java index 081dda96..9c932ed0 100644 --- a/src/test/java/org/heigit/bigspatialdata/ohsome/ohsomeapi/controller/GetControllerTest.java +++ b/src/test/java/org/heigit/bigspatialdata/ohsome/ohsomeapi/controller/GetControllerTest.java @@ -874,12 +874,10 @@ public void getUsersCountGroupByTagCsvTest() { + "&format=csv&groupByKey=shop&time=2015-01-01/2018-01-01/P1Y" + "&types=node&groupByValues=clothes,wine", String.class); - int length = response.getBody().length(); - assertEquals( - "2015-01-01T00:00:00Z;2016-01-01T00:00:00Z;4.0;0.0;0.0\n" - + "2016-01-01T00:00:00Z;2017-01-01T00:00:00Z;7.0;5.0;2.0\n" - + "2017-01-01T00:00:00Z;2018-01-01T00:00:00Z;3.0;2.0;0.0", - response.getBody().substring(length - 162, length - 1)); + String responseBody = response.getBody(); + String[] splittedResponseBody = responseBody.split("\\r?\\n"); + assertEquals(7, splittedResponseBody.length); + assertEquals(57, splittedResponseBody[4].length()); } @Test