@azuro-org/toolkit 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/aggregateOutcomesByMarkets.d.ts +4 -7
- package/dist/index.es.js +30 -29
- package/lib/aggregateOutcomesByMarkets.d.ts +4 -7
- package/lib/index.js +30 -29
- package/package.json +1 -1
|
@@ -6,25 +6,22 @@ type Outcome<T> = T & {
|
|
|
6
6
|
lpAddress: string;
|
|
7
7
|
coreAddress: string;
|
|
8
8
|
};
|
|
9
|
-
type
|
|
9
|
+
type FinalMarket<T> = {
|
|
10
10
|
marketName: string;
|
|
11
11
|
outcomes: Outcome<T>[][];
|
|
12
|
-
}
|
|
12
|
+
};
|
|
13
13
|
type Props = {
|
|
14
14
|
lpAddress: string;
|
|
15
15
|
conditions: {
|
|
16
16
|
[key: string]: any;
|
|
17
17
|
conditionId: string;
|
|
18
|
+
coreAddress: string;
|
|
18
19
|
outcomes: {
|
|
19
20
|
[key: string]: any;
|
|
20
21
|
outcomeId: string;
|
|
21
22
|
}[];
|
|
22
|
-
core: {
|
|
23
|
-
[key: string]: any;
|
|
24
|
-
address: string;
|
|
25
|
-
};
|
|
26
23
|
}[];
|
|
27
24
|
dictionaries: Dictionaries;
|
|
28
25
|
};
|
|
29
|
-
export default function aggregateOutcomesByMarkets<T extends {}>(props: Props):
|
|
26
|
+
export default function aggregateOutcomesByMarkets<T extends {}>(props: Props): FinalMarket<T>[];
|
|
30
27
|
export {};
|
package/dist/index.es.js
CHANGED
|
@@ -36,52 +36,53 @@ function __rest(s, e) {
|
|
|
36
36
|
return t;
|
|
37
37
|
}function aggregateOutcomesByMarkets(props) {
|
|
38
38
|
var lpAddress = props.lpAddress, conditions = props.conditions, dictionaries = props.dictionaries;
|
|
39
|
-
|
|
40
|
-
var outcomesByMarketKey = {};
|
|
41
|
-
var result = {};
|
|
39
|
+
var marketsMap = {};
|
|
42
40
|
conditions.forEach(function (_a) {
|
|
43
|
-
var conditionId = _a.conditionId, outcomes = _a.outcomes,
|
|
41
|
+
var conditionId = _a.conditionId, outcomes = _a.outcomes, coreAddress = _a.coreAddress;
|
|
44
42
|
outcomes.forEach(function (_a) {
|
|
45
43
|
var outcomeId = _a.outcomeId, rest = __rest(_a, ["outcomeId"]);
|
|
44
|
+
// we are using the same key format that was discussed earlier
|
|
46
45
|
var marketKey = getMarketKey(outcomeId, dictionaries);
|
|
46
|
+
// we are obtaining the human-readable names of each market and the corresponding outcome selections
|
|
47
47
|
var marketName = getMarketName(outcomeId, dictionaries);
|
|
48
48
|
var selectionName = assembleSelectionName(outcomeId, dictionaries);
|
|
49
|
-
var outcome = __assign({ conditionId: conditionId, outcomeId: outcomeId,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
// "marketKey" is a string template "marketId-gamePeriodId-gameTypeId[-teamPlayerId]"
|
|
53
|
-
if (!outcomesByMarketKey[marketKey]) {
|
|
54
|
-
outcomesByMarketKey[marketKey] = [];
|
|
55
|
-
result[marketKey] = {
|
|
49
|
+
var outcome = __assign({ conditionId: conditionId, outcomeId: outcomeId, lpAddress: lpAddress, coreAddress: coreAddress, selectionName: selectionName }, rest);
|
|
50
|
+
if (!marketsMap[marketKey]) {
|
|
51
|
+
marketsMap[marketKey] = {
|
|
56
52
|
marketName: marketName,
|
|
57
53
|
outcomes: [],
|
|
58
54
|
};
|
|
59
55
|
}
|
|
60
|
-
|
|
56
|
+
marketsMap[marketKey].outcomes.push(outcome);
|
|
61
57
|
});
|
|
62
58
|
});
|
|
59
|
+
var finalMarketsMap = {};
|
|
63
60
|
// sort by outcomeId and group by conditionId
|
|
64
|
-
Object.keys(
|
|
65
|
-
var
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
61
|
+
Object.keys(marketsMap).forEach(function (marketKey) {
|
|
62
|
+
var _a = marketsMap[marketKey], marketName = _a.marketName, outcomes = _a.outcomes;
|
|
63
|
+
finalMarketsMap[marketKey] = {
|
|
64
|
+
marketName: marketName,
|
|
65
|
+
outcomes: null,
|
|
66
|
+
};
|
|
67
|
+
// sort the outcomes by `selectionId` (outcome's selection reference)
|
|
69
68
|
outcomes.sort(function (a, b) {
|
|
70
69
|
var left = dictionaries.outcomes[a.outcomeId].selectionId;
|
|
71
70
|
var right = dictionaries.outcomes[b.outcomeId].selectionId;
|
|
72
71
|
return left - right;
|
|
73
72
|
});
|
|
74
|
-
//
|
|
75
|
-
var
|
|
76
|
-
|
|
77
|
-
|
|
73
|
+
// "Full Time Result" and "Double Chance" are the markets whose outcomes don't require sorting
|
|
74
|
+
var MARKETS_THAT_DONT_NEED_GROUPING = [1, 2];
|
|
75
|
+
var marketId = marketKey.split('-')[0];
|
|
76
|
+
if (MARKETS_THAT_DONT_NEED_GROUPING.includes(+marketId)) {
|
|
77
|
+
// it's worth noting that the outcomes are wrapped within an array here due to the "rows" that are presented below
|
|
78
|
+
finalMarketsMap[marketKey].outcomes = [outcomes];
|
|
78
79
|
}
|
|
79
|
-
// group by conditionId to allow draw outcomes by rows in UI, e.g.
|
|
80
|
-
//
|
|
81
|
-
// Team 1 - Total Goals:
|
|
82
|
-
// Over (1.5) Under (1.5)
|
|
83
|
-
// Over (0.5) Under (0.5)
|
|
84
80
|
else {
|
|
81
|
+
// group the outcomes by condition ID, which will allow us to display the draw outcomes in separate rows
|
|
82
|
+
//
|
|
83
|
+
// Handicap:
|
|
84
|
+
// H1 (-0.5) H2 (0.5)
|
|
85
|
+
// H1 (0.5) H2 (-0.5)
|
|
85
86
|
var outcomesByConditionId_1 = {};
|
|
86
87
|
outcomes.forEach(function (outcome) {
|
|
87
88
|
var key = outcome.conditionId;
|
|
@@ -90,8 +91,8 @@ function __rest(s, e) {
|
|
|
90
91
|
}
|
|
91
92
|
outcomesByConditionId_1[key].push(outcome);
|
|
92
93
|
});
|
|
93
|
-
var
|
|
94
|
-
|
|
94
|
+
var rows = Object.values(outcomesByConditionId_1);
|
|
95
|
+
finalMarketsMap[marketKey].outcomes = rows.sort(function (a, b) {
|
|
95
96
|
var aSum = a.reduce(function (acc, _a) {
|
|
96
97
|
var outcomeId = _a.outcomeId;
|
|
97
98
|
return acc + +outcomeId;
|
|
@@ -104,5 +105,5 @@ function __rest(s, e) {
|
|
|
104
105
|
});
|
|
105
106
|
}
|
|
106
107
|
});
|
|
107
|
-
return Object.values(
|
|
108
|
+
return Object.values(finalMarketsMap);
|
|
108
109
|
}export{aggregateOutcomesByMarkets};
|
|
@@ -6,25 +6,22 @@ type Outcome<T> = T & {
|
|
|
6
6
|
lpAddress: string;
|
|
7
7
|
coreAddress: string;
|
|
8
8
|
};
|
|
9
|
-
type
|
|
9
|
+
type FinalMarket<T> = {
|
|
10
10
|
marketName: string;
|
|
11
11
|
outcomes: Outcome<T>[][];
|
|
12
|
-
}
|
|
12
|
+
};
|
|
13
13
|
type Props = {
|
|
14
14
|
lpAddress: string;
|
|
15
15
|
conditions: {
|
|
16
16
|
[key: string]: any;
|
|
17
17
|
conditionId: string;
|
|
18
|
+
coreAddress: string;
|
|
18
19
|
outcomes: {
|
|
19
20
|
[key: string]: any;
|
|
20
21
|
outcomeId: string;
|
|
21
22
|
}[];
|
|
22
|
-
core: {
|
|
23
|
-
[key: string]: any;
|
|
24
|
-
address: string;
|
|
25
|
-
};
|
|
26
23
|
}[];
|
|
27
24
|
dictionaries: Dictionaries;
|
|
28
25
|
};
|
|
29
|
-
export default function aggregateOutcomesByMarkets<T extends {}>(props: Props):
|
|
26
|
+
export default function aggregateOutcomesByMarkets<T extends {}>(props: Props): FinalMarket<T>[];
|
|
30
27
|
export {};
|
package/lib/index.js
CHANGED
|
@@ -36,52 +36,53 @@ function __rest(s, e) {
|
|
|
36
36
|
return t;
|
|
37
37
|
}function aggregateOutcomesByMarkets(props) {
|
|
38
38
|
var lpAddress = props.lpAddress, conditions = props.conditions, dictionaries$1 = props.dictionaries;
|
|
39
|
-
|
|
40
|
-
var outcomesByMarketKey = {};
|
|
41
|
-
var result = {};
|
|
39
|
+
var marketsMap = {};
|
|
42
40
|
conditions.forEach(function (_a) {
|
|
43
|
-
var conditionId = _a.conditionId, outcomes = _a.outcomes,
|
|
41
|
+
var conditionId = _a.conditionId, outcomes = _a.outcomes, coreAddress = _a.coreAddress;
|
|
44
42
|
outcomes.forEach(function (_a) {
|
|
45
43
|
var outcomeId = _a.outcomeId, rest = __rest(_a, ["outcomeId"]);
|
|
44
|
+
// we are using the same key format that was discussed earlier
|
|
46
45
|
var marketKey = dictionaries.getMarketKey(outcomeId, dictionaries$1);
|
|
46
|
+
// we are obtaining the human-readable names of each market and the corresponding outcome selections
|
|
47
47
|
var marketName = dictionaries.getMarketName(outcomeId, dictionaries$1);
|
|
48
48
|
var selectionName = dictionaries.assembleSelectionName(outcomeId, dictionaries$1);
|
|
49
|
-
var outcome = __assign({ conditionId: conditionId, outcomeId: outcomeId,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
// "marketKey" is a string template "marketId-gamePeriodId-gameTypeId[-teamPlayerId]"
|
|
53
|
-
if (!outcomesByMarketKey[marketKey]) {
|
|
54
|
-
outcomesByMarketKey[marketKey] = [];
|
|
55
|
-
result[marketKey] = {
|
|
49
|
+
var outcome = __assign({ conditionId: conditionId, outcomeId: outcomeId, lpAddress: lpAddress, coreAddress: coreAddress, selectionName: selectionName }, rest);
|
|
50
|
+
if (!marketsMap[marketKey]) {
|
|
51
|
+
marketsMap[marketKey] = {
|
|
56
52
|
marketName: marketName,
|
|
57
53
|
outcomes: [],
|
|
58
54
|
};
|
|
59
55
|
}
|
|
60
|
-
|
|
56
|
+
marketsMap[marketKey].outcomes.push(outcome);
|
|
61
57
|
});
|
|
62
58
|
});
|
|
59
|
+
var finalMarketsMap = {};
|
|
63
60
|
// sort by outcomeId and group by conditionId
|
|
64
|
-
Object.keys(
|
|
65
|
-
var
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
61
|
+
Object.keys(marketsMap).forEach(function (marketKey) {
|
|
62
|
+
var _a = marketsMap[marketKey], marketName = _a.marketName, outcomes = _a.outcomes;
|
|
63
|
+
finalMarketsMap[marketKey] = {
|
|
64
|
+
marketName: marketName,
|
|
65
|
+
outcomes: null,
|
|
66
|
+
};
|
|
67
|
+
// sort the outcomes by `selectionId` (outcome's selection reference)
|
|
69
68
|
outcomes.sort(function (a, b) {
|
|
70
69
|
var left = dictionaries$1.outcomes[a.outcomeId].selectionId;
|
|
71
70
|
var right = dictionaries$1.outcomes[b.outcomeId].selectionId;
|
|
72
71
|
return left - right;
|
|
73
72
|
});
|
|
74
|
-
//
|
|
75
|
-
var
|
|
76
|
-
|
|
77
|
-
|
|
73
|
+
// "Full Time Result" and "Double Chance" are the markets whose outcomes don't require sorting
|
|
74
|
+
var MARKETS_THAT_DONT_NEED_GROUPING = [1, 2];
|
|
75
|
+
var marketId = marketKey.split('-')[0];
|
|
76
|
+
if (MARKETS_THAT_DONT_NEED_GROUPING.includes(+marketId)) {
|
|
77
|
+
// it's worth noting that the outcomes are wrapped within an array here due to the "rows" that are presented below
|
|
78
|
+
finalMarketsMap[marketKey].outcomes = [outcomes];
|
|
78
79
|
}
|
|
79
|
-
// group by conditionId to allow draw outcomes by rows in UI, e.g.
|
|
80
|
-
//
|
|
81
|
-
// Team 1 - Total Goals:
|
|
82
|
-
// Over (1.5) Under (1.5)
|
|
83
|
-
// Over (0.5) Under (0.5)
|
|
84
80
|
else {
|
|
81
|
+
// group the outcomes by condition ID, which will allow us to display the draw outcomes in separate rows
|
|
82
|
+
//
|
|
83
|
+
// Handicap:
|
|
84
|
+
// H1 (-0.5) H2 (0.5)
|
|
85
|
+
// H1 (0.5) H2 (-0.5)
|
|
85
86
|
var outcomesByConditionId_1 = {};
|
|
86
87
|
outcomes.forEach(function (outcome) {
|
|
87
88
|
var key = outcome.conditionId;
|
|
@@ -90,8 +91,8 @@ function __rest(s, e) {
|
|
|
90
91
|
}
|
|
91
92
|
outcomesByConditionId_1[key].push(outcome);
|
|
92
93
|
});
|
|
93
|
-
var
|
|
94
|
-
|
|
94
|
+
var rows = Object.values(outcomesByConditionId_1);
|
|
95
|
+
finalMarketsMap[marketKey].outcomes = rows.sort(function (a, b) {
|
|
95
96
|
var aSum = a.reduce(function (acc, _a) {
|
|
96
97
|
var outcomeId = _a.outcomeId;
|
|
97
98
|
return acc + +outcomeId;
|
|
@@ -104,5 +105,5 @@ function __rest(s, e) {
|
|
|
104
105
|
});
|
|
105
106
|
}
|
|
106
107
|
});
|
|
107
|
-
return Object.values(
|
|
108
|
+
return Object.values(finalMarketsMap);
|
|
108
109
|
}exports.aggregateOutcomesByMarkets=aggregateOutcomesByMarkets;
|