mirror of
https://github.com/ultrasn0w/huso.git
synced 2025-12-14 12:09:53 +01:00
Charts V2
This commit is contained in:
2
huso.go
2
huso.go
@@ -19,7 +19,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
husoVersion = "1.2"
|
husoVersion = "1.3"
|
||||||
registerSecret = "綾波レイ"
|
registerSecret = "綾波レイ"
|
||||||
seasonApiJikan = "seasons/now"
|
seasonApiJikan = "seasons/now"
|
||||||
seasonStrJikan = "seasons/"
|
seasonStrJikan = "seasons/"
|
||||||
|
|||||||
2
ober.go
2
ober.go
@@ -624,7 +624,7 @@ func processUpdateReq(ctx *fasthttp.RequestCtx, update bool) {
|
|||||||
if update {
|
if update {
|
||||||
// anime exitsts => save
|
// anime exitsts => save
|
||||||
// get watch progress
|
// get watch progress
|
||||||
progress, updated, listState, _ := FetchProgress(anime.Anime, userId, username, 0)
|
progress, updated, _, listState, _ := FetchProgress(anime.Anime, username)
|
||||||
// anime is already completed big baka user
|
// anime is already completed big baka user
|
||||||
if listState == malApiStatusC {
|
if listState == malApiStatusC {
|
||||||
ctx.WriteString("Du hast schon fertig geschaut bro")
|
ctx.WriteString("Du hast schon fertig geschaut bro")
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ func Arbeit() {
|
|||||||
for _, a := range animesUsers {
|
for _, a := range animesUsers {
|
||||||
// iterate users
|
// iterate users
|
||||||
for _, u := range a.Users {
|
for _, u := range a.Users {
|
||||||
newProgress, updated, listState, err := FetchProgress(a.Anime, u.MalID, u.Username, u.Progress)
|
newProgress, updated, score, listState, err := FetchProgress(a.Anime, u.Username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
color.Errorln(err.Error())
|
color.Errorln(err.Error())
|
||||||
logOut.WriteError(err)
|
logOut.WriteError(err)
|
||||||
@@ -67,8 +67,8 @@ func Arbeit() {
|
|||||||
}
|
}
|
||||||
// check if user set anime as completed
|
// check if user set anime as completed
|
||||||
if listState == malApiStatusC {
|
if listState == malApiStatusC {
|
||||||
color.Infof("%s finished %d\n", u.Username, a.Anime)
|
color.Infof("%s finished %d scored %d\n", u.Username, a.Anime, score)
|
||||||
logOut.WriteLine(fmt.Sprintf("📜 %s finished %d !", u.Username, a.Anime))
|
logOut.WriteLine(fmt.Sprintf("📜 %s finished %d scored %d !", u.Username, a.Anime, score))
|
||||||
// delete user from anime
|
// delete user from anime
|
||||||
_, err = DeleteUserFromAnime(u.Username, u.MalID, a.Anime)
|
_, err = DeleteUserFromAnime(u.Username, u.MalID, a.Anime)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
70
schaffer.go
70
schaffer.go
@@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -181,57 +182,56 @@ func SearchAppointments(animeId int64) ([]Appointment, error) {
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func FetchProgress(animeId, userId int64, username string, progress int) (int, time.Time, string, error) {
|
func FetchProgress(animeId int64, username string) (int, time.Time, int, string, error) {
|
||||||
// check watching first
|
// check watching first
|
||||||
newProgress, updated, err := fetchProgressOnState(animeId, userId, progress, username, malApiStatusW)
|
newProgress, updated, score, err := FetchProgressOnState(animeId, username, malApiStatusW)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return newProgress, updated, "", err
|
return newProgress, updated, score, "", err
|
||||||
}
|
}
|
||||||
if newProgress != -1 {
|
if newProgress != -1 {
|
||||||
return newProgress, updated, malApiStatusW, err
|
return newProgress, updated, score, malApiStatusW, err
|
||||||
}
|
}
|
||||||
// check on hold
|
// check on hold
|
||||||
newProgress, updated, err = fetchProgressOnState(animeId, userId, progress, username, malApiStatusH)
|
newProgress, updated, score, err = FetchProgressOnState(animeId, username, malApiStatusH)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return newProgress, updated, "", err
|
return newProgress, updated, score, "", err
|
||||||
}
|
}
|
||||||
if newProgress != -1 {
|
if newProgress != -1 {
|
||||||
return newProgress, updated, malApiStatusH, err
|
return newProgress, updated, score, malApiStatusH, err
|
||||||
}
|
}
|
||||||
// check completed
|
// check completed
|
||||||
newProgress, updated, err = fetchProgressOnState(animeId, userId, progress, username, malApiStatusC)
|
newProgress, updated, score, err = FetchProgressOnState(animeId, username, malApiStatusC)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return newProgress, updated, "", err
|
return newProgress, updated, score, "", err
|
||||||
}
|
}
|
||||||
if newProgress != -1 {
|
if newProgress != -1 {
|
||||||
return newProgress, updated, malApiStatusC, err
|
return newProgress, updated, score, malApiStatusC, err
|
||||||
}
|
}
|
||||||
// check dropped
|
// check dropped
|
||||||
newProgress, updated, err = fetchProgressOnState(animeId, userId, progress, username, malApiStatusD)
|
newProgress, updated, score, err = FetchProgressOnState(animeId, username, malApiStatusD)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return newProgress, updated, "", err
|
return newProgress, updated, score, "", err
|
||||||
}
|
}
|
||||||
if newProgress != -1 {
|
if newProgress != -1 {
|
||||||
return newProgress, updated, malApiStatusD, err
|
return newProgress, updated, score, malApiStatusD, err
|
||||||
}
|
}
|
||||||
// has no progress or PTW
|
// has no progress or PTW
|
||||||
return 0, updated, "", nil
|
return 0, updated, 0, "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchProgressOnState(animeId, userId int64, progress int, username, malStatus string) (int, time.Time, error) {
|
func FetchProgressOnState(animeId int64, username, malStatus string) (int, time.Time, int, error) {
|
||||||
list, _, err := GetUserAnimeListData(username, malStatus)
|
list, _, err := GetUserAnimeListData(username, malStatus)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, time.Time{}, err
|
return 0, time.Time{}, 0, err
|
||||||
}
|
}
|
||||||
for _, a := range list.Data {
|
for _, a := range list.Data {
|
||||||
// check if found
|
// check if found
|
||||||
if a.Node.ID == animeId {
|
if a.Node.ID == animeId {
|
||||||
// check if progress changed
|
return a.ListStatus.NumEpisodesWatched, a.ListStatus.UpdatedAt, a.ListStatus.Score, nil
|
||||||
return a.ListStatus.NumEpisodesWatched, a.ListStatus.UpdatedAt, nil
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// no progess found
|
// no progess found
|
||||||
return -1, time.Now(), nil
|
return -1, time.Now(), 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddToChat(old, new, user string) string {
|
func AddToChat(old, new, user string) string {
|
||||||
@@ -287,6 +287,11 @@ func BuildMovieCharts() ([]MovieChart, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
users, err := ReadRegisteredUsers()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
charts = make([]MovieChart, 0)
|
charts = make([]MovieChart, 0)
|
||||||
for _, m := range movieList {
|
for _, m := range movieList {
|
||||||
c := MovieChart{
|
c := MovieChart{
|
||||||
@@ -295,12 +300,33 @@ func BuildMovieCharts() ([]MovieChart, error) {
|
|||||||
anime, err := SearchAnime(m.Anime)
|
anime, err := SearchAnime(m.Anime)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
color.Errorln(err.Error())
|
color.Errorln(err.Error())
|
||||||
} else {
|
continue
|
||||||
c.Data = *anime
|
|
||||||
charts = append(charts, c)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.Data = *anime
|
||||||
|
scoreSum := 0
|
||||||
|
for _, u := range users {
|
||||||
|
progress, _, score, err := FetchProgressOnState(anime.Anime, u.Username, malApiStatusC)
|
||||||
|
if err != nil {
|
||||||
|
color.Errorln(err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if progress == -1 || score == 0 {
|
||||||
|
// user has no progress/score
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
scoreSum += score
|
||||||
|
c.UserCount++
|
||||||
|
}
|
||||||
|
if c.UserCount > 0 {
|
||||||
|
c.AvgScore = float64(scoreSum) / float64(c.UserCount)
|
||||||
|
}
|
||||||
|
|
||||||
|
charts = append(charts, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sort.SliceStable(charts, func(i, j int) bool { return charts[i].AvgScore > charts[j].AvgScore })
|
||||||
|
|
||||||
bytes, err := json.Marshal(charts)
|
bytes, err := json.Marshal(charts)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
mmCache.Set(key, bytes)
|
mmCache.Set(key, bytes)
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ body { background-color: #1a1a1a; color: #fff; }
|
|||||||
{% for _, anime := range animes %}
|
{% for _, anime := range animes %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="{%s anime.URL %}" target="_blank" rel="noopener noreferrer">{%dl anime.Anime %}</a></td>
|
<td><a href="{%s anime.URL %}" target="_blank" rel="noopener noreferrer">{%dl anime.Anime %}</a></td>
|
||||||
<td>{%f anime.Score %}</td>
|
<td>{%f.2 anime.Score %}</td>
|
||||||
<td><strong>{%s anime.Title %}</strong></td>
|
<td><strong>{%s anime.Title %}</strong></td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
@@ -57,7 +57,7 @@ body { background-color: #1a1a1a; color: #fff; }
|
|||||||
<td><a href="https://movies.hanami.family/movie/{%d chart.MmId %}" target="_blank" rel="noopener noreferrer">{%d chart.MmId %}</a></td>
|
<td><a href="https://movies.hanami.family/movie/{%d chart.MmId %}" target="_blank" rel="noopener noreferrer">{%d chart.MmId %}</a></td>
|
||||||
<td><a href="{%s chart.Data.URL %}" target="_blank" rel="noopener noreferrer">{%dl chart.Data.Anime %}</a></td>
|
<td><a href="{%s chart.Data.URL %}" target="_blank" rel="noopener noreferrer">{%dl chart.Data.Anime %}</a></td>
|
||||||
<td>{%d chart.UserCount %}</td>
|
<td>{%d chart.UserCount %}</td>
|
||||||
<td><strong>{%f chart.AvgScore %}</strong></td>
|
<td><strong>{%f.2 chart.AvgScore %}</strong></td>
|
||||||
<td><strong>{%s chart.Data.Title %}</strong></td>
|
<td><strong>{%s chart.Data.Title %}</strong></td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ func StreamIndex(qw422016 *qt422016.Writer, animes []Anime, oracles []MmOracle,
|
|||||||
//line season.qtpl:40
|
//line season.qtpl:40
|
||||||
qw422016.N().S(`</a></td> <td>`)
|
qw422016.N().S(`</a></td> <td>`)
|
||||||
//line season.qtpl:41
|
//line season.qtpl:41
|
||||||
qw422016.N().F(anime.Score)
|
qw422016.N().FPrec(anime.Score, 2)
|
||||||
//line season.qtpl:41
|
//line season.qtpl:41
|
||||||
qw422016.N().S(`</td> <td><strong>`)
|
qw422016.N().S(`</td> <td><strong>`)
|
||||||
//line season.qtpl:42
|
//line season.qtpl:42
|
||||||
@@ -81,7 +81,7 @@ func StreamIndex(qw422016 *qt422016.Writer, animes []Anime, oracles []MmOracle,
|
|||||||
//line season.qtpl:59
|
//line season.qtpl:59
|
||||||
qw422016.N().S(`</td> <td><strong>`)
|
qw422016.N().S(`</td> <td><strong>`)
|
||||||
//line season.qtpl:60
|
//line season.qtpl:60
|
||||||
qw422016.N().F(chart.AvgScore)
|
qw422016.N().FPrec(chart.AvgScore, 2)
|
||||||
//line season.qtpl:60
|
//line season.qtpl:60
|
||||||
qw422016.N().S(`</strong></td> <td><strong>`)
|
qw422016.N().S(`</strong></td> <td><strong>`)
|
||||||
//line season.qtpl:61
|
//line season.qtpl:61
|
||||||
|
|||||||
Reference in New Issue
Block a user