diff --git a/src/merge.py b/src/merge.py new file mode 100644 index 0000000000000000000000000000000000000000..4cb6c911454a8d34c564d8cd2f3c62597c4d6767 --- /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 5c7c207fc5e3d68de9c3d7d514b1363c0c2c010f..0000000000000000000000000000000000000000 --- 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()