|
|
|
@ -1,22 +1,31 @@
|
|
|
|
|
# -*- coding:utf-8 -*- |
|
|
|
|
#!/usr/bin/env python |
|
|
|
|
from __future__ import print_function |
|
|
|
|
from base import Lo |
|
|
|
|
import os, csv |
|
|
|
|
import os |
|
|
|
|
import csv |
|
|
|
|
import sys |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
los = Lo() |
|
|
|
|
model_count = { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_rank_thing(filename, **kwargs): |
|
|
|
|
model_count = { |
|
|
|
|
'I': {}, 'P': {}, 'C': {}, 'M': {}, 'F': {}, |
|
|
|
|
'H': {}, 'S': {}, 'D': {}, 'F': {} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
def get_rank_thing(filename): |
|
|
|
|
} |
|
|
|
|
output_filename = kwargs.get('output', '%s-output.csv' % filename) |
|
|
|
|
count = tot = lo_match = 0 |
|
|
|
|
with open(os.path.join(os.getcwd(), 'build', output_filename), 'wb') as o: |
|
|
|
|
owriter = csv.writer(o, delimiter=',', quotechar='"', |
|
|
|
|
quoting=csv.QUOTE_ALL) |
|
|
|
|
with open(os.path.join(os.getcwd(), 'raw', filename)) as f: |
|
|
|
|
reader = csv.reader(f) |
|
|
|
|
reader.next() |
|
|
|
|
for r in reader: |
|
|
|
|
mn, cnt = r[0], r[9] |
|
|
|
|
w = [r[10], r[11], r[12], r[13], r[14]] |
|
|
|
|
q = ( |
|
|
|
|
('A', r[1]), ('B', r[2]), ('C', r[3]), ('D', r[4]), |
|
|
|
|
('E', r[5]), ('F', r[6]), ('G', r[7]), ('H', r[8]), |
|
|
|
@ -27,24 +36,49 @@ def get_rank_thing(filename):
|
|
|
|
|
if result: |
|
|
|
|
# print(u'%s > %s' % (r[0], list(result))) |
|
|
|
|
count += 1 |
|
|
|
|
if cnt not in model_count[mn]: model_count[mn][cnt] = set() |
|
|
|
|
owriter.writerow([','.join(list(result)), cnt] + w) |
|
|
|
|
if cnt not in model_count[mn]: |
|
|
|
|
model_count[mn][cnt] = set() |
|
|
|
|
model_count[mn][cnt] = model_count[mn][cnt].union(result) |
|
|
|
|
print(u'[%s]\n Count = %s | Total = %s | Lo_w_match = %s' % ( |
|
|
|
|
filename, count, tot, lo_match)) |
|
|
|
|
|
|
|
|
|
def main(): |
|
|
|
|
fs = ('Case1_LS.csv', 'Case1_Gender.csv', 'Case1_Level.csv', 'Case1_SciF.csv') |
|
|
|
|
for f in fs: |
|
|
|
|
get_rank_thing(f) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for i, j in model_count.items(): |
|
|
|
|
print('\n===== %s =====' % i) |
|
|
|
|
for k, v in j.items(): |
|
|
|
|
print('%s: \n' \ |
|
|
|
|
' %s' % (k, list(v))) |
|
|
|
|
return model_count |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main(*argv): |
|
|
|
|
fs = ('Case1_LS.csv', 'Case1_Gender.csv', |
|
|
|
|
'Case1_Level.csv', 'Case1_SciF.csv') |
|
|
|
|
result = ['IPC', 'MF', 'HS', 'FS'] |
|
|
|
|
for f in xrange(0, len(fs)): |
|
|
|
|
mc = get_rank_thing(fs[f]) |
|
|
|
|
x = {} |
|
|
|
|
for i in result[f]: |
|
|
|
|
x[i] = mc[i] |
|
|
|
|
# print('x: ', x) |
|
|
|
|
mx = [set(j) for i, j in x.items()] |
|
|
|
|
order = sorted(list(set.union(*mx)), reverse=True) |
|
|
|
|
sum_file = '%s-result.csv' % fs[f] |
|
|
|
|
with open(os.path.join(os.getcwd(), 'build', sum_file), 'wb') as o: |
|
|
|
|
result_writer = csv.writer(o, delimiter=',', quotechar='"', |
|
|
|
|
quoting=csv.QUOTE_ALL) |
|
|
|
|
for i in xrange(0, 3): |
|
|
|
|
result_writer.writerow(['count', order[i]]) |
|
|
|
|
# print('count , ', order[i], ' / ', type(order[i])) |
|
|
|
|
for j in x.keys(): |
|
|
|
|
try: |
|
|
|
|
# print(j, ', ', s) |
|
|
|
|
lo_result = mc[j][order[i]] |
|
|
|
|
# print(order[i], ' == ', len(lo_result)) |
|
|
|
|
if i == 2 and len(mc[j]) > 3: |
|
|
|
|
for _i in xrange(3, len(mc[j])): |
|
|
|
|
lo_result = lo_result.union(mc[j][order[_i]]) |
|
|
|
|
# print(' ==EX== ', len(lo_result)) |
|
|
|
|
result_writer.writerow([j, ','.join(list(lo_result))]) |
|
|
|
|
except KeyError: |
|
|
|
|
print(' no key ', j, '[', order[i], ']') |
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
|
if len(sys.argv) > 1: |
|
|
|
|
main(sys.argv[1:]) |
|
|
|
|
else: |
|
|
|
|
main() |