Commit cbf837a6 authored by nanahira's avatar nanahira

Merge branch 'sql-pt' into 'master'

use sql calc in post score

See merge request !1
parents 68a40801 a2185368
Pipeline #3080 passed with stages
in 6 minutes and 17 seconds
export class EloUtility { export class EloUtility {
static getSqlString(num: number) {
if (num === 0 || !num) {
return '';
} else if (num > 0) {
return `+ ${num}`;
} else {
return `- ${-num}`;
}
}
static getExpScore( static getExpScore(
expA: number, expA: number,
expB: number, expB: number,
scoreA: number, scoreA: number,
scoreB: number, scoreB: number,
) { ) {
let rExpA = expA, let rExpA = 0,
rExpB = expB; rExpB = 0;
if (scoreA === scoreB) { if (scoreA === scoreB) {
rExpA += 0.5; rExpA += 0.5;
rExpB += 0.5; rExpB += 0.5;
...@@ -22,7 +32,7 @@ export class EloUtility { ...@@ -22,7 +32,7 @@ export class EloUtility {
static getEloScore(rA: number, rB: number, sA: number, sB: number) { static getEloScore(rA: number, rB: number, sA: number, sB: number) {
//17.07.18 增加规则,平局不加分. //17.07.18 增加规则,平局不加分.
if (sA === sB) { if (sA === sB) {
return { ptA: rA, ptB: rB }; return { ptA: 0, ptB: 0 };
} }
const k = 24; const k = 24;
...@@ -52,7 +62,7 @@ export class EloUtility { ...@@ -52,7 +62,7 @@ export class EloUtility {
diffA = -15; diffA = -15;
} }
const rrA = rA + diffA; //const rrA = rA + diffA;
let diffB = k * (sB - eB); let diffB = k * (sB - eB);
...@@ -77,7 +87,7 @@ export class EloUtility { ...@@ -77,7 +87,7 @@ export class EloUtility {
diffB = -15; diffB = -15;
} }
const rrB = rB + diffB; //const rrB = rB + diffB;
//console.log(diffA, diffB); //console.log(diffA, diffB);
...@@ -91,6 +101,6 @@ export class EloUtility { ...@@ -91,6 +101,6 @@ export class EloUtility {
// rrB = rB - 8; // rrB = rB - 8;
// } // }
return { ptA: rrA, ptB: rrB }; return { ptA: diffA, ptB: diffB };
} }
} }
...@@ -643,17 +643,17 @@ export class AppService { ...@@ -643,17 +643,17 @@ export class AppService {
if (userscoreA === -5 || userscoreB === -5) { if (userscoreA === -5 || userscoreB === -5) {
pre_exit = true; pre_exit = true;
firstWin = false; firstWin = false;
ptResult.ptA = userA.pt; ptResult.ptA = 0;
ptResult.ptB = userB.pt; ptResult.ptB = 0;
if (userscoreA === -9) { if (userscoreA === -9) {
ptResult.ptA = userA.pt - 2; ptResult.ptA = -2;
this.log.compatLog( this.log.compatLog(
usernameA, usernameA,
'开局退房', '开局退房',
moment(start).format('YYYY-MM-DD HH:mm'), moment(start).format('YYYY-MM-DD HH:mm'),
); );
} else if (userscoreB === -9) { } else if (userscoreB === -9) {
ptResult.ptB = userB.pt - 2; ptResult.ptB = -2;
this.log.compatLog( this.log.compatLog(
usernameB, usernameB,
'开局退房', '开局退房',
...@@ -666,8 +666,8 @@ export class AppService { ...@@ -666,8 +666,8 @@ export class AppService {
//按加减8或16处理:高分赢低分 高分加8低分减8,低分赢高分,低分加16,高分减16. //按加减8或16处理:高分赢低分 高分加8低分减8,低分赢高分,低分加16,高分减16.
if (!pre_exit && userA.pt - userB.pt > 137) { if (!pre_exit && userA.pt - userB.pt > 137) {
if (winner === usernameA) { if (winner === usernameA) {
ptResult.ptA = userA.pt + 8; ptResult.ptA = +8;
ptResult.ptB = userB.pt - 8; ptResult.ptB = -8;
this.log.compatLog( this.log.compatLog(
userA.pt, userA.pt,
userB.pt, userB.pt,
...@@ -677,8 +677,8 @@ export class AppService { ...@@ -677,8 +677,8 @@ export class AppService {
} }
if (winner === usernameB) { if (winner === usernameB) {
ptResult.ptA = userA.pt - 15; ptResult.ptA = -15;
ptResult.ptB = userB.pt + 16; ptResult.ptB = +16;
this.log.compatLog( this.log.compatLog(
userA.pt, userA.pt,
userB.pt, userB.pt,
...@@ -690,8 +690,8 @@ export class AppService { ...@@ -690,8 +690,8 @@ export class AppService {
if (!pre_exit && userB.pt - userA.pt > 137) { if (!pre_exit && userB.pt - userA.pt > 137) {
if (winner === usernameA) { if (winner === usernameA) {
ptResult.ptA = userA.pt + 16; ptResult.ptA = +16;
ptResult.ptB = userB.pt - 15; ptResult.ptB = -15;
this.log.compatLog( this.log.compatLog(
userA.pt, userA.pt,
userB.pt, userB.pt,
...@@ -701,8 +701,8 @@ export class AppService { ...@@ -701,8 +701,8 @@ export class AppService {
} }
if (winner === usernameB) { if (winner === usernameB) {
ptResult.ptA = userA.pt - 8; ptResult.ptA = -8;
ptResult.ptB = userB.pt + 8; ptResult.ptB = +8;
this.log.compatLog( this.log.compatLog(
userA.pt, userA.pt,
userB.pt, userB.pt,
...@@ -716,7 +716,7 @@ export class AppService { ...@@ -716,7 +716,7 @@ export class AppService {
const isLess3Min = moment(start).add(1, 'm').isAfter(moment(end)); const isLess3Min = moment(start).add(1, 'm').isAfter(moment(end));
if (!pre_exit && isLess3Min) { if (!pre_exit && isLess3Min) {
if (winner === usernameA) { if (winner === usernameA) {
ptResult.ptA = userA.pt; ptResult.ptA = 0;
this.log.compatLog( this.log.compatLog(
usernameA, usernameA,
'当局有人存在早退,胜利不加分', '当局有人存在早退,胜利不加分',
...@@ -724,7 +724,7 @@ export class AppService { ...@@ -724,7 +724,7 @@ export class AppService {
); );
} }
if (winner === usernameB) { if (winner === usernameB) {
ptResult.ptB = userB.pt; ptResult.ptB = 0;
this.log.compatLog( this.log.compatLog(
usernameB, usernameB,
'当局有人存在早退,胜利不加分', '当局有人存在早退,胜利不加分',
...@@ -765,12 +765,12 @@ export class AppService { ...@@ -765,12 +765,12 @@ export class AppService {
battleHistory.usernameb = userB.username; battleHistory.usernameb = userB.username;
battleHistory.userscorea = userscoreA; battleHistory.userscorea = userscoreA;
battleHistory.userscoreb = userscoreB; battleHistory.userscoreb = userscoreB;
battleHistory.expa = expResult.expA; battleHistory.expa = expResult.expA + userA.exp;
battleHistory.expb = expResult.expB; battleHistory.expb = expResult.expB + userB.exp;
battleHistory.expa_ex = userA.exp; battleHistory.expa_ex = userA.exp;
battleHistory.expb_ex = userB.exp; battleHistory.expb_ex = userB.exp;
battleHistory.pta = ptResult.ptA; battleHistory.pta = ptResult.ptA + userA.pt;
battleHistory.ptb = ptResult.ptB; battleHistory.ptb = ptResult.ptB + userB.pt;
battleHistory.pta_ex = userA.pt; battleHistory.pta_ex = userA.pt;
battleHistory.ptb_ex = userB.pt; battleHistory.ptb_ex = userB.pt;
battleHistory.type = arena; battleHistory.type = arena;
...@@ -818,8 +818,8 @@ export class AppService { ...@@ -818,8 +818,8 @@ export class AppService {
.createQueryBuilder() .createQueryBuilder()
.update(UserInfo) .update(UserInfo)
.set({ .set({
exp: expResult.expA, exp: () => `exp ${EloUtility.getSqlString(expResult.expA)}`,
pt: ptResult.ptA, pt: () => `pt ${EloUtility.getSqlString(ptResult.ptA)}`,
athletic_win: () => `athletic_win + ${paramA.athletic_win}`, athletic_win: () => `athletic_win + ${paramA.athletic_win}`,
athletic_lose: () => `athletic_lose + ${paramA.athletic_lose}`, athletic_lose: () => `athletic_lose + ${paramA.athletic_lose}`,
athletic_draw: () => `athletic_draw + ${paramA.athletic_draw}`, athletic_draw: () => `athletic_draw + ${paramA.athletic_draw}`,
...@@ -831,8 +831,8 @@ export class AppService { ...@@ -831,8 +831,8 @@ export class AppService {
.createQueryBuilder() .createQueryBuilder()
.update(UserInfo) .update(UserInfo)
.set({ .set({
exp: expResult.expB, exp: () => `exp ${EloUtility.getSqlString(expResult.expB)}`,
pt: ptResult.ptB, pt: () => `pt ${EloUtility.getSqlString(ptResult.ptB)}`,
athletic_win: () => `athletic_win + ${paramB.athletic_win}`, athletic_win: () => `athletic_win + ${paramB.athletic_win}`,
athletic_lose: () => `athletic_lose + ${paramB.athletic_lose}`, athletic_lose: () => `athletic_lose + ${paramB.athletic_lose}`,
athletic_draw: () => `athletic_draw + ${paramB.athletic_draw}`, athletic_draw: () => `athletic_draw + ${paramB.athletic_draw}`,
...@@ -874,8 +874,8 @@ export class AppService { ...@@ -874,8 +874,8 @@ export class AppService {
battleHistory.usernameb = userB.username; battleHistory.usernameb = userB.username;
battleHistory.userscorea = userscoreA; battleHistory.userscorea = userscoreA;
battleHistory.userscoreb = userscoreB; battleHistory.userscoreb = userscoreB;
battleHistory.expa = expResult.expA; battleHistory.expa = expResult.expA + userA.exp;
battleHistory.expb = expResult.expB; battleHistory.expb = expResult.expB + userB.exp;
battleHistory.expa_ex = userA.exp; battleHistory.expa_ex = userA.exp;
battleHistory.expb_ex = userB.exp; battleHistory.expb_ex = userB.exp;
battleHistory.pta = userA.pt; battleHistory.pta = userA.pt;
...@@ -898,7 +898,7 @@ export class AppService { ...@@ -898,7 +898,7 @@ export class AppService {
.createQueryBuilder() .createQueryBuilder()
.update(UserInfo) .update(UserInfo)
.set({ .set({
exp: expResult.expA, exp: () => `exp ${EloUtility.getSqlString(expResult.expA)}`,
entertain_win: () => `entertain_win + ${paramA.entertain_win}`, entertain_win: () => `entertain_win + ${paramA.entertain_win}`,
entertain_lose: () => entertain_lose: () =>
`entertain_lose + ${paramA.entertain_lose}`, `entertain_lose + ${paramA.entertain_lose}`,
...@@ -912,7 +912,7 @@ export class AppService { ...@@ -912,7 +912,7 @@ export class AppService {
.createQueryBuilder() .createQueryBuilder()
.update(UserInfo) .update(UserInfo)
.set({ .set({
exp: expResult.expB, exp: () => `exp ${EloUtility.getSqlString(expResult.expB)}`,
entertain_win: () => `entertain_win + ${paramB.entertain_win}`, entertain_win: () => `entertain_win + ${paramB.entertain_win}`,
entertain_lose: () => entertain_lose: () =>
`entertain_lose + ${paramB.entertain_lose}`, `entertain_lose + ${paramB.entertain_lose}`,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment