Author: nextgens
Date: 2008-07-26 17:40:12 +0000 (Sat, 26 Jul 2008)
New Revision: 21424

Modified:
   trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java
Log:
ensure that the node's location is consistent everywhere on the stats page and 
display the category we are into in bold

Modified: trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java       
2008-07-26 17:11:51 UTC (rev 21423)
+++ trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java       
2008-07-26 17:40:12 UTC (rev 21424)
@@ -163,6 +163,7 @@

                // FIXME! We need some nice images
                final long now = System.currentTimeMillis();
+               double myLocation = node.getLocation();
                final long nodeUptimeSeconds = (now - node.startupTime) / 1000;

                if(ctx.isAllowedFullAccess())
@@ -207,7 +208,7 @@
                        // store size box
                        HTMLNode storeSizeInfobox = 
nextTableCell.addChild("div", "class", "infobox");

-                       drawStoreSizeBox(storeSizeInfobox, nodeUptimeSeconds);
+                       drawStoreSizeBox(storeSizeInfobox, myLocation, 
nodeUptimeSeconds);

                        if(numberOfConnected + numberOfRoutingBackedOff > 0) {
                                // Load balancing box
@@ -285,7 +286,7 @@

                        //Swap statistics box
                        HTMLNode locationSwapInfobox = 
nextTableCell.addChild("div", "class", "infobox");
-                       drawSwapStatsBox(locationSwapInfobox, 
nodeUptimeSeconds, swaps, noSwaps);
+                       drawSwapStatsBox(locationSwapInfobox, myLocation, 
nodeUptimeSeconds, swaps, noSwaps);

                        // unclaimedFIFOMessageCounts box
                        HTMLNode unclaimedFIFOMessageCountsInfobox = 
nextTableCell.addChild("div", "class", "infobox");
@@ -314,14 +315,14 @@
                        HTMLNode peerCircleInfobox = 
nextTableCell.addChild("div", "class", "infobox");
                        peerCircleInfobox.addChild("div", "class", 
"infobox-header", "Peer\u00a0Location\u00a0Distribution (w/pReject)");
                        HTMLNode peerCircleTable = 
peerCircleInfobox.addChild("div", "class", "infobox-content").addChild("table");
-                       addPeerCircle(peerCircleTable, peerNodeStatuses);
+                       addPeerCircle(peerCircleTable, peerNodeStatuses, 
myLocation);
                        nextTableCell = overviewTableRow.addChild("td");

                        // node distribution box
                        HTMLNode nodeCircleInfobox = 
nextTableCell.addChild("div", "class", "infobox");
                        nodeCircleInfobox.addChild("div", "class", 
"infobox-header", "Node\u00a0Location\u00a0Distribution (w/Swap\u00a0Age)");
                        HTMLNode nodeCircleTable = 
nodeCircleInfobox.addChild("div", "class", "infobox-content").addChild("table");
-                       addNodeCircle(nodeCircleTable);
+                       addNodeCircle(nodeCircleTable, myLocation);

                        // specialisation box
                        int[] incomingRequestCountArray = new int[1];
@@ -332,7 +333,7 @@
                                HTMLNode nodeSpecialisationInfobox = 
nextTableCell.addChild("div", "class", "infobox");
                                nodeSpecialisationInfobox.addChild("div", 
"class", "infobox-header", "Incoming\u00a0Request\u00a0Distribution");
                                HTMLNode nodeSpecialisationTable = 
nodeSpecialisationInfobox.addChild("div", "class", 
"infobox-content").addChild("table");
-                               addSpecialisation(nodeSpecialisationTable, 
incomingRequestsCount, incomingRequestLocation);
+                               addSpecialisation(nodeSpecialisationTable, 
myLocation, incomingRequestsCount, incomingRequestLocation);
                        }
                }

@@ -423,7 +424,7 @@
                }
        }

-       private void drawStoreSizeBox(HTMLNode storeSizeInfobox, long 
nodeUptimeSeconds) {
+       private void drawStoreSizeBox(HTMLNode storeSizeInfobox, double loc, 
long nodeUptimeSeconds) {

                storeSizeInfobox.addChild("div", "class", "infobox-header", 
"Datastore");
                HTMLNode storeSizeInfoboxContent = 
storeSizeInfobox.addChild("div", "class", "infobox-content");
@@ -526,16 +527,7 @@
                row.addChild("td", 
fix1p2.format(1.0*cacheWrites/nodeUptimeSeconds)+" /sec");

                // location-based stats
-               boolean hasLoc=true;
                double nodeLoc=0.0;
-               try {
-                       nodeLoc=node.getLocationManager().getLocation();
-               } catch (Error e) {
-                       //FIXME: PLEASE, how do we get the node location on the 
stats page?
-                       //Logger.error(this, "why?", e);
-                       e.printStackTrace();
-                       hasLoc=false;
-               }

                double 
avgCacheLocation=node.nodeStats.avgCacheLocation.currentValue();
                double 
avgStoreLocation=node.nodeStats.avgStoreLocation.currentValue();
@@ -561,28 +553,27 @@
                row.addChild("td", fix1p4.format(furthestStoreSuccess));
                row.addChild("td", fix1p4.format(furthestCacheSuccess));

-               if (hasLoc) {
-                       row=storeSizeTable.addChild("tr");
-                       row.addChild("td", "Avg. Distance");
-                       row.addChild("td", fix1p4.format(storeDist));
-                       row.addChild("td", fix1p4.format(cacheDist));
-                       
-                       long 
cacheLocationReports=node.nodeStats.avgCacheLocation.countReports();
-                       long 
storeLocationReports=node.nodeStats.avgStoreLocation.countReports();
-                       
-                       double storePercent=1.0*storeLocationReports/storeKeys;
-                       double cachePercent=1.0*cacheLocationReports/cachedKeys;
-                       
-                       //Cap the reported value at 100%, as the decaying 
average does not account beyond that anyway.
-                       if (storePercent>1.0) storePercent=1.0;
-                       if (cachePercent>1.0) cachePercent=1.0;
-                       
-                       row=storeSizeTable.addChild("tr");
-                       row.addChild("td", "Distance Stats");
-                       row.addChild("td", fix3p1pct.format(storePercent));
-                       row.addChild("td", fix3p1pct.format(cachePercent));
-               }
-               
+               row = storeSizeTable.addChild("tr");
+               row.addChild("td", "Avg. Distance");
+               row.addChild("td", fix1p4.format(storeDist));
+               row.addChild("td", fix1p4.format(cacheDist));
+
+               long cacheLocationReports = 
node.nodeStats.avgCacheLocation.countReports();
+               long storeLocationReports = 
node.nodeStats.avgStoreLocation.countReports();
+
+               double storePercent = 1.0 * storeLocationReports / storeKeys;
+               double cachePercent = 1.0 * cacheLocationReports / cachedKeys;
+
+               //Cap the reported value at 100%, as the decaying average does 
not account beyond that anyway.
+               if(storePercent > 1.0)
+                       storePercent = 1.0;
+               if(cachePercent > 1.0)
+                       cachePercent = 1.0;
+
+               row = storeSizeTable.addChild("tr");
+               row.addChild("td", "Distance Stats");
+               row.addChild("td", fix3p1pct.format(storePercent));
+               row.addChild("td", fix3p1pct.format(cachePercent));
        }

        private void drawUnclaimedFIFOMessageCountsBox(HTMLNode 
unclaimedFIFOMessageCountsInfobox) {
@@ -617,10 +608,9 @@

        }

-       private void drawSwapStatsBox(HTMLNode locationSwapInfobox, long 
nodeUptimeSeconds, double swaps, double noSwaps) {
+       private void drawSwapStatsBox(HTMLNode locationSwapInfobox, double 
location, long nodeUptimeSeconds, double swaps, double noSwaps) {

                locationSwapInfobox.addChild("div", "class", "infobox-header", 
"Location swaps");
-               double location = node.getLocation();
                int startedSwaps = node.getStartedSwaps();
                int swapsRejectedAlreadyLocked = 
node.getSwapsRejectedAlreadyLocked();
                int swapsRejectedNowhereToGo = 
node.getSwapsRejectedNowhereToGo();
@@ -1057,7 +1047,7 @@
        private final static long MAX_CIRCLE_AGE_THRESHOLD = 24l*60*60*1000;   
// 24 hours
        private final static int HISTOGRAM_LENGTH = 10;

-       private void addNodeCircle (HTMLNode circleTable) {
+       private void addNodeCircle (HTMLNode circleTable, double myLocation) {
                int[] histogram = new int[HISTOGRAM_LENGTH];
                for (int i = 0; i < HISTOGRAM_LENGTH; i++) {
                        histogram[i] = 0;
@@ -1102,7 +1092,7 @@
                        histogram[histogramIndex]++;
                        nodeCircleInfoboxContent.addChild("span", new String[] 
{ "style", "class" }, new String[] { 
generatePeerCircleStyleString(location.doubleValue(), false, strength), 
"connected" }, "x");
                }
-               nodeCircleInfoboxContent.addChild("span", new String[] { 
"style", "class" }, new String[] { 
generatePeerCircleStyleString(node.getLocation(), true, 1.0), "me" }, "x");
+               nodeCircleInfoboxContent.addChild("span", new String[] { 
"style", "class" }, new String[] { generatePeerCircleStyleString(myLocation, 
true, 1.0), "me" }, "x");
                //
                double histogramPercent;
                for (int i = 0; i < HISTOGRAM_LENGTH; i++) {
@@ -1115,19 +1105,23 @@
                }
        }

-       private void addSpecialisation(HTMLNode table, int 
incomingRequestsCount, int[] incomingRequestLocation) {
+       private void addSpecialisation(HTMLNode table, double peerLocation, int 
incomingRequestsCount, int[] incomingRequestLocation) {
                HTMLNode nodeHistogramLegendTableRow = table.addChild("tr");
                HTMLNode nodeHistogramGraphTableRow = table.addChild("tr");
+               int myIndex = (int)(peerLocation * 
incomingRequestLocation.length);
                for (int i = 0; i<incomingRequestLocation.length; i++) {
                        HTMLNode nodeHistogramLegendCell = 
nodeHistogramLegendTableRow.addChild("td");
                        HTMLNode nodeHistogramGraphCell = 
nodeHistogramGraphTableRow.addChild("td", "style", "height: 100px;");
-                       nodeHistogramLegendCell.addChild("div", "class", 
"histogramLabel").addChild("#", fix1p1.format(((double) i) / 
incomingRequestLocation.length ));
+                       HTMLNode nodeHistogramGraphCell2 = 
nodeHistogramLegendCell.addChild("div", "class", "histogramLabel");
+                       if(i == myIndex)
+                                nodeHistogramGraphCell2 = 
nodeHistogramGraphCell2.addChild("span", "class", "me");
+                       nodeHistogramGraphCell2.addChild("#", 
fix1p1.format(((double) i) / incomingRequestLocation.length ));
                        nodeHistogramGraphCell.addChild("div", new String[] { 
"class", "style" }, new String[] { "histogramConnected", "height: " + 
fix3pctUS.format(((double)incomingRequestLocation[i]) / incomingRequestsCount) 
+ "; width: 100%;" }, "\u00a0");
                }

        }

-       private void addPeerCircle (HTMLNode circleTable, PeerNodeStatus[] 
peerNodeStatuses) {
+       private void addPeerCircle (HTMLNode circleTable, PeerNodeStatus[] 
peerNodeStatuses, double myLocation) {
                int[] histogramConnected = new int[HISTOGRAM_LENGTH];
                int[] histogramDisconnected = new int[HISTOGRAM_LENGTH];
                for (int i = 0; i < HISTOGRAM_LENGTH; i++) {
@@ -1149,8 +1143,7 @@
                peerCircleInfoboxContent.addChild("span", new String[] { 
"style", "class" }, new String[] { generatePeerCircleStyleString(0.625, false, 
1.0), "mark" }, "+");
                peerCircleInfoboxContent.addChild("span", new String[] { 
"style", "class" }, new String[] { generatePeerCircleStyleString(0.75, false, 
1.0),  "mark" }, "--");
                peerCircleInfoboxContent.addChild("span", new String[] { 
"style", "class" }, new String[] { "position: absolute; top: " + 
PEER_CIRCLE_RADIUS + "px; left: " + (PEER_CIRCLE_RADIUS + 
PEER_CIRCLE_ADDITIONAL_FREE_SPACE) + "px", "mark" }, "+");
-               //
-               double myLocation = node.getLocation();
+
                PeerNodeStatus peerNodeStatus;
                double peerLocation;
                double peerDistance;


Reply via email to