Skip to content

Commit

Permalink
implementing ‘total’ category for /users/count/groupBy/tag|key
Browse files Browse the repository at this point in the history
which gives value for all active users based on filters (excluding groupBy filters)
  • Loading branch information
FabiKo117 committed Apr 12, 2019
1 parent a44f624 commit 41d0c83
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ public static Response executeCountGroupByTag(HttpServletRequest servletRequest,
if (res.isEmpty()) {
res.add(new ImmutablePair<>(new ImmutablePair<Integer, Integer>(-1, -1), f));
}
res.add(new ImmutablePair<>(new ImmutablePair<Integer, Integer>(-2, -2), f));
return res;
}).aggregateByTimestamp().aggregateBy(Pair::getKey, zeroFill).map(Pair::getValue)
.map(OSMContribution::getContributorUserId).countUniq();
Expand All @@ -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++;
Expand Down Expand Up @@ -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();
Expand All @@ -246,11 +249,12 @@ public static Response executeCountGroupByKey(HttpServletRequest servletRequest,
for (Entry<Integer, SortedMap<OSHDBTimestamp, Integer>> 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++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 41d0c83

Please sign in to comment.