mirror of https://github.com/velour/catbase.git
Merge pull request #193 from velour/newpoints
newsbid: divide all bids amongst winners
This commit is contained in:
commit
c25cd7b9c2
|
@ -102,8 +102,8 @@ func (p *NewsBid) check(conn bot.Connector, ch string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, res := range wr {
|
for _, res := range wr {
|
||||||
msg := fmt.Sprintf("%s won %d and lost %d for a score of %d",
|
msg := fmt.Sprintf("%s won %d for a score of %d",
|
||||||
res.User, res.Won, res.Lost, res.Score)
|
res.User, res.Won, res.Score)
|
||||||
if len(res.WinningArticles) > 0 {
|
if len(res.WinningArticles) > 0 {
|
||||||
msg += "\nWinning articles: " + res.WinningArticles.Titles()
|
msg += "\nWinning articles: " + res.WinningArticles.Titles()
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,6 @@ type WeeklyResult struct {
|
||||||
User string
|
User string
|
||||||
Won int
|
Won int
|
||||||
WinningArticles Stories
|
WinningArticles Stories
|
||||||
Lost int
|
|
||||||
LosingArticles Stories
|
LosingArticles Stories
|
||||||
Score int
|
Score int
|
||||||
}
|
}
|
||||||
|
@ -155,14 +154,16 @@ func (w *Webshit) Check() ([]WeeklyResult, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Webshit) checkBids(bids []Bid, storyMap map[string]Story) []WeeklyResult {
|
func (w *Webshit) checkBids(bids []Bid, storyMap map[string]Story) []WeeklyResult {
|
||||||
|
|
||||||
|
var wins []Bid
|
||||||
|
total, totalWinning := 0, 0
|
||||||
wr := map[string]WeeklyResult{}
|
wr := map[string]WeeklyResult{}
|
||||||
|
|
||||||
for _, b := range bids {
|
for _, b := range bids {
|
||||||
score := w.GetScore(b.User)
|
score := w.GetScore(b.User)
|
||||||
if _, ok := wr[b.User]; !ok {
|
if _, ok := wr[b.User]; !ok {
|
||||||
wr[b.User] = WeeklyResult{
|
wr[b.User] = WeeklyResult{
|
||||||
User: b.User,
|
User: b.User,
|
||||||
Won: 0,
|
|
||||||
Lost: 0,
|
|
||||||
Score: score,
|
Score: score,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -176,21 +177,24 @@ func (w *Webshit) checkBids(bids []Bid, storyMap map[string]Story) []WeeklyResul
|
||||||
id := u.Query().Get("id")
|
id := u.Query().Get("id")
|
||||||
|
|
||||||
if s, ok := storyMap[id]; ok {
|
if s, ok := storyMap[id]; ok {
|
||||||
log.Debug().Interface("story", s).Msg("won bid")
|
wins = append(wins, b)
|
||||||
rec.Won += b.Bid
|
|
||||||
rec.Score += b.Bid
|
|
||||||
rec.WinningArticles = append(rec.WinningArticles, s)
|
rec.WinningArticles = append(rec.WinningArticles, s)
|
||||||
log.Debug().Interface("story", s).Msg("Appending to winning log")
|
totalWinning += b.Bid
|
||||||
} else {
|
} else {
|
||||||
log.Debug().Interface("story", s).Msg("lost bid")
|
rec.LosingArticles = append(rec.LosingArticles, Story{b.Title, b.URL})
|
||||||
rec.Lost += b.Bid
|
|
||||||
rec.Score -= b.Bid
|
|
||||||
rec.LosingArticles = append(rec.LosingArticles, Story{Title: b.Title, URL: b.URL})
|
|
||||||
log.Debug().Interface("story", s).Msg("Appending to losing log")
|
|
||||||
}
|
}
|
||||||
|
total += b.Bid
|
||||||
wr[b.User] = rec
|
wr[b.User] = rec
|
||||||
log.Debug().Interface("WR User", wr[b.User]).Str("user", b.User).Msg("setting WR")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, b := range wins {
|
||||||
|
payout := b.Bid / totalWinning * total
|
||||||
|
rec := wr[b.User]
|
||||||
|
rec.Won += payout
|
||||||
|
rec.Score += payout
|
||||||
|
wr[b.User] = rec
|
||||||
|
}
|
||||||
|
|
||||||
return wrMapToSlice(wr)
|
return wrMapToSlice(wr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue