Skip to content

Commit

Permalink
Update progress bar and time remaining behavior (#475)
Browse files Browse the repository at this point in the history
* update the progress bar and time remaining with overall progress and not test individual options.
  • Loading branch information
aanorbel authored Apr 7, 2022
1 parent af755ff commit 21c6219
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 28 deletions.
1 change: 1 addition & 0 deletions ooniprobe/Test/RunningTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, strong) AbstractSuite *testSuite;
@property (nonatomic, strong) AbstractTest *testRunning;
@property (nonatomic) BOOL isTestRunning;
@property (nonatomic) NSMutableArray *iTestSuites;

@end

Expand Down
1 change: 1 addition & 0 deletions ooniprobe/Test/RunningTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ -(void)clearSuites {
}

-(void)setAndRun:(NSMutableArray*)testSuites {
self.iTestSuites= [testSuites mutableCopy];
@synchronized(self)
{
currentTest.testSuites = testSuites;
Expand Down
23 changes: 19 additions & 4 deletions ooniprobe/View/RunTest/ProgressViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,28 @@ -(void)testStarted:(NSNotification *)notification{
-(void)updateProgress:(NSNotification *)notification{
NSDictionary *userInfo = notification.userInfo;
NSNumber *prog = [userInfo objectForKey:@"prog"];
int totalRuntime = 0;
for (AbstractSuite *n in [RunningTest currentTest].iTestSuites) {
totalRuntime += n.getRuntime;
}

float previousProgress = 0;
for (AbstractSuite *n in [RunningTest currentTest].iTestSuites) {
if (![[RunningTest currentTest].testSuites containsObject:n]) {
previousProgress += n.getRuntime;
}
}
float totalTests = [RunningTest currentTest].testSuite.totalTests;
int index = [RunningTest currentTest].testSuite.measurementIdx;
float prevProgress = index/totalTests;
float progress = ([prog floatValue]/totalTests)+prevProgress;
dispatch_async(dispatch_get_main_queue(), ^{
[self.progressBar setProgress:progress animated:YES];
});
if (totalRuntime > 0){
float ratio = [RunningTest currentTest].testSuite.getRuntime/(float)totalRuntime;
float progress = ([prog floatValue]/totalTests)+prevProgress;
progress = ((previousProgress/(float)totalRuntime)+(progress*ratio));
dispatch_async(dispatch_get_main_queue(), ^{
[self.progressBar setProgress:progress animated:YES];
});
}
}

-(void)networkTestEndedUI{
Expand Down
59 changes: 35 additions & 24 deletions ooniprobe/View/RunTest/TestRunningViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ - (void)viewDidLoad {
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
if ([RunningTest currentTest].isTestRunning)
[self testStart];
if ([[ReachabilityManager sharedManager] isVPNConnected])
[MessageUtility alertWithTitle:NSLocalizedString(@"Modal.DisableVPN.Title", nil)
message:NSLocalizedString(@"Modal.DisableVPN.Message", nil) inView:self];
}

-(void)viewDidAppear:(BOOL)animated{
Expand Down Expand Up @@ -73,7 +70,11 @@ -(void)testStart{

-(void)setRuntime{
dispatch_async(dispatch_get_main_queue(), ^{
self.totalRuntime = [[RunningTest currentTest].testSuite getRuntime];
int sum = 0;
for (AbstractSuite *n in [RunningTest currentTest].iTestSuites) {
sum += n.getRuntime;
}
self.totalRuntime = sum;
//We don't want to show -1 seconds before downloading the URL list
if (self.totalRuntime <= [MAX_RUNTIME_DISABLED intValue])
return;
Expand Down Expand Up @@ -121,21 +122,31 @@ -(void)updateProgress:(NSNotification *)notification{
NSNumber *prog = [userInfo objectForKey:@"prog"];
//TODO-2.1 this doesn't take in consideration different test runtimes, only the total
//But still fixes https://github.com/ooni/probe/issues/805
float previousProgress = 0;
for (AbstractSuite *n in [RunningTest currentTest].iTestSuites) {
if (![[RunningTest currentTest].testSuites containsObject:n]) {
previousProgress += n.getRuntime;
}
}
float totalTests = [RunningTest currentTest].testSuite.totalTests;
int index = [RunningTest currentTest].testSuite.measurementIdx;
float prevProgress = index/totalTests;
float progress = ([prog floatValue]/totalTests)+prevProgress;
long eta = self.totalRuntime;
if (progress > 0) {
eta = lroundf(self.totalRuntime - progress * self.totalRuntime);
}
if (self.totalRuntime > 0){
float ratio = [RunningTest currentTest].testSuite.getRuntime/(float)self.totalRuntime;
float progress = ([prog floatValue]/totalTests)+prevProgress;
progress = ((previousProgress/(float)self.totalRuntime)+(progress*ratio));
long eta = self.totalRuntime;
if (progress > 0) {
eta = lroundf(self.totalRuntime - progress * self.totalRuntime);
}

dispatch_async(dispatch_get_main_queue(), ^{
[self.progressBar setProgress:progress animated:YES];
NSString *time = NSLocalizedFormatString(@"Dashboard.Running.Seconds", [NSString stringWithFormat:@"%ld", eta]);
[self.timeLabel setText:time];
dispatch_async(dispatch_get_main_queue(), ^{
[self.progressBar setProgress:progress animated:YES];
NSString *time = NSLocalizedFormatString(@"Dashboard.Running.Seconds", [NSString stringWithFormat:@"%ld", eta]);
[self.timeLabel setText:time];

});
});
}
[self.animation playWithCompletion:^(BOOL animationFinished) {}];

}
Expand Down Expand Up @@ -164,11 +175,11 @@ -(void)networkTestEndedUI{

-(void)showError{
UIAlertAction* okButton = [UIAlertAction
actionWithTitle:NSLocalizedString(@"Modal.OK", nil)
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
[self dismissViewControllerAnimated:YES completion:nil];
}];
actionWithTitle:NSLocalizedString(@"Modal.OK", nil)
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
[self dismissViewControllerAnimated:YES completion:nil];
}];
[MessageUtility alertWithTitle:NSLocalizedString(@"Modal.Error", nil)
message:NSLocalizedString(@"Modal.Error.CantDownloadURLs", nil)
okButton:okButton
Expand All @@ -178,11 +189,11 @@ -(void)showError{

-(IBAction)cancelTest:(id)sender{
UIAlertAction* okButton = [UIAlertAction
actionWithTitle:NSLocalizedString(@"Modal.OK", nil)
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
[[NSNotificationCenter defaultCenter] postNotificationName:@"interruptTest" object:nil];
}];
actionWithTitle:NSLocalizedString(@"Modal.OK", nil)
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
[[NSNotificationCenter defaultCenter] postNotificationName:@"interruptTest" object:nil];
}];
[MessageUtility alertWithTitle:NSLocalizedString(@"Modal.InterruptTest.Title", nil)
message:NSLocalizedString(@"Modal.InterruptTest.Paragraph", nil)
okButton:okButton
Expand Down

0 comments on commit 21c6219

Please sign in to comment.