private static ComplianceIndicatorsViewModel ClearTheView(ComplianceIndicatorsViewModel vm) { vm.ReviewsRead = 0; vm.IndicatorsGenerated = 0; vm.ProjectsRead = 0; vm.CompletedProjects = 0; vm.SamplesRead = 0; vm.ReviewsCompleted = 0; vm.TotalCompliancePoints = 0; return(vm); }
private void ProcessReview(ComplianceIndicatorsViewModel vm, Review review, IDictionary <string, CountStat> countList, Project project, IEnumerable <ProjectContract> contractList) { var upload = GetUpload(review.UploadId); // Only looking at accepted reviews if (!upload.AcceptedFlag) { return; } var reviewOutcome = ReviewOutcome(review); vm.ReviewsRead++; if (!IsCompleted(review)) { return; } // Only looking at completed reviews vm.ReviewsCompleted++; var orgCode = OrgCodeFor(review); var esaCode = EsaCodeFor(review); var orgEsaCode = OrgEsaCodeFor(orgCode, esaCode); var multiplier = MultiplierFor(project, upload.RandomFlag, upload.NationalFlag); // we have a positive multiplier var compliancePoints = WeightedScore(multiplier, reviewOutcome); vm.TotalCompliancePoints += compliancePoints; var quarter = review.Quarter(); foreach (var programme in contractList) { IncrementCounts(programme.ContractType, multiplier, quarter, orgCode, orgEsaCode, compliancePoints, countList, review.ReviewId); } }
private ComplianceIndicatorsViewModel GenerateProgrammeIndicators(ComplianceIndicatorsViewModel vm) { vm = ClearTheView(vm); var countList = new Dictionary <string, CountStat>(); var projectList = projectRepository.GetAll(new DateTime(1, 1, 1), new DateTime(1, 1, 1)); foreach (var project in projectList) { var projectProgrammeList = projectContractRepository.GetAllByProjectId(project.ProjectId); vm.ProjectsRead++; var reviewList = reviewRepository.GetAllByProjectId(project.ProjectId); foreach (var review in reviewList) { //if ( ( review.OrgCode != "BALT" ) || review.ESACode != "4TWE" || review.Quarter() != "20122" ) continue; //TODO: take this away its just to speed testing //if ( ( review.OrgCode != "LEON" ) || review.ESACode != "4ONB" || review.Quarter() != "20114" // || (review.ProjectId != 255 && review.ProjectId != 333 ) ) continue; //TODO: take this away its just to speed testing ProcessReview(vm, review, countList, project, projectProgrammeList); } } #if DEBUG // for proof of calculation foreach (var pair in countList) { var ciLine = string.Format("Key:{0} - {1} - {2}", pair.Key, pair.Value, pair.Value.ReviewList()); var ua = new UserActivity { Activity = ciLine, UserId = "CI-GEN" }; activityRepository.Add(ua); } #endif StoreIndicators(countList, vm); return(vm); }
private static void UpdateComplianceIndicators(IPatService patService, string how, PatControl control) { var lastComplianceRun = control.LastComplianceRun; string auditMsg; string why; if (ReadyToGenerateAgain(lastComplianceRun, how, out why)) { var stopwatch = new Stopwatch(); stopwatch.Start(); var ciViewModel = new ComplianceIndicatorsViewModel(); // Options currently required by PAM var cigen = new ComplianceIndicators(); ciViewModel = cigen.Generate(ciViewModel); control.LastComplianceRun = DateTime.Now; control.UpdatedBy = BatchUser; control.ReviewCount = ciViewModel.ReviewsRead; control.ProjectCount = ciViewModel.ProjectsRead; control.ProjectCompletion = AppHelper.Percent(ciViewModel.CompletedProjects, ciViewModel.ProjectsRead); control.SampleCount = ciViewModel.SamplesRead; control.TotalComplianceIndicator = AppHelper.Average(ciViewModel.TotalCompliancePoints, ciViewModel.ReviewsRead); var timeElapsed = AppHelper.StopTheWatch(stopwatch); auditMsg = string.Format("CI Generation complete: {0} indicators generated in {1}", ciViewModel.IndicatorsGenerated, timeElapsed); } else { auditMsg = string.Format("CI Generation skipped ({1}) for now: last Run {0}", lastComplianceRun, why); } patService.SaveActivity(CreateAuditRecord(auditMsg, "CIGEN")); }
/// <summary> /// Generatea all the compliance Indicators /// </summary> public ComplianceIndicatorsViewModel Generate(ComplianceIndicatorsViewModel vm) { ClearOutOldComplianceIndicators(); vm = GenerateProgrammeIndicators(vm); return(vm); }
private static void StoreIndicators(ICollection <KeyValuePair <string, CountStat> > countList, ComplianceIndicatorsViewModel vm) { foreach (var ci in countList.Select(pair => new ComplianceIndicator { Programme = pair.Value.Programme, ComplianceIndicatorId = 0, CreatedBy = DataConstants.BatchUserId, UpdatedBy = DataConstants.BatchUserId, Quarter = pair.Value.Quarter, SubjectTypeCode = SubjectTypeOf(pair.Value.SubjectArea), Subject = OrgOutOf(pair.Value.SubjectArea, pair.Value.Subject), EsaCode = EsaOutOf(pair.Value.SubjectArea, pair.Value.Subject), Value = pair.Value.ComplianceIndicator() })) { ciRepository.Update(ci); } vm.IndicatorsGenerated += countList.Count; countList.Clear(); }