Skip to content

Commit

Permalink
*) fixed wrong calculation of network words, network links, network P…
Browse files Browse the repository at this point in the history
…PM if peer is senior or principal peer

*) added network QPH
*) banner is cached for 1 second to avoid DOS
*) still no logo


git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@4154 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
low012 committed Oct 9, 2007
1 parent 3b85401 commit fdb0b86
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 80 deletions.
107 changes: 44 additions & 63 deletions htroot/Banner.java
Expand Up @@ -7,8 +7,8 @@
//
// This File is contributed by Marc Nause
//
// $LastChangedDate: 2007-10-07 $
// $LastChangedRevision: $
// $LastChangedDate: 2007-10-09 23:07:00 +0200 (Mi, 09 Okt 2007) $
// $LastChangedRevision: 4154 $
// $LastChangedBy: low012 $
//
// This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -69,73 +69,54 @@ public static ymageMatrix respond(httpHeader header, serverObjects post, serverS
bordercolor = post.get("bordercolor", bordercolor);
}

yacySeed seed = yacyCore.seedDB.mySeed();
String name = seed.get(yacySeed.NAME, "-");
name = addTrailingBlanks(name,19).toUpperCase();
String links = seed.get(yacySeed.LCOUNT, "0");
links = addDots(links);
links = addTrailingBlanks(links,19);
String words = seed.get(yacySeed.ICOUNT, "0");
words = addDots(words);
words = addTrailingBlanks(words,19);

String name = "";
long links = 0;
long words = 0;
int myppm = 0;
double myqph = 0;
String type = "";
if (yacyCore.seedDB.mySeed().isVirgin()) {
type = "VIRGIN";
} else if(yacyCore.seedDB.mySeed().isJunior()) {
type = "JUNIOR";
} else if(yacyCore.seedDB.mySeed().isSenior()) {
type = "SENIOR";
} else if(yacyCore.seedDB.mySeed().isPrincipal()) {
type = "PRINCIPAL";
}
type = addTrailingBlanks(type,19);
String ppm = seed.getPPM() + " PAGES/MINUTE";
ppm = addTrailingBlanks(ppm,19);
String network = "";
long nlinks = 0;
long nwords = 0;
double nqpm = 0;
double nqph = 0;
long nppm = 0;

String network = env.getConfig("network.unit.name", "unspecified").toUpperCase();
network = addTrailingBlanks(network,19);
String nlinks = yacyCore.seedDB.countActiveURL()+"";
nlinks = addDots(nlinks);
nlinks = addTrailingBlanks(nlinks,19);
String nwords = yacyCore.seedDB.countActiveRWI()+"";
nwords = addDots(nwords);
nwords = addTrailingBlanks(nwords,19);
String nqph = yacyCore.seedDB.countActiveQPM() + " QUERIES/MINUTE";
nqph = addTrailingBlanks(nqph,19);
String nppm = yacyCore.seedDB.countActivePPM() + " PAGES/MINUTE";
nppm = addTrailingBlanks(nppm,19);

return plasmaGrafics.getBannerPicture(width, height, bgcolor, textcolor, bordercolor, name, links, words, type, ppm, network, nlinks, nwords, nqph, nppm);
}
yacySeed seed = yacyCore.seedDB.mySeed();
if (seed != null){
name = seed.get(yacySeed.NAME, "-").toUpperCase();
links = Long.parseLong(seed.get(yacySeed.LCOUNT, "0"));
words = Long.parseLong(seed.get(yacySeed.ICOUNT, "0"));
myppm = seed.getPPM();
myqph = 60d * seed.getQPM();
network = env.getConfig("network.unit.name", "unspecified").toUpperCase();
nlinks = yacyCore.seedDB.countActiveURL();
nwords = yacyCore.seedDB.countActiveRWI();
nqpm = yacyCore.seedDB.countActiveQPM();
nppm = yacyCore.seedDB.countActivePPM();

private static String addDots(String word) {
String tmp = "";
int len = word.length();
while(len > 3) {
if(tmp.equals("")) {
tmp = word.substring(len-3,len);
} else {
tmp = word.substring(len-3,len) + "." + tmp;
if (yacyCore.seedDB.mySeed().isVirgin()) {
type = "VIRGIN";
nqph = Math.round(6000d * nqpm) / 100d;
} else if(yacyCore.seedDB.mySeed().isJunior()) {
type = "JUNIOR";
nqph = Math.round(6000d * nqpm) / 100d;
} else if(yacyCore.seedDB.mySeed().isSenior()) {
type = "SENIOR";
nlinks = nlinks + links;
nwords = nwords + words;
nqph = Math.round(6000d * nqpm + 100d * myqph) / 100d;
nppm = nppm + myppm;
} else if(yacyCore.seedDB.mySeed().isPrincipal()) {
type = "PRINCIPAL";
nlinks = nlinks + links;
nwords = nwords + words;
nqph = Math.round(6000d * nqpm + 100d * myqph) / 100d;
nppm = nppm + myppm;
}
word = word.substring(0,len-3);
len = word.length();
}
word = word + "." + tmp;
return word;
}

private static String addTrailingBlanks(String word, int length) {
if (length > word.length()) {
String blanks = "";
length = length - word.length();
int i = 0;
while(i++ < length) {
blanks += " ";
}
word = blanks + word;
}
return word;
return plasmaGrafics.getBannerPicture(1000, width, height, bgcolor, textcolor, bordercolor, name, links, words, type, myppm, network, nlinks, nwords, nqph, nppm);
}

}
84 changes: 67 additions & 17 deletions source/de/anomic/plasma/plasmaGrafics.java
Expand Up @@ -122,7 +122,7 @@ public void setFraction(long totalBusyTime) {
private static long peerloadPictureDate = 0;

private static ymageMatrix bannerPicture = null; // [MN]
//private static long bannerPictureDate = 0; // [MN]
private static long bannerPictureDate = 0; // [MN]

public static ymageMatrix getSearchEventPicture(String eventID) {
plasmaSearchEvent event = plasmaSearchEvent.getEvent(eventID);
Expand Down Expand Up @@ -361,32 +361,34 @@ private static void drawLegendLine(Graphics2D g, int x, int y, String caption, C
}

//[MN]
public static ymageMatrix getBannerPicture(int width, int height, String bgcolor, String textcolor, String bordercolor, String name, String links, String words, String type, String ppm, String network, String nlinks, String nwords, String nqph, String nppm) {
//if ((bannerPicture == null) || ((System.currentTimeMillis() - bannerDate) > maxAge)) {
public static ymageMatrix getBannerPicture(long maxAge, int width, int height, String bgcolor, String textcolor, String bordercolor, String name, long links, long words, String type, int ppm, String network, long nlinks, long nwords, double nqph, long nppm) {
if ((bannerPicture == null) || ((System.currentTimeMillis() - bannerPictureDate) > maxAge)) {
drawBannerPicture(width, height, bgcolor, textcolor, bordercolor, name, links, words, type, ppm, network, nlinks, nwords, nqph, nppm);
//}
}
return bannerPicture;
}

//[MN]
private static void drawBannerPicture(int width, int height, String bgcolor, String textcolor, String bordercolor, String name, String links, String words, String type, String ppm, String network, String nlinks, String nwords, String nqph, String nppm) {
private static void drawBannerPicture(int width, int height, String bgcolor, String textcolor, String bordercolor, String name, long links, long words, String type, int ppm, String network, long nlinks, long nwords, double nqph, long nppm) {

int exprlength = 19;

bannerPicture = new ymageMatrix(width, height, bgcolor);
bannerPicture.setMode(ymageMatrix.MODE_SUB);

// draw description
bannerPicture.setColor(textcolor);
ymageToolPrint.print(bannerPicture, 100, 12, 0, "PEER: " +name , -1);
ymageToolPrint.print(bannerPicture, 100, 22, 0, "LINKS: " + links , -1);
ymageToolPrint.print(bannerPicture, 100, 32, 0, "WORDS: " + words , -1);
ymageToolPrint.print(bannerPicture, 100, 42, 0, "TYPE: " + type , -1);
ymageToolPrint.print(bannerPicture, 100, 52, 0, "SPEED: " + ppm , -1);

ymageToolPrint.print(bannerPicture, 285, 12, 0, "NETWORK: " +network , -1);
ymageToolPrint.print(bannerPicture, 285, 22, 0, "LINKS: " + nlinks , -1);
ymageToolPrint.print(bannerPicture, 285, 32, 0, "WORDS: " + nwords , -1);
//ymageToolPrint.print(bannerPicture, 285, 42, 0, "QUERIES: " + nqph , -1);
ymageToolPrint.print(bannerPicture, 285, 52, 0, "SPEED: " + nppm , -1);
ymageToolPrint.print(bannerPicture, 100, 12, 0, "PEER: " + addTrailingBlanks(name, exprlength), -1);
ymageToolPrint.print(bannerPicture, 100, 22, 0, "LINKS: " + addBlanksAndDots(links, exprlength), -1);
ymageToolPrint.print(bannerPicture, 100, 32, 0, "WORDS: " + addBlanksAndDots(words, exprlength), -1);
ymageToolPrint.print(bannerPicture, 100, 42, 0, "TYPE: " + addTrailingBlanks(type, exprlength), -1);
ymageToolPrint.print(bannerPicture, 100, 52, 0, "SPEED: " + addTrailingBlanks(ppm + " PAGES/MINUTE", exprlength), -1);

ymageToolPrint.print(bannerPicture, 285, 12, 0, "NETWORK: " + addTrailingBlanks(network, exprlength), -1);
ymageToolPrint.print(bannerPicture, 285, 22, 0, "LINKS: " + addBlanksAndDots(nlinks, exprlength), -1);
ymageToolPrint.print(bannerPicture, 285, 32, 0, "WORDS: " + addBlanksAndDots(nwords, exprlength), -1);
ymageToolPrint.print(bannerPicture, 285, 42, 0, "QUERIES: " + addTrailingBlanks(nqph + " QUERIES/HOUR", exprlength), -1);
ymageToolPrint.print(bannerPicture, 285, 52, 0, "SPEED: " + addTrailingBlanks(nppm + " PAGES/MINUTE", exprlength), -1);

if (!bordercolor.equals("")) {
bannerPicture.setColor(bordercolor);
Expand All @@ -397,7 +399,55 @@ private static void drawBannerPicture(int width, int height, String bgcolor, Str
}

// set timestamp
// bannerPictureDate = System.currentTimeMillis();
bannerPictureDate = System.currentTimeMillis();
}

//[MN]
private static String addBlanksAndDots(int input, int length) {
return addBlanksAndDots(input + "", length);
}

//[MN]
private static String addBlanksAndDots(long input, int length) {
return addBlanksAndDots(input + "", length);
}

//[MN]
private static String addBlanksAndDots(String input, int length) {
input = addDots(input);
input = addTrailingBlanks(input,length);
return input;
}

//[MN]
private static String addDots(String word) {
String tmp = "";
int len = word.length();
while(len > 3) {
if(tmp.equals("")) {
tmp = word.substring(len-3,len);
} else {
tmp = word.substring(len-3,len) + "." + tmp;
}
word = word.substring(0,len-3);
len = word.length();
}
word = word + "." + tmp;
return word;
}

//[MN]
private static String addTrailingBlanks(String word, int length) {
if (length > word.length()) {
String blanks = "";
length = length - word.length();
int i = 0;
while(i++ < length) {
blanks += " ";
}
word = blanks + word;
}
return word;
}

}

0 comments on commit fdb0b86

Please sign in to comment.