Archived
1

Massive refactoring for future development

This commit is contained in:
2017-11-21 06:06:32 +04:00
parent f5d801b768
commit dfe0d08ecc
45 changed files with 742 additions and 640 deletions

View File

@@ -0,0 +1,28 @@
// i2_bot Instinct PokememBro Bot
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
package statistics
import (
"lab.pztrn.name/fat0troll/i2_bot/lib/appcontext"
"lab.pztrn.name/fat0troll/i2_bot/lib/statistics/statisticsinterface"
)
var (
c *appcontext.Context
)
// Statistics is a function-handling struct for package statistics.
type Statistics struct{}
// New is an initialization function for appcontext
func New(ac *appcontext.Context) {
c = ac
s := &Statistics{}
c.RegisterStatisticsInterface(statisticsinterface.StatisticsInterface(s))
}
// Init is a initialization function for package
func (s *Statistics) Init() {
c.Log.Info("Initializing Statistics...")
}

40
lib/statistics/points.go Normal file
View File

@@ -0,0 +1,40 @@
// i2_bot Instinct PokememBro Bot
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
package statistics
import (
"strconv"
"strings"
)
// GetPoints returns points to use in database
func (s *Statistics) GetPoints(pointsStr string) int {
value := 0
if strings.HasSuffix(pointsStr, "K") {
valueNumber := strings.Replace(pointsStr, "K", "", 1)
valueFloat, _ := strconv.ParseFloat(valueNumber, 64)
value = int(valueFloat * 1000)
} else if strings.HasSuffix(pointsStr, "M") {
valueNumber := strings.Replace(pointsStr, "M", "", 1)
valueFloat, _ := strconv.ParseFloat(valueNumber, 64)
value = int(valueFloat * 1000000)
} else {
value, _ = strconv.Atoi(pointsStr)
}
return value
}
// GetPrintablePoints returns to output points (ht, attack, mp...) formatted
// like in PokememBroBot itself.
func (s *Statistics) GetPrintablePoints(points int) string {
if points < 1000 {
return strconv.Itoa(points)
} else if points < 1000000 {
floatNum := float64(points) / 1000.0
return strconv.FormatFloat(floatNum, 'f', -1, 64) + "K"
} else {
floatNum := float64(points) / 1000000.0
return strconv.FormatFloat(floatNum, 'f', -1, 64) + "M"
}
}

View File

@@ -0,0 +1,76 @@
// i2_bot Instinct PokememBro Bot
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
package statistics
// PossibilityRequiredPokeballs returns possibility of catching pokememe
// It's based on location, grade of pokememe and current level of player
func (s *Statistics) PossibilityRequiredPokeballs(location int, grade int, lvl int) (float64, int) {
var basePossibility float64
var requiredPokeballs int
var percentile float64
if lvl > 3 {
switch {
case grade == (lvl + 1):
basePossibility = 0.05
case grade == lvl:
basePossibility = 0.5
case grade == (lvl - 1):
basePossibility = 0.3
case grade == (lvl - 2):
basePossibility = 0.1
case grade == (lvl - 3):
basePossibility = 0.05
default:
basePossibility = 0.00
}
} else if lvl == 3 {
switch grade {
case 4:
basePossibility = 0.05
case 3:
basePossibility = 0.5
case 2:
basePossibility = 0.3
case 1:
basePossibility = 0.15
default:
basePossibility = 0.00
}
} else if lvl == 2 {
switch grade {
case 3:
basePossibility = 0.05
case 2:
basePossibility = 0.70
case 1:
basePossibility = 0.25
default:
basePossibility = 0.00
}
} else if lvl == 1 {
switch grade {
case 2:
basePossibility = 0.80
case 1:
basePossibility = 0.20
default:
basePossibility = 0.00
}
}
var pokememesCount int
err := c.Db.Get(&pokememesCount, c.Db.Rebind("SELECT count(*) FROM pokememes p, pokememes_locations pl WHERE p.grade = ? AND pl.location_id = ? AND pl.pokememe_id = p.id;"), grade, location)
if err != nil {
c.Log.Error(err)
}
if basePossibility != 0 && pokememesCount != 0 {
percentile = basePossibility * 100.0 / float64(pokememesCount)
requiredPokeballs = int(100.0 / percentile)
}
return percentile, requiredPokeballs
}

View File

@@ -0,0 +1,14 @@
// i2_bot Instinct PokememBro Bot
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
package statisticsinterface
// StatisticsInterface implements Statistics for importing via appcontext.
type StatisticsInterface interface {
Init()
GetPoints(pointsStr string) int
GetPrintablePoints(points int) string
PossibilityRequiredPokeballs(location int, grade int, lvl int) (float64, int)
}