Improved plotting

pull/42/head
otter 9 years ago
parent c91e712178
commit 770bb1d41f

@ -388,7 +388,7 @@ document.getElementById("apilink").setAttribute("href", "Network.xml?" + window.
scale: number of hours per scale unit in the bottom line scale: number of hours per scale unit in the bottom line
--> -->
<h3><b>Count of Connected Senior Peers</b> in the last two days, scale = 1h</h3> <h3><b>Count of Connected Senior Peers</b> in the last two days, scale = 1h</h3>
<img src="/NetworkHistory.png?columns=cC&scale=1&maxtime=48" /> <img src="/NetworkHistory.png?columns=cC&scale=1&maxtime=48&width=809" />
<h3><b>Count of all Active Peers Per Day</b> in the last week, scale = 1d</h3> <h3><b>Count of all Active Peers Per Day</b> in the last week, scale = 1d</h3>
<img src="/NetworkHistory.png?columns=aD&scale=24&maxtime=168" /> <img src="/NetworkHistory.png?columns=aD&scale=24&maxtime=168" />
<h3><b>Count of all Active Peers Per Week</b> in the last 30d, scale = 7d</h3> <h3><b>Count of all Active Peers Per Week</b> in the last 30d, scale = 7d</h3>

@ -97,8 +97,20 @@ public class NetworkHistory {
if (v != null && v.longValue() > 0) minpeers = Math.min(minpeers, (int) v.longValue()); if (v != null && v.longValue() > 0) minpeers = Math.min(minpeers, (int) v.longValue());
} }
} }
maxpeers = 10 * ((maxpeers / 9 * 10) / 10); if (minpeers < 0) {
minpeers = 10 * ((minpeers * 9 / 10) / 10); ConcurrentLog.warn("NetworkHistory", "Negative value in plot. columns:"+columns);
minpeers=0;
}
if (minpeers==maxpeers) {
minpeers=Math.max(0,minpeers-10);
maxpeers+=10;
}
if (maxpeers-minpeers > 2*minpeers) minpeers=0; // if we are close enough to zero, use zero as minimum
int order=(int)Math.log10(maxpeers-minpeers);
int scale=(int)Math.pow(10, order);
minpeers=(minpeers/scale)*scale;
maxpeers=((maxpeers/scale)+1)*scale;
if ((maxpeers-minpeers)/scale < 3) scale=scale/2;
final int leftborder = 30; final int leftborder = 30;
final int rightborder = 10; final int rightborder = 10;
final int width = post.getInt("width", 768 + leftborder + rightborder); final int width = post.getInt("width", 768 + leftborder + rightborder);
@ -107,7 +119,7 @@ public class NetworkHistory {
final int topborder = 20; final int topborder = 20;
final int bottomborder = 20; final int bottomborder = 20;
final int vspace = height - topborder - bottomborder; final int vspace = height - topborder - bottomborder;
final int leftscale = 10 * (maxpeers / 100); final int leftscale = scale;
String timestr = maxtime + " HOURS"; String timestr = maxtime + " HOURS";
if (maxtime > 24 && maxtime % 24 == 0) timestr = (maxtime / 24) + " DAYS"; if (maxtime > 24 && maxtime % 24 == 0) timestr = (maxtime / 24) + " DAYS";
if (maxtime == 168) timestr = "WEEK"; if (maxtime == 168) timestr = "WEEK";
@ -120,12 +132,14 @@ public class NetworkHistory {
if (columns.contains("cC")) headline += ", ACTIVE SENIOR PEERS"; if (columns.contains("cC")) headline += ", ACTIVE SENIOR PEERS";
if (columns.contains("cD")) headline += ", PASSIVE SENIOR PEERS"; if (columns.contains("cD")) headline += ", PASSIVE SENIOR PEERS";
if (columns.contains("cP")) headline += ", POTENTIAL JUNIOR PEERS"; if (columns.contains("cP")) headline += ", POTENTIAL JUNIOR PEERS";
if (columns.contains("cI")) headline = "YACY PEER '" + sb.peers.myName() + "' INDEX SIZE HISTORY: NUMBER OF DOCUMENTS"; if (columns.contains("cI")) headline = "YACY PEER '" + sb.peers.myName().toUpperCase() + "' INDEX SIZE HISTORY: NUMBER OF DOCUMENTS";
if (columns.contains("cR")) headline = "YACY PEER '" + sb.peers.myName() + "' INDEX SIZE HISTORY: NUMBER OF RWI ENTRIES"; if (columns.contains("cR")) headline = "YACY PEER '" + sb.peers.myName().toUpperCase() + "' INDEX SIZE HISTORY: NUMBER OF RWI ENTRIES";
ChartPlotter chart = new ChartPlotter(width, height, 0xFFFFFFl, 0x000000l, 0xAAAAAAl, leftborder, rightborder, topborder, bottomborder, headline, "IN THE LAST " + timestr); ChartPlotter chart = new ChartPlotter(width, height, 0xFFFFFFl, 0x000000l, 0xAAAAAAl, leftborder, rightborder, topborder, bottomborder, headline, "IN THE LAST " + timestr);
int pixelperscale = Math.max(16, hspace / (maxtime / bottomscale)); long pps = (long)hspace * (long)bottomscale / maxtime;
int pixelperscale = Math.max(8, (int)pps );
chart.declareDimension(ChartPlotter.DIMENSION_BOTTOM, bottomscale, pixelperscale, -maxtime, 0x000000l, 0xCCCCCCl, "TIME/HOURS"); chart.declareDimension(ChartPlotter.DIMENSION_BOTTOM, bottomscale, pixelperscale, -maxtime, 0x000000l, 0xCCCCCCl, "TIME/HOURS");
pixelperscale = Math.max(16, 10 * ((vspace * leftscale / (maxpeers - minpeers)) / 10)); pps = (long)vspace * (long)leftscale / (maxpeers-minpeers);
pixelperscale = Math.max(8, (int)pps );
chart.declareDimension(ChartPlotter.DIMENSION_LEFT, leftscale, pixelperscale, minpeers, 0x008800l, null , columns.contains("cI") ? "DOCUMENTS" : columns.contains("cR") ? "RWIs" : "PEERS"); chart.declareDimension(ChartPlotter.DIMENSION_LEFT, leftscale, pixelperscale, minpeers, 0x008800l, null , columns.contains("cI") ? "DOCUMENTS" : columns.contains("cR") ? "RWIs" : "PEERS");
// write the data // write the data

@ -168,7 +168,7 @@ public class ChartPlotter extends RasterPlotter {
} }
setColor(colorNaming); setColor(colorNaming);
line(x - 3, y, x + 3, y, 100); line(x - 3, y, x + 3, y, 100);
s1 = (s >= 1000000 && s % 10000 == 0) ? Integer.toString(s / 1000000) + "M" : (s >= 1000 && s % 1000 == 0) ? Integer.toString(s / 1000) + "K" : Integer.toString(s); s1 = (s >= 1000000 && s % 1000000 == 0) ? Integer.toString(s / 1000000) + "M" : (s >= 1000 && s % 1000 == 0) ? Integer.toString(s / 1000) + "K" : Integer.toString(s);
if (s1.length() > s1max) s1max = s1.length(); if (s1.length() > s1max) s1max = s1.length();
PrintTool.print(this, (left) ? this.leftborder - 4 : this.width - this.rightborder + 4, y, 0, s1, (left) ? 1 : -1, 80); PrintTool.print(this, (left) ? this.leftborder - 4 : this.width - this.rightborder + 4, y, 0, s1, (left) ? 1 : -1, 80);
y -= pixelperscale; y -= pixelperscale;

Loading…
Cancel
Save