Browse Source

Part 2 should be completed

master
sipp11 11 years ago
parent
commit
a98adb8ba4
  1. 17
      base.py
  2. 1138
      raw/Case1_SciF.csv
  3. 4
      s1.py
  4. 135
      s2.py

17
base.py

@ -72,3 +72,20 @@ class Lo:
if m:
r.append(m)
return set.intersection(*[set(k) for k in r])
def create_csv(filename, data, **kwargs):
if not isinstance(data, list):
print('Nope, data are not list')
directory = kwargs.get('directory', '')
path = os.path.join(os.getcwd(), 'build', directory)
try:
os.mkdir(path)
except OSError:
pass
fpath = os.path.join(path, filename)
with open(fpath, 'wb') as f:
owriter = csv.writer(
f, delimiter=',', quotechar='"', quoting=csv.QUOTE_ALL)
for r in data:
owriter.writerow(r)

1138
raw/Case1_SciF.csv

File diff suppressed because it is too large Load Diff

4
s1.py

@ -13,7 +13,7 @@ los = Lo()
def get_rank_thing(filename, **kwargs):
model_count = {
'I': {}, 'P': {}, 'C': {}, 'M': {}, 'F': {},
'H': {}, 'S': {}, 'D': {}, 'F': {}
'H': {}, 'S': {}, 'D': {}, 'f': {}
}
output_filename = kwargs.get('output', '%s-output.csv' % filename)
count = tot = lo_match = 0
@ -48,7 +48,7 @@ def get_rank_thing(filename, **kwargs):
def main(*argv):
fs = ('Case1_LS.csv', 'Case1_Gender.csv',
'Case1_Level.csv', 'Case1_SciF.csv')
result = ['IPC', 'MF', 'HS', 'FS']
result = ['IPC', 'MF', 'HS', 'fS']
for f in xrange(0, len(fs)):
mc = get_rank_thing(fs[f])
x = {}

135
s2.py

@ -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…
Cancel
Save