Total Complexity | 6 |
Total Lines | 39 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | 1 | class Unit(): |
|
2 | |||
3 | |||
4 | 1 | @staticmethod |
|
5 | def aggregate(judgments, config): |
||
6 | """ aggregate the judgments of a unit """ |
||
7 | 1 | agg = {} |
|
8 | 1 | for col in config.input.values(): |
|
9 | # for each input column the first value is taken. |
||
10 | # all rows have the same value for each unit. |
||
11 | 1 | agg[col] = 'first' |
|
12 | 1 | for col in config.output.values(): |
|
13 | # each output column dict is summed |
||
14 | 1 | agg[col] = 'sum' |
|
15 | 1 | agg['job'] = 'first' |
|
16 | 1 | agg['worker'] = 'count' |
|
17 | 1 | agg['duration'] = 'mean' |
|
18 | |||
19 | 1 | units = judgments.groupby('unit').agg(agg) |
|
20 | |||
21 | # |
||
22 | # get unit metrics |
||
23 | # |
||
24 | # for each vector in the unit get the unit metrics |
||
25 | 1 | units = units.apply(lambda row: Unit.get_metrics(row, config), axis=1) |
|
26 | |||
27 | # sort columns |
||
28 | 1 | units = units.reindex(sorted(units.columns), axis=1) |
|
29 | |||
30 | 1 | return units |
|
31 | |||
32 | 1 | @staticmethod |
|
33 | def get_metrics(row, config): |
||
34 | """ count the number of annotations for each unit """ |
||
35 | 1 | for col in config.output.values(): |
|
36 | 1 | row[col+'.unique_annotations'] = len(row[col]) |
|
37 | 1 | row[col+'.annotations'] = sum(row[col].values()) |
|
38 | return row |
||
39 |