import Numeric as Num
import random
import math
import die


def make_bump(info):
	return info['label'].startswith('P')


def test_bump(ds, ws, testtype, ts, info):
	tc = info['tc']
	if testtype.startswith('Gauss'):
		g, a, sigma = testtype.split()
		a = float(a) * make_bump(info)
		sigma = float(sigma)
		ds += a * Num.exp(-(ts-tc)**2/(2*sigma**2))
	elif testtype.startswith('GaussSlope'):
		g, a, sigma = testtype.split()
		a = float(a) * make_bump(info)
		sigma = float(sigma)
		ds += a * ((ts-tc)/sigma)*Num.exp(-(ts-tc)**2/(2*sigma**2))
	elif testtype.startswith('AddVar'):
		g, a, sigma = testtype.split()
		a = float(a) * make_bump(info)
		sigma = float(sigma)
		phase = 2*math.pi*random.uniform(0.0, 1.0)
		gauss = a * Num.exp(-(ts-tc)**2/(2*sigma**2))
		ds += gauss * (math.cos(phase) + ((ts-tc)/sigma)*math.sin(phase))
	elif testtype.startswith('WobblyGaussVar'):
		g, a, sigma = testtype.split()
		a = float(a) * random.gauss(0.0, 1.0) * make_bump(info)
		sigma = float(sigma)
		tc += random.gauss(0.0, sigma)
		ds += a * Num.exp(-(ts-tc)**2/(2*sigma**2))
	else:
		die.die("Bad testtype: %s" % testtype)
	return (ds, ws)
