Skip to content

Commit

Permalink
commit progress organisation metrics, branch off from master #3146
Browse files Browse the repository at this point in the history
  • Loading branch information
salomon-j committed Jun 25, 2024
1 parent 0b777aa commit f17daaa
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,36 @@ class OrganisationController {
values
}

def organisationMetrics(String id) {

def organisation = Organisation.findByOrganisationId(id)

boolean approvedOnly = true

List scoreIds
Map aggregationConfig = null

Map paramData = request.JSON
if (!paramData) {
approvedOnly = params.getBoolean('approvedOnly')
scoreIds = params.getList('scoreIds')
}
else {

if (paramData.approvedOnly != null) {
approvedOnly = paramData.approvedOnly
}

scoreIds = paramData.scoreIds
aggregationConfig = paramData.aggregationConfig
}

if (organisation) {
render organisationService.organisationMetrics(id, approvedOnly, scoreIds, aggregationConfig) as JSON

} else {
render (status: 404, text: 'No such id')
}
}

}
3 changes: 3 additions & 0 deletions grails-app/domain/au/org/ala/ecodata/Activity.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Activity {
bulkImportId index: true
version false
externalIds index:true
organisationId index:true
}

static hasMany = [externalIds:ExternalId]
Expand All @@ -58,6 +59,7 @@ class Activity {
Date startDate
Date endDate
List<ExternalId> externalIds
String organisationId

/** The type of activity performed. This field must match the name of an ActivityForm */
String type
Expand Down Expand Up @@ -132,6 +134,7 @@ class Activity {
verificationStatus nullable: true, inList: ['not applicable', 'not approved', 'not verified', 'under review' , 'approved']
bulkImportId nullable: true
externalIds nullable: true
organisationId nullable: true
}

static Activity findByExternalId(String externalId) {
Expand Down
11 changes: 11 additions & 0 deletions grails-app/services/au/org/ala/ecodata/ActivityService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -645,4 +645,15 @@ class ActivityService {
}
}

List findAllForOrganisationId(id, levelOfDetail = [], includeDeleted = false) {
List activities
if (includeDeleted) {
activities = Activity.findAllByOrganisationId(id).collect {toMap(it, levelOfDetail)}
}
else {
activities = Activity.findAllByOrganisationIdAndStatus(id, ACTIVE).collect { toMap(it, levelOfDetail) }
}
activities
}

}
23 changes: 23 additions & 0 deletions grails-app/services/au/org/ala/ecodata/OrganisationService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ class OrganisationService {
public static final String PROJECTS = 'projects'

static transactional = 'mongo'
static final FLAT = 'flat'

def commonService, projectService, userService, permissionService, documentService, collectoryService, messageSource, emailService, grailsApplication
ReportingService reportingService
ActivityService activityService
ReportService reportService

def get(String id, levelOfDetail = [], includeDeleted = false) {
Organisation organisation
Expand Down Expand Up @@ -217,4 +219,25 @@ class OrganisationService {
organisationDetails
}

/**
* Returns the reportable metrics for a organisation as determined by the organisation output targets and activities
* that have been undertaken.
* @param id identifies the organisation.
* @return a Map containing the aggregated results.
*
*/
def organisationMetrics(String id, approvedOnly = false, List scoreIds = null, Map aggregationConfig = null) {
def org = Organisation.findByOrganisationId(id)
if (org) {
List toAggregate = Score.findAllByScoreIdInList(scoreIds)
List outputSummary = reportService.organisationSummary(id, toAggregate, approvedOnly, aggregationConfig) ?: []

return outputSummary
} else {
def error = "Error retrieving metrics for project - no such id ${id}"
log.error error
return [status: 'error', error: error]
}
}

}
16 changes: 16 additions & 0 deletions grails-app/services/au/org/ala/ecodata/ReportService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -526,4 +526,20 @@ class ReportService {
}
return message
}

/**
* Returns aggregated scores for a specified project.
* @param organisationId the organisation of interest.
* @param aggregationSpec defines the scores to be aggregated and if any grouping needs to occur.
* [{score:{name: , units:, aggregationType}, groupBy: {entity: <one of 'activity', 'output', 'organisation', 'site>, property: String <the entity property to group by>}, ...]
*
* @return the results of the aggregation. The results will be a List of Maps, the structure of each Map is
* described in @see au.org.ala.ecodata.reporting.Aggregation.results()
*
*/
List organisationSummary(String organisationId, List aggregationSpec, boolean approvedActivitiesOnly = false, Map topLevelAggregationConfig = null) {

List activities = activityService.findAllForOrganisationId(organisationId, 'FLAT')
aggregate(activities, aggregationSpec, approvedActivitiesOnly, topLevelAggregationConfig)
}
}

0 comments on commit f17daaa

Please sign in to comment.