Added duration column in stat visitors.

This commit is contained in:
Christian P. MOMON 2021-06-06 01:00:59 +02:00
parent c8e4dcad0c
commit 8e38a03eb0
4 changed files with 61 additions and 4 deletions

View file

@ -453,7 +453,9 @@ public class StatoolInfos
for (VisitorStat stat : stator.getVisitorStats().sortByVisitCount().reverse()) 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())); System.err.println(String.format("%s %10d", "Visitor count: ", stator.getVisitorStats().size()));

View file

@ -18,6 +18,7 @@
*/ */
package fr.devinsy.statoolinfos.metrics.http; package fr.devinsy.statoolinfos.metrics.http;
import java.time.Duration;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.YearMonth; 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() public LocalDateTime getEnd()
{ {
return this.end; return this.end;
@ -241,5 +257,4 @@ public class Visit
{ {
this.start = start; this.start = start;
} }
} }

View file

@ -18,6 +18,7 @@
*/ */
package fr.devinsy.statoolinfos.metrics.http; package fr.devinsy.statoolinfos.metrics.http;
import java.time.Duration;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.YearMonth; import java.time.YearMonth;
@ -204,4 +205,23 @@ public class Visits extends ArrayList<Visit>
// //
return result; 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;
}
} }

View file

@ -94,8 +94,7 @@ public class Chrono
{ {
LocalDateTime end = LocalDateTime.now(); LocalDateTime end = LocalDateTime.now();
Duration duration = Duration.between(this.start, end); Duration duration = Duration.between(this.start, end);
result = format(duration);
result = String.format("%02d:%02d:%02d", duration.getSeconds() / 60 / 60, duration.getSeconds() / 60, duration.getSeconds() % 60);
} }
// //
@ -153,4 +152,25 @@ public class Chrono
// //
return result; 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;
}
} }