From 46db8bd7705cd20ef2224c6a4a51093cea4db1d4 Mon Sep 17 00:00:00 2001
From: Victor Zimmermann <zimmermann@cl.uni-heidelberg.de>
Date: Tue, 20 Mar 2018 17:08:30 +0100
Subject: [PATCH] Renaming, commenting, final.txts have now individual names.
 Collected in final directory.

---
 src/merge.py         | 47 ++++++++++++++++++++++++++++++++++++++++++++
 src/result_merger.py | 23 ----------------------
 2 files changed, 47 insertions(+), 23 deletions(-)
 create mode 100644 src/merge.py
 delete mode 100644 src/result_merger.py

diff --git a/src/merge.py b/src/merge.py
new file mode 100644
index 0000000..4cb6c91
--- /dev/null
+++ b/src/merge.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+"""Merges .absinth-files into one document.
+
+Collect file names from the directory specified in config.py. Ignore every first
+line and merge the rest. Write to file with timestamp as name.
+
+"""
+
+import config
+import os
+import time
+
+def main():
+    
+    file_path = config.output
+
+    files = [file_path+'/'+f for f in os.listdir(file_path)]
+
+    results = list()
+
+    for f in files:
+        with open(f, 'r') as lines:
+            for line in lines.readlines()[1:]:
+                results.append(line.split('\t'))
+                
+    results = sorted(results, key=lambda x: x[0])
+
+    time_int = int(time.strftime("%Y%m%d%H%M%S")[2:])
+
+    final_path = 'final/{}.absinth'.format(hex(time_int)[2:])
+    
+    if not os.path.exists('final'):
+        os.makedirs('final')
+    
+    final = open(final_path, 'w')
+
+    final.write('subTopicID\tresultID\n')
+
+    for r in results:
+        final.write('\t'.join(r))
+        
+    final.close()
+    
+
+if __name__ == "__main__":
+    main()
diff --git a/src/result_merger.py b/src/result_merger.py
deleted file mode 100644
index 5c7c207..0000000
--- a/src/result_merger.py
+++ /dev/null
@@ -1,23 +0,0 @@
-import os
-
-file_path = '/home/students/zimmermann/Courses/ws17/fsem/absinth/clustering/'
-
-files = [file_path+'/'+f for f in os.listdir(file_path)]
-
-results = list()
-
-for f in files:
-    with open(f, 'r') as lines:
-        for line in lines.readlines()[1:]:
-            results.append(line.split('\t'))
-            
-sorted(results, key=lambda x: x[0])
-
-final = open('final.txt', 'w')
-
-final.write('subTopicID\tresultID\n')
-
-for r in results:
-    final.write('\t'.join(r))
-    
-final.close()
-- 
GitLab