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.
 
 

66 lines
1.7 KiB

'''
Step 4
'''
# -*- 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 get_match_all():
result = {}
fpath = os.path.join(os.getcwd(), 'build', 'part3', 'step3_match_all.csv')
with open(fpath, 'rb') as f:
rows = csv.reader(f)
for r in rows:
result[r[0]] = r[1].split(',')
return result
def get_weight(xmodel):
result = {}
fpath = os.path.join(os.getcwd(), 'build', 'part2', '%s-3.csv' % xmodel)
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]]
return result
def produce(match_all):
for ii in xmodels.keys():
rows = []
weight = get_weight(ii)
for lo in sorted(los.los):
is_matched = 1 if lo in match_all[ii] else 0
r = [lo, is_matched, los.los[lo]['weight']]
if is_matched:
r += weight[lo][1:]
rows.append(r)
_f = '%s-step4.csv' % ii
create_csv(_f, rows, directory='part4')
def main(*argv):
ma_data = get_match_all()
produce(ma_data)
if __name__ == '__main__':
if len(sys.argv) > 1:
main(sys.argv[1:])
else:
main()