Skip to content

Commit

Permalink
Update model.go
Browse files Browse the repository at this point in the history
  • Loading branch information
xyy0411 authored Aug 25, 2024
1 parent bc63eb0 commit 117d56b
Showing 1 changed file with 9 additions and 21 deletions.
30 changes: 9 additions & 21 deletions plugin/niuniu/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,38 +60,26 @@ func (m users) negative() []userInfo {
}

func (m users) sort(isDesc bool) users {
var t func(i, j int) bool
t := func(i, j int) bool {
return m[i].UserCount < m[j].UserCount
}
if isDesc {
t = func(i, j int) bool {
return m[i].Length > m[j].Length
}
} else {
t = func(i, j int) bool {
return m[i].Length < m[j].Length
}
}
sort.Slice(m, t)
return m
}

func (m users) ranking(niuniu float64, uid int64) int {
var ranking int
switch {
case niuniu > 0:
for i, info := range m.sort(true) {
if info.UID == uid {
ranking = i + 1
break
}
}
default:
for i, info := range m.sort(false) {
if info.UID == uid {
ranking = i + 1
break
}
result := niuniu > 0
for i, user := range m.sort(result) {
if user.UID == uid {
return i + 1
}
}
return ranking
return -1
}

func (db *model) randLength() decimal.Decimal {
Expand Down

0 comments on commit 117d56b

Please sign in to comment.