mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-03-06 03:50:47 +08:00
Merge pull request #207 from nagisa77/codex/add-site-statistics-page-for-dau-chart
Add admin stats page with DAU chart
This commit is contained in:
@@ -8,6 +8,8 @@ import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@@ -37,4 +39,22 @@ public class UserVisitService {
|
||||
LocalDate d = date != null ? date : LocalDate.now();
|
||||
return userVisitRepository.countByVisitDate(d);
|
||||
}
|
||||
|
||||
public Map<LocalDate, Long> countDauRange(LocalDate start, LocalDate end) {
|
||||
Map<LocalDate, Long> result = new LinkedHashMap<>();
|
||||
if (start == null || end == null || start.isAfter(end)) {
|
||||
return result;
|
||||
}
|
||||
var list = userVisitRepository.countRange(start, end);
|
||||
for (var obj : list) {
|
||||
LocalDate d = (LocalDate) obj[0];
|
||||
Long c = (Long) obj[1];
|
||||
result.put(d, c);
|
||||
}
|
||||
// fill zero counts for missing dates
|
||||
for (LocalDate d = start; !d.isAfter(end); d = d.plusDays(1)) {
|
||||
result.putIfAbsent(d, 0L);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user