diff --git a/s4.py b/s4.py new file mode 100755 index 0000000..796db7f --- /dev/null +++ b/s4.py @@ -0,0 +1,66 @@ +''' +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()