from	bokeh.charts	import	Area, show, output_file, defaults
from	bokeh.layouts	import	row
# import	bokeh.colors		as	colors
from colour import Color
import	numpy	as	np
# import	decimal

def frange(x, y, jump):
	while x < y:
		yield x
		x += jump

defaults.width  = 1700
defaults.height = 1200

stat_data = [
				[	'v1.6A'	,	343	,	53	,	38	,	73	]
			,	[	'v1.6B'	,	277	,	46	,	40	,	60	]
			,	[	'v1.6C'	,	297	,	55	,	38	,	72	]
			]

data			=	{}
chart_colors	=	[]

outcomes	=	[
					[	2	,	'coming back'	,	.4	]
				,	[	3	,	'interested'	,	.7	]
				,	[	4	,	'uninterested'	,	.01	]
				]

iter_		=	0
for			stat	in	stat_data		:
	iter_	+=	1
	for		outcome	in	outcomes		:
		dist = []

		for 	p		in	frange(	0.001	,	1.	,	0.001	)	:
			chance	=	pow	(
								1.	-	p
							,	stat[1]	-	stat[ outcome[0] ]
							)	*	pow	(
											p
										,	stat[ outcome[0] ]
										)
			dist.append	(
						chance
						)

		d	=	np.array	(	dist	)
		max_=	max(	d	)
		d	/=	max_
		d	+=	len(stat_data)	-	iter_
		data[
				stat[0]
			+	' '
			+	outcome[1]	#	name of outcome
			]			=	d

		chart_colors.append	(
							Color	(
									hsl	=	(
												.01	*	(	iter_	*	0.3	)
												+	outcome[2]
											,	.2	+	.2	*	 outcome[0]
											,	.1	+	(outcome[0]	*	0.15	)
											)
									).hex_l
							)

	data[
			stat[0]
		+	'-'
		]			=	d	*	0.	+	len(stat_data)	-	iter_
	chart_colors.append	(
						'white'
						)


area1 = Area(
				data
			,	title	=	"What's the TRUE chance of certain user outcome?"
			,	legend	=	"top_left"
			,	xlabel	=	"probability that THIS is TRUE, ‰"
			,	ylabel	=	"how likely that we're correct"
			,	color	=	chart_colors
			,	webgl	=	True
			)

output_file("probabilities.html", title="probabilities")

show(row(	area1	))
