#!/usr/bin/env python
import sys, re, getopt
import vplot
from math import sqrt 
(options,arguements)=getopt.getopt(sys.argv[1:],'t:o:')
title="neural network forecast"
outfile='temp.eps'
infilename='brier.dat'
for o,a in options:
	if o=="-t":
		title=a
	if o=="-o":
		outfile=a
	if o=="-i":
		infilename=a
b=vplot.eps_class(fname=outfile)
inf=open(infilename,'r')
b.xaxis()
b.yaxis()
yl=[]
nl=[]
ol=[]
while 1:
	aline=inf.readline()
	if not aline: break
	if re.match('\#',aline):
		a=aline.split()
		for x in a:
			exec(x)
		continue
	[i,y,n,o]=aline.split()
	yl.append(float(y))	
	nl.append(float(n))	
	ol.append(float(o))	
todraw=[]
for i in range(0,len(yl)):
	todraw.append(yl[i])
	todraw.append(ol[i])
b.line(0., ob, 1., ob)
b.line(ob, 0., ob, 1.)
b.line(0., ob/2., 1., .5+ob/2.)
b.line(0., 0., 1., 1.)
b.dashdraw(todraw)
b.color(1., 0., 0.)
for i in range(0,len(yl)):
	y=yl[i]
	o=ol[i]
	rad=int(round(sqrt(nl[i]))) # area of circle will be proportional to n
	s=ob/2.+y/2.
	if (y<ob and o<s) or (y>=ob and o>s):
		b.circle(y,o,rad,'F')
	else:
		b.circle(y,o,rad)
b.color(0.,0.,0.)
b.text(.03,1.02,0.,24,title)
b.text(-.07,.3,90.,14,'observed relative frequency')
b.text(.3,-.08,0.,14,'forecast probability')
b.close()
