Search in sources :

Example 6 with Wallet

use of it.angelic.mpw.model.jsonpojos.wallet.Wallet in project MPW by shineangelic.

the class NoobPoolInstrumentedTest method testJsonWalletRequest.

@Test
public void testJsonWalletRequest() throws Exception {
    final GsonBuilder builder = new GsonBuilder();
    JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET, Utils.getWalletStatsUrl(sharedPreferences) + minerAddr, null, new Response.Listener<JSONObject>() {

        @Override
        public void onResponse(final JSONObject response) {
            Log.i(Constants.TAG, response.toString());
            Gson gson = builder.create();
            // Register an adapter to manage the date types as long values
            Wallet retrieved = gson.fromJson(response.toString(), Wallet.class);
            assertNotNull(retrieved);
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            Log.e(Constants.TAG, "Error: " + error.getMessage());
        }
    });
    // Adding request to request queue
    JSONClientSingleton.getInstance(appContext).addToRequestQueue(jsonObjReq);
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) JSONObject(org.json.JSONObject) GsonBuilder(com.google.gson.GsonBuilder) Wallet(it.angelic.mpw.model.jsonpojos.wallet.Wallet) Gson(com.google.gson.Gson) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest) Test(org.junit.Test)

Example 7 with Wallet

use of it.angelic.mpw.model.jsonpojos.wallet.Wallet in project MPW by shineangelic.

the class ChartUtils method drawWalletHashRateHistory.

public static void drawWalletHashRateHistory(TextView titleTextView, LineView chart, LinkedMap<Date, Wallet> dateWalletLinkedMap, GranularityEnum grane) {
    SummaryStatistics stats = new SummaryStatistics();
    ArrayList<Float> dataList = new ArrayList<>();
    ArrayList<String> labelsArr = new ArrayList<>();
    List<Date> dates = dateWalletLinkedMap.asList();
    Wallet campione = dateWalletLinkedMap.values().iterator().next();
    for (Date date2 : dates) {
        labelsArr.add(getLabelFormat(grane, date2));
        dataList.add(Utils.condenseHashRate(dateWalletLinkedMap.get(date2).getHashrate()));
        stats.addValue(dateWalletLinkedMap.get(date2).getHashrate());
    }
    titleTextView.setText("Wallet Hashrate History " + "(avg: " + Utils.formatHashrate((long) stats.getMean()) + ", max: " + Utils.formatHashrate((long) stats.getMax()) + ", min: " + Utils.formatHashrate((long) stats.getMin()) + ", now: " + Utils.formatHashrate(dateWalletLinkedMap.get(dates.get(dataList.size() - 1)).getHashrate()) + ", std dev: " + Utils.formatHashrate((long) stats.getStandardDeviation()) + ")");
    ArrayList<ArrayList<Float>> dataLists = new ArrayList<>();
    dataLists.add(dataList);
    chart.setShowPopup(LineView.SHOW_POPUPS_All);
    // optional
    chart.setDrawDotLine(false);
    chart.setBottomTextList(labelsArr);
    chart.setColorArray(new int[] { Color.DKGRAY, Color.CYAN });
    // or lineView.setFloatDataList(floatDataLists)
    chart.setFloatDataList(dataLists);
}
Also used : Wallet(it.angelic.mpw.model.jsonpojos.wallet.Wallet) ArrayList(java.util.ArrayList) SummaryStatistics(org.apache.commons.math3.stat.descriptive.SummaryStatistics) Date(java.util.Date)

Example 8 with Wallet

use of it.angelic.mpw.model.jsonpojos.wallet.Wallet in project MPW by shineangelic.

the class PoolQueryGrouper method groupAvgWalletQueryResult.

public static LinkedMap<Date, Wallet> groupAvgWalletQueryResult(LinkedMap<Date, Wallet> queryResult, GranularityEnum radioCheckedId) {
    if (queryResult.isEmpty())
        return queryResult;
    LinkedMap<Date, Wallet> 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;
    Wallet avgSet = new Wallet();
    for (Date cursorDates : queryResult.keySet()) {
        Wallet current = queryResult.get(cursorDates);
        divideCnt++;
        totCnt++;
        // aggiorna medie
        avgSet.setHashrate(avgSet.getHashrate() + current.getHashrate());
        avgSet.setWorkersOnline(avgSet.getWorkersOnline() + current.getWorkersOnline());
        avgSet.getStats().setBalance(avgSet.getStats().getBalance() + current.getStats().getBalance());
        Calendar cursorDate = Calendar.getInstance();
        cursorDate.setTime(cursorDates);
        // 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.setWorkersOnline(avgSet.getWorkersOnline() / divideCnt);
            avgSet.getStats().setBalance(avgSet.getStats().getBalance() / divideCnt);
            divideCnt = 0;
            ret.put(firstDate.getTime(), avgSet);
            avgSet = new Wallet();
            firstDate.setTime(cursorDate.getTime());
            firstDateOut.setTime(firstDate.getTime());
            firstDateOut.add(calendarGranularity, 1);
        }
    }
    return ret;
}
Also used : Wallet(it.angelic.mpw.model.jsonpojos.wallet.Wallet) Calendar(java.util.Calendar) LinkedMap(org.apache.commons.collections4.map.LinkedMap) Date(java.util.Date)

Example 9 with Wallet

use of it.angelic.mpw.model.jsonpojos.wallet.Wallet in project MPW by shineangelic.

the class MaxHashInstrumentedTest method testJsonWalletRequest.

@Test
public void testJsonWalletRequest() throws Exception {
    final GsonBuilder builder = new GsonBuilder();
    JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET, Utils.getWalletStatsUrl(sharedPreferences) + minerAddr, null, new Response.Listener<JSONObject>() {

        @Override
        public void onResponse(final JSONObject response) {
            Log.i(Constants.TAG, response.toString());
            Gson gson = builder.create();
            // Register an adapter to manage the date types as long values
            Wallet retrieved = gson.fromJson(response.toString(), Wallet.class);
            assertNotNull(retrieved);
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            Log.e(Constants.TAG, "Error: " + error.getMessage());
        }
    });
    // Adding request to request queue
    JSONClientSingleton.getInstance(appContext).addToRequestQueue(jsonObjReq);
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) JSONObject(org.json.JSONObject) GsonBuilder(com.google.gson.GsonBuilder) Wallet(it.angelic.mpw.model.jsonpojos.wallet.Wallet) Gson(com.google.gson.Gson) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest) Test(org.junit.Test)

Example 10 with Wallet

use of it.angelic.mpw.model.jsonpojos.wallet.Wallet in project MPW by shineangelic.

the class PoolDbHelper method getWalletHistoryData.

public LinkedMap<Date, Wallet> getWalletHistoryData(@NonNull BackToEnum cutoff) {
    LinkedMap<Date, Wallet> ret = new LinkedMap<>();
    int cnt = 0;
    SQLiteDatabase db = this.getReadableDatabase();
    String limitCause = "";
    Calendar now = Calendar.getInstance();
    switch(cutoff) {
        case ONE_DAY:
            now.add(Calendar.DATE, -1);
            limitCause = DataBaseContract.Wallet_.COLUMN_NAME_DTM + "  > " + now.getTime().getTime();
            break;
        case ONE_WEEK:
            now.add(Calendar.DATE, -7);
            limitCause = DataBaseContract.Wallet_.COLUMN_NAME_DTM + "  > " + now.getTime().getTime();
            break;
        case ONE_MONTH:
            now.add(Calendar.MONTH, -1);
            limitCause = DataBaseContract.Wallet_.COLUMN_NAME_DTM + "  > " + now.getTime().getTime();
            break;
        default:
            Log.e("DB", "Unexpected switch ERROR");
            break;
    }
    // Cursor cursor = db.rawQuery(selectQuery, null);
    Cursor cursor = db.query(DataBaseContract.Wallet_.TABLE_NAME, new String[] { DataBaseContract.Wallet_._ID, DataBaseContract.Wallet_.COLUMN_NAME_DTM, DataBaseContract.Wallet_.COLUMN_NAME_JSON }, limitCause, // String[] selectionArgs
    null, null, // HAVING
    null, // ORDER BY
    DataBaseContract.Wallet_.COLUMN_NAME_DTM + " ASC");
    // looping through all rows and adding to list
    if (cursor.moveToFirst()) {
        Gson gson = builder.create();
        do {
            try {
                // Register an adapter to manage the date types as long values
                Wallet retrieved = gson.fromJson(cursor.getString(cursor.getColumnIndexOrThrow(DataBaseContract.Wallet_.COLUMN_NAME_JSON)), Wallet.class);
                cnt++;
                // Adding contact to list
                Date curDate = new Date(cursor.getLong(cursor.getColumnIndexOrThrow(DataBaseContract.Wallet_.COLUMN_NAME_DTM)));
                ret.put(curDate, retrieved);
            } catch (Exception ce) {
                Log.e(TAG, "Cant read WalletHistoryData entry: " + ce.getMessage());
            }
        } while (cursor.moveToNext());
    }
    Log.i(TAG, "SELECT DONE. WALLET HISTORY SIZE: " + cnt);
    cursor.close();
    return ret;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Wallet(it.angelic.mpw.model.jsonpojos.wallet.Wallet) Calendar(java.util.Calendar) Gson(com.google.gson.Gson) Cursor(android.database.Cursor) LinkedMap(org.apache.commons.collections4.map.LinkedMap) Date(java.util.Date)

Aggregations

Wallet (it.angelic.mpw.model.jsonpojos.wallet.Wallet)13 Gson (com.google.gson.Gson)10 Response (com.android.volley.Response)7 VolleyError (com.android.volley.VolleyError)7 JsonObjectRequest (com.android.volley.toolbox.JsonObjectRequest)7 JSONObject (org.json.JSONObject)7 Date (java.util.Date)5 GsonBuilder (com.google.gson.GsonBuilder)4 LinkedMap (org.apache.commons.collections4.map.LinkedMap)4 Cursor (android.database.Cursor)3 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)3 Test (org.junit.Test)3 SharedPreferences (android.content.SharedPreferences)2 Calendar (java.util.Calendar)2 NotificationManager (android.app.NotificationManager)1 Context (android.content.Context)1 TextView (android.widget.TextView)1 JobParameters (com.firebase.jobdispatcher.JobParameters)1 MyDateTypeAdapter (it.angelic.mpw.model.MyDateTypeAdapter)1 MyTimeStampTypeAdapter (it.angelic.mpw.model.MyTimeStampTypeAdapter)1