Skip to content

Commit

Permalink
Refined progress messaging. Added type group percentage tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Chicoine committed Oct 1, 2024
1 parent e5f2430 commit ac3597d
Showing 1 changed file with 35 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class HttpClientUtils {

//used for POST order by resource type:
public enum HttpPOSTResourceType {
BUNDLE("Bundle"),
BUNDLE("Bundles"),
LIBRARY_DEPS("Library Dependencies"),
VALUESETS("Value Sets"),
TESTS("Tests"),
Expand Down Expand Up @@ -298,7 +298,7 @@ private static Callable<Void> createPostCallable(HttpPost post, PostComponent po
}

runningPostTaskList.remove(postComponent.resource);
reportProgress(postComponent.type.getDisplayName());
reportProgress(postComponent.type);
return null;
};
}
Expand Down Expand Up @@ -342,25 +342,54 @@ private static String getDiagnosticString(String jsonString) {
}
}

private static String getSectionPercentage(HttpPOSTResourceType postType) {
//processedPostCounter holds the count we're at.
//logically all preceding items up until this point are processed
//add all sections until we get to this type, subtract total processed from other type count
//get percentage from that using (processedPostCounter - theseTypesCount) / currentTypeProcessedCount

int otherTypesProcessedCount = 0;

for (int i = 0; i < resourceTypePostOrder.size(); i++) {
HttpPOSTResourceType iterType = resourceTypePostOrder.get(i);
if (iterType == postType){
break;
}
if (mappedTasksByPriorityRank.containsKey(iterType)) {
otherTypesProcessedCount = otherTypesProcessedCount + (mappedTasksByPriorityRank.get(iterType)).size();
}
}

int thisTypeProcessedCount = mappedTasksByPriorityRank.get(postType).size();
int currentCounter = processedPostCounter - otherTypesProcessedCount;

double percentage = (double) currentCounter / thisTypeProcessedCount * 100;

return String.format("%.2f%%", percentage);
}

/**
* Reports the progress of HTTP POST calls and the current thread pool size.
* <p>
* This method updates and prints the progress of HTTP POST calls by calculating the percentage of completed tasks
* relative to the total number of tasks. It also displays the current size of the running thread pool. The progress
* and pool size information is printed to the standard output.
*/
private static void reportProgress(String postType) {
private static void reportProgress(HttpPOSTResourceType postType) {
int currentCounter = processedPostCounter++;

String fileGroup = "";
if (postType != null) {
fileGroup = "Current resource type: " + postType + " ";
fileGroup = "Current POST group: " + postType.getDisplayName() + " " + getSectionPercentage(postType) + " ";
}
int currentCounter = processedPostCounter++;

double percentage = (double) currentCounter / getTotalTaskCount() * 100;
System.out.print("\rProgress: " + String.format("%.2f%%", percentage) + " processed. " +
System.out.print("\rOverall Progress: " + String.format("%.2f%%", percentage) + ". " +
"POST response pool size: " + runningPostTaskList.size() + ". " +
fileGroup);
}


private static void reportProgress(){
reportProgress(null);
}
Expand Down

0 comments on commit ac3597d

Please sign in to comment.