use of it.angelic.mpw.model.jsonpojos.home.HomeStats in project MPW by shineangelic.
the class PoolQueryGrouper method groupAvgQueryResult.
public static LinkedMap<Date, HomeStatsChartData> groupAvgQueryResult(LinkedMap<Date, HomeStats> queryResult, GranularityEnum radioCheckedId) {
if (queryResult.isEmpty())
return new LinkedMap<>();
LinkedMap<Date, HomeStatsChartData> ret = new LinkedMap<>();
Calendar firstDate = Calendar.getInstance();
firstDate.setTime(queryResult.keySet().iterator().next());
Calendar firstDateOut = Calendar.getInstance();
firstDateOut.setTime(firstDate.getTime());
int calendarGranularity = Calendar.DATE;
switch(radioCheckedId) {
case DAY:
break;
case HOUR:
calendarGranularity = Calendar.HOUR;
break;
case MINUTE:
calendarGranularity = Calendar.MINUTE;
break;
}
firstDateOut.add(calendarGranularity, 1);
int divideCnt = 0;
int totCnt = 0;
HomeStatsChartData avgSet = new HomeStatsChartData();
for (HomeStats current : queryResult.values()) {
divideCnt++;
totCnt++;
// aggiorna medie
avgSet.setHashrate(avgSet.getHashrate() + current.getHashrate());
if (current.getHashrate() > avgSet.getHashrateMax())
avgSet.setHashrateMax(current.getHashrate());
if (current.getHashrate() < avgSet.getHashrateMin())
avgSet.setHashrateMin(current.getHashrate());
// avgSet.setCandidatesTotal(avgSet.getCandidatesTotal() + current.getCandidatesTotal());
avgSet.setImmatureTotal(avgSet.getImmatureTotal() + current.getImmatureTotal());
avgSet.setMaturedTotal(avgSet.getMaturedTotal() + current.getMaturedTotal());
long avgDif = avgSet.getNodes().get(0).getDifficulty() == null ? 0L : Long.parseLong(avgSet.getNodes().get(0).getDifficulty());
long curDif = current.getNodes().get(0).getDifficulty() == null ? 0L : Long.parseLong(current.getNodes().get(0).getDifficulty());
avgSet.getNodes().get(0).setDifficulty("" + (avgDif + curDif));
// sovrascrive e amen
avgSet.getNodes().get(0).setName(current.getNodes().get(0).getName());
Calendar cursorDate = Calendar.getInstance();
cursorDate.setTime(current.getNow().getTime());
// Log.d(TAG, "cursorDate" + cursorDate.getTime());
if (cursorDate.after(firstDateOut) || totCnt == queryResult.values().size()) {
// Log.d(TAG, " calcola medie " + ret.keySet().size());
// fase finita, calcola medie e vai
avgSet.setHashrate(avgSet.getHashrate() / divideCnt);
// avgSet.setCandidatesTotal(avgSet.getCandidatesTotal() / divideCnt);
avgSet.setImmatureTotal(avgSet.getImmatureTotal() / divideCnt);
avgSet.setMaturedTotal(avgSet.getMaturedTotal() / divideCnt);
avgSet.getNodes().get(0).setDifficulty("" + Long.parseLong(avgSet.getNodes().get(0).getDifficulty()) / divideCnt);
divideCnt = 0;
ret.put(firstDate.getTime(), avgSet);
avgSet = new HomeStatsChartData();
firstDate.setTime(cursorDate.getTime());
firstDateOut.setTime(firstDate.getTime());
firstDateOut.add(calendarGranularity, 1);
}
}
return ret;
}
Aggregations