From e667c1a57b6b2b36f516700bfe35985d545f5965 Mon Sep 17 00:00:00 2001 From: sipp11 Date: Thu, 31 Jul 2014 03:26:56 +0700 Subject: [PATCH] s5 --- base.py | 7 +++++++ s5.py | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 s5.py diff --git a/base.py b/base.py index ef8be56..aac3ec3 100644 --- a/base.py +++ b/base.py @@ -4,6 +4,13 @@ import os RAW_DIR = os.path.join(os.getcwd(), 'raw', 'july') TARGET_DIR = os.path.join(os.getcwd(), 'build') +MODEL_LIST = [ + 'PMSf', 'PMSD', 'PMHf', 'PMHD', 'PFSf', + 'PFSD', 'PFHf', 'PFHD', 'IMSf', 'IMSD', + 'IMHf', 'IMHD', 'IFSf', 'IFSD', 'IFHf', + 'IFHD', 'CMSf', 'CMSD', 'CMHf', 'CMHD', + 'CFSf', 'CFSD', 'CFHf', 'CFHD' +] class Lo: diff --git a/s5.py b/s5.py new file mode 100644 index 0000000..20c2d4e --- /dev/null +++ b/s5.py @@ -0,0 +1,65 @@ +''' +Step 5 +''' +# -*- coding:utf-8 -*- +#!/usr/bin/env python +from __future__ import print_function +from base import create_csv, TARGET_DIR, MODEL_LIST +import os +import csv +import sys + + +def get_sorted_list(model_name): + _m = model_name + result = [] + fpath = os.path.join(TARGET_DIR, 'part4', '%s-step4.csv' % _m) + if _m not in MODEL_LIST: + return [] + weight_index = MODEL_LIST.index(_m) + 5 # offset + with open(fpath, 'rb') as f: + rows = csv.reader(f) + for r in rows: + # result[r[0]] = [r[1], r[2], r[3], r[4], r[5], r[6]] + result.append([ + r[0], # no of tree + r[1], # lo_id + r[2], # ??? + r[3], # ?? + r[4], # something count + r[weight_index] + ]) + sorted_result = sorted(result, key=lambda x: x[5], reverse=True) + + return sorted_result + + +def loop_thru_model(): + result = {} + max_count = 0 + for m in MODEL_LIST: + result[m] = get_sorted_list(m) + max_count = max_count if max_count > len(result[m]) else len(result[m]) + + return (result, max_count) + + +sorted_by_weight, max_count = loop_thru_model() +rows = [] +# fill up header since there is no way to know what model is +row = ['|', ] +for m in MODEL_LIST: + row += ['-', '-', m, '-', '-', '|'] +rows.append(row) + +for i in xrange(0, max_count): + row = [i, ] + for m in MODEL_LIST: + try: + row += sorted_by_weight[m][i] + except IndexError: + row += ['', '', '', '', '', ''] + + rows.append(row) + +create_csv('sorted_all.csv', rows, directory='part5')