refactoring
This commit is contained in:
@@ -39,6 +39,7 @@
|
|||||||
<script src="./js/SymptomVsSymptomChartView.js"></script>
|
<script src="./js/SymptomVsSymptomChartView.js"></script>
|
||||||
<script src="./js/SymptomVsSymptomChartDataProvider.js"></script>
|
<script src="./js/SymptomVsSymptomChartDataProvider.js"></script>
|
||||||
<script src="./js/SymptomVsSymptomChartViewInitializer.js"></script>
|
<script src="./js/SymptomVsSymptomChartViewInitializer.js"></script>
|
||||||
|
<script src="./js/DictUtils.js"></script>
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener(
|
document.addEventListener(
|
||||||
"DOMContentLoaded",
|
"DOMContentLoaded",
|
||||||
|
|||||||
28
docs/SymptomsCausedByCOVIDLots/js/DictUtils.js
Normal file
28
docs/SymptomsCausedByCOVIDLots/js/DictUtils.js
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
class DictUtils {
|
||||||
|
|
||||||
|
static retainCommonKeys({ dict1, dict2 }) {
|
||||||
|
const commonKeys = DictUtils.#getCommonKeys(dict1, dict2);
|
||||||
|
return {
|
||||||
|
dict1: DictUtils.#retainKeysOfDict(dict1, commonKeys),
|
||||||
|
dict2: DictUtils.#retainKeysOfDict(dict2, commonKeys)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static #getCommonKeys(dict1, dict2) {
|
||||||
|
return Sets.intersection(
|
||||||
|
DictUtils.#getKeySet(dict1),
|
||||||
|
DictUtils.#getKeySet(dict2));
|
||||||
|
}
|
||||||
|
|
||||||
|
static #getKeySet(dict) {
|
||||||
|
return new Set(Object.keys(dict));
|
||||||
|
}
|
||||||
|
|
||||||
|
static #retainKeysOfDict(dict, keys2Retain) {
|
||||||
|
const entries2Retain =
|
||||||
|
Object
|
||||||
|
.entries(dict)
|
||||||
|
.filter(([key, _]) => keys2Retain.has(key));
|
||||||
|
return Object.fromEntries(entries2Retain);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,17 +1,8 @@
|
|||||||
class SymptomVsSymptomChartDataProvider {
|
class SymptomVsSymptomChartDataProvider {
|
||||||
|
|
||||||
// FK-TODO: extract utility class and test
|
|
||||||
static retainCommonKeys({ dict1, dict2 }) {
|
|
||||||
const commonKeys = SymptomVsSymptomChartDataProvider.#getCommonKeys(dict1, dict2);
|
|
||||||
return {
|
|
||||||
dict1: SymptomVsSymptomChartDataProvider.#retainKeysOfDict(dict1, commonKeys),
|
|
||||||
dict2: SymptomVsSymptomChartDataProvider.#retainKeysOfDict(dict2, commonKeys)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
static getChartData({ prrByLotX, prrByLotY }) {
|
static getChartData({ prrByLotX, prrByLotY }) {
|
||||||
const { dict1: prrByLotXCommon, dict2: prrByLotYCommon } =
|
const { dict1: prrByLotXCommon, dict2: prrByLotYCommon } =
|
||||||
SymptomVsSymptomChartDataProvider.retainCommonKeys(
|
DictUtils.retainCommonKeys(
|
||||||
{
|
{
|
||||||
dict1: prrByLotX,
|
dict1: prrByLotX,
|
||||||
dict2: prrByLotY
|
dict2: prrByLotY
|
||||||
@@ -27,22 +18,4 @@ class SymptomVsSymptomChartDataProvider {
|
|||||||
}))
|
}))
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static #getCommonKeys(dict1, dict2) {
|
|
||||||
return Sets.intersection(
|
|
||||||
SymptomVsSymptomChartDataProvider.#getKeySet(dict1),
|
|
||||||
SymptomVsSymptomChartDataProvider.#getKeySet(dict2));
|
|
||||||
}
|
|
||||||
|
|
||||||
static #getKeySet(dict) {
|
|
||||||
return new Set(Object.keys(dict));
|
|
||||||
}
|
|
||||||
|
|
||||||
static #retainKeysOfDict(dict, keys2Retain) {
|
|
||||||
const entries2Retain =
|
|
||||||
Object
|
|
||||||
.entries(dict)
|
|
||||||
.filter(([key, _]) => keys2Retain.has(key));
|
|
||||||
return Object.fromEntries(entries2Retain);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
52
docs/SymptomsCausedByCOVIDLots/test/DictUtilsTest.js
Normal file
52
docs/SymptomsCausedByCOVIDLots/test/DictUtilsTest.js
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
QUnit.module('DictUtilsTest', function () {
|
||||||
|
|
||||||
|
QUnit.test.each(
|
||||||
|
'shouldRetainCommonKeys',
|
||||||
|
[
|
||||||
|
[
|
||||||
|
{
|
||||||
|
dict1: {
|
||||||
|
"lotX": 1.0
|
||||||
|
},
|
||||||
|
dict2: {
|
||||||
|
"lotY": 2.0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
dict1: {
|
||||||
|
},
|
||||||
|
dict2: {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
dict1: {
|
||||||
|
"lotX": 1.0,
|
||||||
|
"lotCommon": 2.0
|
||||||
|
},
|
||||||
|
dict2: {
|
||||||
|
"lotCommon": 3.0,
|
||||||
|
"lotY": 4.0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
dict1: {
|
||||||
|
"lotCommon": 2.0
|
||||||
|
},
|
||||||
|
dict2: {
|
||||||
|
"lotCommon": 3.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
],
|
||||||
|
(assert, [dicts, dictsHavingCommonKeys]) => {
|
||||||
|
// Given
|
||||||
|
|
||||||
|
// When
|
||||||
|
const dictsHavingCommonKeysActual = DictUtils.retainCommonKeys(dicts);
|
||||||
|
|
||||||
|
// Then
|
||||||
|
assert.deepEqual(dictsHavingCommonKeysActual, dictsHavingCommonKeys);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,55 +1,5 @@
|
|||||||
QUnit.module('SymptomVsSymptomChartDataProviderTest', function () {
|
QUnit.module('SymptomVsSymptomChartDataProviderTest', function () {
|
||||||
|
|
||||||
QUnit.test.each(
|
|
||||||
'shouldRetainCommonLots',
|
|
||||||
[
|
|
||||||
[
|
|
||||||
{
|
|
||||||
dict1: {
|
|
||||||
"lotX": 1.0
|
|
||||||
},
|
|
||||||
dict2: {
|
|
||||||
"lotY": 2.0
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
dict1: {
|
|
||||||
},
|
|
||||||
dict2: {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{
|
|
||||||
dict1: {
|
|
||||||
"lotX": 1.0,
|
|
||||||
"lotCommon": 2.0
|
|
||||||
},
|
|
||||||
dict2: {
|
|
||||||
"lotCommon": 3.0,
|
|
||||||
"lotY": 4.0
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
dict1: {
|
|
||||||
"lotCommon": 2.0
|
|
||||||
},
|
|
||||||
dict2: {
|
|
||||||
"lotCommon": 3.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
],
|
|
||||||
(assert, [dicts, dictsHavingCommonKeys]) => {
|
|
||||||
// Given
|
|
||||||
|
|
||||||
// When
|
|
||||||
const dictsHavingCommonKeysActual = SymptomVsSymptomChartDataProvider.retainCommonKeys(dicts);
|
|
||||||
|
|
||||||
// Then
|
|
||||||
assert.deepEqual(dictsHavingCommonKeysActual, dictsHavingCommonKeys);
|
|
||||||
});
|
|
||||||
|
|
||||||
QUnit.test('shouldProvideChartData', function (assert) {
|
QUnit.test('shouldProvideChartData', function (assert) {
|
||||||
// Given
|
// Given
|
||||||
const prrByLotX = {
|
const prrByLotX = {
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
<script src="../js/SymptomVsSymptomChartView.js"></script>
|
<script src="../js/SymptomVsSymptomChartView.js"></script>
|
||||||
<script src="../js/SymptomVsSymptomChartDataProvider.js"></script>
|
<script src="../js/SymptomVsSymptomChartDataProvider.js"></script>
|
||||||
<script src="../js/SymptomVsSymptomChartViewInitializer.js"></script>
|
<script src="../js/SymptomVsSymptomChartViewInitializer.js"></script>
|
||||||
|
<script src="../js/DictUtils.js"></script>
|
||||||
<link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-2.17.2.css">
|
<link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-2.17.2.css">
|
||||||
<script src="https://code.jquery.com/qunit/qunit-2.17.2.js"></script>
|
<script src="https://code.jquery.com/qunit/qunit-2.17.2.js"></script>
|
||||||
<script type="text/javascript" src="./jshamcrest.js"></script>
|
<script type="text/javascript" src="./jshamcrest.js"></script>
|
||||||
@@ -28,6 +29,7 @@
|
|||||||
JsMockito.Integration.QUnit();
|
JsMockito.Integration.QUnit();
|
||||||
</script>
|
</script>
|
||||||
<script src="./SymptomVsSymptomChartDataProviderTest.js"></script>
|
<script src="./SymptomVsSymptomChartDataProviderTest.js"></script>
|
||||||
|
<script src="./DictUtilsTest.js"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
Reference in New Issue
Block a user