C1Service.go 5.7 KB
Newer Older
M
monomania 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
package service

import (
	"math"
	"strconv"
	"tesou.io/platform/foot-parent/foot-api/common/base"
	entity5 "tesou.io/platform/foot-parent/foot-api/module/analy/pojo"
	"tesou.io/platform/foot-parent/foot-api/module/match/pojo"
	entity3 "tesou.io/platform/foot-parent/foot-api/module/odds/pojo"
	"tesou.io/platform/foot-parent/foot-core/common/utils"
	"tesou.io/platform/foot-parent/foot-core/module/analy/constants"
	"tesou.io/platform/foot-parent/foot-core/module/match/service"
	"time"
)

type C1Service struct {
	AnalyService
	service.BFScoreService
	service.BFBattleService
	service.BFFutureEventService

	//最大让球数据
	MaxLetBall float64
}

func (this *C1Service) ModelName() string {
	//alFlag := reflect.TypeOf(*this).Name()
	return "C1"
}

func (this *C1Service) Analy() {
32 33
	matchList := this.MatchLastService.FindNotFinished()
	//matchList := this.MatchLastService.FindAll()
M
monomania 已提交
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
	this.Analy_Process(matchList)

}

func (this *C1Service) Analy_Near() {
	matchList := this.MatchLastService.FindNear()
	this.Analy_Process(matchList)
}

func (this *C1Service) Analy_Process(matchList []*pojo.MatchLast) {
	data_list_slice := make([]interface{}, 0)
	data_modify_list_slice := make([]interface{}, 0)
	for _, v := range matchList {
		stub, data := this.analyStub(v)

		if stub == 0 || stub == 1 {
			hours := v.MatchDate.Sub(time.Now()).Hours()
			if hours > 0 {
				hours = math.Abs(hours * 0.5)
				data.THitCount = int(hours)
			} else {
				data.THitCount = 1
			}
			if stub == 0 {
				data_list_slice = append(data_list_slice, data)
			} else if stub == 1 {
				data_modify_list_slice = append(data_modify_list_slice, data)
			}
		} else {
			temp_data := this.Find(v.Id, this.ModelName())
			if len(temp_data.Id) > 0 {
				hit_count_str := utils.GetVal(constants.SECTION_NAME, "hit_count")
				hit_count, _ := strconv.Atoi(hit_count_str)
				if temp_data.HitCount >= hit_count {
					temp_data.HitCount = (hit_count / 2) - 1
				} else {
					temp_data.HitCount = 0
				}
				this.AnalyService.Modify(temp_data)
			}
		}
	}
	this.AnalyService.SaveList(data_list_slice)
	this.AnalyService.ModifyList(data_modify_list_slice)
}

func (this *C1Service) analyStub(v *pojo.MatchLast) (int, *entity5.AnalyResult) {
	matchId := v.Id
	//声明使用变量
	var a18betData *entity3.AsiaLast
	//亚赔
	aList := this.AsiaLastService.FindByMatchIdCompId(matchId, "18Bet")
	if len(aList) < 1 {
		return -1, nil
	}
	a18betData = aList[0]
M
1.xxxx  
monomania 已提交
90 91 92 93
	if matchId == "1738911"{

	}
	if math.Abs(a18betData.ELetBall) > this.MaxLetBall {
M
monomania 已提交
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
		return -2, nil
	}

	//得出结果
	var preResult int
	letBall := 0.00
	//------
	bfs_arr := this.BFScoreService.FindByMatchId(matchId)
	if len(bfs_arr) < 1 {
		return -1, nil
	}

	//排名越小越好
	rankDiff := 4.0
	var temp_val float64
	temp_val = float64(bfs_arr[0].Ranking - bfs_arr[4].Ranking)
	if temp_val >= rankDiff {
		letBall += -0.25 * (temp_val / rankDiff)
	}
	temp_val = float64(bfs_arr[4].Ranking - bfs_arr[0].Ranking)
	if temp_val >= rankDiff {
		letBall += 0.25 * (temp_val / rankDiff)
	}
	temp_val = float64(bfs_arr[1].Ranking - bfs_arr[6].Ranking)
	if temp_val >= rankDiff {
		letBall += -0.25 * (temp_val / rankDiff)
	}
	temp_val = float64(bfs_arr[6].Ranking - bfs_arr[1].Ranking)
	if temp_val >= rankDiff {
		letBall += 0.25 * (temp_val / rankDiff)
	}
	//------
	bfb_arr := this.BFBattleService.FindByMatchId(matchId)
	mainWin := 0
	guestWin := 0
	for _, e := range bfb_arr {
		if e.BattleMainTeamGoals > e.BattleGuestTeamGoals {
			mainWin++
		}
		if e.BattleGuestTeamGoals > e.BattleMainTeamGoals {
			guestWin++
		}
	}
	if mainWin > (guestWin + 1) {
		letBall += 0.25
	}
	if guestWin > (mainWin + 1) {
		letBall += -0.25
	}
	//------
	bffe_main := this.BFFutureEventService.FindNextBattle(matchId, v.MainTeamId)
	bffe_guest := this.BFFutureEventService.FindNextBattle(matchId, v.GuestTeamId)
	//如果主队下一场打客场,战意充足
	if v.MainTeamId == bffe_main.EventGuestTeamId {
		letBall += 0.25
	}
	//如果客队下一场打主场,战意懈怠
	if v.GuestTeamId == bffe_guest.EventMainTeamId {
		letBall += 0.25
	}

	var mainLetball bool
M
1.xxxx  
monomania 已提交
156
	if a18betData.ELetBall > 0 {
M
monomania 已提交
157
		mainLetball = true
M
1.xxxx  
monomania 已提交
158
	} else {
M
monomania 已提交
159 160 161 162 163 164
		mainLetball = false
	}
	sLetBall := math.Abs(a18betData.SLetBall)
	eLetBall := math.Abs(a18betData.ELetBall)
	tLetBall := math.Abs(letBall)

M
1.xxxx  
monomania 已提交
165 166 167
	if (sLetBall >= tLetBall && eLetBall >= tLetBall) || (sLetBall < tLetBall && eLetBall >= tLetBall ){
		if math.Abs(eLetBall-tLetBall) < 0.26 {
			if mainLetball {
M
monomania 已提交
168
				preResult = 3
M
1.xxxx  
monomania 已提交
169
			} else {
M
monomania 已提交
170 171
				preResult = 0
			}
M
1.xxxx  
monomania 已提交
172 173
		}else{
			if mainLetball {
M
monomania 已提交
174
				preResult = 0
M
1.xxxx  
monomania 已提交
175
			} else {
M
monomania 已提交
176 177 178
				preResult = 3
			}
		}
M
1.xxxx  
monomania 已提交
179 180 181
	}else if (sLetBall < tLetBall && eLetBall < tLetBall) || (sLetBall >= tLetBall && eLetBall < tLetBall ) {
		if math.Abs(tLetBall-eLetBall) < 0.26 {
			if mainLetball {
M
monomania 已提交
182
				preResult = 3
M
1.xxxx  
monomania 已提交
183
			} else {
M
monomania 已提交
184 185
				preResult = 0
			}
M
1.xxxx  
monomania 已提交
186 187
		}else{
			if mainLetball {
M
monomania 已提交
188
				preResult = 0
M
1.xxxx  
monomania 已提交
189
			} else {
M
monomania 已提交
190 191 192
				preResult = 3
			}
		}
M
1.xxxx  
monomania 已提交
193 194
	}else {
		base.Log.Error("C1分析模型出现错误!!!")
M
monomania 已提交
195
	}
M
1.xxxx  
monomania 已提交
196
	base.Log.Info("计算得出让球为:", letBall, ",初盘让球:", a18betData.SLetBall, ",即时盘让球:", a18betData.ELetBall)
M
monomania 已提交
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
	var data *entity5.AnalyResult
	temp_data := this.Find(v.Id, this.ModelName())
	if len(temp_data.Id) > 0 {
		temp_data.PreResult = preResult
		temp_data.HitCount = temp_data.HitCount + 1
		temp_data.LetBall = a18betData.ELetBall
		data = temp_data
		//比赛结果
		data.Result = this.IsRight(a18betData, v, data)
		return 1, data
	} else {
		data = new(entity5.AnalyResult)
		data.MatchId = v.Id
		data.MatchDate = v.MatchDate
		data.LetBall = a18betData.ELetBall
		data.AlFlag = this.ModelName()
		format := time.Now().Format("0102150405")
		data.AlSeq = format
		data.PreResult = preResult
		data.HitCount = 1
		data.LetBall = a18betData.ELetBall
		//比赛结果
		data.Result = this.IsRight(a18betData, v, data)
		return 0, data
	}

}