Skip to content

Commit

Permalink
#492 Split stats request into two separate asynchronous requests
Browse files Browse the repository at this point in the history
  • Loading branch information
cdausmus committed Nov 9, 2021
1 parent cd7da11 commit 98631d7
Show file tree
Hide file tree
Showing 6 changed files with 491 additions and 156 deletions.
120 changes: 69 additions & 51 deletions grails-app/assets/javascripts/digivol-stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,68 +4,86 @@
//=require_self

function digivolStats(config) {
var stats = angular.module('stats', ['digivol']);
var stats = angular.module('stats', ['digivol']);

stats.controller('StatsCtrl', [
'$scope', '$http', '$log',
function ($scope, $http, $log) {
$scope.loading = true;
stats.controller('StatsCtrl', [
'$scope', '$http', '$log',
function ($scope, $http, $log) {
$scope.lbLoading = true;
$scope.conLoading = true;

$scope.transcriberCount = null;
$scope.completedTasks = null;
$scope.totalTasks = null;
$scope.transcriberCount = null;
$scope.completedTasks = null;
$scope.totalTasks = null;

$scope.daily = { userId: -1, email: '', name: '', score: null };
$scope.weekly = { userId: -1, email: '', name: '', score: null };
$scope.monthly = { userId: -1, email: '', name: '', score: null };
$scope.alltime = { userId: -1, email: '', name: '', score: null };
$scope.daily = {userId: -1, email: '', name: '', score: null};
$scope.weekly = {userId: -1, email: '', name: '', score: null};
$scope.monthly = {userId: -1, email: '', name: '', score: null};
$scope.alltime = {userId: -1, email: '', name: '', score: null};

$scope.contributors = [];
$scope.contributors = [];

$scope.avatarUrl = function (user) {
var email = user.email || "";
return "//www.gravatar.com/avatar/" + email + "?s=40&d=mm"
};
$scope.avatarUrl = function (user) {
var email = user.email || "";
return "//www.gravatar.com/avatar/" + email + "?s=40&d=mm"
};

$scope.userProfileUrl = function(user) {
var id = user.userId || "";
return config.userProfileUrl.replace("-1", id);
};
$scope.userProfileUrl = function (user) {
var id = user.userId || "";
return config.userProfileUrl.replace("-1", id);
};

$scope.projectUrl = function(project) {
var id = project.projectId || "";
return config.projectUrl.replace('-1', id);
};
$scope.projectUrl = function (project) {
var id = project.projectId || "";
return config.projectUrl.replace('-1', id);
};

$scope.additionalTranscribedThumbs = function(contrib) {
return Math.max(contrib.transcribedItems - 5, 0);
};
$scope.additionalTranscribedThumbs = function (contrib) {
return Math.max(contrib.transcribedItems - 5, 0);
};


$scope.taskSummaryUrl = function(thumb) {
var id = thumb.id || "";
return config.taskSummaryUrl.replace('-1', id);
};
$scope.taskSummaryUrl = function (thumb) {
var id = thumb.id || "";
return config.taskSummaryUrl.replace('-1', id);
};

var p = $http.get(config.statsUrl, {
params: {
institutionId: config.institutionId,
projectId: config.projectId,
projectType: config.projectType,
tags: config.tags,
maxContributors: config.maxContributors,
disableStats: config.disableStats,
disableHonourBoard: config.disableHonourBoard
var p = $http.get(config.statsUrl, {
params: {
institutionId: config.institutionId,
projectId: config.projectId,
projectType: config.projectType,
tags: config.tags,
maxContributors: config.maxContributors,
disableStats: config.disableStats,
disableHonourBoard: config.disableHonourBoard
}
});
p.then(function (resp) {
angular.extend($scope, resp.data);
$scope.lbLoading = false;
},
function (resp) {
$log.error("Got error response for leaderboard", resp);
});

var c = $http.get(config.contributorsUrl, {
params: {
institutionId: config.institutionId,
projectId: config.projectId,
projectType: config.projectType,
tags: config.tags,
maxContributors: config.maxContributors
}
});
c.then(function (resp) {
angular.extend($scope, resp.data);
$scope.conLoading = false;
},
function (resp) {
$log.error("Got error response for contributors", resp);
});
}
});
p.then(function (resp) {
angular.extend($scope, resp.data);
$scope.loading = false;
},
function (resp) {
$log.error("Got error response for leaderboard", resp);
});
}
]);
]);
}

Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ class IndexController {
render result as JSON
}

def contributors(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)
def result = volunteerStatsService.generateContributors(institutionId, projectId, projectType, tags, maxContributors)
render result as JSON
}

/* private generateContributors(Institution institution, Project projectInstance, ProjectType pt, maxContributors) {
def latestTranscribers = LatestTranscribers.withCriteria {
Expand Down
Loading

0 comments on commit 98631d7

Please sign in to comment.