资讯专栏INFORMATION COLUMN

[No.004]预测beta

LiuRhoRamen / 556人阅读

摘要:总进球预测场次场次场次前个进球数以及比例将的所有结果保存到文件中球总共场场次主赔平陪一共场球球球球球球平负前个进球数以及比例将的所有结果保存到文件中球总共场平赔负陪一共场球球球球球球胜负前个进球数以及比例将的所有结果

#encoding:utf-8
#!/usr/local/bin/python2.7
from __future__ import division
import MySQLdb as mdb
import re

def myAdd(x,y):
    return x+y

def myMin(x,y):
    return x-y

def preZjq(cur,scr,w,d,l,a):
    print "======总进球预测======"
    sql_wd = "select zjq,count(*) from results where win between %s and %s and dog between %s and %s group by zjq order by count(*)" % (myMin(w,a),myAdd(w,a),myMin(d,a),myAdd(d,a))
    sql_dl = "select zjq,count(*) from results where dog between %s and %s and los between %s and %s group by zjq order by count(*)" % (myMin(d,a),myAdd(d,a),myMin(l,a),myAdd(l,a))
    sql_wl = "select zjq,count(*) from results where win between %s and %s or los between %s and %s group by zjq order by count(*)" % (myMin(w,a),myAdd(w,a),myMin(l,a),myAdd(l,a))
    temp_wd=["win&dog"+"
"]
    temp_wd.append(("场次:%s 
") % str(scr))
    temp_wd.append(("win:%s  dog:%s  los:%s  acc:%s"+"
") % (str(w),str(d),str(l),str(a)))
    temp_dl=["win&dog"+"
"]
    temp_dl.append(("场次:%s 
") % str(scr))
    temp_dl.append(("win:%s  dog:%s  los:%s  acc:%s"+"
") % (str(w),str(d),str(l),str(a)))
    temp_wl=["win&dog"+"
"]
    temp_wl.append(("场次:%s 
") % str(scr))
    temp_wl.append(("win:%s  dog:%s  los:%s  acc:%s"+"
") % (str(w),str(d),str(l),str(a)))

    f = open("/root/bet/prediction.txt","a")

    sum_wd=0
    #wd_alldata:前4个进球数以及比例
    wd_alldata=[]
    #将SQL的所有结果保存到文件中
    cur.execute(sql_wd)
    for item in cur.fetchall():
        temp_wd_str1=str(item[0])+"球,"
        temp_wd.append(temp_wd_str1)
        temp1_wd=str(item[1])
        sum_wd+=item[1]
        temp_wd_str2 = re.search("d{1,3}",temp1_wd).group()
        temp_wd.append(temp_wd_str2+"
")
    temp_wd.append("总共:"+str(sum_wd)+"场")
    temp_wd.append("


")
    cur.execute(sql_wd)
    for d in cur.fetchall():
        wd_alldata.append(str(d[0]))
        tmp4=str(d[1])
        temp_srt3 = re.search("d{1,3}",tmp4).group()
        wd_alldata.append(temp_srt3)
    for item in temp_wd:
        f.writelines(str(item))
    l = len(wd_alldata)
    print ("场次: %s 
主赔+平陪-->"+"一共 "+str(sum_wd)+"场") % str(scr)
    if l==2:
        temp_wd_alldata = wd_alldata[-2:]
        print str((temp_wd_alldata[0])+"球:")+str(format(int(temp_wd_alldata[1])/sum_wd,".2%"))
    elif l==4:
        temp_wd_alldata = wd_alldata[-4:]
        print str((temp_wd_alldata[0])+"球:")+str(format(int(temp_wd_alldata[1])/sum_wd,".2%"))
        print str((temp_wd_alldata[2])+"球:")+str(format(int(temp_wd_alldata[3])/sum_wd,".2%"))
    elif l>=6:
        temp_wd_alldata = wd_alldata[-6:]
        print str((temp_wd_alldata[0])+"球:")+str(format(int(temp_wd_alldata[1])/sum_wd,".2%"))
        print str((temp_wd_alldata[2])+"球:")+str(format(int(temp_wd_alldata[3])/sum_wd,".2%"))
        print str((temp_wd_alldata[4])+"球:")+str(format(int(temp_wd_alldata[5])/sum_wd,".2%"))

    #平负
    sum_dl=0
    #dl_alldata:前4个进球数以及比例
    dl_alldata=[]
    #将SQL的所有结果保存到文件中
    cur.execute(sql_dl)
    for item in cur.fetchall():
        temp_dl_str1=str(item[0])+"球,"
        temp_dl.append(temp_dl_str1)
        temp1_dl=str(item[1])
        sum_dl+=item[1]
        temp_dl_str2 = re.search("d{1,3}",temp1_dl).group()
        temp_dl.append(temp_dl_str2+"
")
    temp_dl.append("总共:"+str(sum_dl)+"场")
    temp_dl.append("


")
    cur.execute(sql_dl)
    for d in cur.fetchall():
        dl_alldata.append(str(d[0]))
        tmp4=str(d[1])
        temp_srt3 = re.search("d{1,3}",tmp4).group()
        dl_alldata.append(temp_srt3)
    for item in temp_dl:
        f.writelines(str(item))
    l = len(dl_alldata)
    print ("
平赔+负陪-->"+"一共 "+str(sum_dl)+"场")
    if l==2:
        temp_dl_alldata = dl_alldata[-2:]
        print str((temp_dl_alldata[0])+"球:")+str(format(int(temp_dl_alldata[1])/sum_dl,".2%"))
    elif l==4:
        temp_dl_alldata = dl_alldata[-4:]
        print str((temp_dl_alldata[0])+"球:")+str(format(int(temp_dl_alldata[1])/sum_dl,".2%"))
        print str((temp_dl_alldata[2])+"球:")+str(format(int(temp_dl_alldata[3])/sum_dl,".2%"))
    elif l>=6:
        temp_dl_alldata = dl_alldata[-6:]
        print str((temp_dl_alldata[0])+"球:")+str(format(int(temp_dl_alldata[1])/sum_dl,".2%"))
        print str((temp_dl_alldata[2])+"球:")+str(format(int(temp_dl_alldata[3])/sum_dl,".2%"))
        print str((temp_dl_alldata[4])+"球:")+str(format(int(temp_dl_alldata[5])/sum_dl,".2%"))

    #胜负
    sum_wl=0
    #wl_alldata:前4个进球数以及比例
    wl_alldata=[]
    #将SQL的所有结果保存到文件中
    cur.execute(sql_wl)
    for item in cur.fetchall():
        temp_wl_str1=str(item[0])+"球,"
        temp_wl.append(temp_wl_str1)
        temp1_wl=str(item[1])
        sum_wl+=item[1]
        temp_wl_str2 = re.search("d{1,3}",temp1_wl).group()
        temp_wl.append(temp_wl_str2+"
")
    temp_wl.append("总共:"+str(sum_wl)+"场")
    temp_wl.append("


")
    cur.execute(sql_wl)
    for d in cur.fetchall():
        wl_alldata.append(str(d[0]))
        tmp4=str(d[1])
        temp_srt3 = re.search("d{1,3}",tmp4).group()
        wl_alldata.append(temp_srt3)
    for item in temp_wl:
        f.writelines(str(item))
    l = len(wl_alldata)
    print ("
主赔+负陪-->"+"一共 "+str(sum_wl)+"场")
    if l==2:
        temp_wl_alldata = wl_alldata[-2:]
        print str((temp_wl_alldata[0])+"球:")+str(format(int(temp_wl_alldata[1])/sum_wl,".2%"))
    elif l==4:
        temp_wl_alldata = wl_alldata[-4:]
        print str((temp_wl_alldata[0])+"球:")+str(format(int(temp_wl_alldata[1])/sum_wl,".2%"))
        print str((temp_wl_alldata[2])+"球:")+str(format(int(temp_wl_alldata[3])/sum_wl,".2%"))
    elif l>=6:
        temp_wl_alldata = wl_alldata[-6:]
        print str((temp_wl_alldata[0])+"球:")+str(format(int(temp_wl_alldata[1])/sum_wl,".2%"))
        print str((temp_wl_alldata[2])+"球:")+str(format(int(temp_wl_alldata[3])/sum_wl,".2%"))
        print str((temp_wl_alldata[4])+"球:")+str(format(int(temp_wl_alldata[5])/sum_wl,".2%"))
    print "============"
    f.close()

def preSpf(cur,scr,w,d,l,a):
    print "======胜平负预测======"
    sql_spf_wd = "select spf,count(*) from results where win between %s and %s and dog between %s and %s group by spf order by count(*)" % (myMin(w,a),myAdd(w,a),myMin(d,a),myAdd(d,a))
    sql_spf_dl = "select spf,count(*) from results where dog between %s and %s and los between %s and %s group by spf order by count(*)" % (myMin(d,a),myAdd(d,a),myMin(l,a),myAdd(l,a))
    sql_spf_wl = "select spf,count(*) from results where win between %s and %s or los between %s and %s group by spf order by count(*)" % (myMin(w,a),myAdd(w,a),myMin(l,a),myAdd(l,a))

    temp_spf_wd = []
    temp_spf_dl = []
    temp_spf_wl = []
    temp = []
    #添加场次信息
    temp.append(("场次:%s 
") % str(scr))
    #添加赔率信息
    temp.append(("win:%s  dog:%s  los:%s  acc:%s"+"
") % (str(w),str(d),str(l),str(a)))

    #写入到文件Precdiction.txt
    f = open("/root/bet/prediction.txt","a")

    #1.对于sql_spf_wd的输出进行处理
    cur.execute(sql_spf_wd)
    #统计胜平负场次总和
    sum_spf_wd=0
    #将SQL的所有结果保存到文件中
    for item in cur.fetchall():
        temp_spf_wd.append(str(item[0]))
        temp_spf_wd.append(str(item[1]))
        sum_spf_wd+=(item[1])
    #收集胜平负的场次,并求百分比
    print "胜平-->共"+str(sum_spf_wd)+"场"
    #统计胜平负的比例
    cur.execute(sql_spf_wd)
    l = len(temp_spf_wd)
    print ("场次: %s 
主赔+平陪-->"+"一共 "+str(sum_spf_wd)+"场") % str(scr)
    if l==2:
        temp_spf_wd = temp_spf_wd[-2:]
        print str((temp_spf_wd[0])+":")+str(format(int(temp_spf_wd[1])/sum_spf_wd,".2%"))
    elif l==4:
        temp_spf_wd = temp_spf_wd[-4:]
        print str((temp_spf_wd[0])+":")+str(format(int(temp_spf_wd[1])/sum_spf_wd,".2%"))
        print str((temp_spf_wd[2])+":")+str(format(int(temp_spf_wd[3])/sum_spf_wd,".2%"))
    elif l>=6:
        temp_spf_wd = temp_spf_wd[-6:]
        print str((temp_spf_wd[0])+":")+str(format(int(temp_spf_wd[1])/sum_spf_wd,".2%"))
        print str((temp_spf_wd[2])+":")+str(format(int(temp_spf_wd[3])/sum_spf_wd,".2%"))
        print str((temp_spf_wd[4])+":")+str(format(int(temp_spf_wd[5])/sum_spf_wd,".2%"))

    #2.对于sql_spf_dl的输出进行处理
    cur.execute(sql_spf_dl)
    #统计胜平负场次总和
    sum_spf_dl=0
    #将SQL的所有结果保存到文件中
    for item in cur.fetchall():
        temp_spf_dl.append(str(item[0]))
        temp_spf_dl.append(str(item[1]))
        sum_spf_dl+=(item[1])
    #统计胜平负的比例
    cur.execute(sql_spf_dl)
    l = len(temp_spf_dl)
    print ("
平陪+负赔-->"+"一共 "+str(sum_spf_dl)+"场")
    if l==2:
        temp_spf_dl = temp_spf_dl[-2:]
        print str((temp_spf_dl[0])+":")+str(format(int(temp_spf_dl[1])/sum_spf_dl,".2%"))
    elif l==4:
        temp_spf_dl = temp_spf_dl[-4:]
        print str((temp_spf_dl[0])+":")+str(format(int(temp_spf_dl[1])/sum_spf_dl,".2%"))
        print str((temp_spf_dl[2])+":")+str(format(int(temp_spf_dl[3])/sum_spf_dl,".2%"))
    elif l>=6:
        temp_spf_dl = temp_spf_dl[-6:]
        print str((temp_spf_dl[0])+":")+str(format(int(temp_spf_dl[1])/sum_spf_dl,".2%"))
        print str((temp_spf_dl[2])+":")+str(format(int(temp_spf_dl[3])/sum_spf_dl,".2%"))
        print str((temp_spf_dl[4])+":")+str(format(int(temp_spf_dl[5])/sum_spf_dl,".2%"))

    #3.对于sql_spf_wl的输出进行处理
    cur.execute(sql_spf_wl)
    #统计胜平负场次总和
    sum_spf_wl=0
    #将SQL的所有结果保存到文件中
    for item in cur.fetchall():
        temp_spf_wl.append(str(item[0]))
        temp_spf_wl.append(str(item[1]))
        sum_spf_wl+=(item[1])
    #统计胜平负的比例
    cur.execute(sql_spf_wl)
    l = len(temp_spf_wl)
    print ("
主陪+负赔-->"+"一共 "+str(sum_spf_wl)+"场")
    if l==2:
        temp_spf_wl = temp_spf_wl[-2:]
        print str((temp_spf_wl[0])+":")+str(format(int(temp_spf_wl[1])/sum_spf_wl,".2%"))
    elif l==4:
        temp_spf_wl = temp_spf_wl[-4:]
        print str((temp_spf_wl[0])+":")+str(format(int(temp_spf_wl[1])/sum_spf_wl,".2%"))
        print str((temp_spf_wl[2])+":")+str(format(int(temp_spf_wl[3])/sum_spf_wl,".2%"))
    elif l>=6:
        temp_spf_wl = temp_spf_wl[-6:]
        print str((temp_spf_wl[0])+":")+str(format(int(temp_spf_wl[1])/sum_spf_wl,".2%"))
        print str((temp_spf_wl[2])+":")+str(format(int(temp_spf_wl[3])/sum_spf_wl,".2%"))
        print str((temp_spf_wl[4])+":")+str(format(int(temp_spf_wl[5])/sum_spf_wl,".2%"))
    print "============"
    f.close()

#=========================================
#比分预测   
def preRes(cur,scr,w,d,l,a):
    sql_res_wd = "select res,count(*) from results where win between %s and %s and dog between %s and %s group by res order by count(*)" % (myMin(w,a),myAdd(w,a),myMin(d,a),myAdd(d,a))
    sql_res_dl = "select res,count(*) from results where dog between %s and %s and los between %s and %s group by res order by count(*)" % (myMin(d,a),myAdd(d,a),myMin(l,a),myAdd(l,a))
    sql_res_wl = "select res,count(*) from results where win between %s and %s or los between %s and %s group by res order by count(*)" % (myMin(w,a),myAdd(w,a),myMin(l,a),myAdd(l,a))

    #统计比分的场次之和
    sum_res_wd = 0
    sum_res_dl = 0
    sum_res_wl = 0

    #暂存保存到文件的信息
    temp_res_wd = []
    temp_res_dl = []
    temp_res_wl = []
    #添加场次信息
    temp_res_wd.append(("场次:%s 
") % str(scr))
    #添加赔率信息
    temp_res_wd.append(("win:%s  dog:%s  los:%s  acc:%s"+"
") % (str(w),str(d),str(l),str(a)))
    #对于总共收集的场次
    sum_res = 0
    #对于比分以及场次进行收集
    all_res_data=[]

    #写入到文件Precdiction.txt
    f = open("/root/bet/prediction.txt","a")

    print "======比分预测======"

    #1.对于sql_res_wd的输出进行处理
    cur.execute(sql_res_wd)
    #将SQL的所有结果保存到文件中
    for item in cur.fetchall():
        temp_res_wd.append(str(item[0]))
        temp_res_wd.append(str(item[1]))
        sum_res_wd+=item[1]
    print "
胜平预测-->共"+str(sum_res_wd)+"场"
    #统计比分比例
    cur.execute(sql_res_wd)
    l = len(temp_res_wd)
    if l==4:
        temp_res_wd2 = temp_res_wd[-2:]
        print str((temp_res_wd2[0])+"==》")+str(format(int(temp_res_wd2[1])/sum_res_wd,".2%"))
    elif l==6:
        temp_res_wd2 = temp_res_wd[-4:]
        print str((temp_res_wd2[0])+"==》")+str(format(int(temp_res_wd2[1])/sum_res_wd,".2%"))
        print str((temp_res_wd2[2])+"==》")+str(format(int(temp_res_wd2[3])/sum_res_wd,".2%"))
    elif l>6:
        temp_res_wd2 = temp_res_wd[-8:]
        print str((temp_res_wd2[0])+"==》")+str(format(int(temp_res_wd2[1])/sum_res_wd,".2%"))
        print str((temp_res_wd2[2])+"==》")+str(format(int(temp_res_wd2[3])/sum_res_wd,".2%"))
        print str((temp_res_wd2[4])+"==》")+str(format(int(temp_res_wd2[5])/sum_res_wd,".2%"))
        print str((temp_res_wd2[6])+"==》")+str(format(int(temp_res_wd2[7])/sum_res_wd,".2%"))

    #2.对于sql_res_dl的输出进行处理
    cur.execute(sql_res_dl)
    #将SQL的所有结果保存到文件中
    for item in cur.fetchall():
        temp_res_dl.append(str(item[0]))
        temp_res_dl.append(str(item[1]))
        sum_res_dl+=item[1]
    print "
平负预测-->共"+str(sum_res_dl)+"场"
    #统计比分比例
    cur.execute(sql_res_dl)
    l = len(temp_res_dl)
    if l==4:
        temp_res_dl2 = temp_res_dl[-2:]
        print str((temp_res_dl2[0])+"==》")+str(format(int(temp_res_dl2[1])/sum_res_dl,".2%"))
    elif l==6:
        temp_res_dl2 = temp_res_dl[-4:]
        print str((temp_res_dl2[0])+"==》")+str(format(int(temp_res_dl2[1])/sum_res_dl,".2%"))
        print str((temp_res_dl2[2])+"==》")+str(format(int(temp_res_dl2[3])/sum_res_dl,".2%"))
    elif l>6:
        temp_res_dl2 = temp_res_dl[-8:]
        print str((temp_res_dl2[0])+"==》")+str(format(int(temp_res_dl2[1])/sum_res_dl,".2%"))
        print str((temp_res_dl2[2])+"==》")+str(format(int(temp_res_dl2[3])/sum_res_dl,".2%"))
        print str((temp_res_dl2[4])+"==》")+str(format(int(temp_res_dl2[5])/sum_res_dl,".2%"))
        print str((temp_res_dl2[6])+"==》")+str(format(int(temp_res_dl2[7])/sum_res_dl,".2%"))

    #3.对于sql_res_wl的输出进行处理
    cur.execute(sql_res_wl)
    #将SQL的所有结果保存到文件中
    for item in cur.fetchall():
        temp_res_wl.append(str(item[0]))
        temp_res_wl.append(str(item[1]))
        sum_res_wl+=item[1]
    print "
胜负预测-->共"+str(sum_res_wl)+"场"
    #统计比分比例
    cur.execute(sql_res_wl)
    l = len(temp_res_wl)
    if l==4:
        temp_res_wl2 = temp_res_wl[-2:]
        print str((temp_res_wl2[0])+"==》")+str(format(int(temp_res_wl2[1])/sum_res_wl,".2%"))
    elif l==6:
        temp_res_wl2 = temp_res_wl[-4:]
        print str((temp_res_wl2[0])+"==》")+str(format(int(temp_res_wl2[1])/sum_res_wl,".2%"))
        print str((temp_res_wl2[2])+"==》")+str(format(int(temp_res_wl2[3])/sum_res_wl,".2%"))
    elif l>6:
        temp_res_wl2 = temp_res_wl[-12:]
        print str((temp_res_wl2[0])+"==》")+str(format(int(temp_res_wl2[1])/sum_res_wl,".2%"))
        print str((temp_res_wl2[2])+"==》")+str(format(int(temp_res_wl2[3])/sum_res_wl,".2%"))
        print str((temp_res_wl2[4])+"==》")+str(format(int(temp_res_wl2[5])/sum_res_wl,".2%"))
        print str((temp_res_wl2[6])+"==》")+str(format(int(temp_res_wl2[7])/sum_res_wl,".2%"))
        print str((temp_res_wl2[8])+"==》")+str(format(int(temp_res_wl2[9])/sum_res_wl,".2%"))
        print str((temp_res_wl2[10])+"==》")+str(format(int(temp_res_wl2[11])/sum_res_wl,".2%"))
    #======END OF THE FUNCTION======
    f.close()

def preAll(cur,scr,w,d,l,a):
    preSpf(cur,scr,w,d,l,a)
    preZjq(cur,scr,w,d,l,a)
    preRes(cur,scr,w,d,l,a)

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/37385.html

相关文章

  • 利用线性回归模型进行卫星轨道预报

    摘要:数据问题解所有数据平均值平均值回归方程回归方程回归系数估计轨道文件回归系数预测结果回归系数预测 数据 300,21182.88,-7044.56,14639.48 600,21707.87,-6930.28,13906.68 900,22207.04,-6828.65,13147.66 1200,22679.16,-6738.66,12363.84 1500,23123.06,-665...

    Wuv1Up 评论0 收藏0
  • 基于Keras实现加密卷积神经网络

    摘要:奥胡斯大学密码学机器学习工程师介绍了如何实现基于加密数据进行训练和预测的卷积神经网络。通过卷积神经网络分析图像在最近几年极为流行,因为在图像相关任务上的表现超过了其他许多方法。 奥胡斯大学密码学PhD、Datadog机器学习工程师Morten Dahl介绍了如何实现基于加密数据进行训练和预测的卷积神经网络。TL;DR 我们选取了一个经典的CNN深度学习模型,经过一系列步骤的改造,使其得以基于...

    fjcgreat 评论0 收藏0
  • 写在 TiDB 1.0 发布之际 | 预测未来最好的方式就是创造未来

    摘要:还记得有人说预测未来最好的方式就是创造未来,以前看到这句话总觉得是废话,如今看到这一切在自己身上变成现实的一刻,感受是如此的真切,敲击键盘的手居然有点颤抖,是的,预测未来最好的方式就是创造未来。 如果只能用一个词来描述此刻的心情,我想说恍如隔世,这样说多少显得有几分矫情,或许内心还是想在能矫情的时候再矫情一次,毕竟当初做这一切的起因是为了梦想。还记得有人说预测未来最好的方式就是创造未来...

    ysl_unh 评论0 收藏0
  • Google Coral Edge TPU USB加速棒上手体验

    摘要:谷歌在年国际消费电子展以及今年的开发峰会上首次展示了他们的,然后于三月份发布了。树莓派上性能的局限性不幸的是,业余爱好者最喜欢树莓派无法充分发挥加速器的功能和速度。使用端口,目前的树莓派设备没有或,而只能使用速度较慢的。 Edge AI是什么?它为何如此重要? 传统意义上,AI解决方案需要强大的并行计算处理能力,长期以来,AI服务都是通过联网在线的云端基于服务器的计算来提供服务。但是具...

    hiyayiji 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<