Search in sources :

Example 11 with HomeStats

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;
}
Also used : HomeStatsChartData(it.angelic.mpw.model.HomeStatsChartData) Calendar(java.util.Calendar) HomeStats(it.angelic.mpw.model.jsonpojos.home.HomeStats) LinkedMap(org.apache.commons.collections4.map.LinkedMap) Date(java.util.Date)

Aggregations

HomeStats (it.angelic.mpw.model.jsonpojos.home.HomeStats)11 Gson (com.google.gson.Gson)7 Response (com.android.volley.Response)5 VolleyError (com.android.volley.VolleyError)5 JsonObjectRequest (com.android.volley.toolbox.JsonObjectRequest)5 Calendar (java.util.Calendar)5 JSONObject (org.json.JSONObject)5 GsonBuilder (com.google.gson.GsonBuilder)4 MyDateTypeAdapter (it.angelic.mpw.model.MyDateTypeAdapter)4 MyTimeStampTypeAdapter (it.angelic.mpw.model.MyTimeStampTypeAdapter)4 LinkedMap (org.apache.commons.collections4.map.LinkedMap)4 TextView (android.widget.TextView)3 BigDecimal (java.math.BigDecimal)3 MathContext (java.math.MathContext)3 Date (java.util.Date)3 Test (org.junit.Test)3 SharedPreferences (android.content.SharedPreferences)2 Cursor (android.database.Cursor)2 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)2 NavigationView (android.support.design.widget.NavigationView)2