individualwaterpoolconf.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package individualwaterpool
  2. import (
  3. "encoding/json"
  4. "os"
  5. "time"
  6. "bet24.com/log"
  7. platformconfig "bet24.com/servers/micros/platformconfig/proto"
  8. )
  9. const config_key = "individualwaterpool_config"
  10. // 游戏系数
  11. type GameCoefficient struct {
  12. GameId int // 游戏Id
  13. GameType int // 游戏类型
  14. BaseScore int // 房间底分
  15. MinValue int // 保底分数
  16. Coefficient float64 // 系数值
  17. IsMatch bool // 是否比赛场
  18. }
  19. func (g *GameCoefficient) dump() {
  20. log.Release("GameId[%d] GameType[%d] BaseScore[%d] minValue[%d]Coefficient[%v] IsMatch[%v]",
  21. g.GameId, g.GameType, g.BaseScore, g.MinValue, g.Coefficient, g.IsMatch)
  22. }
  23. // 个人奖池系数配置
  24. type IndividualPoolConfig struct {
  25. ConstantK int // 常量系数K
  26. MinProb int // 保底概率
  27. MaxProb int // 概率上限
  28. GameCoefficients []GameCoefficient // 所有游戏系数
  29. }
  30. func (h *IndividualPoolConfig) getGameCoefficient(gameId, gameType, baseScore int, isMatch bool) (float64, int) {
  31. for i := 0; i < len(h.GameCoefficients); i++ {
  32. if h.GameCoefficients[i].GameId == gameId &&
  33. isMatch == h.GameCoefficients[i].IsMatch &&
  34. h.GameCoefficients[i].GameType == gameType &&
  35. ((h.GameCoefficients[i].BaseScore == baseScore && !isMatch) || isMatch) {
  36. return h.GameCoefficients[i].Coefficient, h.GameCoefficients[i].MinValue
  37. }
  38. }
  39. return 0, 0
  40. }
  41. func (h *IndividualPoolConfig) dump() {
  42. log.Release("ConstantK[%d] MinProb[%d] MaxProb[%d]", h.ConstantK, h.MinProb, h.MaxProb)
  43. log.Release("GameCoefficients:")
  44. for _, g := range h.GameCoefficients {
  45. g.dump()
  46. }
  47. }
  48. func (wpm *waterPoolMgr) loadConfig() {
  49. wpm.loadRedisConfig()
  50. go time.AfterFunc(5*time.Minute, wpm.loadConfig)
  51. }
  52. func (wpm *waterPoolMgr) loadRedisConfig() {
  53. configString := platformconfig.GetConfig(config_key)
  54. if configString == "" {
  55. data, err := os.ReadFile("serviceconf/individualwaterpool_extra.json")
  56. if err != nil {
  57. log.Release("IndividualWaterPool.readConf read individualwaterpool_extra failed")
  58. return
  59. }
  60. configString = string(data)
  61. if configString != "" {
  62. platformconfig.SetConfig(config_key, configString)
  63. }
  64. }
  65. err := json.Unmarshal([]byte(configString), &wpm.config)
  66. if err != nil {
  67. log.Release("IndualWaterPool.readConf Unmarshal failed err:%v", err)
  68. }
  69. }