|
@@ -15,6 +15,71 @@ class EliminateService extends CrudService {
|
|
|
this.userModel = this.ctx.model.Race.User;
|
|
|
this.teamApplyModel = this.ctx.model.Race.TeamApply;
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 查询淘汰赛的排名
|
|
|
+ * @param {Object} query 查询参数
|
|
|
+ */
|
|
|
+ async ranking({ match_id, group_id, project_id }) {
|
|
|
+ let raceList = await this.model.find({ match_id, group_id, project_id });
|
|
|
+ if (raceList.length <= 0) return [];
|
|
|
+ raceList = JSON.parse(JSON.stringify(raceList));
|
|
|
+ const rarr = [];
|
|
|
+ for (const i of raceList) {
|
|
|
+ const d = await this.getPlayerName(i);
|
|
|
+ rarr.push(d);
|
|
|
+ }
|
|
|
+ const { edges, nodes } = await this.graphData({ match_id, group_id, project_id });
|
|
|
+ const topEdges = this.getTopNodes(edges);
|
|
|
+ const topNodes = nodes.filter(f => topEdges.find(ff => ff.target === f.id));
|
|
|
+ // 然后将顶点的节点排序,根据标记进行排序
|
|
|
+ // 第一名一定是 w, 胜者组: w开头,l越多,越优先; 败者组: l越少,越优先
|
|
|
+ let winGroup = topNodes.filter(f => f.mark.includes('w'));
|
|
|
+ winGroup = winGroup.map(i => {
|
|
|
+ const markArr = i.mark.split('');
|
|
|
+ i.sort = markArr.length;
|
|
|
+ return i;
|
|
|
+ });
|
|
|
+ winGroup = _.orderBy(winGroup, [ 'sort' ], [ 'asc' ]);
|
|
|
+ let loseGroup = topNodes.filter(f => !f.mark.includes('w'));
|
|
|
+ loseGroup = loseGroup.map(i => {
|
|
|
+ const markArr = i.mark.split('');
|
|
|
+ i.sort = markArr.length;
|
|
|
+ return i;
|
|
|
+ });
|
|
|
+ loseGroup = _.orderBy(loseGroup, [ 'sort' ], [ 'asc' ]);
|
|
|
+ const orderNodes = [ ...winGroup, ...loseGroup ];
|
|
|
+ const arr = [];
|
|
|
+ let num = 1;
|
|
|
+ for (const n of orderNodes) {
|
|
|
+ const { id } = n;
|
|
|
+ const es = topEdges.filter(f => f.target === id);
|
|
|
+ const s1 = _.head(es);
|
|
|
+ const s2 = _.last(es);
|
|
|
+ const r = rarr.find(f => (f.player_one_node === s1.source && f.player_two_node === s2.source) || (f.player_one_node === s2.source && f.player_two_node === s1.source));
|
|
|
+ if (!r) continue;
|
|
|
+ const { player_one_score, player_two_score, player_one_name, player_two_name } = r;
|
|
|
+ let win,
|
|
|
+ lose;
|
|
|
+ if (player_one_score > player_two_score) {
|
|
|
+ win = player_one_name;
|
|
|
+ lose = player_two_name;
|
|
|
+ } else {
|
|
|
+ win = player_two_name;
|
|
|
+ lose = player_one_name;
|
|
|
+ }
|
|
|
+ arr.push({ name: win, num });
|
|
|
+ num++;
|
|
|
+ arr.push({ name: lose, num });
|
|
|
+ num++;
|
|
|
+ }
|
|
|
+ return arr;
|
|
|
+ }
|
|
|
+
|
|
|
+ getTopNodes(edges) {
|
|
|
+ const list = edges.filter(f => !edges.find(ff => ff.source === f.target));
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取流程图数据
|
|
|
* @param {Object} param 比赛项目的参数
|