forked from I2P_Developers/i2p.i2p
i2psnark:
- Cycle through downloaded/size sorters - Cycle through uploaded/ratio sorters - Fix ratio comparator - Display ratio when sorted by ratio, and on details page (ticket #1298)
This commit is contained in:
@ -503,15 +503,26 @@ public class I2PSnarkServlet extends BasicServlet {
|
|||||||
out.write("</a>");
|
out.write("</a>");
|
||||||
}
|
}
|
||||||
out.write("</th>\n<th align=\"right\">");
|
out.write("</th>\n<th align=\"right\">");
|
||||||
// sort by size, not downloaded
|
// cycle through sort by size or downloaded
|
||||||
|
boolean isDlSort = false;
|
||||||
if (showSort) {
|
if (showSort) {
|
||||||
sort = ("5".equals(currentSort)) ? "-5" : "5";
|
if ("5".equals(currentSort)) {
|
||||||
|
sort = "-5";
|
||||||
|
} else if ("-5".equals(currentSort)) {
|
||||||
|
sort = "6";
|
||||||
|
isDlSort = true;
|
||||||
|
} else if ("6".equals(currentSort)) {
|
||||||
|
sort = "-6";
|
||||||
|
isDlSort = true;
|
||||||
|
} else {
|
||||||
|
sort = "5";
|
||||||
|
}
|
||||||
out.write("<a href=\"" + _contextPath + '/' + getQueryString(req, null, null, sort));
|
out.write("<a href=\"" + _contextPath + '/' + getQueryString(req, null, null, sort));
|
||||||
out.write("\">");
|
out.write("\">");
|
||||||
}
|
}
|
||||||
out.write("<img border=\"0\" src=\"" + _imgPath + "head_rx.png\" title=\"");
|
out.write("<img border=\"0\" src=\"" + _imgPath + "head_rx.png\" title=\"");
|
||||||
if (showSort)
|
if (showSort)
|
||||||
out.write(_("Sort by {0}", _("Size")));
|
out.write(_("Sort by {0}", (isDlSort ? _("Downloaded") : _("Size"))));
|
||||||
else
|
else
|
||||||
out.write(_("Downloaded"));
|
out.write(_("Downloaded"));
|
||||||
out.write("\" alt=\"");
|
out.write("\" alt=\"");
|
||||||
@ -521,15 +532,32 @@ public class I2PSnarkServlet extends BasicServlet {
|
|||||||
if (showSort)
|
if (showSort)
|
||||||
out.write("</a>");
|
out.write("</a>");
|
||||||
out.write("</th>\n<th align=\"right\">");
|
out.write("</th>\n<th align=\"right\">");
|
||||||
|
boolean isRatSort = false;
|
||||||
if (!snarks.isEmpty()) {
|
if (!snarks.isEmpty()) {
|
||||||
|
// cycle through sort by uploaded or ratio
|
||||||
|
boolean nextRatSort = false;
|
||||||
if (showSort) {
|
if (showSort) {
|
||||||
sort = ("7".equals(currentSort)) ? "-7" : "7";
|
if ("7".equals(currentSort)) {
|
||||||
|
sort = "-7";
|
||||||
|
} else if ("-7".equals(currentSort)) {
|
||||||
|
sort = "11";
|
||||||
|
nextRatSort = true;
|
||||||
|
} else if ("11".equals(currentSort)) {
|
||||||
|
sort = "-11";
|
||||||
|
nextRatSort = true;
|
||||||
|
isRatSort = true;
|
||||||
|
} else if ("-11".equals(currentSort)) {
|
||||||
|
sort = "7";
|
||||||
|
isRatSort = true;
|
||||||
|
} else {
|
||||||
|
sort = "7";
|
||||||
|
}
|
||||||
out.write("<a href=\"" + _contextPath + '/' + getQueryString(req, null, null, sort));
|
out.write("<a href=\"" + _contextPath + '/' + getQueryString(req, null, null, sort));
|
||||||
out.write("\">");
|
out.write("\">");
|
||||||
}
|
}
|
||||||
out.write("<img border=\"0\" src=\"" + _imgPath + "head_tx.png\" title=\"");
|
out.write("<img border=\"0\" src=\"" + _imgPath + "head_tx.png\" title=\"");
|
||||||
if (showSort)
|
if (showSort)
|
||||||
out.write(_("Sort by {0}", _("Uploaded")));
|
out.write(_("Sort by {0}", (nextRatSort ? _("Upload ratio") : _("Uploaded"))));
|
||||||
else
|
else
|
||||||
out.write(_("Uploaded"));
|
out.write(_("Uploaded"));
|
||||||
out.write("\" alt=\"");
|
out.write("\" alt=\"");
|
||||||
@ -635,7 +663,7 @@ public class I2PSnarkServlet extends BasicServlet {
|
|||||||
Snark snark = snarks.get(i);
|
Snark snark = snarks.get(i);
|
||||||
boolean showPeers = showDebug || "1".equals(peerParam) || Base64.encode(snark.getInfoHash()).equals(peerParam);
|
boolean showPeers = showDebug || "1".equals(peerParam) || Base64.encode(snark.getInfoHash()).equals(peerParam);
|
||||||
boolean hide = i < start || i >= start + pageSize;
|
boolean hide = i < start || i >= start + pageSize;
|
||||||
displaySnark(out, req, snark, uri, i, stats, showPeers, isDegraded, noThinsp, showDebug, hide);
|
displaySnark(out, req, snark, uri, i, stats, showPeers, isDegraded, noThinsp, showDebug, hide, isRatSort);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (total == 0) {
|
if (total == 0) {
|
||||||
@ -1356,8 +1384,8 @@ public class I2PSnarkServlet extends BasicServlet {
|
|||||||
*/
|
*/
|
||||||
private void displaySnark(PrintWriter out, HttpServletRequest req,
|
private void displaySnark(PrintWriter out, HttpServletRequest req,
|
||||||
Snark snark, String uri, int row, long stats[], boolean showPeers,
|
Snark snark, String uri, int row, long stats[], boolean showPeers,
|
||||||
boolean isDegraded, boolean noThinsp, boolean showDebug, boolean statsOnly)
|
boolean isDegraded, boolean noThinsp, boolean showDebug, boolean statsOnly,
|
||||||
throws IOException {
|
boolean showRatios) throws IOException {
|
||||||
// stats
|
// stats
|
||||||
long uploaded = snark.getUploaded();
|
long uploaded = snark.getUploaded();
|
||||||
stats[0] += snark.getDownloaded();
|
stats[0] += snark.getDownloaded();
|
||||||
@ -1590,8 +1618,17 @@ public class I2PSnarkServlet extends BasicServlet {
|
|||||||
// out.write("??"); // no meta size yet
|
// out.write("??"); // no meta size yet
|
||||||
out.write("</td>\n\t");
|
out.write("</td>\n\t");
|
||||||
out.write("<td align=\"right\" class=\"snarkTorrentUploaded\">");
|
out.write("<td align=\"right\" class=\"snarkTorrentUploaded\">");
|
||||||
if (isValid && uploaded > 0)
|
if (isValid) {
|
||||||
out.write(formatSize(uploaded));
|
if (showRatios) {
|
||||||
|
if (total > 0) {
|
||||||
|
double ratio = uploaded / ((double) total);
|
||||||
|
out.write((new DecimalFormat("0.000")).format(ratio));
|
||||||
|
out.write(" x");
|
||||||
|
}
|
||||||
|
} else if (uploaded > 0) {
|
||||||
|
out.write(formatSize(uploaded));
|
||||||
|
}
|
||||||
|
}
|
||||||
out.write("</td>\n\t");
|
out.write("</td>\n\t");
|
||||||
out.write("<td align=\"right\" class=\"snarkTorrentRateDown\">");
|
out.write("<td align=\"right\" class=\"snarkTorrentRateDown\">");
|
||||||
if (isRunning && needed > 0)
|
if (isRunning && needed > 0)
|
||||||
@ -2702,9 +2739,20 @@ public class I2PSnarkServlet extends BasicServlet {
|
|||||||
.append(":</b> ")
|
.append(":</b> ")
|
||||||
.append((new DecimalFormat("0.00%")).format(completion));
|
.append((new DecimalFormat("0.00%")).format(completion));
|
||||||
else
|
else
|
||||||
buf.append(" <img alt=\"\" border=\"0\" src=\"").append(_imgPath).append("head_rx.png\" > ")
|
buf.append(" <img alt=\"\" border=\"0\" src=\"").append(_imgPath).append("head_rx.png\" > <b>")
|
||||||
.append(_("Complete"));
|
.append(_("Complete")).append("</b>");
|
||||||
// else unknown
|
// up ratio
|
||||||
|
buf.append(" <img alt=\"\" border=\"0\" src=\"").append(_imgPath).append("head_tx.png\" > <b>")
|
||||||
|
.append(_("Upload ratio"))
|
||||||
|
.append(":</b> ");
|
||||||
|
long uploaded = snark.getUploaded();
|
||||||
|
if (uploaded > 0) {
|
||||||
|
double ratio = uploaded / ((double) snark.getTotalLength());
|
||||||
|
buf.append((new DecimalFormat("0.000")).format(ratio));
|
||||||
|
buf.append(" x");
|
||||||
|
} else {
|
||||||
|
buf.append('0');
|
||||||
|
}
|
||||||
long needed = snark.getNeededLength();
|
long needed = snark.getNeededLength();
|
||||||
if (needed > 0)
|
if (needed > 0)
|
||||||
buf.append(" <img alt=\"\" border=\"0\" src=\"").append(_imgPath).append("head_rx.png\" > <b>")
|
buf.append(" <img alt=\"\" border=\"0\" src=\"").append(_imgPath).append("head_rx.png\" > <b>")
|
||||||
|
@ -288,13 +288,15 @@ class Sorters {
|
|||||||
|
|
||||||
private static class RatioComparator extends Sort {
|
private static class RatioComparator extends Sort {
|
||||||
|
|
||||||
|
private static final long M = 128 * 1024 * 1024;
|
||||||
|
|
||||||
public RatioComparator(boolean rev) { super(rev); }
|
public RatioComparator(boolean rev) { super(rev); }
|
||||||
|
|
||||||
public int compareIt(Snark l, Snark r) {
|
public int compareIt(Snark l, Snark r) {
|
||||||
long lt = l.getTotalLength();
|
long lt = l.getTotalLength();
|
||||||
long ld = lt > 0 ? ((4096 * l.getUploaded()) / (4096 * lt)) : 0;
|
long ld = lt > 0 ? ((M * l.getUploaded()) / lt) : 0;
|
||||||
long rt = r.getTotalLength();
|
long rt = r.getTotalLength();
|
||||||
long rd = rt > 0 ? ((4096 * r.getUploaded()) / (4096 * rt)) : 0;
|
long rd = rt > 0 ? ((M * r.getUploaded()) / rt) : 0;
|
||||||
return compLong(ld, rd);
|
return compLong(ld, rd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user