All code formatted with gofmt
This commit is contained in:
@@ -4,25 +4,25 @@
|
||||
package getters
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"log"
|
||||
// local
|
||||
"../appcontext"
|
||||
"../getters/gettersinterface"
|
||||
// stdlib
|
||||
"log"
|
||||
// local
|
||||
"../appcontext"
|
||||
"../getters/gettersinterface"
|
||||
)
|
||||
|
||||
var (
|
||||
c *appcontext.Context
|
||||
c *appcontext.Context
|
||||
)
|
||||
|
||||
type Getters struct {}
|
||||
type Getters struct{}
|
||||
|
||||
func New(ac *appcontext.Context) {
|
||||
c = ac
|
||||
g := &Getters{}
|
||||
c.RegisterGettersInterface(gettersinterface.GettersInterface(g))
|
||||
c = ac
|
||||
g := &Getters{}
|
||||
c.RegisterGettersInterface(gettersinterface.GettersInterface(g))
|
||||
}
|
||||
|
||||
func (g *Getters) Init() {
|
||||
log.Printf("Initializing getters...")
|
||||
log.Printf("Initializing getters...")
|
||||
}
|
||||
|
@@ -4,21 +4,21 @@
|
||||
package gettersinterface
|
||||
|
||||
import (
|
||||
// local
|
||||
"../../dbmapping"
|
||||
// local
|
||||
"../../dbmapping"
|
||||
)
|
||||
|
||||
type GettersInterface interface {
|
||||
Init()
|
||||
// Player
|
||||
GetOrCreatePlayer(telegram_id int) (dbmapping.Player, bool)
|
||||
GetPlayerByID(player_id int) (dbmapping.Player, bool)
|
||||
// Profile
|
||||
GetProfile(player_id int) (dbmapping.Profile, bool)
|
||||
// Pokememes
|
||||
GetPokememes() ([]dbmapping.PokememeFull, bool)
|
||||
GetBestPokememes(player_id int) ([]dbmapping.PokememeFull, bool)
|
||||
GetPokememeByID(pokememe_id string) (dbmapping.PokememeFull, bool)
|
||||
// Possibilities
|
||||
PossibilityRequiredPokeballs(location int, grade int, lvl int) (float64, int)
|
||||
Init()
|
||||
// Player
|
||||
GetOrCreatePlayer(telegram_id int) (dbmapping.Player, bool)
|
||||
GetPlayerByID(player_id int) (dbmapping.Player, bool)
|
||||
// Profile
|
||||
GetProfile(player_id int) (dbmapping.Profile, bool)
|
||||
// Pokememes
|
||||
GetPokememes() ([]dbmapping.PokememeFull, bool)
|
||||
GetBestPokememes(player_id int) ([]dbmapping.PokememeFull, bool)
|
||||
GetPokememeByID(pokememe_id string) (dbmapping.PokememeFull, bool)
|
||||
// Possibilities
|
||||
PossibilityRequiredPokeballs(location int, grade int, lvl int) (float64, int)
|
||||
}
|
||||
|
@@ -4,46 +4,46 @@
|
||||
package getters
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"log"
|
||||
"time"
|
||||
// local
|
||||
"../dbmapping"
|
||||
// stdlib
|
||||
"log"
|
||||
"time"
|
||||
// local
|
||||
"../dbmapping"
|
||||
)
|
||||
|
||||
func (g *Getters) GetPlayerByID(player_id int) (dbmapping.Player, bool) {
|
||||
player_raw := dbmapping.Player{}
|
||||
err := c.Db.Get(&player_raw, c.Db.Rebind("SELECT * FROM players WHERE id=?"), player_id)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return player_raw, false
|
||||
}
|
||||
player_raw := dbmapping.Player{}
|
||||
err := c.Db.Get(&player_raw, c.Db.Rebind("SELECT * FROM players WHERE id=?"), player_id)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return player_raw, false
|
||||
}
|
||||
|
||||
return player_raw, true
|
||||
return player_raw, true
|
||||
}
|
||||
|
||||
func (g *Getters) GetOrCreatePlayer(telegram_id int) (dbmapping.Player, bool) {
|
||||
player_raw := dbmapping.Player{}
|
||||
err := c.Db.Get(&player_raw, c.Db.Rebind("SELECT * FROM players WHERE telegram_id=?"), telegram_id)
|
||||
if err != nil {
|
||||
log.Printf("Message user not found in database.")
|
||||
log.Printf(err.Error())
|
||||
player_raw := dbmapping.Player{}
|
||||
err := c.Db.Get(&player_raw, c.Db.Rebind("SELECT * FROM players WHERE telegram_id=?"), telegram_id)
|
||||
if err != nil {
|
||||
log.Printf("Message user not found in database.")
|
||||
log.Printf(err.Error())
|
||||
|
||||
// Create "nobody" user
|
||||
player_raw.Telegram_id = telegram_id
|
||||
player_raw.League_id = 0
|
||||
player_raw.Squad_id = 0
|
||||
player_raw.Status = "nobody"
|
||||
player_raw.Created_at = time.Now().UTC()
|
||||
player_raw.Updated_at = time.Now().UTC()
|
||||
_, err = c.Db.NamedExec("INSERT INTO players VALUES(NULL, :telegram_id, :league_id, :squad_id, :status, :created_at, :updated_at)", &player_raw)
|
||||
if err != nil {
|
||||
log.Printf(err.Error())
|
||||
return player_raw, false
|
||||
}
|
||||
} else {
|
||||
log.Printf("Message user found in database.")
|
||||
}
|
||||
// Create "nobody" user
|
||||
player_raw.Telegram_id = telegram_id
|
||||
player_raw.League_id = 0
|
||||
player_raw.Squad_id = 0
|
||||
player_raw.Status = "nobody"
|
||||
player_raw.Created_at = time.Now().UTC()
|
||||
player_raw.Updated_at = time.Now().UTC()
|
||||
_, err = c.Db.NamedExec("INSERT INTO players VALUES(NULL, :telegram_id, :league_id, :squad_id, :status, :created_at, :updated_at)", &player_raw)
|
||||
if err != nil {
|
||||
log.Printf(err.Error())
|
||||
return player_raw, false
|
||||
}
|
||||
} else {
|
||||
log.Printf("Message user found in database.")
|
||||
}
|
||||
|
||||
return player_raw, true
|
||||
return player_raw, true
|
||||
}
|
||||
|
@@ -4,178 +4,178 @@
|
||||
package getters
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"log"
|
||||
"strconv"
|
||||
// local
|
||||
"../dbmapping"
|
||||
// stdlib
|
||||
"log"
|
||||
"strconv"
|
||||
// local
|
||||
"../dbmapping"
|
||||
)
|
||||
|
||||
// Internal functions
|
||||
|
||||
func (g *Getters) formFullPokememes(pokememes []dbmapping.Pokememe) ([]dbmapping.PokememeFull, bool) {
|
||||
pokememes_full := []dbmapping.PokememeFull{}
|
||||
elements := []dbmapping.Element{}
|
||||
err := c.Db.Select(&elements, "SELECT * FROM elements");
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememes_full, false
|
||||
}
|
||||
locations := []dbmapping.Location{}
|
||||
err = c.Db.Select(&locations, "SELECT * FROM locations");
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememes_full, false
|
||||
}
|
||||
pokememes_elements := []dbmapping.PokememeElement{}
|
||||
err = c.Db.Select(&pokememes_elements, "SELECT * FROM pokememes_elements");
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememes_full, false
|
||||
}
|
||||
pokememes_locations := []dbmapping.PokememeLocation{}
|
||||
err = c.Db.Select(&pokememes_locations, "SELECT * FROM pokememes_locations");
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememes_full, false
|
||||
}
|
||||
pokememes_full := []dbmapping.PokememeFull{}
|
||||
elements := []dbmapping.Element{}
|
||||
err := c.Db.Select(&elements, "SELECT * FROM elements")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememes_full, false
|
||||
}
|
||||
locations := []dbmapping.Location{}
|
||||
err = c.Db.Select(&locations, "SELECT * FROM locations")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememes_full, false
|
||||
}
|
||||
pokememes_elements := []dbmapping.PokememeElement{}
|
||||
err = c.Db.Select(&pokememes_elements, "SELECT * FROM pokememes_elements")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememes_full, false
|
||||
}
|
||||
pokememes_locations := []dbmapping.PokememeLocation{}
|
||||
err = c.Db.Select(&pokememes_locations, "SELECT * FROM pokememes_locations")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememes_full, false
|
||||
}
|
||||
|
||||
for i := range(pokememes) {
|
||||
full_pokememe := dbmapping.PokememeFull{}
|
||||
elements_listed := []dbmapping.Element{}
|
||||
locations_listed := []dbmapping.Location{}
|
||||
for i := range pokememes {
|
||||
full_pokememe := dbmapping.PokememeFull{}
|
||||
elements_listed := []dbmapping.Element{}
|
||||
locations_listed := []dbmapping.Location{}
|
||||
|
||||
for j := range(pokememes_locations) {
|
||||
if pokememes_locations[j].Pokememe_id == pokememes[i].Id {
|
||||
for l := range(locations) {
|
||||
if pokememes_locations[j].Location_id == locations[l].Id {
|
||||
locations_listed = append(locations_listed, locations[l])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for j := range pokememes_locations {
|
||||
if pokememes_locations[j].Pokememe_id == pokememes[i].Id {
|
||||
for l := range locations {
|
||||
if pokememes_locations[j].Location_id == locations[l].Id {
|
||||
locations_listed = append(locations_listed, locations[l])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for k := range(pokememes_elements) {
|
||||
if pokememes_elements[k].Pokememe_id == pokememes[i].Id {
|
||||
for e := range(elements) {
|
||||
if pokememes_elements[k].Element_id == elements[e].Id {
|
||||
elements_listed = append(elements_listed, elements[e])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for k := range pokememes_elements {
|
||||
if pokememes_elements[k].Pokememe_id == pokememes[i].Id {
|
||||
for e := range elements {
|
||||
if pokememes_elements[k].Element_id == elements[e].Id {
|
||||
elements_listed = append(elements_listed, elements[e])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
full_pokememe.Pokememe = pokememes[i]
|
||||
full_pokememe.Elements = elements_listed
|
||||
full_pokememe.Locations = locations_listed
|
||||
full_pokememe.Pokememe = pokememes[i]
|
||||
full_pokememe.Elements = elements_listed
|
||||
full_pokememe.Locations = locations_listed
|
||||
|
||||
pokememes_full = append(pokememes_full, full_pokememe)
|
||||
}
|
||||
pokememes_full = append(pokememes_full, full_pokememe)
|
||||
}
|
||||
|
||||
return pokememes_full, true
|
||||
return pokememes_full, true
|
||||
}
|
||||
|
||||
// External functions
|
||||
|
||||
func (g *Getters) GetPokememes() ([]dbmapping.PokememeFull, bool) {
|
||||
pokememes_full := []dbmapping.PokememeFull{}
|
||||
pokememes := []dbmapping.Pokememe{}
|
||||
err := c.Db.Select(&pokememes, "SELECT * FROM pokememes ORDER BY grade asc, name asc");
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememes_full, false
|
||||
}
|
||||
pokememes_full := []dbmapping.PokememeFull{}
|
||||
pokememes := []dbmapping.Pokememe{}
|
||||
err := c.Db.Select(&pokememes, "SELECT * FROM pokememes ORDER BY grade asc, name asc")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememes_full, false
|
||||
}
|
||||
|
||||
pokememes_full, ok := g.formFullPokememes(pokememes)
|
||||
return pokememes_full, ok
|
||||
pokememes_full, ok := g.formFullPokememes(pokememes)
|
||||
return pokememes_full, ok
|
||||
}
|
||||
|
||||
func (g *Getters) GetBestPokememes(player_id int) ([]dbmapping.PokememeFull, bool) {
|
||||
pokememes_full := []dbmapping.PokememeFull{}
|
||||
player_raw, ok := g.GetPlayerByID(player_id)
|
||||
if !ok {
|
||||
return pokememes_full, ok
|
||||
}
|
||||
profile_raw, ok := g.GetProfile(player_id)
|
||||
if !ok {
|
||||
return pokememes_full, ok
|
||||
}
|
||||
pokememes_full := []dbmapping.PokememeFull{}
|
||||
player_raw, ok := g.GetPlayerByID(player_id)
|
||||
if !ok {
|
||||
return pokememes_full, ok
|
||||
}
|
||||
profile_raw, ok := g.GetProfile(player_id)
|
||||
if !ok {
|
||||
return pokememes_full, ok
|
||||
}
|
||||
|
||||
if player_raw.League_id == 0 {
|
||||
return pokememes_full, false
|
||||
}
|
||||
if player_raw.League_id == 0 {
|
||||
return pokememes_full, false
|
||||
}
|
||||
|
||||
// TODO: make it more complicated
|
||||
pokememes := []dbmapping.Pokememe{}
|
||||
err := c.Db.Select(&pokememes, c.Db.Rebind("SELECT p.* FROM pokememes p, pokememes_elements pe, elements e WHERE e.league_id = ? AND p.grade = ? AND pe.element_id = e.id AND pe.pokememe_id = p.id ORDER BY p.attack DESC"), player_raw.League_id, profile_raw.Level_id + 1)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememes_full, false
|
||||
}
|
||||
// TODO: make it more complicated
|
||||
pokememes := []dbmapping.Pokememe{}
|
||||
err := c.Db.Select(&pokememes, c.Db.Rebind("SELECT p.* FROM pokememes p, pokememes_elements pe, elements e WHERE e.league_id = ? AND p.grade = ? AND pe.element_id = e.id AND pe.pokememe_id = p.id ORDER BY p.attack DESC"), player_raw.League_id, profile_raw.Level_id+1)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememes_full, false
|
||||
}
|
||||
|
||||
pokememes_full, ok = g.formFullPokememes(pokememes)
|
||||
return pokememes_full, ok
|
||||
pokememes_full, ok = g.formFullPokememes(pokememes)
|
||||
return pokememes_full, ok
|
||||
}
|
||||
|
||||
func (g *Getters) GetPokememeByID(pokememe_id string) (dbmapping.PokememeFull, bool) {
|
||||
pokememe_full := dbmapping.PokememeFull{}
|
||||
pokememe := dbmapping.Pokememe{}
|
||||
err := c.Db.Get(&pokememe, c.Db.Rebind("SELECT * FROM pokememes WHERE id=?"), pokememe_id)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememe_full, false
|
||||
}
|
||||
elements := []dbmapping.Element{}
|
||||
err = c.Db.Select(&elements, "SELECT * FROM elements");
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememe_full, false
|
||||
}
|
||||
locations := []dbmapping.Location{}
|
||||
err = c.Db.Select(&locations, "SELECT * FROM locations");
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememe_full, false
|
||||
}
|
||||
pokememes_elements := []dbmapping.PokememeElement{}
|
||||
err = c.Db.Select(&pokememes_elements, "SELECT * FROM pokememes_elements WHERE pokememe_id='" + strconv.Itoa(pokememe.Id) + "'");
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememe_full, false
|
||||
}
|
||||
pokememes_locations := []dbmapping.PokememeLocation{}
|
||||
err = c.Db.Select(&pokememes_locations, "SELECT * FROM pokememes_locations WHERE pokememe_id='" + strconv.Itoa(pokememe.Id) + "'");
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememe_full, false
|
||||
}
|
||||
pokememe_full := dbmapping.PokememeFull{}
|
||||
pokememe := dbmapping.Pokememe{}
|
||||
err := c.Db.Get(&pokememe, c.Db.Rebind("SELECT * FROM pokememes WHERE id=?"), pokememe_id)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememe_full, false
|
||||
}
|
||||
elements := []dbmapping.Element{}
|
||||
err = c.Db.Select(&elements, "SELECT * FROM elements")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememe_full, false
|
||||
}
|
||||
locations := []dbmapping.Location{}
|
||||
err = c.Db.Select(&locations, "SELECT * FROM locations")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememe_full, false
|
||||
}
|
||||
pokememes_elements := []dbmapping.PokememeElement{}
|
||||
err = c.Db.Select(&pokememes_elements, "SELECT * FROM pokememes_elements WHERE pokememe_id='"+strconv.Itoa(pokememe.Id)+"'")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememe_full, false
|
||||
}
|
||||
pokememes_locations := []dbmapping.PokememeLocation{}
|
||||
err = c.Db.Select(&pokememes_locations, "SELECT * FROM pokememes_locations WHERE pokememe_id='"+strconv.Itoa(pokememe.Id)+"'")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememe_full, false
|
||||
}
|
||||
|
||||
elements_listed := []dbmapping.Element{}
|
||||
locations_listed := []dbmapping.Location{}
|
||||
elements_listed := []dbmapping.Element{}
|
||||
locations_listed := []dbmapping.Location{}
|
||||
|
||||
for j := range(pokememes_locations) {
|
||||
if pokememes_locations[j].Pokememe_id == pokememe.Id {
|
||||
for l := range(locations) {
|
||||
if pokememes_locations[j].Location_id == locations[l].Id {
|
||||
locations_listed = append(locations_listed, locations[l])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for j := range pokememes_locations {
|
||||
if pokememes_locations[j].Pokememe_id == pokememe.Id {
|
||||
for l := range locations {
|
||||
if pokememes_locations[j].Location_id == locations[l].Id {
|
||||
locations_listed = append(locations_listed, locations[l])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for k := range(pokememes_elements) {
|
||||
if pokememes_elements[k].Pokememe_id == pokememe.Id {
|
||||
for e := range(elements) {
|
||||
if pokememes_elements[k].Element_id == elements[e].Id {
|
||||
elements_listed = append(elements_listed, elements[e])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for k := range pokememes_elements {
|
||||
if pokememes_elements[k].Pokememe_id == pokememe.Id {
|
||||
for e := range elements {
|
||||
if pokememes_elements[k].Element_id == elements[e].Id {
|
||||
elements_listed = append(elements_listed, elements[e])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pokememe_full.Pokememe = pokememe
|
||||
pokememe_full.Elements = elements_listed
|
||||
pokememe_full.Locations = locations_listed
|
||||
pokememe_full.Pokememe = pokememe
|
||||
pokememe_full.Elements = elements_listed
|
||||
pokememe_full.Locations = locations_listed
|
||||
|
||||
return pokememe_full, true
|
||||
return pokememe_full, true
|
||||
}
|
||||
|
@@ -4,76 +4,76 @@
|
||||
package getters
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"log"
|
||||
// stdlib
|
||||
"log"
|
||||
)
|
||||
|
||||
func (g *Getters) PossibilityRequiredPokeballs(location int, grade int, lvl int) (float64, int) {
|
||||
var base_possibility float64 = 0.00
|
||||
var required_pokeballs int = 0
|
||||
var percentile = 0.00
|
||||
var base_possibility float64 = 0.00
|
||||
var required_pokeballs int = 0
|
||||
var percentile = 0.00
|
||||
|
||||
if lvl > 3 {
|
||||
switch {
|
||||
case grade == (lvl + 1):
|
||||
base_possibility = 0.05
|
||||
case grade == lvl:
|
||||
base_possibility = 0.5
|
||||
case grade == (lvl - 1):
|
||||
base_possibility = 0.3
|
||||
case grade == (lvl - 2):
|
||||
base_possibility = 0.1
|
||||
case grade == (lvl - 3):
|
||||
base_possibility = 0.05
|
||||
default:
|
||||
base_possibility = 0.00
|
||||
}
|
||||
} else if lvl == 3 {
|
||||
switch grade {
|
||||
case 4:
|
||||
base_possibility = 0.05
|
||||
case 3:
|
||||
base_possibility = 0.5
|
||||
case 2:
|
||||
base_possibility = 0.3
|
||||
case 1:
|
||||
base_possibility = 0.15
|
||||
default:
|
||||
base_possibility = 0.00
|
||||
}
|
||||
} else if lvl == 2 {
|
||||
switch grade {
|
||||
case 3:
|
||||
base_possibility = 0.05
|
||||
case 2:
|
||||
base_possibility = 0.70
|
||||
case 1:
|
||||
base_possibility = 0.25
|
||||
default:
|
||||
base_possibility = 0.00
|
||||
}
|
||||
} else if lvl == 1 {
|
||||
switch grade {
|
||||
case 2:
|
||||
base_possibility = 0.80
|
||||
case 1:
|
||||
base_possibility = 0.20
|
||||
default:
|
||||
base_possibility = 0.00
|
||||
}
|
||||
}
|
||||
if lvl > 3 {
|
||||
switch {
|
||||
case grade == (lvl + 1):
|
||||
base_possibility = 0.05
|
||||
case grade == lvl:
|
||||
base_possibility = 0.5
|
||||
case grade == (lvl - 1):
|
||||
base_possibility = 0.3
|
||||
case grade == (lvl - 2):
|
||||
base_possibility = 0.1
|
||||
case grade == (lvl - 3):
|
||||
base_possibility = 0.05
|
||||
default:
|
||||
base_possibility = 0.00
|
||||
}
|
||||
} else if lvl == 3 {
|
||||
switch grade {
|
||||
case 4:
|
||||
base_possibility = 0.05
|
||||
case 3:
|
||||
base_possibility = 0.5
|
||||
case 2:
|
||||
base_possibility = 0.3
|
||||
case 1:
|
||||
base_possibility = 0.15
|
||||
default:
|
||||
base_possibility = 0.00
|
||||
}
|
||||
} else if lvl == 2 {
|
||||
switch grade {
|
||||
case 3:
|
||||
base_possibility = 0.05
|
||||
case 2:
|
||||
base_possibility = 0.70
|
||||
case 1:
|
||||
base_possibility = 0.25
|
||||
default:
|
||||
base_possibility = 0.00
|
||||
}
|
||||
} else if lvl == 1 {
|
||||
switch grade {
|
||||
case 2:
|
||||
base_possibility = 0.80
|
||||
case 1:
|
||||
base_possibility = 0.20
|
||||
default:
|
||||
base_possibility = 0.00
|
||||
}
|
||||
}
|
||||
|
||||
var number_of_pokememes int = 0
|
||||
var number_of_pokememes int = 0
|
||||
|
||||
err := c.Db.Get(&number_of_pokememes, 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 {
|
||||
log.Println(err)
|
||||
}
|
||||
err := c.Db.Get(&number_of_pokememes, 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 {
|
||||
log.Println(err)
|
||||
}
|
||||
|
||||
if base_possibility != 0 && number_of_pokememes != 0 {
|
||||
percentile = base_possibility * 100.0 / float64(number_of_pokememes)
|
||||
required_pokeballs = int(100.0 / percentile)
|
||||
}
|
||||
if base_possibility != 0 && number_of_pokememes != 0 {
|
||||
percentile = base_possibility * 100.0 / float64(number_of_pokememes)
|
||||
required_pokeballs = int(100.0 / percentile)
|
||||
}
|
||||
|
||||
return percentile, required_pokeballs
|
||||
return percentile, required_pokeballs
|
||||
}
|
||||
|
@@ -4,19 +4,19 @@
|
||||
package getters
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"log"
|
||||
// local
|
||||
"../dbmapping"
|
||||
// stdlib
|
||||
"log"
|
||||
// local
|
||||
"../dbmapping"
|
||||
)
|
||||
|
||||
func (g *Getters) GetProfile(player_id int) (dbmapping.Profile, bool) {
|
||||
profile_raw := dbmapping.Profile{}
|
||||
err := c.Db.Get(&profile_raw, c.Db.Rebind("SELECT * FROM profiles WHERE player_id=? ORDER BY created_at DESC LIMIT 1"), player_id)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return profile_raw, false
|
||||
}
|
||||
profile_raw := dbmapping.Profile{}
|
||||
err := c.Db.Get(&profile_raw, c.Db.Rebind("SELECT * FROM profiles WHERE player_id=? ORDER BY created_at DESC LIMIT 1"), player_id)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return profile_raw, false
|
||||
}
|
||||
|
||||
return profile_raw, true
|
||||
return profile_raw, true
|
||||
}
|
||||
|
Reference in New Issue
Block a user