Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b7b83d9

Browse files
author
vikasrohit
committedOct 30, 2015
SUP-2386, Code and first to finish show ratings not wins
-- Fixed #wins on profile page as well. Need to refactor the code so that it uses the same processing of track ranks from UserStatsService
1 parent 279df4f commit b7b83d9

File tree

3 files changed

+26
-56
lines changed

3 files changed

+26
-56
lines changed
 

‎app/my-dashboard/subtrack-stats/subtrack-stats.controller.js

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
angular.module('tc.myDashboard').controller('SubtrackStatsController', SubtrackStatsController);
55

6-
SubtrackStatsController.$inject = ['$filter', 'ProfileService', 'userIdentity'];
6+
SubtrackStatsController.$inject = ['$filter', 'ProfileService', 'UserStatsService', 'userIdentity'];
77

8-
function SubtrackStatsController($filter, ProfileService, userIdentity) {
8+
function SubtrackStatsController($filter, ProfileService, UserStatsService, userIdentity) {
99
var vm = this;
1010
vm.loading = true;
1111

@@ -17,9 +17,9 @@
1717
ProfileService.getUserStats(vm.handle)
1818
.then(function(stats) {
1919
var trackRanks = ProfileService.getRanks(stats);
20-
var subtrackRanks = compileSubtracks(trackRanks);
20+
var subtrackRanks = UserStatsService.compileSubtracks(trackRanks);
2121

22-
processStats(subtrackRanks);
22+
UserStatsService.processStats(subtrackRanks);
2323
// sort subtrack ranks
2424
subtrackRanks = $filter('orderBy')(subtrackRanks, 'mostRecentEventDate', true);
2525

@@ -33,45 +33,5 @@
3333
vm.loading = false;
3434
});
3535
}
36-
37-
function compileSubtracks(trackRanks) {
38-
return _.reduce(trackRanks, function(result, subtracks, track) {
39-
if (Array.isArray(subtracks) && subtracks.length) {
40-
if (track === 'DEVELOP') {
41-
_.remove(subtracks, function(subtrackObj) {
42-
return subtrackObj.subTrack === 'COPILOT_POSTING';
43-
});
44-
}
45-
46-
return result.concat(subtracks);
47-
48-
} else {
49-
return result;
50-
}
51-
}, []);
52-
}
53-
54-
function processStats(ranks) {
55-
angular.forEach(ranks, function(rank) {
56-
if (rank.track === 'DESIGN') {
57-
rank.stat = rank.wins;
58-
rank.statType = 'Wins';
59-
} else if (rank.track === 'COPILOT') {
60-
rank.stat = rank.activeContests;
61-
rank.statType = 'Challenges';
62-
} else if (rank.track === 'DEVELOP') {
63-
if (['CODE', 'FIRST_2_FINISH'].indexOf(rank.subTrack) != -1) {
64-
rank.stat = rank.wins;
65-
rank.statType = 'Wins';
66-
} else {
67-
rank.stat = rank.rating;
68-
rank.statType = 'Rating';
69-
}
70-
} else {
71-
rank.stat = rank.rating;
72-
rank.statType = 'Rating';
73-
}
74-
});
75-
}
7636
}
7737
})();

‎app/profile/about/about.jade

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777

7878
.tag Ranking
7979

80-
.ranking(ng-if="subtrack.wins && !subtrack.rank && !subtrack.rating")
80+
.ranking(ng-if="subtrack.wins !== null && subtrack.rank === null && !subtrack.rating")
8181
.number(style="color: #21B2F1") {{subtrack.wins}}
8282

8383
.tag Wins

‎app/services/userStats.service.js

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
function UserStatsService($filter) {
1313

1414
var service = {
15-
getIterableStats: getIterableStats
15+
getIterableStats: getIterableStats,
16+
processStats: processStats,
17+
compileSubtracks: compileSubtracks
1618
};
1719

1820
var percentageFunc = function(n) { return $filter('percentage')(n);};
@@ -109,17 +111,25 @@
109111
}, []);
110112
}
111113

112-
function processStats(subtrackRanks) {
113-
angular.forEach(subtrackRanks, function(subtrack) {
114-
if (subtrack.track === 'DESIGN') {
115-
subtrack.stat = subtrack.wins;
116-
subtrack.statType = 'Wins';
117-
} else if (subtrack.track === 'COPILOT') {
118-
subtrack.stat = subtrack.activeContests;
119-
subtrack.statType = 'Challenges';
114+
function processStats(ranks) {
115+
angular.forEach(ranks, function(rank) {
116+
if (rank.track === 'DESIGN') {
117+
rank.stat = rank.wins;
118+
rank.statType = 'Wins';
119+
} else if (rank.track === 'COPILOT') {
120+
rank.stat = rank.activeContests;
121+
rank.statType = 'Challenges';
122+
} else if (rank.track === 'DEVELOP') {
123+
if (['CODE', 'FIRST_2_FINISH'].indexOf(rank.subTrack) != -1) {
124+
rank.stat = rank.wins;
125+
rank.statType = 'Wins';
126+
} else {
127+
rank.stat = rank.rating;
128+
rank.statType = 'Rating';
129+
}
120130
} else {
121-
subtrack.stat = subtrack.rating;
122-
subtrack.statType = 'Rating';
131+
rank.stat = rank.rating;
132+
rank.statType = 'Rating';
123133
}
124134
});
125135
}

0 commit comments

Comments
 (0)
This repository has been archived.