Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(278)

Side by Side Diff: write_features_csv.py

Issue 1289123002: Merge branch 'master' into heuristics Base URL: git@github.com:chromium/dom-distiller.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « quick_score.py ('k') | write_html.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
OLDNEW
« no previous file with comments | « quick_score.py ('k') | write_html.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698