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);
}
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);
}
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;
}
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);
}
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;
}
Aggregations