Mercurial > hg > horiscopes
comparison V3/compatibility.py @ 12:18e337b2550d
timesheet and notes from meeting
author | DaveM |
---|---|
date | Thu, 01 Feb 2018 17:32:49 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
11:903559cb34d0 | 12:18e337b2550d |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 import csv | |
4 | |
5 | |
6 def readFile(filename): | |
7 text = [] | |
8 with open(filename) as fp: | |
9 line = fp.readline() | |
10 text.append(line.strip()) | |
11 while line: | |
12 line = fp.readline() | |
13 text.append(line.strip()) | |
14 return text | |
15 | |
16 def parseCompatDef(filename): | |
17 comList = readFile(filename) | |
18 compat = {} | |
19 for com in comList: | |
20 c = com.split(',') | |
21 # print c | |
22 if len(c) == 4: | |
23 if len(c[1]) > 1: | |
24 for subset in c[1].split(' '): | |
25 key = sorted((c[0],c[2])) | |
26 key.append(subset) | |
27 compat[tuple(key)] = c[3] | |
28 elif len(c[1]) == 0 : | |
29 key = (c[0],c[2]) | |
30 compat[key] = c[3] | |
31 return compat | |
32 # pdb.set_trace() | |
33 | |
34 def applyCompatScore(people,rules): | |
35 # ruleKeys = rules.keys() | |
36 for person in people: | |
37 print "newPerson: " + str(person['ID']) | |
38 person['score'] = 0 | |
39 for pRule in person.keys(): | |
40 if pRule in rules: | |
41 person['score'] += int(rules[pRule]) | |
42 print pRule, rules[pRule] | |
43 print person['score'] | |
44 |