Search in sources :

Example 11 with LinkedMap

use of org.apache.commons.collections4.map.LinkedMap 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

LinkedMap (org.apache.commons.collections4.map.LinkedMap)11 Date (java.util.Date)6 Gson (com.google.gson.Gson)5 Cursor (android.database.Cursor)4 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)4 HomeStats (it.angelic.mpw.model.jsonpojos.home.HomeStats)4 Wallet (it.angelic.mpw.model.jsonpojos.wallet.Wallet)4 Calendar (java.util.Calendar)4 GsonBuilder (com.google.gson.GsonBuilder)2 MyDateTypeAdapter (it.angelic.mpw.model.MyDateTypeAdapter)2 MyTimeStampTypeAdapter (it.angelic.mpw.model.MyTimeStampTypeAdapter)2 PoolDbHelper (it.angelic.mpw.model.db.PoolDbHelper)2 NotificationManager (android.app.NotificationManager)1 Context (android.content.Context)1 SharedPreferences (android.content.SharedPreferences)1 FloatingActionButton (android.support.design.widget.FloatingActionButton)1 NavigationView (android.support.design.widget.NavigationView)1 DrawerLayout (android.support.v4.widget.DrawerLayout)1 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)1 Toolbar (android.support.v7.widget.Toolbar)1