Skip to content

Commit

Permalink
Merge branch 'release/5.3.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
sbearcsiro committed Apr 20, 2020
2 parents 5d6a58b + ce69567 commit 79c22de
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 39 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ plugins {
// id "com.moowork.node" version "1.1.1"
}

version "5.3.7"
version "5.3.8"
group "au.org.ala"
description "Digivol application"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class IndexController {
[:]
}

def stats(long institutionId, long projectId, String projectType, String tags) {
def stats(long institutionId, long projectId, String projectType) {
List<String> tags = params.list('tags') ?: []
def maxContributors = (params.maxContributors as Integer) ?: 5
def disableStats = params.getBoolean('disableStats', false)
def disableHonourBoard = params.getBoolean('disableHonourBoard', false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,12 +355,12 @@ class ProjectController {

ProjectType pt = landingPage.getProjectType()
def labels = landingPage.label
def tag = null
def tags = null
if (labels && labels.size() > 0) {
tag = labels*.value
tags = labels*.value
}

def projectSummaryList = projectService.getProjectSummaryList(statusFilterMode, activeFilterMode, q, sort, offset, max, order, pt, tag, false)
def projectSummaryList = projectService.getProjectSummaryList(statusFilterMode, activeFilterMode, q, sort, offset, max, order, pt, tags, false)

def numberOfUncompletedProjects = projectSummaryList.numberOfIncompleteProjects < numbers.size() ? numbers[projectSummaryList.numberOfIncompleteProjects] : "" + projectSummaryList.numberOfIncompleteProjects;

Expand All @@ -369,7 +369,7 @@ class ProjectController {
def model = [
landingPageInstance: landingPage,
projectType: pt.name,
tags: tag,
tags: tags,
projects: projectSummaryList.projectRenderList,
filteredProjectsCount: projectSummaryList.matchingProjectCount,
numberOfUncompletedProjects: numberOfUncompletedProjects,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,22 +171,25 @@ class LeaderBoardService {
scoreMap[kvp.key] += kvp.value
}

scoreMap = scoreMap.sort { it.value }
if (scoreMap.size() > count) {
scoreMap = scoreMap.take(count)
}

// Flatten the map into a list for easy sorting, so we can slice off the top N
def list = []
def userDetails = userService.detailsForUserIds(scoreMap.keySet() as List<String>).collectEntries { [(it.userId): it] }
scoreMap.each { kvp ->
def user = User.findByUserId(kvp.key)
def details = userService.detailsForUserId(kvp.key)
def details = userDetails[kvp.key]
if (user) {
list << [name: details?.displayName, email: details?.email, score: kvp?.value ?: 0, userId: user?.id]
} else {
println "Failed to find user with key: ${kvp.key}"
}
}

// Sort in descending order...
list?.sort { a, b -> b.score <=> a.score }
// and just return the top N items
return list.subList(0, Math.min(list.size(), count))
return list
}

Map getUserMapForPeriod(Date startDate, Date endDate, ActivityType activityType, Institution institution, List<String> ineligibleUserIds, def projectsInLabels = null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,31 @@ class VolunteerStatsService {

LinkGenerator grailsLinkGenerator

@Cacheable(value = 'MainVolunteerContribution', key = "(#institutionId?.toString()?:'-1') + (#projectId?.toString()?:'-1') + (#projectType?:'') + (#tags?:'[]') + (#disableStats.toString()) + (#disableHonourBoard.toString())")
def generateStats(long institutionId, long projectId, String projectType, String tags, int maxContributors, boolean disableStats, boolean disableHonourBoard) {
@Cacheable(value = 'MainVolunteerContribution', key = "(#institutionId?.toString()?:'-1') + (#projectId?.toString()?:'-1') + (#projectTypeName?:'') + (#tags?.toString()?:'[]') + (#maxContributors.toString()) + (#disableStats.toString()) + (#disableHonourBoard.toString())")
def generateStats(long institutionId, long projectId, String projectTypeName, List<String> tags, int maxContributors, boolean disableStats, boolean disableHonourBoard) {
Institution institution = (institutionId == -1l) ? null : Institution.get(institutionId)
Project projectInstance = (projectId == -1l) ? null : Project.get(projectId)

List<Project> projectsInLabels = null
if (tags && tags != '[]') {
List<String> tagList = tags.tokenize(',[]')*.trim()
def labels = tags ? Label.findAllByValueInList(tagList) : null
if (labels && labels.size() > 0) {
//projectsInLabels = labels*.projects?.id[0]
projectsInLabels = labels*.projects[0].grep { project ->
if (projectType) {
project.projectType?.name == projectType
} else {
return true
List<Long> projectsInLabels = null
if (tags || projectTypeName) {
projectsInLabels = Project.withCriteria {
if (tags) {
labels {
'in'('value', tags)
}
}.id
}
if (projectTypeName) {
projectType {
eq('name', projectTypeName)
}
}
projections {
property('id')
}
}
} else if (projectType) {
ProjectType pt = projectType ? ProjectType.findByName(projectType) : null
projectsInLabels = Project.findAllByProjectType(pt)?.id

}

log.debug("Generating stats for inst id $institutionId, proj id: $projectId, maxContrib: $maxContributors, disableStats: $disableStats, disableHB: $disableHonourBoard, projectType: $projectType, projectsInLabels: $projectsInLabels")
log.debug("Generating stats for inst id $institutionId, proj id: $projectId, maxContrib: $maxContributors, disableStats: $disableStats, disableHB: $disableHonourBoard, projectType: $projectTypeName, projectsInLabels: $projectsInLabels")

def sw = Stopwatch.createStarted()

Expand Down Expand Up @@ -106,17 +105,17 @@ class VolunteerStatsService {

}

def generateContributors(Institution institution, Project projectInstance, def pt = null, maxContributors) {
def generateContributors(Institution institution, Project projectInstance, List<Long> projectIds, Integer maxContributors) {

def latestTranscribers = LatestTranscribers.withCriteria {
if (institution) {
project {
eq('institution', institution)
ne('inactive', true)
}
} else if (pt) {
} else if (projectIds) {
project {
'in' 'id', pt
'in' 'id', projectIds
ne('inactive', true)
}
} else if (projectInstance) {
Expand All @@ -135,10 +134,10 @@ class VolunteerStatsService {
if (institution) {
latestMessages = ForumMessage.findAll('FROM ForumMessage fm WHERE fm.topic.project.institution = :institution ORDER BY date desc', [institution: institution], [max: maxContributors])
latestMessages += ForumMessage.findAll('FROM ForumMessage fm WHERE fm.topic.task.project.institution = :institution ORDER BY date desc', [institution: institution], [max: maxContributors])
} else if (pt) {
} else if (projectIds) {
// latestMessages = ForumMessage.findAll('FROM ForumMessage fm WHERE fm.topic.project.projectType = :pt ORDER BY date desc', [pt: pt], [max: maxContributors])
// latestMessages += ForumMessage.findAll('FROM ForumMessage fm WHERE fm.topic.task.project.projectType = :pt ORDER BY date desc', [pt: pt], [max: maxContributors])
def projects = Project.findAllByIdInList(pt)
def projects = Project.findAllByIdInList(projectIds)
/*Project.createCriteria().list {
and {
if (pt) {
Expand Down Expand Up @@ -199,10 +198,11 @@ class VolunteerStatsService {
}
}

def userDetails = userService.detailsForUserIds(latestMessages*.user*.userId).collectEntries { [(it.userId): it] }
def messages = latestMessages.collect {
def topic = it.topic
def topicId = topic.id
def details = userService.detailsForUserId(it.user.userId)
def details = userDetails[it.user.userId]
def timestamp = it.date.time / 1000
def topicUrl = grailsLinkGenerator.link(controller: 'forum', action: 'viewForumTopic', id: topic.id)

Expand Down Expand Up @@ -230,10 +230,11 @@ class VolunteerStatsService {
thumbnailUrl: thumbnail, timestamp: timestamp]
}

userDetails = userService.detailsForUserIds(latestTranscribers*.fullyTranscribedBy).collectEntries { [(it.userId): it] }
def transcribers = latestTranscribers.collect {
def proj = it.project
def userId = it.fullyTranscribedBy
def details = userService.detailsForUserId(userId)
def details = userDetails[userId]

def tasks = LatestTranscribersTask.withCriteria() {
eq('project', proj)
Expand Down
2 changes: 1 addition & 1 deletion grails-app/views/leaderBoard/_stats.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ taskSummaryUrl: "${createLink(controller: 'task', action: 'summary', id: -1)}",
institutionId: ${institutionId ?: -1},
projectId: ${projectId ?: -1},
projectType: "${projectType ?: ''}",
tags: "${tagName ?: []}",
tags: <cl:json value="${tagName}" />,
maxContributors: ${maxContributors ?: 5},
disableStats: ${disableStats ? 'true' : 'false' },
disableHonourBoard: ${disableHonourBoard ? 'true' : 'false' },
Expand Down
2 changes: 1 addition & 1 deletion grails-app/views/project/customLandingPage.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
</div>
<div class="col-sm-4">
%{--<g:set var="model" value="${[institutionName: 'Wildlife Spotter', projectType: projectType, tagName, tags]}" />--}%
<g:render template="/leaderBoard/stats" model="[institutionName: 'Wildlife Spotter', tagName: tags, projectType: projectType]" />
<g:render template="/leaderBoard/stats" model="[institutionName: landingPageInstance.title, tagName: tags, projectType: projectType]" />
</div>
</div>
</div>
Expand Down

0 comments on commit 79c22de

Please sign in to comment.