-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshared.py
More file actions
39 lines (28 loc) · 1.13 KB
/
shared.py
File metadata and controls
39 lines (28 loc) · 1.13 KB
1
2
3
4
5
6
7
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
34
35
36
37
38
39
import pandas as pd
# Category mapping
PATH_PACKAGE_CATEGORY_MAPPING = '/path/to/package_category_mapping.pkl.gz'
category_mapping = pd.read_pickle(PATH_PACKAGE_CATEGORY_MAPPING, compression='gzip')
category_mapping = pd.Series(category_mapping.Category.values, index=category_mapping.PackageName).to_dict()
# Filter active
def filter_active(active):
has_summary = {}
package_group_count = {}
for n in active:
pn = n['packageName']
gk = n['groupKeyCompat'] if 'groupKeyCompat' in n else ''
key = pn + gk
if key not in has_summary:
has_summary[key] = False
package_group_count[key] = 0
if n['isGroupSummaryCompat']:
has_summary[key] = True
package_group_count[key] = package_group_count[key] + 1
result = []
for n in active:
pn = n['packageName']
gk = n['groupKeyCompat'] if 'groupKeyCompat' in n else ''
key = pn + gk
is_summary = n['isGroupSummaryCompat']
if (package_group_count[key] == 1) or (has_summary[key] and is_summary) or (not has_summary[key]):
result.append(n)
return result