Skip to content
This repository has been archived by the owner on Dec 20, 2017. It is now read-only.

Commit

Permalink
Increasing historical transfer batch size to max value and fixing iss…
Browse files Browse the repository at this point in the history
…ue with 0 eq value
  • Loading branch information
bilthon committed Dec 28, 2016
1 parent ee7ac88 commit 39b581d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import android.widget.ImageView;
import android.widget.TextView;

import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
Expand Down Expand Up @@ -151,114 +150,8 @@ private View renderAmount(HistoricalTransferEntry historicalTransfer) {
Log.d(TAG,"Fiat amount: "+eqValue);
fiatAmountTextView.setText(eqValue);
}else{
Log.w(TAG,"Fiat amount is null");
Log.w(TAG, String.format("Fiat amount is null for transfer: %d %s", assetAmount.getAmount().longValue(), assetAmount.getAsset().getSymbol()));
}

// Locale locale;
NumberFormat format;
// String language;
// language = Helper.fetchStringSharePref(getContext(), getContext().getString(R.string.pref_language));
// locale = new Locale(language);
Helper.setLocaleNumberFormat(locale, 1);
// if( historicalTransfer.getOperation().getFrom().getObjectId().equals(userAccount.getObjectId())) {
// // The transaction was sent from this user's account
// TextView transferAmount = (TextView) root.findViewById(R.id.transactionssendamount);
// transferAmount.setTextColor(ContextCompat.getColor(getContext(),R.color.sendamount));
// String amount = Helper.setLocaleNumberFormat(locale, historicalTransfer.getOperation().getTransferAmount().getAmount());
// transferAmount.setText(String.format("- %s %s", amount, "-"));
// amount = "";
//
// if ( transactiondetails.getFaitAmount() == 0 )
// {
// TextView textView2 = (TextView) root.findViewById(R.id.transactionssendfaitamount);
// textView2.setText("");
// }
// else
// {
// TextView textView2 = (TextView) root.findViewById(R.id.transactionssendfaitamount);
// textView2.setTextColor(ContextCompat.getColor(getContext(),R.color.sendamount));
//
// double faitAmount = transactiondetails.getFaitAmount();
//
// if ( faitAmount > 0.009 )
// {
// amount = String.format(locale,"%.2f",faitAmount);
// }
// else if ( (faitAmount < 0.009) && (faitAmount > 0.0009) )
// {
// amount = String.format(locale,"%.3f",faitAmount);
// }
// else if ( (faitAmount < 0.0009) && (faitAmount > 0.00009) )
// {
// amount = String.format(locale,"%.4f",faitAmount);
// }
// else
// {
// amount = String.format(locale,"%.5f",faitAmount);
// }
//
// String displayFaitAmount = "";
// if ( Helper.isRTL(locale,transactiondetails.getFaitAssetSymbol()) )
// {
// displayFaitAmount = String.format(locale,"%s %s",amount,transactiondetails.getFaitAssetSymbol());
// }
// else
// {
// displayFaitAmount = String.format(locale,"%s %s",transactiondetails.getFaitAssetSymbol(),amount);
// }
// textView2.setText("- " + displayFaitAmount);
// }
// }
// else
// {
// TextView textView = (TextView) root.findViewById(R.id.transactionssendamount);
// textView.setTextColor(ContextCompat.getColor(getContext(),R.color.recieveamount));
// String amount = Helper.setLocaleNumberFormat(locale,transactiondetails.getAmount());
// textView.setText("+ " + amount + " " + transactiondetails.getAssetSymbol());
// amount = "";
//
// if ( transactiondetails.getFaitAmount() == 0 )
// {
// TextView textView2 = (TextView) root.findViewById(R.id.transactionssendfaitamount);
// textView2.setText("");
// }
// else
// {
// TextView textView2 = (TextView) root.findViewById(R.id.transactionssendfaitamount);
// textView2.setTextColor(ContextCompat.getColor(getContext(), R.color.recieveamount));
//
// double faitAmount = transactiondetails.getFaitAmount();
//
// if ( faitAmount > 0.009 )
// {
// amount = String.format(locale,"%.2f",faitAmount);
// }
// else if ( (faitAmount < 0.009) && (faitAmount > 0.0009) )
// {
// amount = String.format(locale,"%.3f",faitAmount);
// }
// else if ( (faitAmount < 0.0009) && (faitAmount > 0.00009) )
// {
// amount = String.format(locale,"%.4f",faitAmount);
// }
// else
// {
// amount = String.format(locale,"%.5f",faitAmount);
// }
//
// String displayFaitAmount = "";
// if ( Helper.isRTL(locale,transactiondetails.getFaitAssetSymbol()) )
// {
// displayFaitAmount = String.format(locale,"%s %s",amount,transactiondetails.getFaitAssetSymbol());
// }
// else
// {
// displayFaitAmount = String.format(locale,"%s %s",transactiondetails.getFaitAssetSymbol(),amount);
// }
//
// textView2.setText("+ " + displayFaitAmount);
// }
// }
return root;
}

Expand Down
16 changes: 10 additions & 6 deletions app/src/main/java/de/bitshares_munich/database/SCWallDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,16 @@ public List<HistoricalTransferEntry> getTransactions(UserAccount userAccount){
historicalTransfer.setOperation(transferOperation);
historicalTransfer.setBlockNum(cursor.getInt(cursor.getColumnIndex(SCWallDatabaseContract.Transfers.COLUMN_BLOCK_NUM)));

// Adding the HistoricalTransfer instance
transferEntry.setHistoricalTransfer(historicalTransfer);

// Setting the timestamp
transferEntry.setTimestamp(cursor.getLong(cursor.getColumnIndex(SCWallDatabaseContract.Transfers.COLUMN_TIMESTAMP)));

// Adding equivalent value data
String id = cursor.getString(cursor.getColumnIndex(SCWallDatabaseContract.Transfers.COLUMN_EQUIVALENT_VALUE_ASSET_ID));
long equivalentValue = cursor.getLong(cursor.getColumnIndex(SCWallDatabaseContract.Transfers.COLUMN_EQUIVALENT_VALUE));
if(id != null && equivalentValue != 0){
if(id != null){
Log.v(TAG,String.format("Eq value asset id: %s, value: %d", id, equivalentValue));
String table = SCWallDatabaseContract.Assets.TABLE_NAME;
String[] columns = new String[] {
Expand All @@ -183,17 +189,15 @@ public List<HistoricalTransferEntry> getTransactions(UserAccount userAccount){
int precision = assetCursor.getInt(1);
AssetAmount eqValueAssetAmount = new AssetAmount(UnsignedLong.valueOf(equivalentValue), new Asset(id, symbol, precision));
transferEntry.setEquivalentValue(eqValueAssetAmount);
assetCursor.close();
}else{
Log.w(TAG,"Got empty cursor while trying to fill asset data");
}
assetCursor.close();
}else{
Log.v(TAG, "Failed do put equivalent data");
Date date = new Date(transferEntry.getTimestamp() * 1000);
Log.w(TAG,String.format("Got no eq value for transaction at %s", date.toString()));
}

transferEntry.setHistoricalTransfer(historicalTransfer);
transferEntry.setTimestamp(cursor.getLong(cursor.getColumnIndex(SCWallDatabaseContract.Transfers.COLUMN_TIMESTAMP)));

// Adding historical transfer entry to array
transfers.add(transferEntry);
}while(cursor.moveToNext());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public BalancesFragment() {
webSocketCallHelper myWebSocketHelper;

/* Constant used to fix the number of historical transfers to fetch in one batch */
private int HISTORICAL_TRANSFER_BATCH_SIZE = 20;
private int HISTORICAL_TRANSFER_BATCH_SIZE = 100;

/* Parameters to be used as the start and stop arguments in the 'get_relative_account_history' API call */
private int start = 1;
Expand Down Expand Up @@ -354,14 +354,15 @@ public void onSuccess(WitnessResponse response) {
Asset quote = database.fillAssetDetails(bucket.key.quote);

if(quote.equals(mSmartcoin)){
Log.i(TAG,String.format("quote is smartcoin. base: %s, quote: %s", base.getObjectId(), quote.getObjectId()));
Log.i(TAG,String.format("quote is my smartcoin. base: %s, quote: %s", base.getObjectId(), quote.getObjectId()));

// Doing conversion and updating the database
Converter converter = new Converter(base, quote, bucket);
long convertedBaseValue = converter.convert(transferAmount, Converter.CLOSE_VALUE);
AssetAmount equivalentValue = new AssetAmount(UnsignedLong.valueOf(convertedBaseValue), mSmartcoin);

Log.d(TAG,String.format("Saving eq value. %s %d, original: %s %d", equivalentValue.getAsset().getSymbol(), equivalentValue.getAmount().longValue(), transferAmount.getAsset().getSymbol(), transferAmount.getAmount().longValue()));
Date date = new Date(transferEntry.getTimestamp()*1000);
Log.d(TAG,String.format("Saving eq value. %s %d, original: %s %d. Date: %s", equivalentValue.getAsset().getSymbol(), equivalentValue.getAmount().longValue(), transferAmount.getAsset().getSymbol(), transferAmount.getAmount().longValue(), date.toString()));
transferEntry.setEquivalentValue(equivalentValue);
database.updateEquivalentValue(transferEntry);

Expand Down Expand Up @@ -411,15 +412,15 @@ public void run() {
getMissingEquivalentValues.start();
}
}else{
// Log.w(TAG, String.format("Got no bucket from the requested time period for asset: %s ", transferEntry.getHistoricalTransfer().getOperation().getTransferAmount().getAsset().getSymbol()));
Log.w(TAG, String.format("Got no bucket from the requested time period for asset: %s ", transferEntry.getHistoricalTransfer().getOperation().getTransferAmount().getAsset().getSymbol()));
Date currentStart = getMarketHistory.getStart();
Calendar calendar = Calendar.getInstance();
int previousCount = getMarketHistory.getCount() > 0 ? getMarketHistory.getCount() - 1 : 0;
int currentCount = getMarketHistory.getCount();
long previousExponentialFactor = (long) Math.pow(2, previousCount) * Constants.DEFAULT_BUCKET_SIZE * 1000;
long newExponentialFactor = (long) Math.pow(2, currentCount) * Constants.DEFAULT_BUCKET_SIZE * 1000;
long adjustedStartValue = currentStart.getTime() + previousExponentialFactor - newExponentialFactor;
// Log.d(TAG,String.format("prev: %d, current: %d, start: %d", previousExponentialFactor, newExponentialFactor, adjustedStartValue));
Log.d(TAG,String.format("prev: %d, current: %d, start: %d", previousExponentialFactor, newExponentialFactor, adjustedStartValue));
calendar.setTimeInMillis(adjustedStartValue);
getMarketHistory.setStart(calendar.getTime());
getMarketHistory.retry();
Expand Down Expand Up @@ -614,7 +615,7 @@ public void run() {
if(resp.result.size() == HISTORICAL_TRANSFER_BATCH_SIZE){
Log.i(TAG,String.format("Got %d transactions, which es exactly the requested amount, so we might have more.", resp.result.size()));
start = historicalTransferCount * HISTORICAL_TRANSFER_BATCH_SIZE;
stop = ((historicalTransferCount + 1) * HISTORICAL_TRANSFER_BATCH_SIZE) + 1;
stop = start + HISTORICAL_TRANSFER_BATCH_SIZE + 1;
Log.i(TAG,String.format("Calling get_relative_account_history. start: %d, limit: %d, stop: %d", start, HISTORICAL_TRANSFER_BATCH_SIZE, stop));
transferHistoryThread = new WebsocketWorkerThread(new GetRelativeAccountHistory(new UserAccount(accountId), start, HISTORICAL_TRANSFER_BATCH_SIZE, stop, mTransferHistoryListener));
transferHistoryThread.start();
Expand Down Expand Up @@ -974,7 +975,7 @@ public void onResume() {

if (!accountId.equals("")) {
start = historicalTransferCount * HISTORICAL_TRANSFER_BATCH_SIZE;
stop = ((historicalTransferCount + 1) * HISTORICAL_TRANSFER_BATCH_SIZE) + 1;
stop = start + HISTORICAL_TRANSFER_BATCH_SIZE + 1;
Log.i(TAG,String.format("Calling get_relative_account_history. start: %d, limit: %d, stop: %d", start, HISTORICAL_TRANSFER_BATCH_SIZE, stop));
transferHistoryThread = new WebsocketWorkerThread(new GetRelativeAccountHistory(new UserAccount(accountId), start, HISTORICAL_TRANSFER_BATCH_SIZE, stop, mTransferHistoryListener));
transferHistoryThread.start();
Expand Down Expand Up @@ -2623,7 +2624,6 @@ public void TransactionUpdate(final List<TransactionDetails> transactionDetails,

@Override
public void transactionsLoadComplete(List<TransactionDetails> transactionDetails, int newTransactionsLoaded) {
Log.d(TAG, "transactionLoadComplete. new tx: " + newTransactionsLoaded);
try {
if (updateTriggerFromNetworkBroadcast && (newTransactionsLoaded == 0) && (counterRepeatTransactionLoad++ < 15)) {
if (Application.isReady) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/transactionsendamountview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:textSize="11sp"
android:textSize="13sp"
android:textColor="@color/sendamount"
android:layout_gravity="end"
android:textAlignment="textEnd"
Expand Down

0 comments on commit 39b581d

Please sign in to comment.