[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] [metrics/master] Write daily geoip stats for bridge usage, too, not only monthly.
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Wed, 1 Jul 2009 18:58:31 +0200
Subject: Write daily geoip stats for bridge usage, too, not only monthly.
Commit: 403935bd34153387f79d7c864cbbf764448ddafb
---
.../metrics/bridges/ParseBridgeData.java | 53 +++++++++++++++-----
1 files changed, 41 insertions(+), 12 deletions(-)
diff --git a/src/org/torproject/metrics/bridges/ParseBridgeData.java b/src/org/torproject/metrics/bridges/ParseBridgeData.java
index 79b57db..ffa5791 100644
--- a/src/org/torproject/metrics/bridges/ParseBridgeData.java
+++ b/src/org/torproject/metrics/bridges/ParseBridgeData.java
@@ -127,6 +127,8 @@ public final class ParseBridgeData {
+ File.separatorChar + "bandwidth.csv");
File geoipOutFile = new File(outputDirectory.getAbsolutePath()
+ File.separatorChar + "geoip.csv");
+ File geoipDailyOutFile = new File(outputDirectory.getAbsolutePath()
+ + File.separatorChar + "geoip-daily.csv");
BufferedWriter runningOut = new BufferedWriter(new FileWriter(
runningOutFile, false));
runningOut.write("time,total,running\n");
@@ -137,6 +139,8 @@ public final class ParseBridgeData {
BufferedWriter geoipOut = new BufferedWriter(new FileWriter(
geoipOutFile, false));
+ BufferedWriter geoipDailyOut = new BufferedWriter(new FileWriter(
+ geoipDailyOutFile, false));
SortedSet<String> allCountryCodes = new TreeSet<String>();
String[] allCC = new String[] { "ad", "ae", "af", "ag", "ai", "al",
"am", "an", "ao", "aq", "ar", "as", "at", "au", "aw", "ax",
@@ -163,11 +167,14 @@ public final class ParseBridgeData {
"um", "us", "uy", "uz", "va", "vc", "ve", "vg", "vi", "vn",
"vu", "wf", "ws", "ye", "yt", "za", "zm", "zw" };
geoipOut.write("time,");
+ geoipDailyOut.write("time,");
for (String c : allCC) {
geoipOut.write(c + ",");
+ geoipDailyOut.write(c + ",");
allCountryCodes.add(c);
}
geoipOut.write("total\n");
+ geoipDailyOut.write("total\n");
// obtain list of all bridge fingerprints
long started = System.currentTimeMillis();
@@ -264,6 +271,7 @@ public final class ParseBridgeData {
int month = -1;
int noRouterDesc = 0, noExtraInfo = 0, noHistory = 0, noGeoip = 0;
Map<String, Double> geoipClients = new HashMap<String, Double>();
+ Map<String, Double> geoipDailyClients = new HashMap<String, Double>();
SimpleDateFormat timeFormat = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
timeFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
@@ -567,19 +575,18 @@ public final class ParseBridgeData {
+ (noHistory / timestampsSeen) + ","
+ (noGeoip / timestampsSeen) + ","
+ (allRunnings / timestampsSeen) + "\n");
- /* do we want daily or monthly geoip stats?
- geoipOut.write(date + ",");
+ geoipDailyOut.write(date + ",");
double totalClients = 0.0D;
for (String cc : allCountryCodes) {
- if (geoipClients.containsKey(cc)) {
- geoipOut.write(geoipClients.get(cc) + ",");
- totalClients += geoipClients.get(cc);
+ if (geoipDailyClients.containsKey(cc)) {
+ geoipDailyOut.write(String.format("%.2f,", geoipDailyClients.get(cc)));
+ totalClients += geoipDailyClients.get(cc);
} else {
- geoipOut.write("0,");
+ geoipDailyOut.write("0,");
}
}
- geoipOut.write(totalClients + "\n");
- geoipClients.clear();*/
+ geoipDailyOut.write(String.format("%.2f%n", totalClients));
+ geoipDailyClients.clear();
date = timestamp / (24 * 60 * 60 * 1000);
allTotals = 0;
allRunnings = 0;
@@ -603,13 +610,13 @@ public final class ParseBridgeData {
double totalClients = 0.0D;
for (String cc : allCountryCodes) {
if (geoipClients.containsKey(cc)) {
- geoipOut.write(geoipClients.get(cc) + ",");
+ geoipOut.write(String.format("%.2f,", geoipClients.get(cc)));
totalClients += geoipClients.get(cc);
} else {
geoipOut.write("0,");
}
}
- geoipOut.write(totalClients + "\n");
+ geoipOut.write(String.format("%.2f%n", totalClients));
month = currentMonth;
geoipClients.clear();
}
@@ -695,6 +702,16 @@ public final class ParseBridgeData {
geoipClients.put(countryCode,
clientsPerHour);
}
+ if (geoipDailyClients.containsKey(
+ countryCode)) {
+ geoipDailyClients.put(countryCode,
+ geoipDailyClients.get(
+ countryCode)
+ + clientsPerHour);
+ } else {
+ geoipDailyClients.put(countryCode,
+ clientsPerHour);
+ }
}
}
} else {
@@ -737,16 +754,28 @@ public final class ParseBridgeData {
double totalClients = 0.0D;
for (String cc : allCountryCodes) {
if (geoipClients.containsKey(cc)) {
- geoipOut.write(geoipClients.get(cc) + ",");
+ geoipOut.write(String.format("%.2f,", geoipClients.get(cc)));
totalClients += geoipClients.get(cc);
} else {
geoipOut.write("0,");
}
}
- geoipOut.write(totalClients + "\n");
+ geoipOut.write(String.format("%.2f%n", totalClients));
+ geoipDailyOut.write(date + ",");
+ totalClients = 0.0D;
+ for (String cc : allCountryCodes) {
+ if (geoipDailyClients.containsKey(cc)) {
+ geoipDailyOut.write(String.format("%.2f,", geoipDailyClients.get(cc)));
+ totalClients += geoipDailyClients.get(cc);
+ } else {
+ geoipDailyOut.write("0,");
+ }
+ }
+ geoipDailyOut.write(String.format("%.2f%n", totalClients));
runningOut.close();
bandwidthOut.close();
geoipOut.close();
+ geoipDailyOut.close();
System.out.println("Parsed all bridge files. "
+ ((System.currentTimeMillis() - started) / 1000)
+ " seconds");
--
1.5.6.5