Skip to content

Commit fcee135

Browse files
author
Predrag Stojadinovic
committed
gitterjs autocommit 2022-04-10 20:59:14
1 parent 21f4b33 commit fcee135

File tree

5 files changed

+25
-52
lines changed

5 files changed

+25
-52
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"clean": "tslint --config tslint-imports.json --fix --project .",
1616
"format": "prettier --write \"src/**/*.ts\"",
1717
"docs": "typedoc --readme none --out docs src",
18-
"test": "nyc mocha -r ts-node/register test/**/*.spec.ts",
18+
"test": "nyc mocha -r ts-node/register/transpile-only test/**/*.spec.ts",
1919
"coveralls": "cat ./coverage/lcov.info | node node_modules/.bin/coveralls",
2020
"sonar": "sonarjs -e .sonarlint/**,node_modules/**,coverage/**,.nyc_output/**",
2121
"up": "yarn upgrade-interactive",
@@ -35,7 +35,7 @@
3535
".ts"
3636
],
3737
"require": [
38-
"ts-node/register"
38+
"ts-node/register/transpile-only"
3939
],
4040
"reporter": [
4141
"text-summary",

src/prefRating.ts

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
#!/usr/bin/env node
21
'use strict';
32

43
import * as math from 'mathjs';
54

65
import PrefRatingPlayer from './prefRatingPlayer';
7-
import {TPrefRatingObject, TPrefRatingPlayerInput, PrefRatingPlayerObject} from "./prefRating.types";
6+
import {TPrefRatingObject, TPrefRatingPlayerInput, PrefRatingPlayerObject} from './prefRating.types';
87

9-
type _TPrefRatingCalc = { a12: number, a13: number, a23: number }
10-
type _TPrefRatingChanges = { c1: number, c2: number, c3: number }
8+
type _TPrefRatingCalc = {a12: number; a13: number; a23: number};
9+
type _TPrefRatingChanges = {c1: number; c2: number; c3: number};
1110

1211
/**
1312
* @constant
@@ -16,52 +15,28 @@ type _TPrefRatingChanges = { c1: number, c2: number, c3: number }
1615
*/
1716
const MAGIC = 2.8;
1817

19-
const _calcD = (p1: PrefRatingPlayer, p2: PrefRatingPlayer, bula: number): number =>
20-
Number(math.round(
21-
math
22-
.chain(p1.score)
23-
.subtract(p2.score)
24-
.divide(bula)
25-
.done(),
26-
3,
27-
));
18+
const _calcD = (p1: PrefRatingPlayer, p2: PrefRatingPlayer, bula: number): number => Number(math.round(math.chain(p1.score).subtract(p2.score).divide(bula).done(), 3));
2819
const _calculateDs = (p1: PrefRatingPlayer, p2: PrefRatingPlayer, p3: PrefRatingPlayer, bula: number): _TPrefRatingCalc => ({
2920
a12: _calcD(p1, p2, bula),
3021
a13: _calcD(p1, p3, bula),
31-
a23: _calcD(p2, p3, bula),
22+
a23: _calcD(p2, p3, bula)
3223
});
3324

34-
const _calcT = (p1: PrefRatingPlayer, p2: PrefRatingPlayer): number =>
35-
Number(math.round(
36-
math
37-
.chain(p2.rating)
38-
.subtract(p1.rating)
39-
.multiply(MAGIC)
40-
.divide(100)
41-
.done(),
42-
3,
43-
));
25+
const _calcT = (p1: PrefRatingPlayer, p2: PrefRatingPlayer): number => Number(math.round(math.chain(p2.rating).subtract(p1.rating).multiply(MAGIC).divide(100).done(), 3));
4426
const _calculateTs = (p1: PrefRatingPlayer, p2: PrefRatingPlayer, p3: PrefRatingPlayer): _TPrefRatingCalc => ({
4527
a12: _calcT(p1, p2),
4628
a13: _calcT(p1, p3),
47-
a23: _calcT(p2, p3),
29+
a23: _calcT(p2, p3)
4830
});
4931

5032
const _calcN = (p1: PrefRatingPlayer, p2: PrefRatingPlayer, bula: number): number => (p1.score > p2.score ? bula : p1.score < p2.score ? -bula : 0) / 100;
5133
const _calculateNs = (p1: PrefRatingPlayer, p2: PrefRatingPlayer, p3: PrefRatingPlayer, bula: number): _TPrefRatingCalc => ({
5234
a12: _calcN(p1, p2, bula),
5335
a13: _calcN(p1, p3, bula),
54-
a23: _calcN(p2, p3, bula),
36+
a23: _calcN(p2, p3, bula)
5537
});
5638

57-
const _calcC = (c1: number, c2: number): number =>
58-
Number(math.round(
59-
math
60-
.chain(c1)
61-
.add(c2)
62-
.divide(2)
63-
.done(),
64-
));
39+
const _calcC = (c1: number, c2: number): number => Number(math.round(math.chain(c1).add(c2).divide(2).done()));
6540
const _calculateChanges = (p1: PrefRatingPlayer, p2: PrefRatingPlayer, p3: PrefRatingPlayer, bula: number): _TPrefRatingChanges => {
6641
const D: _TPrefRatingCalc = _calculateDs(p1, p2, p3, bula);
6742
const T: _TPrefRatingCalc = _calculateTs(p1, p2, p3);
@@ -74,11 +49,11 @@ const _calculateChanges = (p1: PrefRatingPlayer, p2: PrefRatingPlayer, p3: PrefR
7449
return {
7550
c1: _calcC(C12, C13),
7651
c2: _calcC(-C12, C23),
77-
c3: _calcC(-C13, -C23),
52+
c3: _calcC(-C13, -C23)
7853
};
7954
};
8055

81-
export {TPrefRatingObject, TPrefRatingPlayerInput, PrefRatingPlayerObject}
56+
export {TPrefRatingObject, TPrefRatingPlayerInput, PrefRatingPlayerObject};
8257

8358
/** This is the Preferans Rating main class.
8459
* @typedef {Object} PrefRating
@@ -120,7 +95,7 @@ export default class PrefRating {
12095
bula: this._bula,
12196
p1: this._p1.json,
12297
p2: this._p2.json,
123-
p3: this._p3.json,
98+
p3: this._p3.json
12499
};
125100
}
126101
}

src/prefRating.types.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
#!/usr/bin/env node
21
'use strict';
32

43
export type PrefRatingPlayerObject = {
5-
username: string,
6-
score: number,
7-
rating: number,
8-
change: number,
9-
oldRating: number
10-
}
4+
username: string;
5+
score: number;
6+
rating: number;
7+
change: number;
8+
oldRating: number;
9+
};
1110

12-
export type TPrefRatingObject = { bula: number, p1: PrefRatingPlayerObject, p2: PrefRatingPlayerObject, p3: PrefRatingPlayerObject }
11+
export type TPrefRatingObject = {bula: number; p1: PrefRatingPlayerObject; p2: PrefRatingPlayerObject; p3: PrefRatingPlayerObject};
1312

14-
export type TPrefRatingPlayerInput = { username: string, rating: number, score: number }
13+
export type TPrefRatingPlayerInput = {username: string; rating: number; score: number};

src/prefRatingPlayer.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
#!/usr/bin/env node
21
'use strict';
32

4-
import {PrefRatingPlayerObject} from "./prefRating.types";
3+
import {PrefRatingPlayerObject} from './prefRating.types';
54

65
/**
76
* @typedef {Object} PrefRatingPlayer
@@ -49,6 +48,6 @@ export default class PrefRatingPlayer {
4948
rating: this._rating,
5049
change: this._change,
5150
oldRating: this._oldRating
52-
}
51+
};
5352
}
5453
}

test/mocha.opts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
--require ts-node/register
1+
--require ts-node/register/transpile-only
22
--require source-map-support/register
33
--full-trace
44
test/**/*.spec.ts

0 commit comments

Comments
 (0)