[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [depictor/master] Make the graph's y-axis the standard deviation instead of the min/max.



commit 90396074f5666f56176e1eac3a7f4260ccdba039
Author: Tom Ritter <tom@xxxxxxxxx>
Date:   Tue Jul 5 12:50:26 2016 -0500

    Make the graph's y-axis the standard deviation instead of the min/max.
---
 graphs.py              | 38 +++++++++++++++++++++++++++-----------
 parseOldConsensuses.py |  5 ++++-
 2 files changed, 31 insertions(+), 12 deletions(-)

diff --git a/graphs.py b/graphs.py
index c45c58e..8b55c15 100755
--- a/graphs.py
+++ b/graphs.py
@@ -282,6 +282,7 @@ class GraphWriter:
 			return d3_dsv.csvParse(text);
 		}).then(function(data) {
 
+		// For each of the configured graphs
 		for(g in GRAPHS_TO_GENERATE)
 		{
 			graph = GRAPHS_TO_GENERATE[g];
@@ -291,30 +292,48 @@ class GraphWriter:
 			else
 				data_subset = data
 
+			// Calculate the Graph Boundaries -----------------------------------------
 			min = 10000;
 			max = 0;
+			total = 0;
+			count = 0;
 			for(d in data_subset)
 			{
 				for(b in BWAUTHS)
 				{
 					data_subset[d][BWAUTHS[b]] = Number(data_subset[d][BWAUTHS[b]]);
-					if(data_subset[d][BWAUTHS[b]] < min && data_subset[d][BWAUTHS[b]] > BWAUTH_LOGICAL_MIN) {
-						min = data_subset[d][BWAUTHS[b]];
-					}
-					if(data_subset[d][BWAUTHS[b]] > max) {
-						max = data_subset[d][BWAUTHS[b]];	
-					}
+					var x = data_subset[d][BWAUTHS[b]];
+					if(x < min && x > BWAUTH_LOGICAL_MIN)
+						min = x;
+					if(x > max)
+						max = x;	
+
+					total += x;
+					count++;
 				}
 			}
-			console.log("Data Length: " + data_subset.length + " Y-Axis Min: " + min + " Max: " + max);
+			avg = total / count;
+			sumvariance = 0;
+			for(d in data_subset)
+			{
+				for(b in BWAUTHS)
+				{
+					var x = data_subset[d][BWAUTHS[b]];
+					sumvariance += (x - avg) * (x - avg);
+				}
+			}
+			variance = sumvariance / count;
+			stddev = Math.sqrt(variance);
+			console.log("Data Length: " + data_subset.length + " Y-Axis Min: " + min + " Max: " + max + " Avg: " + avg + " Var: " + variance + " StdDev: " + stddev);
 
+			// Create the Graph  -----------------------------------------
 			var x = d3.scaleTime()
 				.domain([new Date(Number(data_subset[0].date)), new Date(Number(data_subset[data_subset.length-1].date))])
 			    .range([0, WIDTH])
 			;
 
 			var y = d3.scaleLinear()
-				.domain([min, max])
+				.domain([avg-(stddev), avg+(stddev)])
 			    .range([HEIGHT, 0]);
 
 			var lines = []
@@ -401,9 +420,6 @@ if __name__ == '__main__':
 	v = pickle.load(open('votes.p', 'rb'))
 	g.set_votes(v)
 
-	import pdb
-	pdb.set_trace()
-
 	CONFIG = stem.util.conf.config_dict('consensus', {
                                     'ignored_authorities': [],
                                     'bandwidth_authorities': [],
diff --git a/parseOldConsensuses.py b/parseOldConsensuses.py
index e45fd27..834c386 100755
--- a/parseOldConsensuses.py
+++ b/parseOldConsensuses.py
@@ -20,6 +20,9 @@ import stem.util.enum
 from stem import Flag
 from stem.util.lru_cache import lru_cache
 
+def get_dirauths_in_tables():
+	return "faravahar, gabelmoo, dizum, moria1, urras, maatuska, longclaw, tor26, dannenberg, turtles".split(", ")
+
 
 def get_dirauth_from_filename(filename):
 	key = filename.split('-')
@@ -64,7 +67,7 @@ def get_time_from_filename(filename):
 	return voteTime
 
 def main(dir):
-	dirAuths = "faravahar, gabelmoo, dizum, moria1, urras, maatuska, longclaw, tor26, dannenberg, turtles".split(", ")
+	dirAuths = get_dirauths_in_tables()
 	dbc = sqlite3.connect(os.path.join('data', 'historical.db'))
 
 	dirauth_columns = ""



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits