319 private static Pair<Integer, Integer>
getCounts(List<Long> points, Long minTime) {
320 if (points ==
null) {
324 return points.stream().reduce(
326 (total, time) -> Pair.of(total.getLeft() + 1, total.getRight() + (
greaterThanOrEqual(minTime, time) ? 1 : 0)),
327 (pair1, pair2) -> Pair.of(pair1.getLeft() + pair2.getLeft(), pair1.getRight() + pair2.getRight()));
364 if (points ==
null) {
365 return Stream.empty();
368 Map<CityRecord, Long> timeMapping =
new HashMap<>();
376 Long prevTime = timeMapping.get(city);
377 Long curTime = pair.getRight();
378 if (prevTime ==
null || (curTime !=
null && curTime > prevTime)) {
379 timeMapping.put(city, curTime);
383 return timeMapping.entrySet().stream()
384 .map(e -> Pair.of(e.getKey(), e.getValue()));
401 if (geoResult ==
null) {
402 return Stream.empty();
405 List<Set<MapWaypoint>> areas = (geoResult.
getAreas() ==
null) ? Collections.emptyList() : geoResult.
getAreas();
406 List<Set<MapWaypoint>> tracks = (geoResult.
getTracks() ==
null) ? Collections.emptyList() : geoResult.
getTracks();
408 Stream<Pair<CityRecord, Long>> reducedGroupings = Stream.of(areas, tracks)
409 .flatMap((groupingList) -> groupingList.stream())
412 final Set<MapWaypoint> allTracksAndAreas = Stream.of(areas, tracks)
413 .flatMap((groupingList) -> groupingList.stream())
414 .flatMap((group) -> group.stream())
415 .collect(Collectors.toSet());
418 Stream<Pair<CityRecord, Long>> citiesForPoints = pointSet.stream()
421 .filter(pt -> !allTracksAndAreas.contains(pt))
424 return Stream.concat(reducedGroupings, citiesForPoints);
444 ClosestCityMapper closestCityMapper = this.
cityMapper.get();
446 List<Pair<CityRecord, Long>> dataSourcePoints =
processGeoResult(geoResult, closestCityMapper)
447 .collect(Collectors.toList());
449 Map<CityRecord, List<Long>> allCityPoints =
new HashMap<>();
450 List<Long> others =
new ArrayList<>();
451 Long mostRecent =
null;
453 for (Pair<CityRecord, Long> pt : dataSourcePoints) {
458 Long curTime = pt.getRight();
459 if (curTime !=
null && (mostRecent ==
null || curTime > mostRecent)) {
460 mostRecent = curTime;
467 List<Long> cityPoints = allCityPoints.get(city);
468 if (cityPoints ==
null) {
469 cityPoints =
new ArrayList<>();
470 allCityPoints.put(city, cityPoints);
473 cityPoints.add(curTime);
477 final Long mostRecentMinTime = (mostRecent ==
null) ?
null : mostRecent - daysCount *
DAY_SECS;
480 Map<CityRecord, Pair<Integer, Integer>> allCityCounts = allCityPoints.entrySet().stream()
481 .collect(Collectors.toMap((e) -> e.getKey(), (e) ->
getCounts(e.getValue(), mostRecentMinTime)));
483 List<CityRecordCount> mostCommonCounts = allCityCounts.entrySet().stream()
485 .sorted((a, b) -> -Integer.compare(a.getCount(), b.getCount()))
487 .collect(Collectors.toList());
489 List<CityRecordCount> mostRecentCounts = allCityCounts.entrySet().stream()
491 .sorted((a, b) -> -Integer.compare(a.getCount(), b.getCount()))
493 .collect(Collectors.toList());
495 Pair<Integer, Integer> otherCounts =
getCounts(others, mostRecentMinTime);
496 int otherMostCommonCount = otherCounts.getLeft();
497 int otherMostRecentCount = otherCounts.getRight();