@molochko-dev/data 1.4.29 → 1.4.31
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/enums.d.ts +3 -2
- package/dist/enums.js +3 -2
- package/dist/event/animal-event-filter.d.ts +2 -18
- package/dist/event/animal-event-filter.js +94 -157
- package/dist/event/index.d.ts +2 -2
- package/dist/event/index.js +2 -2
- package/package.json +1 -1
- package/src/enums.ts +3 -2
- package/src/event/animal-event-filter.ts +98 -160
- package/src/event/index.ts +2 -2
package/dist/enums.d.ts
CHANGED
|
@@ -109,7 +109,8 @@ export declare enum ANIMAL_STATUS_ENUM {
|
|
|
109
109
|
dnb = "dnb",
|
|
110
110
|
sold = "sold",
|
|
111
111
|
died = "died",
|
|
112
|
-
theft = "theft"
|
|
112
|
+
theft = "theft",
|
|
113
|
+
transferout = "transferout"
|
|
113
114
|
}
|
|
114
115
|
export declare const ANIMAL_STATUS_AS_OBJECT: {
|
|
115
116
|
[key: string]: string;
|
|
@@ -186,7 +187,7 @@ export declare const TRANSFEROUT_TYPES_AS_OBJECT: {
|
|
|
186
187
|
export declare enum TRANSFEROUT_REASON_ENUM {
|
|
187
188
|
leikoz = "leikoz",
|
|
188
189
|
tuberkulez = "tuberkulez",
|
|
189
|
-
|
|
190
|
+
klostirikoz = "klostirikoz",
|
|
190
191
|
nekrobacilez = "nekrobacilez",
|
|
191
192
|
aktinomikoz = "aktinomikoz",
|
|
192
193
|
ginekologic = "ginekologic",
|
package/dist/enums.js
CHANGED
|
@@ -105,7 +105,8 @@ var ANIMAL_STATUS_ENUM;
|
|
|
105
105
|
ANIMAL_STATUS_ENUM["dnb"] = "dnb";
|
|
106
106
|
ANIMAL_STATUS_ENUM["sold"] = "sold";
|
|
107
107
|
ANIMAL_STATUS_ENUM["died"] = "died";
|
|
108
|
-
ANIMAL_STATUS_ENUM["theft"] = "theft";
|
|
108
|
+
ANIMAL_STATUS_ENUM["theft"] = "theft";
|
|
109
|
+
ANIMAL_STATUS_ENUM["transferout"] = "transferout"; // выбыла
|
|
109
110
|
})(ANIMAL_STATUS_ENUM = exports.ANIMAL_STATUS_ENUM || (exports.ANIMAL_STATUS_ENUM = {}));
|
|
110
111
|
exports.ANIMAL_STATUS_AS_OBJECT = (0, helpers_1.enumToObject)(ANIMAL_STATUS_ENUM);
|
|
111
112
|
// heifer, bred, open, fresh
|
|
@@ -175,7 +176,7 @@ var TRANSFEROUT_REASON_ENUM;
|
|
|
175
176
|
(function (TRANSFEROUT_REASON_ENUM) {
|
|
176
177
|
TRANSFEROUT_REASON_ENUM["leikoz"] = "leikoz";
|
|
177
178
|
TRANSFEROUT_REASON_ENUM["tuberkulez"] = "tuberkulez";
|
|
178
|
-
TRANSFEROUT_REASON_ENUM["
|
|
179
|
+
TRANSFEROUT_REASON_ENUM["klostirikoz"] = "klostirikoz";
|
|
179
180
|
TRANSFEROUT_REASON_ENUM["nekrobacilez"] = "nekrobacilez";
|
|
180
181
|
TRANSFEROUT_REASON_ENUM["aktinomikoz"] = "aktinomikoz";
|
|
181
182
|
TRANSFEROUT_REASON_ENUM["ginekologic"] = "ginekologic";
|
|
@@ -1,19 +1,3 @@
|
|
|
1
1
|
import { IAnimal } from '../types';
|
|
2
|
-
import {
|
|
3
|
-
export declare
|
|
4
|
-
animals: IAnimal[];
|
|
5
|
-
eventType: EVENT_TYPES_ENUM;
|
|
6
|
-
constructor(animals: IAnimal[], eventType: EVENT_TYPES_ENUM);
|
|
7
|
-
genderFilter(animal: IAnimal, availableGender: ANIMAL_GENDER_ENUM): Boolean;
|
|
8
|
-
ageFilter(animal: IAnimal, availableMinAge: number): Boolean;
|
|
9
|
-
statusFilter(animal: IAnimal, availableStatuses: ANIMAL_STATUS_ENUM[]): Boolean;
|
|
10
|
-
abortFilter(): IAnimal[];
|
|
11
|
-
neosemFilter(): IAnimal[];
|
|
12
|
-
osemenenieFilter(): IAnimal[];
|
|
13
|
-
otelFilter(): IAnimal[];
|
|
14
|
-
recheckFilter(): IAnimal[];
|
|
15
|
-
suhostoiFilter(): IAnimal[];
|
|
16
|
-
pozSuhostoiFilter(): IAnimal[];
|
|
17
|
-
outputFilter(): IAnimal[];
|
|
18
|
-
filter(): IAnimal[];
|
|
19
|
-
}
|
|
2
|
+
import { EVENT_TYPES_ENUM } from '../enums';
|
|
3
|
+
export declare function filter(animals: IAnimal[], eventType: EVENT_TYPES_ENUM): IAnimal[];
|
|
@@ -1,168 +1,105 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.filter = void 0;
|
|
4
4
|
const enums_1 = require("../enums");
|
|
5
5
|
const date_1 = require("../helpers/date");
|
|
6
6
|
const status = enums_1.ANIMAL_STATUS_ENUM;
|
|
7
7
|
const defaultCowAge = 12;
|
|
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
|
-
const
|
|
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
|
-
if (genderOk && statusOk && ageOk) {
|
|
60
|
-
result.push(animal);
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
return result;
|
|
64
|
-
}
|
|
65
|
-
otelFilter() {
|
|
66
|
-
const result = [];
|
|
67
|
-
this.animals.forEach(animal => {
|
|
68
|
-
let genderOk = false;
|
|
69
|
-
let statusOk = false;
|
|
70
|
-
let ageOk = false;
|
|
71
|
-
if (this.genderFilter(animal, enums_1.ANIMAL_GENDER_ENUM.cow)) {
|
|
72
|
-
genderOk = true;
|
|
73
|
-
}
|
|
74
|
-
if (this.statusFilter(animal, [status.dry, status.pregnant])) {
|
|
75
|
-
statusOk = true;
|
|
76
|
-
}
|
|
77
|
-
if (this.ageFilter(animal, defaultCowAge)) {
|
|
78
|
-
ageOk = true;
|
|
79
|
-
}
|
|
80
|
-
if (genderOk && statusOk && ageOk) {
|
|
81
|
-
result.push(animal);
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
return result;
|
|
85
|
-
}
|
|
86
|
-
recheckFilter() {
|
|
87
|
-
const result = [];
|
|
88
|
-
this.animals.forEach(animal => {
|
|
89
|
-
let genderOk = false;
|
|
90
|
-
let statusOk = false;
|
|
91
|
-
let ageOk = false;
|
|
92
|
-
if (this.genderFilter(animal, enums_1.ANIMAL_GENDER_ENUM.cow)) {
|
|
93
|
-
genderOk = true;
|
|
94
|
-
}
|
|
95
|
-
if (this.ageFilter(animal, defaultCowAge)) {
|
|
96
|
-
ageOk = true;
|
|
97
|
-
}
|
|
98
|
-
let availableStatus = [status.bred, status.pregnant, status.dry];
|
|
99
|
-
if (animal.animalEventRelation) {
|
|
100
|
-
const previousRechecks = animal.animalEventRelation.filter((row) => {
|
|
101
|
-
return row.eventDetail.type === enums_1.EVENT_TYPES_ENUM.recheck;
|
|
102
|
-
});
|
|
103
|
-
if (previousRechecks.length == 0) {
|
|
104
|
-
availableStatus = [status.bred];
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
if (this.statusFilter(animal, availableStatus)) {
|
|
108
|
-
statusOk = true;
|
|
109
|
-
}
|
|
110
|
-
if (genderOk && statusOk && ageOk) {
|
|
111
|
-
result.push(animal);
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
return result;
|
|
115
|
-
}
|
|
116
|
-
suhostoiFilter() {
|
|
117
|
-
return this.abortFilter();
|
|
118
|
-
}
|
|
119
|
-
pozSuhostoiFilter() {
|
|
120
|
-
const result = [];
|
|
121
|
-
this.animals.forEach(animal => {
|
|
122
|
-
let genderOk = false;
|
|
123
|
-
let statusOk = false;
|
|
124
|
-
let ageOk = false;
|
|
125
|
-
if (this.genderFilter(animal, enums_1.ANIMAL_GENDER_ENUM.cow)) {
|
|
126
|
-
genderOk = true;
|
|
127
|
-
}
|
|
128
|
-
if (this.statusFilter(animal, [status.dry])) {
|
|
129
|
-
statusOk = true;
|
|
130
|
-
}
|
|
131
|
-
if (this.ageFilter(animal, defaultCowAge)) {
|
|
132
|
-
ageOk = true;
|
|
133
|
-
}
|
|
134
|
-
if (genderOk && statusOk && ageOk) {
|
|
135
|
-
result.push(animal);
|
|
8
|
+
/*
|
|
9
|
+
|
|
10
|
+
const filtered = filter(animals, eventType)
|
|
11
|
+
|
|
12
|
+
*/
|
|
13
|
+
function genderFilter(animal, availableGender) {
|
|
14
|
+
return animal.gender === availableGender;
|
|
15
|
+
}
|
|
16
|
+
function ageFilter(animal, availableMinAge /*month*/) {
|
|
17
|
+
const months = (0, date_1.getMonthFromDate)(animal.dob.toISOString());
|
|
18
|
+
return months > availableMinAge;
|
|
19
|
+
}
|
|
20
|
+
function statusFilter(animal, availableStatuses) {
|
|
21
|
+
return availableStatuses.includes(animal.status);
|
|
22
|
+
}
|
|
23
|
+
function abortFilter(animals) {
|
|
24
|
+
const result = animals.filter(animal => genderFilter(animal, enums_1.ANIMAL_GENDER_ENUM.cow));
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
function neosemFilter(animals) {
|
|
28
|
+
return abortFilter(animals);
|
|
29
|
+
}
|
|
30
|
+
function osemenenieFilter(animals) {
|
|
31
|
+
const result = animals.filter(animal => {
|
|
32
|
+
const genderOk = genderFilter(animal, enums_1.ANIMAL_GENDER_ENUM.cow);
|
|
33
|
+
const statusOk = statusFilter(animal, [status.heifer, status.bred, status.open, status.fresh]);
|
|
34
|
+
const ageOk = ageFilter(animal, defaultCowAge);
|
|
35
|
+
return genderOk && statusOk && ageOk && animal;
|
|
36
|
+
});
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
function otelFilter(animals) {
|
|
40
|
+
const result = animals.filter(animal => {
|
|
41
|
+
const genderOk = genderFilter(animal, enums_1.ANIMAL_GENDER_ENUM.cow);
|
|
42
|
+
const statusOk = statusFilter(animal, [status.dry, status.pregnant]);
|
|
43
|
+
const ageOk = ageFilter(animal, defaultCowAge);
|
|
44
|
+
return genderOk && statusOk && ageOk && animal;
|
|
45
|
+
});
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
function recheckFilter(animals) {
|
|
49
|
+
const result = animals.filter(animal => {
|
|
50
|
+
const genderOk = genderFilter(animal, enums_1.ANIMAL_GENDER_ENUM.cow);
|
|
51
|
+
const ageOk = ageFilter(animal, defaultCowAge);
|
|
52
|
+
let availableStatus = [status.bred, status.pregnant, status.dry];
|
|
53
|
+
if (animal.animalEventRelation) {
|
|
54
|
+
const previousRechecks = animal.animalEventRelation.filter((row) => {
|
|
55
|
+
return row.eventDetail.type === enums_1.EVENT_TYPES_ENUM.recheck;
|
|
56
|
+
});
|
|
57
|
+
if (previousRechecks.length == 0) {
|
|
58
|
+
availableStatus = [status.bred];
|
|
136
59
|
}
|
|
137
|
-
}
|
|
60
|
+
}
|
|
61
|
+
const statusOk = statusFilter(animal, availableStatus);
|
|
62
|
+
return genderOk && statusOk && ageOk && animal;
|
|
63
|
+
});
|
|
64
|
+
console.info('result', result);
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
function suhostoiFilter(animals) {
|
|
68
|
+
return abortFilter(animals);
|
|
69
|
+
}
|
|
70
|
+
function pozSuhostoiFilter(animals) {
|
|
71
|
+
const result = animals.filter(animal => {
|
|
72
|
+
const genderOk = genderFilter(animal, enums_1.ANIMAL_GENDER_ENUM.cow);
|
|
73
|
+
const statusOk = statusFilter(animal, [status.dry]);
|
|
74
|
+
const ageOk = ageFilter(animal, defaultCowAge);
|
|
75
|
+
return genderOk && statusOk && ageOk && animal;
|
|
76
|
+
});
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
function transferOutFilter(animals) {
|
|
80
|
+
return animals;
|
|
81
|
+
}
|
|
82
|
+
function perevodFilter(animals) {
|
|
83
|
+
return animals;
|
|
84
|
+
}
|
|
85
|
+
function filter(animals, eventType) {
|
|
86
|
+
const filters = {
|
|
87
|
+
[enums_1.EVENT_TYPES_ENUM.abort]: abortFilter,
|
|
88
|
+
[enums_1.EVENT_TYPES_ENUM.neosem]: neosemFilter,
|
|
89
|
+
[enums_1.EVENT_TYPES_ENUM.osemenenie]: osemenenieFilter,
|
|
90
|
+
[enums_1.EVENT_TYPES_ENUM.otel]: otelFilter,
|
|
91
|
+
[enums_1.EVENT_TYPES_ENUM.recheck]: recheckFilter,
|
|
92
|
+
[enums_1.EVENT_TYPES_ENUM.suhostoi]: suhostoiFilter,
|
|
93
|
+
[enums_1.EVENT_TYPES_ENUM.pozSuhostoi]: pozSuhostoiFilter,
|
|
94
|
+
[enums_1.EVENT_TYPES_ENUM.perevod]: perevodFilter,
|
|
95
|
+
[enums_1.EVENT_TYPES_ENUM.transferOut]: transferOutFilter
|
|
96
|
+
};
|
|
97
|
+
try {
|
|
98
|
+
const result = filters[eventType](animals);
|
|
138
99
|
return result;
|
|
139
100
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
filter() {
|
|
144
|
-
switch (this.eventType) {
|
|
145
|
-
case enums_1.EVENT_TYPES_ENUM.abort:
|
|
146
|
-
return this.abortFilter();
|
|
147
|
-
case enums_1.EVENT_TYPES_ENUM.neosem:
|
|
148
|
-
return this.neosemFilter();
|
|
149
|
-
case enums_1.EVENT_TYPES_ENUM.osemenenie:
|
|
150
|
-
return this.osemenenieFilter();
|
|
151
|
-
case enums_1.EVENT_TYPES_ENUM.otel:
|
|
152
|
-
return this.otelFilter();
|
|
153
|
-
case enums_1.EVENT_TYPES_ENUM.recheck:
|
|
154
|
-
return this.recheckFilter();
|
|
155
|
-
case enums_1.EVENT_TYPES_ENUM.suhostoi:
|
|
156
|
-
return this.suhostoiFilter();
|
|
157
|
-
case enums_1.EVENT_TYPES_ENUM.pozSuhostoi:
|
|
158
|
-
return this.pozSuhostoiFilter();
|
|
159
|
-
case enums_1.EVENT_TYPES_ENUM.perevod:
|
|
160
|
-
return this.animals;
|
|
161
|
-
case enums_1.EVENT_TYPES_ENUM.transferOut:
|
|
162
|
-
return this.outputFilter();
|
|
163
|
-
default:
|
|
164
|
-
throw new Error(`AnimalForEventFilter.filter.${this.eventType} not implemented`);
|
|
165
|
-
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
throw new Error(`AnimalForEventFilter.filter.${eventType} not implemented`);
|
|
166
103
|
}
|
|
167
104
|
}
|
|
168
|
-
exports.
|
|
105
|
+
exports.filter = filter;
|
package/dist/event/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { filter as _filter } from './animal-event-filter';
|
|
2
|
+
export { _filter as filter };
|
package/dist/event/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.filter = void 0;
|
|
4
4
|
const animal_event_filter_1 = require("./animal-event-filter");
|
|
5
|
-
Object.defineProperty(exports, "
|
|
5
|
+
Object.defineProperty(exports, "filter", { enumerable: true, get: function () { return animal_event_filter_1.filter; } });
|
package/package.json
CHANGED
package/src/enums.ts
CHANGED
|
@@ -113,7 +113,8 @@ export enum ANIMAL_STATUS_ENUM {
|
|
|
113
113
|
dnb = 'dnb', // Брак
|
|
114
114
|
sold = 'sold', // Продана
|
|
115
115
|
died = 'died', // Сдохла
|
|
116
|
-
theft = 'theft' // Кража
|
|
116
|
+
theft = 'theft', // Кража
|
|
117
|
+
transferout = 'transferout' // выбыла
|
|
117
118
|
}
|
|
118
119
|
|
|
119
120
|
export const ANIMAL_STATUS_AS_OBJECT = enumToObject(ANIMAL_STATUS_ENUM);
|
|
@@ -191,7 +192,7 @@ export const TRANSFEROUT_TYPES_AS_OBJECT = enumToObject(TRANSFEROUT_TYPES_ENUM);
|
|
|
191
192
|
export enum TRANSFEROUT_REASON_ENUM {
|
|
192
193
|
leikoz = 'leikoz', // Лейкоз
|
|
193
194
|
tuberkulez = 'tuberkulez', // Туберкулез
|
|
194
|
-
|
|
195
|
+
klostirikoz = 'klostirikoz', // Клостридиоз
|
|
195
196
|
nekrobacilez = 'nekrobacilez', // Некробациллез
|
|
196
197
|
aktinomikoz = 'aktinomikoz', // Актиномикоз)
|
|
197
198
|
ginekologic = 'ginekologic', // Гинекологические заболевания
|
|
@@ -6,184 +6,122 @@ const status = ANIMAL_STATUS_ENUM
|
|
|
6
6
|
|
|
7
7
|
const defaultCowAge = 12
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
animals: IAnimal[]
|
|
11
|
-
eventType: EVENT_TYPES_ENUM
|
|
9
|
+
/*
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
this.animals = animals
|
|
15
|
-
this.eventType = eventType
|
|
16
|
-
}
|
|
11
|
+
const filtered = filter(animals, eventType)
|
|
17
12
|
|
|
18
|
-
|
|
19
|
-
if (animal.gender === availableGender) {
|
|
20
|
-
return true
|
|
21
|
-
}
|
|
22
|
-
return false
|
|
23
|
-
}
|
|
13
|
+
*/
|
|
24
14
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return true
|
|
29
|
-
}
|
|
30
|
-
return false
|
|
31
|
-
}
|
|
15
|
+
function genderFilter (animal: IAnimal, availableGender: ANIMAL_GENDER_ENUM): Boolean {
|
|
16
|
+
return animal.gender === availableGender
|
|
17
|
+
}
|
|
32
18
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return false
|
|
38
|
-
}
|
|
19
|
+
function ageFilter (animal: IAnimal, availableMinAge: number /*month*/): Boolean {
|
|
20
|
+
const months = getMonthFromDate(animal.dob.toISOString())
|
|
21
|
+
return months > availableMinAge
|
|
22
|
+
}
|
|
39
23
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (this.genderFilter(animal, ANIMAL_GENDER_ENUM.cow)) {
|
|
44
|
-
result.push(animal)
|
|
45
|
-
}
|
|
46
|
-
})
|
|
47
|
-
return result
|
|
48
|
-
}
|
|
24
|
+
function statusFilter (animal: IAnimal, availableStatuses: ANIMAL_STATUS_ENUM[]): Boolean {
|
|
25
|
+
return availableStatuses.includes(animal.status)
|
|
26
|
+
}
|
|
49
27
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
28
|
+
function abortFilter (animals: IAnimal[]): IAnimal[] {
|
|
29
|
+
const result: IAnimal[] = animals.filter(animal => genderFilter(animal, ANIMAL_GENDER_ENUM.cow))
|
|
30
|
+
return result
|
|
31
|
+
}
|
|
53
32
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
let genderOk = false
|
|
58
|
-
let statusOk = false
|
|
59
|
-
let ageOk = false
|
|
33
|
+
function neosemFilter (animals: IAnimal[]): IAnimal[] {
|
|
34
|
+
return abortFilter(animals)
|
|
35
|
+
}
|
|
60
36
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
if (this.ageFilter(animal, defaultCowAge)) {
|
|
68
|
-
ageOk = true
|
|
69
|
-
}
|
|
70
|
-
if (genderOk && statusOk && ageOk) {
|
|
71
|
-
result.push(animal)
|
|
72
|
-
}
|
|
73
|
-
})
|
|
74
|
-
return result
|
|
75
|
-
}
|
|
37
|
+
function osemenenieFilter(animals: IAnimal[]): IAnimal[] {
|
|
38
|
+
const result: IAnimal[] = animals.filter(animal => {
|
|
39
|
+
const genderOk = genderFilter(animal, ANIMAL_GENDER_ENUM.cow)
|
|
40
|
+
const statusOk = statusFilter(animal, [status.heifer, status.bred, status.open, status.fresh])
|
|
41
|
+
const ageOk = ageFilter(animal, defaultCowAge)
|
|
76
42
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
this.animals.forEach(animal => {
|
|
80
|
-
let genderOk = false
|
|
81
|
-
let statusOk = false
|
|
82
|
-
let ageOk = false
|
|
43
|
+
return genderOk && statusOk && ageOk && animal
|
|
44
|
+
})
|
|
83
45
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
if (this.statusFilter(animal, [status.dry, status.pregnant])) {
|
|
88
|
-
statusOk = true
|
|
89
|
-
}
|
|
90
|
-
if (this.ageFilter(animal, defaultCowAge)) {
|
|
91
|
-
ageOk = true
|
|
92
|
-
}
|
|
93
|
-
if (genderOk && statusOk && ageOk) {
|
|
94
|
-
result.push(animal)
|
|
95
|
-
}
|
|
96
|
-
})
|
|
97
|
-
return result
|
|
98
|
-
}
|
|
46
|
+
return result
|
|
47
|
+
}
|
|
99
48
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
let ageOk = false
|
|
49
|
+
function otelFilter (animals: IAnimal[]): IAnimal[] {
|
|
50
|
+
const result: IAnimal[] = animals.filter(animal => {
|
|
51
|
+
const genderOk = genderFilter(animal, ANIMAL_GENDER_ENUM.cow)
|
|
52
|
+
const statusOk = statusFilter(animal, [status.dry, status.pregnant])
|
|
53
|
+
const ageOk = ageFilter(animal, defaultCowAge)
|
|
106
54
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
ageOk = true
|
|
112
|
-
}
|
|
55
|
+
return genderOk && statusOk && ageOk && animal
|
|
56
|
+
})
|
|
57
|
+
return result
|
|
58
|
+
}
|
|
113
59
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
60
|
+
function recheckFilter (animals: IAnimal[]): IAnimal[] {
|
|
61
|
+
const result: IAnimal[] = animals.filter(animal => {
|
|
62
|
+
const genderOk = genderFilter(animal, ANIMAL_GENDER_ENUM.cow)
|
|
63
|
+
const ageOk = ageFilter(animal, defaultCowAge)
|
|
64
|
+
|
|
65
|
+
let availableStatus = [status.bred, status.pregnant, status.dry]
|
|
66
|
+
if (animal.animalEventRelation) {
|
|
67
|
+
const previousRechecks = animal.animalEventRelation.filter((row) => {
|
|
68
|
+
return row.eventDetail.type === EVENT_TYPES_ENUM.recheck
|
|
69
|
+
})
|
|
70
|
+
if (previousRechecks.length == 0) {
|
|
71
|
+
availableStatus = [status.bred]
|
|
122
72
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
73
|
+
}
|
|
74
|
+
const statusOk = statusFilter(animal, availableStatus)
|
|
75
|
+
|
|
76
|
+
return genderOk && statusOk && ageOk && animal
|
|
77
|
+
})
|
|
78
|
+
console.info('result', result)
|
|
79
|
+
return result
|
|
80
|
+
}
|
|
132
81
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
82
|
+
function suhostoiFilter (animals: IAnimal[]): IAnimal[] {
|
|
83
|
+
return abortFilter(animals)
|
|
84
|
+
}
|
|
136
85
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
let ageOk = false
|
|
86
|
+
function pozSuhostoiFilter (animals: IAnimal[]): IAnimal[] {
|
|
87
|
+
const result: IAnimal[] = animals.filter(animal => {
|
|
88
|
+
const genderOk = genderFilter(animal, ANIMAL_GENDER_ENUM.cow)
|
|
89
|
+
const statusOk = statusFilter(animal, [status.dry])
|
|
90
|
+
const ageOk = ageFilter(animal, defaultCowAge)
|
|
143
91
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
statusOk = true
|
|
149
|
-
}
|
|
150
|
-
if (this.ageFilter(animal, defaultCowAge)) {
|
|
151
|
-
ageOk = true
|
|
152
|
-
}
|
|
153
|
-
if (genderOk && statusOk && ageOk) {
|
|
154
|
-
result.push(animal)
|
|
155
|
-
}
|
|
156
|
-
})
|
|
157
|
-
return result
|
|
158
|
-
}
|
|
92
|
+
return genderOk && statusOk && ageOk && animal
|
|
93
|
+
})
|
|
94
|
+
return result
|
|
95
|
+
}
|
|
159
96
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
97
|
+
function transferOutFilter (animals: IAnimal[]): IAnimal[] {
|
|
98
|
+
return animals
|
|
99
|
+
}
|
|
163
100
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
case EVENT_TYPES_ENUM.osemenenie:
|
|
171
|
-
return this.osemenenieFilter()
|
|
172
|
-
case EVENT_TYPES_ENUM.otel:
|
|
173
|
-
return this.otelFilter()
|
|
174
|
-
case EVENT_TYPES_ENUM.recheck:
|
|
175
|
-
return this.recheckFilter()
|
|
176
|
-
case EVENT_TYPES_ENUM.suhostoi:
|
|
177
|
-
return this.suhostoiFilter()
|
|
178
|
-
case EVENT_TYPES_ENUM.pozSuhostoi:
|
|
179
|
-
return this.pozSuhostoiFilter()
|
|
180
|
-
case EVENT_TYPES_ENUM.perevod:
|
|
181
|
-
return this.animals
|
|
182
|
-
case EVENT_TYPES_ENUM.transferOut:
|
|
183
|
-
return this.outputFilter()
|
|
184
|
-
default:
|
|
185
|
-
throw new Error(`AnimalForEventFilter.filter.${this.eventType} not implemented`)
|
|
186
|
-
}
|
|
187
|
-
}
|
|
101
|
+
function perevodFilter (animals: IAnimal[]) {
|
|
102
|
+
return animals
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
interface IFilters {
|
|
106
|
+
[key: string]: (animals: IAnimal[]) => IAnimal[]
|
|
188
107
|
}
|
|
189
108
|
|
|
109
|
+
export function filter (animals: IAnimal[], eventType: EVENT_TYPES_ENUM) {
|
|
110
|
+
const filters: IFilters = {
|
|
111
|
+
[EVENT_TYPES_ENUM.abort]: abortFilter,
|
|
112
|
+
[EVENT_TYPES_ENUM.neosem]: neosemFilter,
|
|
113
|
+
[EVENT_TYPES_ENUM.osemenenie]: osemenenieFilter,
|
|
114
|
+
[EVENT_TYPES_ENUM.otel]: otelFilter,
|
|
115
|
+
[EVENT_TYPES_ENUM.recheck]: recheckFilter,
|
|
116
|
+
[EVENT_TYPES_ENUM.suhostoi]: suhostoiFilter,
|
|
117
|
+
[EVENT_TYPES_ENUM.pozSuhostoi]: pozSuhostoiFilter,
|
|
118
|
+
[EVENT_TYPES_ENUM.perevod]: perevodFilter,
|
|
119
|
+
[EVENT_TYPES_ENUM.transferOut]: transferOutFilter
|
|
120
|
+
}
|
|
121
|
+
try {
|
|
122
|
+
const result = filters[eventType](animals)
|
|
123
|
+
return result
|
|
124
|
+
} catch (err) {
|
|
125
|
+
throw new Error(`AnimalForEventFilter.filter.${eventType} not implemented`)
|
|
126
|
+
}
|
|
127
|
+
}
|
package/src/event/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { filter as _filter } from './animal-event-filter'
|
|
2
2
|
|
|
3
|
-
export {
|
|
3
|
+
export { _filter as filter }
|