Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added functionality to distinguish between different leaderboards [closes #4047] #4318

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 39 additions & 19 deletions frontend/src/js/controllers/challengeCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -933,28 +933,48 @@
parameters.method = 'GET';
parameters.data = {};
parameters.callback = {
onSuccess: function(response) {
var details = response.data;
vm.phaseSplits = details;
if (details.length == 0) {
vm.isChallengeLeaderboardPrivate = true;
onSuccess: function(response) {
var details = response.data;
var groupedPhases = {};

// Grouping phases by challenge_phase_name
details.forEach(function(phase) {
if (!groupedPhases[phase.challenge_phase_name]) {
groupedPhases[phase.challenge_phase_name] = [];
}
for(var i=0; i<details.length; i++) {
if (details[i].visibility !== challengePhaseVisibility.public) {
vm.phaseSplits[i].showPrivate = true;
vm.showPrivateIds.push(vm.phaseSplits[i].id);
}
vm.isMultiMetricLeaderboardEnabled[vm.phaseSplits[i].id] = vm.phaseSplits[i].is_multi_metric_leaderboard;
vm.phaseSplitLeaderboardSchema[vm.phaseSplits[i].id] = vm.phaseSplits[i].leaderboard_schema;
groupedPhases[phase.challenge_phase_name].push(phase);
});

vm.phaseSplits = groupedPhases;

if (Object.keys(vm.phaseSplits).length === 0) {
vm.isChallengeLeaderboardPrivate = true;
}

for (var phaseName in vm.phaseSplits) {
if (vm.phaseSplits.hasOwnProperty(phaseName)) {
var phaseData = vm.phaseSplits[phaseName];

phaseData.forEach(function(phase) {
if (phase.visibility !== challengePhaseVisibility.public) {
phase.showPrivate = true;
vm.showPrivateIds.push(phase.id);
}

vm.isMultiMetricLeaderboardEnabled[phase.id] = phase.is_multi_metric_leaderboard;
vm.phaseSplitLeaderboardSchema[phase.id] = phase.leaderboard_schema;
});
}
utilities.hideLoader();
},
onError: function(response) {
var error = response.data;
utilities.storeData('emailError', error.detail);
$state.go('web.permission-denied');
utilities.hideLoader();
}

utilities.hideLoader();
},
onError: function(response) {
var error = response.data;
utilities.storeData('emailError', error.detail);
$state.go('web.permission-denied');
utilities.hideLoader();
}
};

utilities.sendRequest(parameters);
Expand Down
19 changes: 11 additions & 8 deletions frontend/src/views/web/challenge/leaderboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,24 @@ <h5 class="w-300">Leaderboard</h5>
class="fa fa-refresh text-highlight"></i></span>
</div>
</div>

<div class="row">
<div class="col xs12 s6">
<span>
<md-select ng-model="challenge.phaseName" placeholder="Select Phase" class="rm-margin">
<md-option ui-sref="web.challenge-main.challenge-page.phase-leaderboard({phaseSplitId:key.id})"
value="{{key.id}}" ng-repeat="key in challenge.phaseSplits" ng-show="{{key.visibility}}">
<span class="fs-16 w-300">Phase:
</span>{{key.challenge_phase_name}}, <span class="fs-16 w-300">Split: </span>
{{key.dataset_split_name}} &nbsp; <span class="new badge orange-background"
data-badge-caption="Private" ng-if="key.showPrivate"></span></md-option>
<md-optgroup ng-repeat="(phaseName, phaseGroup) in challenge.phaseSplits" label="{{ phaseName }}">
<md-option ui-sref="web.challenge-main.challenge-page.phase-leaderboard({phaseSplitId:split.id})"
ng-value="split.id" ng-show="split.visibility" ng-repeat="split in phaseGroup">
<span class="fs-16 w-300"> {{ split.challenge_phase_name }}, {{ split.dataset_split_name }}</span>
<span class="new badge orange-background" data-badge-caption="Private" ng-if="split.showPrivate"></span>
</md-option>
</md-optgroup>
<md-option value="leaderboard is private" ng-if="challenge.isChallengeLeaderboardPrivate">Leaderboard is private</md-option>
</md-select>
</span>
</div>
</div>
</div>
</div>

<div class="row" ng-if="challenge.isMultiMetricLeaderboardEnabled[challenge.phaseSplitId]">
<div class="col xs12 s6">
<span>
Expand Down
45 changes: 29 additions & 16 deletions frontend/tests/controllers-test/challengeCtrl.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -546,32 +546,45 @@ describe('Unit tests for challenge controller', function () {
selectExistTeamSuccess = null;
challengePhaseSuccess = null;
challengePhaseSplitSuccess = true;

challengePhaseSplit = true;
// get challenge phase split details response
successResponse = [
{
visibility: 2,
host: 1
}
];

var successResponse = {
phaseGroupName1: [
{
visibility: 2,
host: 1
},
],
};

var challengePhaseVisibility = {
owner_and_host: 1,
host: 2,
public: 3,
};

spyOn(utilities, 'hideLoader');
vm.isParticipated = true;

// Create the controller
vm = createController();
expect(vm.phaseSplits).toEqual(successResponse);
for(var i = 0; i < successResponse.length; i++) {
if (successResponse[i].visibility != challengePhaseVisibility.public) {
expect(vm.phaseSplits[i].showPrivate).toBeTruthy();
vm.onSuccess({ data: successResponse });

// Iterate over phase groups and splits to check visibility and private flags
for (var phaseName in vm.phaseSplits) {
if (vm.phaseSplits.hasOwnProperty(phaseName)) {
var phaseData = vm.phaseSplits[phaseName];

phaseData.forEach(function(phase) {
if (phase.visibility !== challengePhaseVisibility.public) {
expect(phase.showPrivate).toBeTruthy();
}
});
}
}

expect(utilities.hideLoader).toHaveBeenCalled();
});



it('backend error of particular challenge phase split `challenges/<challenge_id>/challenge_phase_split`', function () {
challengeSuccess = null;
participantTeamChallengeSuccess = null;
Expand Down Expand Up @@ -2714,4 +2727,4 @@ describe('Unit tests for challenge controller', function () {
expect($mdDialogOpened).toBe(true);
});
});
});
});