Search in sources :

Example 1 with Matured

use of it.angelic.mpw.model.jsonpojos.blocks.Matured in project MPW by shineangelic.

the class BlocksActivity method doApacheMath.

private SummaryStatistics doApacheMath(List<Matured> maturi) {
    ArrayList<Matured> revElements = new ArrayList<>(maturi);
    Collections.reverse(revElements);
    long[] intervals = new long[maturi.size()];
    Date prevDate = revElements.get(0).getTimestamp();
    int i = 0;
    // parto da 1 a calcolare il 1o intervallo
    for (int t = 1; t < revElements.size(); t++) {
        Date curDate = revElements.get(t).getTimestamp();
        intervals[i++] = curDate.getTime() - prevDate.getTime();
        prevDate = curDate;
    }
    // a oggi, calcolo ultimo intervallo aperto
    intervals[maturi.size() - 1] = (new Date().getTime() - revElements.get(maturi.size() - 1).getTimestamp().getTime());
    // Get a DescriptiveStatistics instance
    SummaryStatistics stats = new SummaryStatistics();
    // Add the data from the array
    for (long interval : intervals) {
        stats.addValue(interval);
    }
    return stats;
}
Also used : Matured(it.angelic.mpw.model.jsonpojos.blocks.Matured) ArrayList(java.util.ArrayList) SummaryStatistics(org.apache.commons.math3.stat.descriptive.SummaryStatistics) Date(java.util.Date)

Example 2 with Matured

use of it.angelic.mpw.model.jsonpojos.blocks.Matured in project MPW by shineangelic.

the class Utils method getPoolBlockAvgReward.

private static double getPoolBlockAvgReward(List<Matured> matured) {
    if (matured == null || matured.size() < 1)
        return 0;
    double summer = 0;
    int cnt = 0;
    // Add the data from the array
    for (Matured m : matured) {
        // sort of 'works, dunno why' thing
        summer += Double.valueOf(m.getReward()) / 1000000000d;
        cnt++;
    }
    return summer / cnt;
}
Also used : Matured(it.angelic.mpw.model.jsonpojos.blocks.Matured)

Aggregations

Matured (it.angelic.mpw.model.jsonpojos.blocks.Matured)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 SummaryStatistics (org.apache.commons.math3.stat.descriptive.SummaryStatistics)1