diff --git a/src/fr/devinsy/statoolinfos/core/StatoolInfos.java b/src/fr/devinsy/statoolinfos/core/StatoolInfos.java index 415b9f9..d7657cb 100644 --- a/src/fr/devinsy/statoolinfos/core/StatoolInfos.java +++ b/src/fr/devinsy/statoolinfos/core/StatoolInfos.java @@ -453,7 +453,9 @@ public class StatoolInfos for (VisitorStat stat : stator.getVisitorStats().sortByVisitCount().reverse()) { - System.out.println(String.format("%d %d %s %s", stat.getVisits().size(), stat.getLogCount(), stat.getIp(), stat.getUserAgent())); + System.out.println( + String.format("%d %d %d %s %s %s", stat.getVisits().size(), stat.getLogCount(), stat.getVisits().getDurationSum().toSeconds(), Chrono.format(stat.getVisits().getDurationSum()), + stat.getIp(), stat.getUserAgent())); } System.err.println(String.format("%s %10d", "Visitor count: ", stator.getVisitorStats().size())); diff --git a/src/fr/devinsy/statoolinfos/metrics/http/Visit.java b/src/fr/devinsy/statoolinfos/metrics/http/Visit.java index 0645299..e10c802 100644 --- a/src/fr/devinsy/statoolinfos/metrics/http/Visit.java +++ b/src/fr/devinsy/statoolinfos/metrics/http/Visit.java @@ -18,6 +18,7 @@ */ package fr.devinsy.statoolinfos.metrics.http; +import java.time.Duration; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.YearMonth; @@ -72,6 +73,21 @@ public class Visit } } + /** + * Gets the duration. + * + * @return the duration + */ + public Duration getDuration() + { + Duration result; + + result = Duration.between(this.start, this.end); + + // + return result; + } + public LocalDateTime getEnd() { return this.end; @@ -241,5 +257,4 @@ public class Visit { this.start = start; } - } diff --git a/src/fr/devinsy/statoolinfos/metrics/http/Visits.java b/src/fr/devinsy/statoolinfos/metrics/http/Visits.java index d3ab719..decd672 100644 --- a/src/fr/devinsy/statoolinfos/metrics/http/Visits.java +++ b/src/fr/devinsy/statoolinfos/metrics/http/Visits.java @@ -18,6 +18,7 @@ */ package fr.devinsy.statoolinfos.metrics.http; +import java.time.Duration; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.YearMonth; @@ -204,4 +205,23 @@ public class Visits extends ArrayList // return result; } + + /** + * Gets the duration sum. + * + * @return the duration sum + */ + public Duration getDurationSum() + { + Duration result; + + result = Duration.ofSeconds(0); + for (Visit visit : this) + { + result = result.plus(visit.getDuration()); + } + + // + return result; + } } diff --git a/src/fr/devinsy/statoolinfos/util/Chrono.java b/src/fr/devinsy/statoolinfos/util/Chrono.java index 38d4321..ce0f49d 100644 --- a/src/fr/devinsy/statoolinfos/util/Chrono.java +++ b/src/fr/devinsy/statoolinfos/util/Chrono.java @@ -94,8 +94,7 @@ public class Chrono { LocalDateTime end = LocalDateTime.now(); Duration duration = Duration.between(this.start, end); - - result = String.format("%02d:%02d:%02d", duration.getSeconds() / 60 / 60, duration.getSeconds() / 60, duration.getSeconds() % 60); + result = format(duration); } // @@ -153,4 +152,25 @@ public class Chrono // return result; } + + /** + * Format. + * + * @param duration + * the duration + * @return the string + */ + public static String format(final Duration duration) + { + String result; + + long seconds = duration.toSecondsPart(); + long minutes = duration.toMinutesPart(); + long hours = duration.toHoursPart(); + + result = String.format("%02d:%02d:%02d", hours, minutes, seconds); + + // + return result; + } }