Update criteria for partial/full IPv6 support.
[tor-metrics-tasks.git] / task-3574 / AggregatePerDay.java
blobcf625a650aba284efc7ee72c1b983813d52dbd1f
1 import java.io.*;
2 import java.text.*;
3 import java.util.*;
4 public class AggregatePerDay {
5 public static void main(String[] args) throws Exception {
6 SortedMap<String, long[]> byteHistory = new TreeMap<String, long[]>();
7 BufferedReader br = new BufferedReader(new FileReader(
8 "bridge-bandwidth-histories-sorted.txt"));
9 String line;
10 SimpleDateFormat dateTimeFormat = new SimpleDateFormat(
11 "yyyy-MM-dd HH:mm:ss");
12 dateTimeFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
13 SimpleDateFormat dateFormat = new SimpleDateFormat(
14 "yyyy-MM-dd");
15 dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
16 SimpleDateFormat timeFormat = new SimpleDateFormat(
17 "HH:mm:ss");
18 timeFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
19 while ((line = br.readLine()) != null) {
20 String[] parts = line.split(" ");
21 if (parts.length < 3) {
22 continue;
24 String fingerprint = parts[2];
25 while (line.contains("-history")) {
26 line = line.substring(line.indexOf("-history") - 4);
27 boolean isReadHistory = line.startsWith("read");
28 line = line.substring(5);
29 parts = line.split(" ");
30 if (parts.length >= 6 && parts[5].length() > 0 && !parts[5].contains("history")) {
31 String[] bytes = parts[5].split(",");
32 long intervalEnd = dateTimeFormat.parse(parts[1] + " " + parts[2]).getTime();
33 for (int i = bytes.length - 1; i >= 0; i--) {
34 String key = fingerprint + ","
35 + dateFormat.format(intervalEnd)
36 + (isReadHistory ? ",read" : ",write");
37 long timeIndex = timeFormat.parse(
38 dateTimeFormat.format(intervalEnd).split(" ")[1]).getTime()
39 / (15L * 60L * 1000L);
40 long value = Long.parseLong(bytes[i]);
41 if (!byteHistory.containsKey(key)) {
42 byteHistory.put(key, new long[96]);
44 byteHistory.get(key)[(int) timeIndex] = value + 1L;
45 intervalEnd -= 15L * 60L * 1000L;
50 br.close();
51 BufferedWriter bw = new BufferedWriter(new FileWriter(
52 "bridge-bandwidth-per-day.csv"));
53 for (Map.Entry<String, long[]> e : byteHistory.entrySet()) {
54 long total = 0L, count = 0L;
55 for (long val : e.getValue()) {
56 if (val > 0L) {
57 total += val - 1L;
58 count += 1L;
61 bw.write(e.getKey() + "," + total + "," + count + "\n");
63 bw.close();