This repository has been archived by the owner on Nov 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
morphline.conf
56 lines (41 loc) · 1.66 KB
/
morphline.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# [...]
{ java {
imports : "import java.util.*; import java.text.DateFormat; import java.text.DateFormatSymbols; import java.text.SimpleDateFormat; import java.util.Arrays; import java.util.Calendar; import java.util.List;"
code : """
TimeZone zone = TimeZone.getTimeZone("CET");
Calendar calendar = Calendar.getInstance(zone);
List<String> weekdays = Arrays.asList(new DateFormatSymbols().getWeekdays());
// Date formatter to get the weekday an hour of the timestamp attribut
DateFormat formatter = new SimpleDateFormat("EEEEE H");
formatter.setTimeZone(zone);
StringBuilder timeSlot = new StringBuilder();
String timeInMillis = record.getFirstValue("timestamp").toString();
calendar.setTimeInMillis(Long.parseLong(timeInMillis, 10));
String weekdayHour[] = formatter.format(calendar.getTime()).split(" ");
String weekday = weekdayHour[0];
String hour = weekdayHour[1];
// DateFormatSymbols().getWeekdays() returns Sunday at first position
// but we want it to have the index 7
int idx = weekdays.indexOf(weekday);
idx = (idx <= 1) ? 7 : idx - 1;
// getting the time slot
int hourStart = Integer.parseInt(hour);
int hourEnd = hourStart + 1;
timeSlot.append(idx).append("-");
timeSlot.append(weekday).append(":");
// add leading zero just for readability
if(hourStart < 10) {
timeSlot.append("0");
}
timeSlot.append(hourStart).append("-");
// add leading zero just for readability
if(hourEnd < 10) {
timeSlot.append("0");
}
timeSlot.append(hourEnd);
record.put("time-slot", timeSlot);
record.put("weekday", weekday);
return child.process(record);
"""
} }
# [...]