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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « quick_score.py ('k') | write_html.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: write_features_csv.py
diff --git a/write_features_csv.py b/write_features_csv.py
new file mode 100755
index 0000000000000000000000000000000000000000..679ff3fffc6e7d35ac163687dfc6a644c7278ea3
--- /dev/null
+++ b/write_features_csv.py
@@ -0,0 +1,60 @@
+#!/usr/bin/env python
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import argparse
+import csv
+import json
+import os
+import shutil
+import sys
+
+def main(argv):
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--out', required=True)
+ parser.add_argument('--marked', required=True)
+ parser.add_argument('--features', required=True)
+ options = parser.parse_args(argv)
+
+ marked = None
+ with open(options.marked) as markedin:
+ marked = json.load(markedin)
+
+ features = None
+ with open(options.features) as features:
+ features = json.load(features)
+
+ markedMap = dict()
+ # good:
+ # -1 error
+ # 0 bad
+ # 1 good
+ # 2 good w/error
+ for m in marked:
+ if not 'good' in m:
+ continue
+ if m['good'] < 0:
+ continue
+ markedMap[m['url']] = m
+
+ merged = []
+ for f in features:
+ url = f['url']
+ if not url in markedMap:
+ continue
+ merged.append(map(float, [0 if markedMap[url]['good'] == 0 else 1] + f['features'][1::2]))
+
+ header = ['good'] + map(str, features[0]['features'][::2])
+
+ with open(options.out, 'w') as csvfile:
+ writer = csv.writer(csvfile)
+ writer.writerow(header)
+ for e in merged:
+ writer.writerow(e)
+
+ return 0
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv[1:]))
+
« 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