Mercurial > hg > horiscopes
comparison V4/synastry.py @ 16:b11cff4b7f83
implement compatibility scores
| author | DaveM |
|---|---|
| date | Mon, 05 Mar 2018 14:22:09 +0000 |
| parents | 50a95089414d |
| children | ae220e89cb3a |
comparison
equal
deleted
inserted
replaced
| 15:50a95089414d | 16:b11cff4b7f83 |
|---|---|
| 1 import random | 1 import random |
| 2 import csv | |
| 3 import re | |
| 4 import pdb | |
| 5 | |
| 6 class compatibility: | |
| 7 def __init__(self): | |
| 8 self.rules = [] | |
| 9 self.uniqueID = 0 | |
| 10 print 'Warning, need to fix [Vertex, Ascendant House, None Location] issues' | |
| 11 | |
| 12 def addRule(self,planetTuple,aspectList,score): | |
| 13 rule = compatibilityRule(self.uniqueID,planetTuple,aspectList,score) | |
| 14 self.rules.append(rule) | |
| 15 self.uniqueID += 1 | |
| 16 | |
| 17 def findRule(self,planet): | |
| 18 ruleList = [r for r in self.rules if r.planet == planet] | |
| 19 print ruleList | |
| 20 return ruleList | |
| 21 | |
| 22 def readFile(self,filename): | |
| 23 text = [] | |
| 24 with open(filename) as fp: | |
| 25 line = fp.readline() | |
| 26 text.append(line.strip()) | |
| 27 while line: | |
| 28 line = fp.readline() | |
| 29 text.append(line.strip()) | |
| 30 return text | |
| 31 | |
| 32 def parseCompatRules(self,filename): | |
| 33 comList = self.readFile(filename) | |
| 34 # compat = {} | |
| 35 for com in comList: | |
| 36 c = com.split(',') | |
| 37 # print c | |
| 38 if len(c) == 4: | |
| 39 if len(c[1]) > 1: | |
| 40 aspectList = [] | |
| 41 planetTuple = tuple(sorted((c[0].lower(),c[2].lower()))) | |
| 42 score = c[3] | |
| 43 for subset in c[1].split(' '): | |
| 44 aspectList.append(subset) | |
| 45 elif len(c[1]) == 0 : | |
| 46 if 'house' not in c[2]: | |
| 47 print 'some error where rule is not house' | |
| 48 planetTuple = (c[0].lower(),'house') | |
| 49 houseNo = re.findall('\d+', c[2]) | |
| 50 if len(houseNo) != 1: | |
| 51 print 'multiple house numbers found - ERROR' | |
| 52 aspectList = int(houseNo[0]) | |
| 53 score = int(c[3]) | |
| 54 self.addRule(planetTuple,aspectList,score) | |
| 55 # return compat | |
| 56 # pdb.set_trace() | |
| 57 | |
| 58 def calcCompatibility(self, horiscope): | |
| 59 score = 0 | |
| 60 for r in self.rules: | |
| 61 if 'vertex' in r.planet: | |
| 62 # print 'ERROR - catch Vertex issue' | |
| 63 pass | |
| 64 elif r.planet[1] == 'house' and r.planet[0] == 'asc': | |
| 65 # print 'ERROR - catch Ascendant House issue' | |
| 66 pass | |
| 67 elif horiscope.planets[r.planet[0]].angleA is None: | |
| 68 # print 'Error - None Location' | |
| 69 return None | |
| 70 elif r.planet[1] == 'house': | |
| 71 if horiscope.isInHouse(r.planet[0],r.aspect): | |
| 72 score += r.score | |
| 73 else: | |
| 74 # print 'query standard synastry' | |
| 75 aspect,variance = horiscope.calcAspect(r.planet[0],r.planet[1]) | |
| 76 if aspect is not None: | |
| 77 if aspect in r.aspect: | |
| 78 score += r.score | |
| 79 return score | |
| 80 | |
| 81 | |
| 82 | |
| 83 class compatibilityRule: | |
| 84 def __init__(self,uniqueId,planetTuple,aspectList,score): | |
| 85 self.id = uniqueId | |
| 86 self.planet = planetTuple | |
| 87 self.aspect = aspectList | |
| 88 self.score = score | |
| 2 | 89 |
| 3 class Person: | 90 class Person: |
| 4 url = 'https://horoscopes.astro-seek.com/calculate-love-compatibility/' | 91 url = 'https://horoscopes.astro-seek.com/calculate-love-compatibility/' |
| 5 def __init__(self,personDict): | 92 def __init__(self,personDict): |
| 6 # self. = planetPositions() | 93 # self. = planetPositions() |
| 13 self.p_cob = personDict['pCOB'] | 100 self.p_cob = personDict['pCOB'] |
| 14 self.horiscope = None | 101 self.horiscope = None |
| 15 | 102 |
| 16 def identifyIssues(self): | 103 def identifyIssues(self): |
| 17 if self.id is None: | 104 if self.id is None: |
| 18 return 'id' | 105 self.issue = 'id' |
| 19 elif self.dob is None: | 106 elif self.dob is None: |
| 20 return 'dob' | 107 self.issue = 'dob' |
| 21 elif self.tob is None: | 108 elif self.tob is None: |
| 22 return 'tob' | 109 self.issue = 'tob' |
| 23 elif self.cob is None: | 110 elif self.cob is None: |
| 24 return 'cob' | 111 self.issue = 'cob' |
| 25 elif self.p_dob is None: | 112 elif self.p_dob is None: |
| 26 return 'p_dob' | 113 self.issue = 'p_dob' |
| 27 elif self.p_tob is None: | 114 elif self.p_tob is None: |
| 28 return 'p_tob' | 115 self.issue = 'p_tob' |
| 29 elif self.p_cob is None: | 116 elif self.p_cob is None: |
| 30 return 'p_cob' | 117 self.issue = 'p_cob' |
| 31 else: | 118 else: |
| 32 return None | 119 self.issue = None |
| 120 return self.issue | |
| 33 | 121 |
| 34 def makePayload(self): | 122 def makePayload(self): |
| 35 if type(self.cob) is str: | 123 if type(self.cob) is str: |
| 36 cob_0 = float(self.cob.split(',')[0][1:]) | 124 cob_0 = float(self.cob.split(',')[0][1:]) |
| 37 cob_1 = float(self.cob.split(',')[1]) | 125 cob_1 = float(self.cob.split(',')[1]) |
| 145 | 233 |
| 146 def calcAspect(self,componentA,componentB): | 234 def calcAspect(self,componentA,componentB): |
| 147 self.calcAngle(componentA,componentB) | 235 self.calcAngle(componentA,componentB) |
| 148 for aspect in planetPositions.aspectDict: | 236 for aspect in planetPositions.aspectDict: |
| 149 if self.angleRange[0] < planetPositions.aspectDict[aspect] and self.angleRange[1] > planetPositions.aspectDict[aspect]: | 237 if self.angleRange[0] < planetPositions.aspectDict[aspect] and self.angleRange[1] > planetPositions.aspectDict[aspect]: |
| 150 self.aspect[componentA,componentB] = aspect | 238 aspectDiff = abs(self.angle - planetPositions.aspectDict[aspect]) |
| 151 self.aspectDiff = abs(self.angle - planetPositions.aspectDict[aspect]) | 239 self.aspect[componentA,componentB] = (aspect,aspectDiff) |
| 152 return self.aspect,self.aspectDiff | 240 return aspect,aspectDiff |
| 153 | 241 return None,None |
| 242 | |
| 243 def isInHouse(self,component,houseNo): | |
| 244 # print (self.planets[component].houseA,self.planets[component].houseB,houseNo) | |
| 245 if (self.planets[component].houseA == houseNo) or (self.planets[component].houseB == houseNo): | |
| 246 return True | |
| 247 return False | |
| 248 | |
| 154 def calcAllAspects(self): | 249 def calcAllAspects(self): |
| 155 for p1 in planetPositions.planetNames: | 250 for p1 in planetPositions.planetNames: |
| 156 for p2 in planetPositions.planetNames: | 251 for p2 in planetPositions.planetNames: |
| 157 self.calcAspect(p1,p2) | 252 self.calcAspect(p1,p2) |
| 158 | 253 |
