You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

104 lines
2.6 KiB

#!/usr/bin/env python
# -*- coding:utf-8 -*-
'''
Step 8
'''
from __future__ import print_function
from base import create_csv, TARGET_DIR, MODEL_LIST, RAW_DIR
import os
import csv
COMPARSION_PAIR = [
(2, 5), (3, 6), (6, 7), (7, 8),
(10, 9), (12, 10), (13, 11), (15, 12),
(17, 13), (18, 14), (19, 15), (21, 16),
(22, 17), (24, 18), (27, 19),
(29, 20), (30, 21), (31, 22), (33, 23),
]
def get_test_data(m):
if not m:
return []
result = []
lo_list = []
fpath = os.path.join(RAW_DIR, 'LO_TestData.csv')
with open(fpath, 'rb') as f:
rows = csv.reader(f)
rows.next()
for r in rows:
if r[1] != m.upper():
continue
result.append(r)
lo_list.append(r[0])
return (lo_list, result)
def get_ro_data(m, suffix):
if not m or not suffix:
return []
result = []
fname = '%s-%s.csv' % (m, suffix)
fpath = os.path.join(TARGET_DIR, 'part7', fname)
with open(fpath, 'rb') as f:
rows = csv.reader(f)
for r in rows:
result.append(r)
return result
def get_similarity_count(l, r, **kwargs):
C_PAIR = kwargs.get('pair', COMPARSION_PAIR)
cnt = 0
for (x, y) in C_PAIR:
r_value = r[y].replace('*', '')
if l[x] == r_value:
cnt += 1
elif r_value == 'Y/N' and l[x] in ('Y', 'N'):
cnt += 1
return cnt
def middleman(ls, rs):
if not len(ls):
return ls
result = []
for lo in ls:
data = lo[:]
for ro in rs:
sim_count = get_similarity_count(lo[:], ro)
data.append(sim_count)
result.append(data)
return result
def main():
header = ['LO_xxx', '____', ]
for m in MODEL_LIST:
l_list, lo_data = get_test_data(m)
for i in '1234':
m_header = header[:]
m_header[1] = m
ros = get_ro_data(m, i)
m_header += [r[0] for r in ros]
result = middleman(lo_data, ros)
output_name = '%s-%s.csv' % (m, i)
# process header -- get ind of first R_xxx
number_ind = 0
cnt_ind = 0
for i in result[0]:
try:
float(i)
number_ind = cnt_ind
cnt_ind = 0
break
except ValueError:
cnt_ind += 1
__h = m_header[:2] + ['_' for i in xrange(0, number_ind-2)] + m_header[2:]
result = [__h] + result
create_csv(output_name, result, directory='part8')
if __name__ == '__main__':
main()