2007-10-07 23:59:36 +02:00
|
|
|
// Banner.java
|
|
|
|
// -----------------------
|
|
|
|
// part of YaCy
|
2008-07-20 19:14:51 +02:00
|
|
|
// (C) by Michael Peter Christen; mc@yacy.net
|
2007-10-07 23:59:36 +02:00
|
|
|
// first published on http://www.anomic.de
|
|
|
|
// Frankfurt, Germany, 2004
|
|
|
|
//
|
|
|
|
// This File is contributed by Marc Nause
|
|
|
|
//
|
2009-09-27 00:07:40 +02:00
|
|
|
// $LastChangedDate$
|
|
|
|
// $LastChangedRevision$
|
|
|
|
// $LastChangedBy$
|
2007-10-07 23:59:36 +02:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
2008-06-06 18:01:27 +02:00
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
|
|
|
2010-08-23 14:32:02 +02:00
|
|
|
import net.yacy.cora.protocol.RequestHeader;
|
2011-10-04 11:06:24 +02:00
|
|
|
import net.yacy.peers.Seed;
|
2011-09-25 18:59:06 +02:00
|
|
|
import net.yacy.peers.graphics.NetworkGraph;
|
|
|
|
import net.yacy.search.Switchboard;
|
|
|
|
import net.yacy.search.SwitchboardConstants;
|
2009-10-20 00:34:44 +02:00
|
|
|
import net.yacy.visualization.RasterPlotter;
|
2007-10-07 23:59:36 +02:00
|
|
|
import de.anomic.server.serverObjects;
|
|
|
|
import de.anomic.server.serverSwitch;
|
2007-12-02 21:37:12 +01:00
|
|
|
|
2007-10-07 23:59:36 +02:00
|
|
|
/** draw a banner with information about the peer */
|
|
|
|
public class Banner {
|
|
|
|
|
2009-10-20 00:34:44 +02:00
|
|
|
public static RasterPlotter respond(final RequestHeader header, final serverObjects post, final serverSwitch env) throws IOException {
|
2009-07-19 22:37:44 +02:00
|
|
|
final Switchboard sb = (Switchboard) env;
|
2011-09-14 02:33:08 +02:00
|
|
|
final String IMAGE = "htroot/env/grafics/yacy.png";
|
2007-10-07 23:59:36 +02:00
|
|
|
int width = 468;
|
|
|
|
int height = 60;
|
2010-09-11 13:05:07 +02:00
|
|
|
String bgcolor = "e7effc";
|
2007-12-07 22:25:36 +01:00
|
|
|
String textcolor = "000000";
|
2010-09-11 13:05:07 +02:00
|
|
|
String bordercolor = "5090d0";
|
2007-10-07 23:59:36 +02:00
|
|
|
|
|
|
|
if (post != null) {
|
|
|
|
bgcolor = post.get("bgcolor", bgcolor);
|
|
|
|
textcolor = post.get("textcolor", textcolor);
|
|
|
|
bordercolor = post.get("bordercolor", bordercolor);
|
2007-12-07 22:25:36 +01:00
|
|
|
width = post.getInt("width", width);
|
|
|
|
height = post.getInt("heigth", height);
|
2007-10-07 23:59:36 +02:00
|
|
|
}
|
|
|
|
|
2007-12-08 02:39:59 +01:00
|
|
|
String name = "";
|
|
|
|
long links = 0;
|
|
|
|
long words = 0;
|
|
|
|
int myppm = 0;
|
|
|
|
double myqph = 0;
|
|
|
|
String type = "";
|
2009-07-19 22:37:44 +02:00
|
|
|
final String network = env.getConfig(SwitchboardConstants.NETWORK_NAME, "unspecified").toUpperCase();
|
2009-05-28 16:26:05 +02:00
|
|
|
final int peers = sb.peers.sizeConnected() + 1; // the '+ 1': the own peer is not included in sizeConnected()
|
|
|
|
long nlinks = sb.peers.countActiveURL();
|
|
|
|
long nwords = sb.peers.countActiveRWI();
|
|
|
|
final double nqpm = sb.peers.countActiveQPM();
|
|
|
|
long nppm = sb.peers.countActivePPM();
|
2007-12-08 02:39:59 +01:00
|
|
|
double nqph = 0;
|
2007-10-07 23:59:36 +02:00
|
|
|
|
2011-10-04 11:06:24 +02:00
|
|
|
final Seed seed = sb.peers.mySeed();
|
2007-10-09 23:47:37 +02:00
|
|
|
if (seed != null){
|
2011-10-04 11:06:24 +02:00
|
|
|
name = seed.get(Seed.NAME, "-").toUpperCase();
|
2009-12-21 12:36:48 +01:00
|
|
|
links = seed.getLinkCount();
|
|
|
|
words = seed.getWordCount();
|
2007-12-02 21:37:12 +01:00
|
|
|
myppm = seed.getPPM();
|
|
|
|
myqph = 60d * seed.getQPM();
|
2007-10-07 23:59:36 +02:00
|
|
|
|
2009-05-28 16:26:05 +02:00
|
|
|
if (sb.peers.mySeed().isVirgin()) {
|
2007-10-09 23:47:37 +02:00
|
|
|
type = "VIRGIN";
|
|
|
|
nqph = Math.round(6000d * nqpm) / 100d;
|
2009-05-28 16:26:05 +02:00
|
|
|
} else if(sb.peers.mySeed().isJunior()) {
|
2007-10-09 23:47:37 +02:00
|
|
|
type = "JUNIOR";
|
|
|
|
nqph = Math.round(6000d * nqpm) / 100d;
|
2009-05-28 16:26:05 +02:00
|
|
|
} else if(sb.peers.mySeed().isSenior()) {
|
2007-10-09 23:47:37 +02:00
|
|
|
type = "SENIOR";
|
|
|
|
nlinks = nlinks + links;
|
|
|
|
nwords = nwords + words;
|
|
|
|
nqph = Math.round(6000d * nqpm + 100d * myqph) / 100d;
|
|
|
|
nppm = nppm + myppm;
|
2009-05-28 16:26:05 +02:00
|
|
|
} else if(sb.peers.mySeed().isPrincipal()) {
|
2007-10-09 23:47:37 +02:00
|
|
|
type = "PRINCIPAL";
|
|
|
|
nlinks = nlinks + links;
|
|
|
|
nwords = nwords + words;
|
|
|
|
nqph = Math.round(6000d * nqpm + 100d * myqph) / 100d;
|
|
|
|
nppm = nppm + myppm;
|
2007-10-07 23:59:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-19 22:37:44 +02:00
|
|
|
if (!NetworkGraph.logoIsLoaded()) {
|
2010-03-26 11:43:31 +01:00
|
|
|
ImageIO.setUseCache(false); // do not write a cache to disc; keep in RAM
|
2008-08-02 14:12:04 +02:00
|
|
|
final BufferedImage logo = ImageIO.read(new File(IMAGE));
|
2009-07-19 22:37:44 +02:00
|
|
|
return NetworkGraph.getBannerPicture(1000, width, height, bgcolor, textcolor, bordercolor, name, links, words, type, myppm, network, peers, nlinks, nwords, nqph, nppm, logo);
|
2007-12-02 21:37:12 +01:00
|
|
|
}
|
2011-09-14 02:33:08 +02:00
|
|
|
|
2009-07-19 22:37:44 +02:00
|
|
|
return NetworkGraph.getBannerPicture(1000, width, height, bgcolor, textcolor, bordercolor, name, links, words, type, myppm, network, peers, nlinks, nwords, nqph, nppm);
|
2007-10-07 23:59:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|