view V3/compatibility.py @ 23:11d4e438045e

make version 5
author DaveM
date Mon, 09 Apr 2018 15:07:21 +0100
parents 18e337b2550d
children
line wrap: on
line source
#!/usr/bin/env python

import csv


def readFile(filename):
	text = []
	with open(filename) as fp:
		line = fp.readline()
		text.append(line.strip())
		while line:
			line = fp.readline()
			text.append(line.strip())
	return text	

def parseCompatDef(filename):
	comList = readFile(filename)
	compat = {}
	for com in comList:
		c = com.split(',')
		# print c
		if len(c) == 4:
			if len(c[1]) > 1:
				for subset in c[1].split(' '):
					key = sorted((c[0],c[2]))
					key.append(subset)
					compat[tuple(key)] = c[3]
			elif len(c[1]) == 0 :
				key = (c[0],c[2])
				compat[key] = c[3]
	return compat
	# pdb.set_trace()

def applyCompatScore(people,rules):
	# ruleKeys = rules.keys()
	for person in people:
		print "newPerson: " + str(person['ID'])
		person['score'] = 0
		for pRule in person.keys():
			if pRule in rules:
				person['score'] += int(rules[pRule])
				print pRule, rules[pRule]
		print person['score']