-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path10-4-rating.js
124 lines (103 loc) Β· 2.61 KB
/
10-4-rating.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/**
* p375 μμ
*/
function rating(voyage, history) {
return createRating(voyage, history).value;
}
class Rating {
#voyage;
#history;
constructor(voyage, history) {
this.#voyage = voyage;
this.#history = history;
}
get voyage() {
return this.#voyage;
}
get history() {
return this.#history;
}
get value() {
const vpf = this.voyageProfitFactor;
const vr = this.voyageRisk;
const chr = this.captainHistoryRisk;
if (vpf * 3 > vr + chr + 2) return 'A';
else return 'B';
}
get voyageRisk() {
let result = 1;
if (this.#voyage.length > 4) result += 2;
if (this.#voyage.length > 8) result += this.#voyage.length - 8;
if (['μ€κ΅', 'λμΈλ'].includes(this.#voyage.zone)) result += 4;
return Math.max(result, 0);
}
get captainHistoryRisk() {
let result = 1;
if (this.#history.length < 5) result += 4;
result += this.#history.filter((v) => v.profit < 0).length;
return Math.max(result, 0);
}
get voyageProfitFactor() {
let result = 2;
if (this.#voyage.zone === 'μ€κ΅') result += 1;
if (this.#voyage.zone === 'λμΈλ') result += 1;
result += this.historyLengthFactor;
result += this.voyageLengthFactor;
return result;
}
get voyageLengthFactor() {
return this.#voyage.length > 14 ? -1 : 0;
}
get historyLengthFactor() {
return this.#history.length > 8 ? 1 : 0;
}
get hasChinaHistory() {
return this.#history.some((v) => 'μ€κ΅' === v.zone);
}
}
class ExperiencedChinaRating extends Rating {
constructor(voyage, history) {
super(voyage, history);
}
get captainHistoryRisk() {
const result = super.captainHistoryRisk - 2;
return Math.max(result, 0);
}
get voyageProfitFactor() {
return super.voyageProfitFactor + 3;
}
get voyageLengthFactor() {
let result = 0;
if (this.voyage.length > 12) result += 1;
if (this.voyage.length > 18) result -= 1;
return result;
}
get historyLengthFactor() {
return this.history.length > 10 ? 1 : 0;
}
}
function createRating(voyage, history) {
if (voyage.zone === 'μ€κ΅' && history.some((v) => 'μ€κ΅' === v.zone)) {
return new ExperiencedChinaRating(voyage, history);
} else {
return new Rating(voyage, history);
}
}
/**
* μμ μ½λ μ¬μ©
*/
const voyage = {
zone: 'μμΈλ',
length: 10,
};
const history = [
{ zone: 'λμΈλ', profit: 5 },
{ zone: 'μμΈλ', profit: 15 },
{ zone: 'μ€κ΅', profit: -2 },
{ zone: 'μμν리카', profit: 7 },
];
const myRating = rating(voyage, history);
/**
* μμ μ€νμ μν μμμ μ½λ
*/
console.log(myRating);