{"action":"created","comment":{"url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/pulls/comments/32982586","id":32982586,"diff_hunk":"@@ -38,45 +38,74 @@\n @implementation APHCalendarDataModel\n \n #pragma mark APHCalendarCollectionViewController delegate\n--(NSDictionary *)userCompliedWithDailyScheduledTasks:(APHCalendarTaskType)task inMonth:(NSUInteger)month inYear:(NSUInteger)year{\n-    \n-    NSMutableDictionary *complianceDictionary = [[NSMutableDictionary alloc]init];\n+-(void)createComplianceDictionaryForTaskType:(APHCalendarTaskType)task\n+                                     inMonth:(NSUInteger)month\n+                                      inYear:(NSUInteger)year\n+{\n     NSDateComponents *comps = [[NSDateComponents alloc] init];\n     NSCalendar *gregorian = [[NSCalendar alloc]\n                              initWithCalendarIdentifier:NSCalendarIdentifierGregorian];\n     APCDateRange *dateRange;\n     \n     if (task == kAPHCalendarTaskTypeParticipation) {\n+        //should reflect the completion of the Daily Survey and Weekly Survey (when shown)\n         \n-        for (int day = 1; day < 32; day++) {\n-            [comps setDay:day];\n-            [comps setMonth:month];\n-            [comps setYear:year];\n-            \n-            NSDate *date = [gregorian dateFromComponents:comps];\n-            \n-            if ([date earlierDate:[NSDate new]] == date) {\n-                \n-                dateRange = [[APCDateRange alloc]initWithStartDate:date durationInterval:86400];\n-                \n-                NSInteger scheduled = [APHCalendarDataModel allScheduledTasksForDateRange:dateRange completed:nil inContext:((APCAppDelegate *)[UIApplication sharedApplication].delegate).dataSubstrate.mainContext].count;\n-                \n-                if (scheduled > 0) {\n-                    \n-                    NSInteger completedScheduled = [APHCalendarDataModel allScheduledTasksForDateRange:dateRange completed:[NSNumber numberWithBool:1] inContext:((APCAppDelegate *)[UIApplication sharedApplication].delegate).dataSubstrate.mainContext].count;\n-                    \n-                    if ((float)completedScheduled / (float)scheduled > kParticipationTrophyThreshold){\n-                        [complianceDictionary setObject:@\"1\" forKey:[NSString stringWithFormat:@\"%i\", day]];\n-                    }else{\n-                        [complianceDictionary setObject:@\"0\" forKey:[NSString stringWithFormat:@\"%i\", day]];\n-                    }\n-                }\n-            }else{\n-                return complianceDictionary;\n-            }\n+        [comps setDay:1];\n+        [comps setMonth:month];\n+        [comps setYear:year];\n+        \n+        NSDate *startDate = [gregorian dateFromComponents:comps];\n+        \n+        NSInteger endDay = 1;\n+        \n+        while ([self isValidDateForDay:endDay month:month year:year]) {\n+            ++endDay;\n         }\n         \n-        return complianceDictionary;\n+        [comps setDay:endDay -1];\n+        [comps setMonth:month];\n+        [comps setYear:year];\n+        NSDate *endDate = [gregorian dateFromComponents:comps];\n+        \n+        NSPredicate *predicate = [NSPredicate predicateWithFormat:@\"taskID == %@ OR taskID == %@\", kDailySurveyTaskID, kWeeklySurveyTaskID];\n+        \n+        [[APCScheduler defaultScheduler] fetchTaskGroupsFromDate:startDate\n+                                                          toDate:endDate\n+                                          forTasksMatchingFilter:predicate\n+                                                      usingQueue:[NSOperationQueue mainQueue]\n+                                                 toReportResults:^(NSDictionary *dates, NSError *queryError)\n+         {\n+             \n+             NSMutableDictionary *complianceDictionary = [[NSMutableDictionary alloc]init];\n+             //iterate over the task groups setting the complianceDictionary\n+             if (!queryError) {\n+                 for (NSDate *date in dates) {\n+                     NSUInteger required = 0;\n+                     NSUInteger completed = 0;\n+                     NSArray *tasks = [dates objectForKey:date];\n+                     for (APCTaskGroup *taskGroup in tasks) {\n+                         required += [taskGroup requiredRemainingTasks].count + [taskGroup requiredCompletedTasks].count;\n+                         completed += [taskGroup requiredCompletedTasks].count;\n+                     }\n+                     \n+                     NSDateComponents* components = [gregorian components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay fromDate:date];\n+                     \n+                     if ([date compare:[NSDate new]] == NSOrderedDescending) {\n+                         [complianceDictionary setObject:@\"\" forKey:[NSString stringWithFormat:@\"%i\", (int)components.day]];\n+                     }else if ((float)completed / (float)required > kParticipationTrophyThreshold){\n+                         [complianceDictionary setObject:@\"1\" forKey:[NSString stringWithFormat:@\"%i\", (int)components.day]];\n+                     }else{\n+                         [complianceDictionary setObject:@\"0\" forKey:[NSString stringWithFormat:@\"%i\", (int)components.day]];\n+                     }\n+                 }\n+                 \n+                 dispatch_async(dispatch_get_main_queue(), ^{\n+                     [[NSNotificationCenter defaultCenter]postNotificationName:calendarDataSourceDidUpdateComplianceDictionaryNotification object:complianceDictionary];","path":"Asthma/TabBarControllers/Dashboard/APHCalendarDataModel.m","position":96,"original_position":96,"commit_id":"90d6c76946f630941ecf8d7a2cab69110e1105d0","original_commit_id":"90d6c76946f630941ecf8d7a2cab69110e1105d0","user":{"login":"YuanZhu-apple","id":11466704,"avatar_url":"https://avatars.githubusercontent.com/u/11466704?v=3","gravatar_id":"","url":"https://api.github.com/users/YuanZhu-apple","html_url":"https://github.com/YuanZhu-apple","followers_url":"https://api.github.com/users/YuanZhu-apple/followers","following_url":"https://api.github.com/users/YuanZhu-apple/following{/other_user}","gists_url":"https://api.github.com/users/YuanZhu-apple/gists{/gist_id}","starred_url":"https://api.github.com/users/YuanZhu-apple/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/YuanZhu-apple/subscriptions","organizations_url":"https://api.github.com/users/YuanZhu-apple/orgs","repos_url":"https://api.github.com/users/YuanZhu-apple/repos","events_url":"https://api.github.com/users/YuanZhu-apple/events{/privacy}","received_events_url":"https://api.github.com/users/YuanZhu-apple/received_events","type":"User","site_admin":false},"body":"Need a space between `]` and `post...`","created_at":"2015-06-22T20:57:22Z","updated_at":"2015-06-22T20:57:22Z","html_url":"https://github.com/ResearchKit/AsthmaHealth/pull/5#discussion_r32982586","pull_request_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/pulls/5","_links":{"self":{"href":"https://api.github.com/repos/ResearchKit/AsthmaHealth/pulls/comments/32982586"},"html":{"href":"https://github.com/ResearchKit/AsthmaHealth/pull/5#discussion_r32982586"},"pull_request":{"href":"https://api.github.com/repos/ResearchKit/AsthmaHealth/pulls/5"}}},"pull_request":{"url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/pulls/5","id":38272290,"html_url":"https://github.com/ResearchKit/AsthmaHealth/pull/5","diff_url":"https://github.com/ResearchKit/AsthmaHealth/pull/5.diff","patch_url":"https://github.com/ResearchKit/AsthmaHealth/pull/5.patch","issue_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/issues/5","number":5,"state":"open","locked":false,"title":"Asthma open source calendar re-host on new scheduler","user":{"login":"chrisinsfo","id":3868802,"avatar_url":"https://avatars.githubusercontent.com/u/3868802?v=3","gravatar_id":"","url":"https://api.github.com/users/chrisinsfo","html_url":"https://github.com/chrisinsfo","followers_url":"https://api.github.com/users/chrisinsfo/followers","following_url":"https://api.github.com/users/chrisinsfo/following{/other_user}","gists_url":"https://api.github.com/users/chrisinsfo/gists{/gist_id}","starred_url":"https://api.github.com/users/chrisinsfo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrisinsfo/subscriptions","organizations_url":"https://api.github.com/users/chrisinsfo/orgs","repos_url":"https://api.github.com/users/chrisinsfo/repos","events_url":"https://api.github.com/users/chrisinsfo/events{/privacy}","received_events_url":"https://api.github.com/users/chrisinsfo/received_events","type":"User","site_admin":false},"body":"- Implement an activity indicator\r\n- Make bracket spacing consistent\r\n- Add observer for activity completion notification\r\n- Update fetch requests for new scheduler","created_at":"2015-06-22T20:24:42Z","updated_at":"2015-06-22T20:57:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e0f6261a7af26bed463c93571f012f008b8b5c8b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/pulls/5/commits","review_comments_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/pulls/5/comments","review_comment_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/issues/5/comments","statuses_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/statuses/90d6c76946f630941ecf8d7a2cab69110e1105d0","head":{"label":"chrisinsfo:AsthmaOpenSourceCalendar","ref":"AsthmaOpenSourceCalendar","sha":"90d6c76946f630941ecf8d7a2cab69110e1105d0","user":{"login":"chrisinsfo","id":3868802,"avatar_url":"https://avatars.githubusercontent.com/u/3868802?v=3","gravatar_id":"","url":"https://api.github.com/users/chrisinsfo","html_url":"https://github.com/chrisinsfo","followers_url":"https://api.github.com/users/chrisinsfo/followers","following_url":"https://api.github.com/users/chrisinsfo/following{/other_user}","gists_url":"https://api.github.com/users/chrisinsfo/gists{/gist_id}","starred_url":"https://api.github.com/users/chrisinsfo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrisinsfo/subscriptions","organizations_url":"https://api.github.com/users/chrisinsfo/orgs","repos_url":"https://api.github.com/users/chrisinsfo/repos","events_url":"https://api.github.com/users/chrisinsfo/events{/privacy}","received_events_url":"https://api.github.com/users/chrisinsfo/received_events","type":"User","site_admin":false},"repo":{"id":36676105,"name":"AsthmaHealth","full_name":"chrisinsfo/AsthmaHealth","owner":{"login":"chrisinsfo","id":3868802,"avatar_url":"https://avatars.githubusercontent.com/u/3868802?v=3","gravatar_id":"","url":"https://api.github.com/users/chrisinsfo","html_url":"https://github.com/chrisinsfo","followers_url":"https://api.github.com/users/chrisinsfo/followers","following_url":"https://api.github.com/users/chrisinsfo/following{/other_user}","gists_url":"https://api.github.com/users/chrisinsfo/gists{/gist_id}","starred_url":"https://api.github.com/users/chrisinsfo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrisinsfo/subscriptions","organizations_url":"https://api.github.com/users/chrisinsfo/orgs","repos_url":"https://api.github.com/users/chrisinsfo/repos","events_url":"https://api.github.com/users/chrisinsfo/events{/privacy}","received_events_url":"https://api.github.com/users/chrisinsfo/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/chrisinsfo/AsthmaHealth","description":"ResearchKit app studying Asthma, developed by Mt Sinai.","fork":true,"url":"https://api.github.com/repos/chrisinsfo/AsthmaHealth","forks_url":"https://api.github.com/repos/chrisinsfo/AsthmaHealth/forks","keys_url":"https://api.github.com/repos/chrisinsfo/AsthmaHealth/keys{/key_id}","collaborators_url":"https://api.github.com/repos/chrisinsfo/AsthmaHealth/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/chrisinsfo/AsthmaHealth/teams","hooks_url":"https://api.github.com/repos/chrisinsfo/AsthmaHealth/hooks","issue_events_url":"https://api.github.com/repos/chrisinsfo/AsthmaHealth/issues/events{/number}","events_url":"https://api.github.com/repos/chrisinsfo/AsthmaHealth/events","assignees_url":"https://api.github.com/repos/chrisinsfo/AsthmaHealth/assignees{/user}","branches_url":"https://api.github.com/repos/chrisinsfo/AsthmaHealth/branches{/branch}","tags_url":"https://api.github.com/repos/chrisinsfo/AsthmaHealth/tags","blobs_url":"https://api.github.com/repos/chrisinsfo/AsthmaHealth/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/chrisinsfo/AsthmaHealth/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/chrisinsfo/AsthmaHealth/git/refs{/sha}","trees_url":"https://api.github.com/repos/chrisinsfo/AsthmaHealth/git/trees{/sha}","statuses_url":"https://api.github.com/repos/chrisinsfo/AsthmaHealth/statuses/{sha}","languages_url":"https://api.github.com/repos/chrisinsfo/AsthmaHealth/languages","stargazers_url":"https://api.github.com/repos/chrisinsfo/AsthmaHealth/stargazers","contributors_url":"https://api.github.com/repos/chrisinsfo/AsthmaHealth/contributors","subscribers_url":"https://api.github.com/repos/chrisinsfo/AsthmaHealth/subscribers","subscription_url":"https://api.github.com/repos/chrisinsfo/AsthmaHealth/subscription","commits_url":"https://api.github.com/repos/chrisinsfo/AsthmaHealth/commits{/sha}","git_commits_url":"https://api.github.com/repos/chrisinsfo/AsthmaHealth/git/commits{/sha}","comments_url":"https://api.github.com/repos/chrisinsfo/AsthmaHealth/comments{/number}","issue_comment_url":"https://api.github.com/repos/chrisinsfo/AsthmaHealth/issues/comments{/number}","contents_url":"https://api.github.com/repos/chrisinsfo/AsthmaHealth/contents/{+path}","compare_url":"https://api.github.com/repos/chrisinsfo/AsthmaHealth/compare/{base}...{head}","merges_url":"https://api.github.com/repos/chrisinsfo/AsthmaHealth/merges","archive_url":"https://api.github.com/repos/chrisinsfo/AsthmaHealth/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/chrisinsfo/AsthmaHealth/downloads","issues_url":"https://api.github.com/repos/chrisinsfo/AsthmaHealth/issues{/number}","pulls_url":"https://api.github.com/repos/chrisinsfo/AsthmaHealth/pulls{/number}","milestones_url":"https://api.github.com/repos/chrisinsfo/AsthmaHealth/milestones{/number}","notifications_url":"https://api.github.com/repos/chrisinsfo/AsthmaHealth/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/chrisinsfo/AsthmaHealth/labels{/name}","releases_url":"https://api.github.com/repos/chrisinsfo/AsthmaHealth/releases{/id}","created_at":"2015-06-01T17:16:53Z","updated_at":"2015-06-01T17:16:54Z","pushed_at":"2015-06-22T20:12:31Z","git_url":"git://github.com/chrisinsfo/AsthmaHealth.git","ssh_url":"git@github.com:chrisinsfo/AsthmaHealth.git","clone_url":"https://github.com/chrisinsfo/AsthmaHealth.git","svn_url":"https://github.com/chrisinsfo/AsthmaHealth","homepage":null,"size":103433,"stargazers_count":0,"watchers_count":0,"language":"Objective-C","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"ResearchKit:master","ref":"master","sha":"ea164f7a5a393ac23e2daddd802fed5162d170bb","user":{"login":"ResearchKit","id":11183179,"avatar_url":"https://avatars.githubusercontent.com/u/11183179?v=3","gravatar_id":"","url":"https://api.github.com/users/ResearchKit","html_url":"https://github.com/ResearchKit","followers_url":"https://api.github.com/users/ResearchKit/followers","following_url":"https://api.github.com/users/ResearchKit/following{/other_user}","gists_url":"https://api.github.com/users/ResearchKit/gists{/gist_id}","starred_url":"https://api.github.com/users/ResearchKit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ResearchKit/subscriptions","organizations_url":"https://api.github.com/users/ResearchKit/orgs","repos_url":"https://api.github.com/users/ResearchKit/repos","events_url":"https://api.github.com/users/ResearchKit/events{/privacy}","received_events_url":"https://api.github.com/users/ResearchKit/received_events","type":"Organization","site_admin":false},"repo":{"id":32883202,"name":"AsthmaHealth","full_name":"ResearchKit/AsthmaHealth","owner":{"login":"ResearchKit","id":11183179,"avatar_url":"https://avatars.githubusercontent.com/u/11183179?v=3","gravatar_id":"","url":"https://api.github.com/users/ResearchKit","html_url":"https://github.com/ResearchKit","followers_url":"https://api.github.com/users/ResearchKit/followers","following_url":"https://api.github.com/users/ResearchKit/following{/other_user}","gists_url":"https://api.github.com/users/ResearchKit/gists{/gist_id}","starred_url":"https://api.github.com/users/ResearchKit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ResearchKit/subscriptions","organizations_url":"https://api.github.com/users/ResearchKit/orgs","repos_url":"https://api.github.com/users/ResearchKit/repos","events_url":"https://api.github.com/users/ResearchKit/events{/privacy}","received_events_url":"https://api.github.com/users/ResearchKit/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ResearchKit/AsthmaHealth","description":"ResearchKit app studying Asthma, developed by Mt Sinai.","fork":false,"url":"https://api.github.com/repos/ResearchKit/AsthmaHealth","forks_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/forks","keys_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/teams","hooks_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/hooks","issue_events_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/issues/events{/number}","events_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/events","assignees_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/assignees{/user}","branches_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/branches{/branch}","tags_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/tags","blobs_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/git/refs{/sha}","trees_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/statuses/{sha}","languages_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/languages","stargazers_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/stargazers","contributors_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/contributors","subscribers_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/subscribers","subscription_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/subscription","commits_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/commits{/sha}","git_commits_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/git/commits{/sha}","comments_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/comments{/number}","issue_comment_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/issues/comments{/number}","contents_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/contents/{+path}","compare_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/merges","archive_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/downloads","issues_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/issues{/number}","pulls_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/pulls{/number}","milestones_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/milestones{/number}","notifications_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/labels{/name}","releases_url":"https://api.github.com/repos/ResearchKit/AsthmaHealth/releases{/id}","created_at":"2015-03-25T18:29:40Z","updated_at":"2015-06-15T22:04:22Z","pushed_at":"2015-06-22T20:24:42Z","git_url":"git://github.com/ResearchKit/AsthmaHealth.git","ssh_url":"git@github.com:ResearchKit/AsthmaHealth.git","clone_url":"https://github.com/ResearchKit/AsthmaHealth.git","svn_url":"https://github.com/ResearchKit/AsthmaHealth","homepage":null,"size":22092,"stargazers_count":67,"watchers_count":67,"language":"Objective-C","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":28,"mirror_url":null,"open_issues_count":2,"forks":28,"open_issues":2,"watchers":67,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ResearchKit/AsthmaHealth/pulls/5"},"html":{"href":"https://github.com/ResearchKit/AsthmaHealth/pull/5"},"issue":{"href":"https://api.github.com/repos/ResearchKit/AsthmaHealth/issues/5"},"comments":{"href":"https://api.github.com/repos/ResearchKit/AsthmaHealth/issues/5/comments"},"review_comments":{"href":"https://api.github.com/repos/ResearchKit/AsthmaHealth/pulls/5/comments"},"review_comment":{"href":"https://api.github.com/repos/ResearchKit/AsthmaHealth/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ResearchKit/AsthmaHealth/pulls/5/commits"},"statuses":{"href":"https://api.github.com/repos/ResearchKit/AsthmaHealth/statuses/90d6c76946f630941ecf8d7a2cab69110e1105d0"}}}}