@molochko-dev/data 1.4.34 → 1.4.35
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/event/animal-event-filter.js +105 -88
- package/package.json +1 -1
- package/src/event/animal-event-filter.ts +113 -97
|
@@ -3,102 +3,119 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.filter = void 0;
|
|
4
4
|
const enums_1 = require("../enums");
|
|
5
5
|
const date_1 = require("../helpers/date");
|
|
6
|
-
const status = enums_1.COW_STATUS;
|
|
7
|
-
const defaultCowAge = 12;
|
|
8
6
|
/*
|
|
9
7
|
|
|
10
8
|
const filtered = filter(animals, eventType)
|
|
11
9
|
|
|
12
10
|
*/
|
|
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
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
11
|
+
class AnimalEcentFilter {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.status = enums_1.COW_STATUS;
|
|
14
|
+
this.defaultCowAge = 12;
|
|
15
|
+
}
|
|
16
|
+
ageFilter(animal, availableMinAge /*month*/) {
|
|
17
|
+
const months = (0, date_1.getMonthFromDate)(animal.dob.toISOString());
|
|
18
|
+
return months > availableMinAge;
|
|
19
|
+
}
|
|
20
|
+
statusFilter(animal, availableStatuses) {
|
|
21
|
+
return availableStatuses.includes(animal.status);
|
|
22
|
+
}
|
|
23
|
+
genderFilter(animal, availableGender) {
|
|
24
|
+
return animal.gender === availableGender;
|
|
25
|
+
}
|
|
26
|
+
abortFilter(animals) {
|
|
27
|
+
const result = animals.filter((animal) => this.genderFilter(animal, enums_1.ANIMAL_GENDER_ENUM.cow));
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
neosemFilter(animals) {
|
|
31
|
+
return this.abortFilter(animals);
|
|
32
|
+
}
|
|
33
|
+
osemenenieFilter(animals) {
|
|
34
|
+
const result = animals.filter((animal) => {
|
|
35
|
+
const genderOk = this.genderFilter(animal, enums_1.ANIMAL_GENDER_ENUM.cow);
|
|
36
|
+
const statusOk = this.statusFilter(animal, [
|
|
37
|
+
this.status.HEIFER,
|
|
38
|
+
this.status.BRED,
|
|
39
|
+
this.status.OPEN,
|
|
40
|
+
this.status.FRESH,
|
|
41
|
+
]);
|
|
42
|
+
const ageOk = this.ageFilter(animal, this.defaultCowAge);
|
|
43
|
+
return genderOk && statusOk && ageOk && animal;
|
|
44
|
+
});
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
otelFilter(animals) {
|
|
48
|
+
const result = animals.filter((animal) => {
|
|
49
|
+
const genderOk = this.genderFilter(animal, enums_1.ANIMAL_GENDER_ENUM.cow);
|
|
50
|
+
const statusOk = this.statusFilter(animal, [this.status.DRY, this.status.PREGNANT]);
|
|
51
|
+
const ageOk = this.ageFilter(animal, this.defaultCowAge);
|
|
52
|
+
return genderOk && statusOk && ageOk && animal;
|
|
53
|
+
});
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
recheckFilter(animals) {
|
|
57
|
+
const result = animals.filter((animal) => {
|
|
58
|
+
const genderOk = this.genderFilter(animal, enums_1.ANIMAL_GENDER_ENUM.cow);
|
|
59
|
+
const ageOk = this.ageFilter(animal, this.defaultCowAge);
|
|
60
|
+
let availableStatus = [this.status.BRED, this.status.PREGNANT, this.status.DRY];
|
|
61
|
+
if (animal.animalEventRelation) {
|
|
62
|
+
const previousRechecks = animal.animalEventRelation.filter((row) => {
|
|
63
|
+
return row.eventDetail.type === enums_1.EVENT_TYPES_ENUM.recheck;
|
|
64
|
+
});
|
|
65
|
+
if (previousRechecks.length == 0) {
|
|
66
|
+
availableStatus = [this.status.BRED];
|
|
67
|
+
}
|
|
59
68
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
});
|
|
64
|
-
return result;
|
|
65
|
-
}
|
|
66
|
-
function suhostoiFilter(animals) {
|
|
67
|
-
return abortFilter(animals);
|
|
68
|
-
}
|
|
69
|
-
function pozSuhostoiFilter(animals) {
|
|
70
|
-
const result = animals.filter((animal) => {
|
|
71
|
-
const genderOk = genderFilter(animal, enums_1.ANIMAL_GENDER_ENUM.cow);
|
|
72
|
-
const statusOk = statusFilter(animal, [status.DRY]);
|
|
73
|
-
const ageOk = ageFilter(animal, defaultCowAge);
|
|
74
|
-
return genderOk && statusOk && ageOk && animal;
|
|
75
|
-
});
|
|
76
|
-
return result;
|
|
77
|
-
}
|
|
78
|
-
function transferOutFilter(animals) {
|
|
79
|
-
return animals;
|
|
80
|
-
}
|
|
81
|
-
function perevodFilter(animals) {
|
|
82
|
-
return animals;
|
|
83
|
-
}
|
|
84
|
-
function filter(animals, eventType) {
|
|
85
|
-
const filters = {
|
|
86
|
-
[enums_1.EVENT_TYPES_ENUM.abort]: abortFilter,
|
|
87
|
-
[enums_1.EVENT_TYPES_ENUM.neosem]: neosemFilter,
|
|
88
|
-
[enums_1.EVENT_TYPES_ENUM.osemenenie]: osemenenieFilter,
|
|
89
|
-
[enums_1.EVENT_TYPES_ENUM.otel]: otelFilter,
|
|
90
|
-
[enums_1.EVENT_TYPES_ENUM.recheck]: recheckFilter,
|
|
91
|
-
[enums_1.EVENT_TYPES_ENUM.suhostoi]: suhostoiFilter,
|
|
92
|
-
[enums_1.EVENT_TYPES_ENUM.pozSuhostoi]: pozSuhostoiFilter,
|
|
93
|
-
[enums_1.EVENT_TYPES_ENUM.perevod]: perevodFilter,
|
|
94
|
-
[enums_1.EVENT_TYPES_ENUM.transferOut]: transferOutFilter,
|
|
95
|
-
};
|
|
96
|
-
try {
|
|
97
|
-
const result = filters[eventType](animals);
|
|
69
|
+
const statusOk = this.statusFilter(animal, availableStatus);
|
|
70
|
+
return genderOk && statusOk && ageOk && animal;
|
|
71
|
+
});
|
|
98
72
|
return result;
|
|
99
73
|
}
|
|
100
|
-
|
|
101
|
-
|
|
74
|
+
suhostoiFilter(animals) {
|
|
75
|
+
return this.abortFilter(animals);
|
|
102
76
|
}
|
|
77
|
+
pozSuhostoiFilter(animals) {
|
|
78
|
+
const result = animals.filter((animal) => {
|
|
79
|
+
const genderOk = this.genderFilter(animal, enums_1.ANIMAL_GENDER_ENUM.cow);
|
|
80
|
+
const statusOk = this.statusFilter(animal, [this.status.DRY]);
|
|
81
|
+
const ageOk = this.ageFilter(animal, this.defaultCowAge);
|
|
82
|
+
return genderOk && statusOk && ageOk && animal;
|
|
83
|
+
});
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
transferOutFilter(animals) {
|
|
87
|
+
return animals;
|
|
88
|
+
}
|
|
89
|
+
perevodFilter(animals) {
|
|
90
|
+
return animals;
|
|
91
|
+
}
|
|
92
|
+
filter(animals, eventType) {
|
|
93
|
+
switch (eventType) {
|
|
94
|
+
case enums_1.EVENT_TYPES_ENUM.abort:
|
|
95
|
+
return this.abortFilter(animals);
|
|
96
|
+
case enums_1.EVENT_TYPES_ENUM.neosem:
|
|
97
|
+
return this.neosemFilter(animals);
|
|
98
|
+
case enums_1.EVENT_TYPES_ENUM.osemenenie:
|
|
99
|
+
return this.osemenenieFilter(animals);
|
|
100
|
+
case enums_1.EVENT_TYPES_ENUM.otel:
|
|
101
|
+
return this.otelFilter(animals);
|
|
102
|
+
case enums_1.EVENT_TYPES_ENUM.recheck:
|
|
103
|
+
return this.recheckFilter(animals);
|
|
104
|
+
case enums_1.EVENT_TYPES_ENUM.suhostoi:
|
|
105
|
+
return this.suhostoiFilter(animals);
|
|
106
|
+
case enums_1.EVENT_TYPES_ENUM.pozSuhostoi:
|
|
107
|
+
return this.pozSuhostoiFilter(animals);
|
|
108
|
+
case enums_1.EVENT_TYPES_ENUM.perevod:
|
|
109
|
+
return this.perevodFilter(animals);
|
|
110
|
+
case enums_1.EVENT_TYPES_ENUM.transferOut:
|
|
111
|
+
return this.transferOutFilter(animals);
|
|
112
|
+
default:
|
|
113
|
+
throw new Error(`AnimalForEventFilter.filter.${eventType} not implemented`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function filter(animals, eventType) {
|
|
118
|
+
const f = new AnimalEcentFilter();
|
|
119
|
+
return f.filter(animals, eventType);
|
|
103
120
|
}
|
|
104
121
|
exports.filter = filter;
|
package/package.json
CHANGED
|
@@ -2,128 +2,144 @@ import { AnimalStatus, BaseAnimal } from '../types';
|
|
|
2
2
|
import { ANIMAL_GENDER_ENUM, COW_STATUS, EVENT_TYPES_ENUM } from '../enums';
|
|
3
3
|
import { getMonthFromDate } from '../helpers/date';
|
|
4
4
|
|
|
5
|
-
const status = COW_STATUS;
|
|
6
|
-
|
|
7
|
-
const defaultCowAge = 12;
|
|
8
|
-
|
|
9
5
|
/*
|
|
10
6
|
|
|
11
7
|
const filtered = filter(animals, eventType)
|
|
12
8
|
|
|
13
9
|
*/
|
|
14
10
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
11
|
+
class AnimalEcentFilter {
|
|
12
|
+
status = COW_STATUS;
|
|
13
|
+
defaultCowAge = 12;
|
|
19
14
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
private ageFilter<T extends BaseAnimal>(animal: T, availableMinAge: number /*month*/): boolean {
|
|
16
|
+
const months = getMonthFromDate(animal.dob.toISOString());
|
|
17
|
+
return months > availableMinAge;
|
|
18
|
+
}
|
|
23
19
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
): boolean {
|
|
28
|
-
|
|
29
|
-
}
|
|
20
|
+
private statusFilter<T extends BaseAnimal>(
|
|
21
|
+
animal: T,
|
|
22
|
+
availableStatuses: AnimalStatus[],
|
|
23
|
+
): boolean {
|
|
24
|
+
return availableStatuses.includes(animal.status);
|
|
25
|
+
}
|
|
30
26
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
private genderFilter<T extends BaseAnimal>(
|
|
28
|
+
animal: T,
|
|
29
|
+
availableGender: ANIMAL_GENDER_ENUM,
|
|
30
|
+
): boolean {
|
|
31
|
+
return animal.gender === availableGender;
|
|
32
|
+
}
|
|
35
33
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
abortFilter<T extends BaseAnimal>(animals: T[]): T[] {
|
|
35
|
+
const result: T[] = animals.filter((animal) =>
|
|
36
|
+
this.genderFilter<T>(animal, ANIMAL_GENDER_ENUM.cow),
|
|
37
|
+
);
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const statusOk = statusFilter(animal, [status.HEIFER, status.BRED, status.OPEN, status.FRESH]);
|
|
44
|
-
const ageOk = ageFilter(animal, defaultCowAge);
|
|
41
|
+
neosemFilter<T extends BaseAnimal>(animals: T[]): T[] {
|
|
42
|
+
return this.abortFilter(animals);
|
|
43
|
+
}
|
|
45
44
|
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
osemenenieFilter<T extends BaseAnimal>(animals: T[]): T[] {
|
|
46
|
+
const result = animals.filter((animal) => {
|
|
47
|
+
const genderOk = this.genderFilter(animal, ANIMAL_GENDER_ENUM.cow);
|
|
48
|
+
const statusOk = this.statusFilter(animal, [
|
|
49
|
+
this.status.HEIFER,
|
|
50
|
+
this.status.BRED,
|
|
51
|
+
this.status.OPEN,
|
|
52
|
+
this.status.FRESH,
|
|
53
|
+
]);
|
|
54
|
+
const ageOk = this.ageFilter(animal, this.defaultCowAge);
|
|
55
|
+
return genderOk && statusOk && ageOk && animal;
|
|
56
|
+
});
|
|
48
57
|
|
|
49
|
-
|
|
50
|
-
}
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
51
60
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
61
|
+
otelFilter<T extends BaseAnimal>(animals: T[]): T[] {
|
|
62
|
+
const result = animals.filter((animal) => {
|
|
63
|
+
const genderOk = this.genderFilter(animal, ANIMAL_GENDER_ENUM.cow);
|
|
64
|
+
const statusOk = this.statusFilter(animal, [this.status.DRY, this.status.PREGNANT]);
|
|
65
|
+
const ageOk = this.ageFilter(animal, this.defaultCowAge);
|
|
57
66
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
67
|
+
return genderOk && statusOk && ageOk && animal;
|
|
68
|
+
});
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
62
71
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
recheckFilter<T extends BaseAnimal>(animals: T[]): T[] {
|
|
73
|
+
const result = animals.filter((animal) => {
|
|
74
|
+
const genderOk = this.genderFilter(animal, ANIMAL_GENDER_ENUM.cow);
|
|
75
|
+
const ageOk = this.ageFilter(animal, this.defaultCowAge);
|
|
76
|
+
|
|
77
|
+
let availableStatus = [this.status.BRED, this.status.PREGNANT, this.status.DRY];
|
|
78
|
+
if (animal.animalEventRelation) {
|
|
79
|
+
const previousRechecks = animal.animalEventRelation.filter((row) => {
|
|
80
|
+
return row.eventDetail.type === EVENT_TYPES_ENUM.recheck;
|
|
81
|
+
});
|
|
82
|
+
if (previousRechecks.length == 0) {
|
|
83
|
+
availableStatus = [this.status.BRED];
|
|
84
|
+
}
|
|
75
85
|
}
|
|
76
|
-
|
|
77
|
-
const statusOk = statusFilter(animal, availableStatus);
|
|
86
|
+
const statusOk = this.statusFilter(animal, availableStatus);
|
|
78
87
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
88
|
+
return genderOk && statusOk && ageOk && animal;
|
|
89
|
+
});
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
83
92
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
93
|
+
suhostoiFilter<T extends BaseAnimal>(animals: T[]): T[] {
|
|
94
|
+
return this.abortFilter(animals);
|
|
95
|
+
}
|
|
87
96
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
97
|
+
pozSuhostoiFilter<T extends BaseAnimal>(animals: T[]): T[] {
|
|
98
|
+
const result = animals.filter((animal) => {
|
|
99
|
+
const genderOk = this.genderFilter(animal, ANIMAL_GENDER_ENUM.cow);
|
|
100
|
+
const statusOk = this.statusFilter(animal, [this.status.DRY]);
|
|
101
|
+
const ageOk = this.ageFilter(animal, this.defaultCowAge);
|
|
93
102
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
103
|
+
return genderOk && statusOk && ageOk && animal;
|
|
104
|
+
});
|
|
105
|
+
return result;
|
|
106
|
+
}
|
|
98
107
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
108
|
+
transferOutFilter<T extends BaseAnimal>(animals: T[]): T[] {
|
|
109
|
+
return animals;
|
|
110
|
+
}
|
|
102
111
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
112
|
+
perevodFilter<T extends BaseAnimal>(animals: T[]) {
|
|
113
|
+
return animals;
|
|
114
|
+
}
|
|
106
115
|
|
|
107
|
-
|
|
108
|
-
|
|
116
|
+
filter<T extends BaseAnimal>(animals: T[], eventType: EVENT_TYPES_ENUM) {
|
|
117
|
+
switch (eventType) {
|
|
118
|
+
case EVENT_TYPES_ENUM.abort:
|
|
119
|
+
return this.abortFilter(animals);
|
|
120
|
+
case EVENT_TYPES_ENUM.neosem:
|
|
121
|
+
return this.neosemFilter(animals);
|
|
122
|
+
case EVENT_TYPES_ENUM.osemenenie:
|
|
123
|
+
return this.osemenenieFilter(animals);
|
|
124
|
+
case EVENT_TYPES_ENUM.otel:
|
|
125
|
+
return this.otelFilter(animals);
|
|
126
|
+
case EVENT_TYPES_ENUM.recheck:
|
|
127
|
+
return this.recheckFilter(animals);
|
|
128
|
+
case EVENT_TYPES_ENUM.suhostoi:
|
|
129
|
+
return this.suhostoiFilter(animals);
|
|
130
|
+
case EVENT_TYPES_ENUM.pozSuhostoi:
|
|
131
|
+
return this.pozSuhostoiFilter(animals);
|
|
132
|
+
case EVENT_TYPES_ENUM.perevod:
|
|
133
|
+
return this.perevodFilter(animals);
|
|
134
|
+
case EVENT_TYPES_ENUM.transferOut:
|
|
135
|
+
return this.transferOutFilter(animals);
|
|
136
|
+
default:
|
|
137
|
+
throw new Error(`AnimalForEventFilter.filter.${eventType} not implemented`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
109
140
|
}
|
|
110
141
|
|
|
111
142
|
export function filter<T extends BaseAnimal>(animals: T[], eventType: EVENT_TYPES_ENUM) {
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
[EVENT_TYPES_ENUM.neosem]: neosemFilter,
|
|
115
|
-
[EVENT_TYPES_ENUM.osemenenie]: osemenenieFilter,
|
|
116
|
-
[EVENT_TYPES_ENUM.otel]: otelFilter,
|
|
117
|
-
[EVENT_TYPES_ENUM.recheck]: recheckFilter,
|
|
118
|
-
[EVENT_TYPES_ENUM.suhostoi]: suhostoiFilter,
|
|
119
|
-
[EVENT_TYPES_ENUM.pozSuhostoi]: pozSuhostoiFilter,
|
|
120
|
-
[EVENT_TYPES_ENUM.perevod]: perevodFilter,
|
|
121
|
-
[EVENT_TYPES_ENUM.transferOut]: transferOutFilter,
|
|
122
|
-
};
|
|
123
|
-
try {
|
|
124
|
-
const result = filters[eventType](animals);
|
|
125
|
-
return result;
|
|
126
|
-
} catch (err) {
|
|
127
|
-
throw new Error(`AnimalForEventFilter.filter.${eventType} not implemented`);
|
|
128
|
-
}
|
|
143
|
+
const f = new AnimalEcentFilter();
|
|
144
|
+
return f.filter(animals, eventType);
|
|
129
145
|
}
|