OLD | NEW |
| (Empty) |
1 #!/usr/bin/env python | |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 | |
6 import argparse | |
7 import csv | |
8 import json | |
9 import os | |
10 import shutil | |
11 import sys | |
12 | |
13 def main(argv): | |
14 parser = argparse.ArgumentParser() | |
15 parser.add_argument('--out', required=True) | |
16 parser.add_argument('--marked', required=True) | |
17 parser.add_argument('--features', required=True) | |
18 options = parser.parse_args(argv) | |
19 | |
20 marked = None | |
21 with open(options.marked) as markedin: | |
22 marked = json.load(markedin) | |
23 | |
24 features = None | |
25 with open(options.features) as features: | |
26 features = json.load(features) | |
27 | |
28 markedMap = dict() | |
29 # good: | |
30 # -1 error | |
31 # 0 bad | |
32 # 1 good | |
33 # 2 good w/error | |
34 for m in marked: | |
35 if not 'good' in m: | |
36 continue | |
37 if m['good'] < 0: | |
38 continue | |
39 markedMap[m['url']] = m | |
40 | |
41 merged = [] | |
42 for f in features: | |
43 url = f['url'] | |
44 if not url in markedMap: | |
45 continue | |
46 merged.append(map(float, [0 if markedMap[url]['good'] == 0 else 1] + f['feat
ures'][1::2])) | |
47 | |
48 header = ['good'] + map(str, features[0]['features'][::2]) | |
49 | |
50 with open(options.out, 'w') as csvfile: | |
51 writer = csv.writer(csvfile) | |
52 writer.writerow(header) | |
53 for e in merged: | |
54 writer.writerow(e) | |
55 | |
56 return 0 | |
57 | |
58 if __name__ == '__main__': | |
59 sys.exit(main(sys.argv[1:])) | |
60 | |
OLD | NEW |