Search in sources :

Example 1 with RateReporter

use of duckutil.RateReporter in project snowblossom by snowblossomcoin.

the class ReportManager method record.

public synchronized void record(String address, long count) {
    total.record(count);
    if (!rate_map.containsKey(address)) {
        rate_map.put(address, new RateReporter());
    }
    rate_map.get(address).record(count);
}
Also used : RateReporter(duckutil.RateReporter)

Example 2 with RateReporter

use of duckutil.RateReporter in project snowblossom by snowblossomcoin.

the class ReportManager method writeReport.

public synchronized void writeReport(String path) {
    try {
        PrintStream out = new PrintStream(new AtomicFileOutputStream(path));
        DecimalFormat df = new DecimalFormat("0.0");
        out.println("Total: " + total.getReportLong(df));
        TreeSet<String> to_remove = new TreeSet<>();
        for (Map.Entry<String, RateReporter> me : rate_map.entrySet()) {
            if (me.getValue().isZero()) {
                to_remove.add(me.getKey());
            } else {
                out.println(me.getKey() + " " + me.getValue().getReportLong(df));
            }
        }
        for (String k : to_remove) {
            rate_map.remove(k);
        }
        out.flush();
        out.close();
    } catch (Exception e) {
        logger.log(Level.WARNING, "Error writing report: " + e.toString());
    }
}
Also used : PrintStream(java.io.PrintStream) AtomicFileOutputStream(duckutil.AtomicFileOutputStream) TreeSet(java.util.TreeSet) DecimalFormat(java.text.DecimalFormat) TreeMap(java.util.TreeMap) Map(java.util.Map) RateReporter(duckutil.RateReporter)

Example 3 with RateReporter

use of duckutil.RateReporter in project snowblossom by snowblossomcoin.

the class ReportManager method writeReportJson.

public synchronized void writeReportJson(JSONObject json) {
    json.put("total", total.getRawRates());
    JSONObject miners = new JSONObject();
    TreeSet<String> to_remove = new TreeSet<>();
    for (Map.Entry<String, RateReporter> me : rate_map.entrySet()) {
        if (me.getValue().isZero()) {
            to_remove.add(me.getKey());
        } else {
            miners.put(me.getKey(), me.getValue().getRawRates());
        }
    }
    for (String k : to_remove) {
        rate_map.remove(k);
    }
    json.put("miners", miners);
}
Also used : JSONObject(net.minidev.json.JSONObject) TreeSet(java.util.TreeSet) TreeMap(java.util.TreeMap) Map(java.util.Map) RateReporter(duckutil.RateReporter)

Aggregations

RateReporter (duckutil.RateReporter)3 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 TreeSet (java.util.TreeSet)2 AtomicFileOutputStream (duckutil.AtomicFileOutputStream)1 PrintStream (java.io.PrintStream)1 DecimalFormat (java.text.DecimalFormat)1 JSONObject (net.minidev.json.JSONObject)1