[英]Group logging entries if time span overlap and less than 30 minutes?
I have log entries for a single user that exist in the following format: 我有一个单一用户的日志条目,其格式如下:
[unique id], [start time],[ end time]
So, in the following example entries: 因此,在以下示例条目中:
1,1100,1200
2,1030,1130
3,1420,1500
4,1519,1700
Find Sessions ie, group log entries into as 'sessions'. 查找会话,即将日志条目分组为“会话”。 The conditions to determine a session are:
确定会话的条件是:
Example: Output should be like: 示例:输出应类似于:
Session 1: 1, 2
Session 2: 3, 4
Logic what I am thinking is: 我想的逻辑是:
I came up with below code but I am confuse on how to work on point 3 logic above. 我想出了下面的代码,但是我对如何处理上面的第3点逻辑感到困惑。
private static List<String> groupSessions(List<String> inputs) {
List<String> output = new ArrayList<>();
List<LogEntries> entries = new ArrayList<>();
for (String input : inputs) {
String[] arr = input.split(",");
LogEntries entry =
new LogEntries(Integer.parseInt(arr[0]), Integer.parseInt(arr[1]),
Integer.parseInt(arr[2]));
entries.add(entry);
}
// sort it basis on startTime
Collections.sort(entries);
// now iterate the entries list - this is where I am confuse
for (int i = 0; i < entries.size(); i++) {
// do some stuff
}
return output;
}
Some thoughts: 一些想法:
Long story short: you have to first develop the algorithm that tells you how to determine sessions. 长话短说:您必须首先开发一种算法,该算法可以告诉您如何确定会话。 Then you turn that sequence of instructions into code.
然后,您将该指令序列转换为代码。 The key is to first conceptually dissect the big problem into its smallest parts and to then see how to bring them together.
关键是首先从概念上将大问题分解为最小的部分,然后查看如何将它们组合在一起。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.