sipp11
11 years ago
4 changed files with 723 additions and 571 deletions
@ -0,0 +1,135 @@
|
||||
# -*- coding:utf-8 -*- |
||||
#!/usr/bin/env python |
||||
from __future__ import print_function |
||||
from base import Lo, create_csv |
||||
import os |
||||
import csv |
||||
import sys |
||||
|
||||
los = Lo() |
||||
|
||||
xmodels = { |
||||
'IMSf': {}, 'IMSD': {}, 'IMHf': {}, 'IMHD': {}, 'IFSf': {}, 'IFSD': {}, |
||||
'IFHf': {}, 'IFHD': {}, 'CMSf': {}, 'CMSD': {}, 'CMHf': {}, 'CMHD': {}, |
||||
'CFSf': {}, 'CFSD': {}, 'CFHf': {}, 'CFHD': {}, 'PMSf': {}, 'PMSD': {}, |
||||
'PMHf': {}, 'PMHD': {}, 'PFSf': {}, 'PFSD': {}, 'PFHf': {}, 'PFHD': {}, |
||||
} |
||||
fs = ('Case1_LS.csv', 'Case1_Gender.csv', 'Case1_Level.csv', 'Case1_SciF.csv') |
||||
|
||||
|
||||
def process_s2_data(): |
||||
sum_result = {} |
||||
rank_result = {} |
||||
step, rank = '', '' |
||||
for i in fs: |
||||
f_name = '%s-result.csv' % i |
||||
# print(f_name) |
||||
with open(os.path.join(os.getcwd(), 'build', f_name), 'rb') as f: |
||||
rows = csv.reader(f) |
||||
for r in rows: |
||||
if r[0] in ('count', 'All Result'): |
||||
step = r[0] |
||||
rank = r[1] if r[0] == 'count' else '' |
||||
continue |
||||
if step == 'count': |
||||
if r[0] not in rank_result: |
||||
rank_result[r[0]] = {} |
||||
rank_result[r[0]][rank] = r[1].split(',') |
||||
elif step == 'All Result': |
||||
if not r[0]: |
||||
continue |
||||
if r[0] in sum_result: |
||||
# print('exists:', r[1], '|', step, '|', rank) |
||||
pass |
||||
sum_result[r[0]] = r[1].split(',') |
||||
return { |
||||
'sum': sum_result, 'rank': rank_result |
||||
} |
||||
|
||||
|
||||
def produce_s2_part1(sum_result): |
||||
# create xxxx-1.csv |
||||
for ii in xmodels.keys(): |
||||
rows = [] |
||||
rows.append([ii, ]) |
||||
for i in ii: |
||||
if i not in sum_result: |
||||
continue |
||||
rows.append([i, ','.join(sum_result[i])]) |
||||
_f = '%s-1.csv' % ii |
||||
create_csv(_f, rows, directory='part2') |
||||
|
||||
|
||||
def produce_s2_part2(rank_result): |
||||
# create xxxx-2.csv |
||||
for ii in xmodels.keys(): |
||||
rows = [] |
||||
for rk in xrange(0, 3): |
||||
rows.append(['Rank#%s' % (rk+1), ]) |
||||
for i in ii: |
||||
# find order |
||||
if i not in rank_result: |
||||
continue |
||||
o = sorted(rank_result[i].keys(), reverse=True) |
||||
rows.append([i, ','.join(rank_result[i][o[rk]])]) |
||||
_f = '%s-2.csv' % ii |
||||
create_csv(_f, rows, directory='part2') |
||||
|
||||
|
||||
def process_lo_weight(): |
||||
los = {} |
||||
for i in fs: |
||||
f_name = '%s-output.csv' % i |
||||
with open(os.path.join(os.getcwd(), 'build', f_name), 'rb') as f: |
||||
rows = csv.reader(f) |
||||
for r in rows: |
||||
_los = r[1].split(',') |
||||
for _l in _los: |
||||
if _l not in los: |
||||
los[_l] = {} |
||||
if r[0] in los[_l]: |
||||
# print('exists:', _l, ':', r[0], ' > ') |
||||
# los[_l]['%s2' % r[0]] = r[2:] |
||||
pass |
||||
los[_l][r[0]] = r[2:] |
||||
return los |
||||
|
||||
|
||||
def produce_part3(sum_result, lo_weight): |
||||
# produce part3 |
||||
for ii in xmodels.keys(): |
||||
rows = [] |
||||
lo_xmodels = set() |
||||
for i in ii: |
||||
if i in sum_result: |
||||
lo_xmodels = lo_xmodels.union(set(sum_result[i])) |
||||
lo_xmodels = sorted(list(lo_xmodels)) |
||||
for l in lo_xmodels: |
||||
lo_sum = [0, 0, 0, 0, 0, 0] |
||||
if l not in lo_weight: |
||||
continue |
||||
for i in ii: |
||||
if i not in lo_weight[l]: |
||||
continue |
||||
lo_sum = [ |
||||
float(x) + float(y) for x, y |
||||
in zip(lo_weight[l][i], lo_sum)] |
||||
rows.append([l] + lo_sum) |
||||
|
||||
_f = '%s-3.csv' % ii |
||||
create_csv(_f, rows, directory='part2') |
||||
|
||||
|
||||
def main(*argv): |
||||
_r = process_s2_data() |
||||
_lw = process_lo_weight() |
||||
produce_s2_part1(_r['sum']) |
||||
produce_s2_part2(_r['rank']) |
||||
produce_part3(_r['sum'], _lw) |
||||
|
||||
|
||||
if __name__ == '__main__': |
||||
if len(sys.argv) > 1: |
||||
main(sys.argv[1:]) |
||||
else: |
||||
main() |
Loading…
Reference in new issue