Skip to content

Commit

Permalink
Support blanks and allow them to be excluded from the average #3369
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisala committed Dec 10, 2024
1 parent f617372 commit cfaa2c2
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 7 deletions.
29 changes: 24 additions & 5 deletions grails-app/assets/javascripts/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,29 @@ function OrganisationServicesViewModel(serviceIds, allServices, outputTargets, p
if (periods.length === 0)
return;

var sum = sumOfPeriodTargets();
var avg = sum / periods.length;

// TODO make the behaviour of the total configurable so we can make this more reusable
var avg = averageOfPeriodTargets();

target.target(avg);
}

function averageOfPeriodTargets() {
// For RCS reporting, targets are evaluated each year so we don't want to include undefined
// targets in the average.
var sum = 0;
var count = 0;
_.each(target.periodTargets, function (periodTarget) {
var target = parseInt(periodTarget.target());
if (!_.isNaN(target)) {
sum += target
count++;
}
});

return sum/count;
}

function sumOfPeriodTargets() {
var sum = 0;
_.each(target.periodTargets, function (periodTarget) {
Expand All @@ -113,14 +132,14 @@ function OrganisationServicesViewModel(serviceIds, allServices, outputTargets, p
return target.scoreId() == outputTarget.scoreId;
});
_.each(periods, function (period, i) {
var periodTarget = 0;
var periodTarget = null;
if (currentTarget) {
var currentPeriodTarget = _.find(currentTarget.periodTargets || [], function (periodTarget) {
return periodTarget.period == period;
return periodTarget.period == period.value;
}) || {};
periodTarget = currentPeriodTarget.target;
}
target.periodTargets[i].target(periodTarget || 0);
target.periodTargets[i].target(periodTarget);
// subscribe after setting the initial value
!subscribed && target.periodTargets[i].target.subscribe(evaluateAndAssignAverage);
});
Expand Down
2 changes: 1 addition & 1 deletion grails-app/views/organisation/_admin.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
<g:if test="${showTargets}">
<div id="organisation-targets" class="tab-pane">
<h3>Total funding</h3>
<g:render template="/organisation/budget"/>
<g:render template="/organisation/funding"/>
<h3>Service Targets</h3>
<g:render template="/organisation/serviceTargets" model="[services:organisation.services, periods:organisation.periods, showTargetDate:organisation.showTargetDate]"/>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!-- ko with:reportingTargetsAndFunding().funding -->
<div class="funding">

<label><b>Funding</b><fc:iconHelp title="Project Budget">${budgetHelpText?:"Enter the budget as reviewed each year"}</fc:iconHelp></label>
<label><b>Funding</b><fc:iconHelp title="Funding">${budgetHelpText?:"Enter the total value of contracts at the date of the review"}</fc:iconHelp></label>
<g:if test="${explanation}">
<p>${explanation}</p>
</g:if>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

load( "../../../utils/audit.js");

let adminUserId = '<system>'

function findRcsReportConfig(reports) {
for (let i=0; i<reports.length; i++) {
if (reports[i].activityType == 'Regional Capacity Services Report') {
return reports[i];
}
}
return null;
}
db.organisation.find({'config.organisationReports':{$exists:true}}).forEach(function(org){
let rcsReportConfig = findRcsReportConfig(org.config.organisationReports);
if (!rcsReportConfig) {
return;
}
rcsReportConfig.description = "Changes are being made to the Regional Capacity Services Reporting template so editing has been temporarily disabled for the Q2 report. Providers will be notified once the report is ready to be accessed again";

//org.config.serviceTargets = serviceTargetsConfig;
print("updating organisation "+org.name+' , id: '+org.organisationId);
db.organisation.replaceOne({organisationId:org.organisationId}, org);
audit(org, org.organisationId, 'au.org.ala.ecodata.Organisation', adminUserId, undefined, 'Update');
});

db.report.updateMany({activityType:'Regional Capacity Services Report', toDate:ISODate('2024-12-31T13:00:00Z')}, {$set:{status:'readonly'}});

0 comments on commit cfaa2c2

Please sign in to comment.