view V1/temp.py @ 31:926b008ccb0c tip

resolving vertex and fixing description results - I believe everything works
author DaveM
date Sat, 19 May 2018 14:50:41 +0100
parents c2898c2a3cc6
children
line wrap: on
line source
def parsePartnerDOB(dob):
	dob_ = dob.split('/')
	if(len(dob_) != 3):
		# deal with no /'s
	try:
		d = int(dob_[0])
		m = int(dob_[1])
		y = int(dob_[2])
		if y < 100:
			y = y + 1900
		if(d > 31 or m > 12 or y > 2017 or y < 1900):
			print 'error with DOB '+d+'/'+m+'/'+y
	except TypeError:
		return None
	return (d,m,y)

def monthStringToNum(s):
	m = {'jan':1,'feb':2,
	'mar':3,'apr':4,'may':5,
	'jun':6,'jul':7,'aug':8,
	'sep':9,'oct':10,'nov':11,
	'dec':12}
	s_ = string.strip()[:3].lower()
	try:
		out = m[s]
		return out
	except:
		raise ValueError('Not a month')

def parseDOB(d,m,y):
	d = int(d.strip())
	y = int(y.strip())
	try:
		m = monthStringToNum(m.strip())
	except ValueError:
		m = int(m.strip())
	if(y < 100):
		y = y + 1900
	return (d,m,y)

def parseTOB(T):
	timeFlat = None
	try:
		T = T.lower().strip()
		if 'am' in T:
			timeFlag = 0
			T.replace('am','')
		if 'pm' in T:
			timeFlag = 1
			T.replace('pm','')
		t.strip()
		if ':' in T:
			T.split(':')
			H = int(T[0])
			M = int(T[1])
		elif '.' in T:
			T.split('.')
			H = int(T[0])
			M = int(T[1]) 
		else:
			int(T)
			if T < 24 :
				H = T
				M = 0
			elif T > 100:
				H = T/100
				M = T%100
		if timeFlag is not None:
			if timeFlag == 0:
				H = H%12
			else:
				H = H%12 + 12
	except ValueError:
		H = 12
		M = 00
	return (H,M)

def regulateData(dataDict):
	p_DOBQ = "What is your partner's date of birth? Please use the format DD/MM/YYYY (for example, 29/03/1981)."
	p_TOBQ = "At what exact time were your partner born? Please use the format HHMM (for example, 2204)."
	DOB_DQ = "Which day (numeric) have you been born?"
	DOB_MQ = "Which month have you been born?"
	DOB_YQ = "Year Of Birth"
	TOB_Q = "At what exact time were you born? Please use the format HHMM (for example, 2204)."
	dataDict['DOB'] = parseDOB(dataDict[DOB_DQ],dataDict[DOB_MQ],dataDict[DOB_YQ])
	dataDict['TOB'] = parseTOB(dataDict[TOB_Q])
	dataDict['pDOB'] = parsePartnerDOB(dataDict[p_DOBQ])
	dataDict['pTOB'] = parseTOB(dataDict[p_TOBQ])

	return dataDict