Exemplo n.º 1
0
Arquivo: tt.py Projeto: wgzhao/scripts
def t7(tag="增长下降比:"):
	vs=[]
	for line in sys.stdin:
		p=line.find(tag)
		if p >= 0:
			p1=line.find("=",p+len(tag))
			if p1 < 0:
				p1=line.find(" ",p+len(tag))
			if p1 < 0:
				p1=line.find("\t",p+len(tag))
			v=float(line[p+len(tag):p1])
			vs.append(v)
	(sum,avg,std,s0)=DictUtil.statis(vs)
	sys.stderr.write("sum:%.4f    loss:%d,%.2f    avg:%.2f%%    std:%.4f    avg/std:%.4f\n"%(sum,s0,float(s0)/len(vs),avg*100,std,avg/(std+1e-64)))
Exemplo n.º 2
0
def t7(tag="增长下降比:"):
    vs = []
    for line in sys.stdin:
        p = line.find(tag)
        if p >= 0:
            p1 = line.find("=", p + len(tag))
            if p1 < 0:
                p1 = line.find(" ", p + len(tag))
            if p1 < 0:
                p1 = line.find("\t", p + len(tag))
            v = float(line[p + len(tag):p1])
            vs.append(v)
    (sum, avg, std, s0) = DictUtil.statis(vs)
    sys.stderr.write(
        "sum:%.4f    loss:%d,%.2f    avg:%.2f%%    std:%.4f    avg/std:%.4f\n"
        % (sum, s0, float(s0) / len(vs), avg * 100, std, avg / (std + 1e-64)))
Exemplo n.º 3
0
Arquivo: tt.py Projeto: wgzhao/scripts
def t3():
	sum=0
	n=0
	vs=[]
	for line in sys.stdin:
		if line.startswith("增长率:"):
			p=line.find("\t")
			try:
				v=float(line[len("增长率:"):p])
			except:
				continue
			if abs(v) > 100:
				#print line
				continue
			#print v
			sum+=v
			n+=1
			vs.append(v)
	#sys.stderr.write("sum:%f\tn:%d\tavg:%f\n"%(sum,n,sum/n))
	(sum,avg,std,s0)=DictUtil.statis(vs)
	sys.stderr.write("sum:%.4f    loss:%d,%.2f    avg:%.2f%%    std:%.4f    avg/std:%.4f\n"%(sum,s0,float(s0)/len(vs),avg*100,std,avg/std))
Exemplo n.º 4
0
def t3():
    sum = 0
    n = 0
    vs = []
    for line in sys.stdin:
        if line.startswith("增长率:"):
            p = line.find("\t")
            try:
                v = float(line[len("增长率:"):p])
            except:
                continue
            if abs(v) > 100:
                #print line
                continue
            #print v
            sum += v
            n += 1
            vs.append(v)
    #sys.stderr.write("sum:%f\tn:%d\tavg:%f\n"%(sum,n,sum/n))
    (sum, avg, std, s0) = DictUtil.statis(vs)
    sys.stderr.write(
        "sum:%.4f    loss:%d,%.2f    avg:%.2f%%    std:%.4f    avg/std:%.4f\n"
        % (sum, s0, float(s0) / len(vs), avg * 100, std, avg / std))
Exemplo n.º 5
0
def combine(f,conf,start=0,end=10000):
	lastDay=""
	curve=loss.Loss(1.0)
	firstMonth=-1
	lastMonth=0
	lastValue=1.0
	vs=[]
	yvs=[]
	lastYear=0
	lastYearValue=1.0
	es=[]
	state=stepBack.State()
	for line in f:
		cols=line.strip().split("\t")
		if len(cols) < 3:
			continue
		day=cols[0]
		year=int(cols[0].split("-")[0])
		if year < start or year > end:
			continue
		month=int(cols[0].split("-")[1])
		month=year*100+month
		if firstMonth <= 0:
			firstMonth=month
		if lastMonth <= 0:
			lastMonth=month
			lastYear=year
		if lastMonth!=month:
			rate=curve.now/lastValue-1.0
			sys.stderr.write("%d-%d\t%.2f%%\n"%(lastMonth/100,lastMonth%100,rate*100))
			vs.append(rate)
			lastMonth=month
			lastValue=curve.now
		if lastYear != year:
			rate=curve.now/lastYearValue-1.0
			yvs.append((lastYear,rate))
			lastYear=year
			lastYearValue=curve.now
		if lastDay == "":
			lastDay=day
		if lastDay != day:
			output(lastDay,es,curve,conf)
			lastDay=day
			es=[]
		e=float(cols[1])
		state.read(cols[2])
		if state.IsBull:
			fac=TrendFac
		else:
			fac=1.0/TrendFac
		if state.LastClose5:
			fac*=Close5Fac
		else:
			fac/=Close5Fac
		es.append((e,fac))
	if lastDay != "":
		rate=curve.now/lastValue-1.0
		sys.stderr.write("%d-%d\t%.2f%%\n"%(lastMonth/100,lastMonth%100,rate*100))
		vs.append(rate)
		rate=curve.now/lastYearValue-1.0
		yvs.append((lastYear,rate))
		output(lastDay,es,curve,conf)
		es=[]
	sys.stderr.write("firstMonth:%d\tlastMonth:%d\n"%(firstMonth,lastMonth))
	curve.setTime(dayDiv(firstMonth,lastMonth))
	sys.stderr.write(curve.confStr(conf)+"\n")
	(sum,avg,std,s0)=DictUtil.statis(vs)
	mrate=math.pow(curve.now,1.0/monthDiv(firstMonth,lastMonth))-1.0
	sys.stderr.write("月均统计	sum:%.4f	loss:%d,%.2f	avg:%.2f%%,%.2f%%	std:%.4f	avg/std:%.4f\n"%(sum,s0,float(s0)/len(vs),avg*100,mrate*100,std,mrate/std))
	rvs=[]
	for lastYear,rate in yvs:
		rvs.append(rate)
		sys.stderr.write("%d\t%.2f%%\n"%(lastYear,rate*100))
	(sum,avg,std,s0)=DictUtil.statis(rvs)
	yrate=curve.rate
	sys.stderr.write("年均统计  sum:%.4f    loss:%d,%.2f	avg:%.2f%%,%.2f%%    std:%.4f    avg/std:%.4f\n"%(sum,s0,float(s0)/len(vs),avg*100,yrate*100,std,yrate/std))