Skip to content

Commit

Permalink
Sample progress reporting improved.
Browse files Browse the repository at this point in the history
  • Loading branch information
lagerspetz committed Nov 13, 2017
1 parent 8e6093d commit bc8e155
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
4 changes: 2 additions & 2 deletions caratApp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ android {
buildToolsVersion "25.0.2"

defaultConfig {
versionCode 126
versionName "2.17.12"
versionCode 127
versionName "2.17.13"
applicationId "edu.berkeley.cs.amplab.carat.android"
minSdkVersion 10
//noinspection OldTargetApi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,14 @@ private void registerMe(CaratService.Client instance, String uuId, String os, St
instance.registerMe(registration);
}

public int uploadSamples(Collection<Sample> samples) {
/**
* Upload the given collection of Samples.
* @param samples
* @param countSoFar number of samples that have been sent so far this time around.
* @param sampleCount The total number of samples in the database to be sent this time around.
* @return Number of samples out out <code>samples</code> that were successfully sent.
*/
public int uploadSamples(Collection<Sample> samples, double countSoFar, double sampleCount) {
int successCount = 0;
registerLocal();
if(rpcService == null){
Expand All @@ -130,10 +137,11 @@ public int uploadSamples(Collection<Sample> samples) {
try {
if(rpcService.uploadSample(sample)){
successCount++;
int progress = (int)(successCount*100.0 / batchSize);
// This is only progress in batch
// int progress = (int)(successCount*100.0 / batchSize);
long progress = Math.round((successCount+countSoFar)*100.0/sampleCount);
String progressString = progress + "% " + CaratApplication.getAppContext().getString(R.string.samplesreported);
CaratApplication.setStatus(progressString);

}
} catch (Throwable th) {
Logger.e(TAG, "Error uploading sample", th);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,24 @@ public static boolean sendSamples(CaratApplication app) {
return false;
}
int sampleCount = db.countSamples();
String progressString = "0 of "+sampleCount +" "+ app.getString(R.string.samplesreported);
String progressString = "0% of "+sampleCount +" "+ app.getString(R.string.samplesreported);
CaratApplication.setStatus(progressString);
int successSum = 0;
int failures = 0;
SortedMap<Long, Sample> batch = db.queryOldestSamples(Constants.COMMS_MAX_UPLOAD_BATCH);
Logger.d(Constants.SF, "Queried a batch of samples of size: " + batch.size());
sendingSamples = true;
while(batch.size() > 0 && failures <= 3){
int sent = commManager.uploadSamples(batch.values());
int sent = commManager.uploadSamples(batch.values(), successSum, sampleCount);
if(sent > 0){
failures = 0; // Reset tries
successSum += sent;
/*
Report this within uploadSamples for better granularity
int progress = (int)(successSum*100.0 / sampleCount);
progressString = progress + "% " + app.getString(R.string.samplesreported);
CaratApplication.setStatus(progressString);

*/
// Delete samples that were sent successfully
Set<Long> sentRowIds = Util.firstEntries(sent, batch).keySet();
db.deleteSamples(sentRowIds);
Expand Down

0 comments on commit bc8e155

Please sign in to comment.