Skip to content

Commit

Permalink
feature mai function updater
Browse files Browse the repository at this point in the history
  • Loading branch information
MoYoez committed Mar 13, 2024
1 parent 0d33851 commit 7cc5d66
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 40 deletions.
24 changes: 16 additions & 8 deletions plugin/mai/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,25 @@ func init() {
}
ctx.SendPlainMessage(true, "目前查询到您的游玩记录如下: \n\n"+returnText)
case getSplitStringList[1] == "status":
// getWebStatus
getWebStatus := ReturnWebStatus()
getZlibError := ReturnZlibError()
getPlayedStatus, err := web.GetData("https://maihook.lemonkoi.one/api/calc")
if err != nil {
return
}
var playerStatus RealConvertPlay
json.Unmarshal(getPlayedStatus, &playerStatus)
// 20s one request.
var getLucyRespHandler int
getLucyRespHandler = getZlibError.Full.Field3
if getZlibError.Full.Field3 < 180 {
getLucyRespHandler = getZlibError.Full.Field3
} else {
getLucyRespHandler = getZlibError.Full.Field3 - 180
}
getLucyRespHandlerStr := strconv.Itoa(getLucyRespHandler)

getZlibWord := "Zlib 压缩跳过率: \n" + "10mins (" + ConvertZlib(getZlibError.ZlibError.Field1, getZlibError.Full.Field1) + " Loss)\n" + "30mins (" + ConvertZlib(getZlibError.ZlibError.Field2, getZlibError.Full.Field2) + " Loss)\n" + "60mins (" + ConvertZlib(getZlibError.ZlibError.Field3, getZlibError.Full.Field3) + " Loss)\n"
getWebStatusCount := "Web Uptime Ping:\n * MaimaiDXCN: " + ConvertFloat(getWebStatus.Details.MaimaiDXCN.Uptime*100) + "%\n * MaimaiDXCN Main Server: " + ConvertFloat(getWebStatus.Details.MaimaiDXCNMain.Uptime*100) + "%\n * MaimaiDXCN Title Server: " + ConvertFloat(getWebStatus.Details.MaimaiDXCNTitle.Uptime*100) + "%\n * MaimaiDXCN Update Server: " + ConvertFloat(getWebStatus.Details.MaimaiDXCNUpdate.Uptime*100) + "%\n * MaimaiDXCN NetLogin Server: " + ConvertFloat(getWebStatus.Details.MaimaiDXCNNetLogin.Uptime*100) + "%\n * MaimaiDXCN Net Server: " + ConvertFloat(getWebStatus.Details.MaimaiDXCNDXNet.Uptime*100) + "%\n"
ctx.SendPlainMessage(true, "* Zlib 压缩跳过率可以很好的反馈当前 MaiNet (Wahlap Service) 当前负载的情况\n* Web Uptime Ping 则可以反馈 MaiNet 在外部原因(DDOS) 下造成的负载详情 ( 100% 即代表服务器为稳定, uptime 越低则代表可用性越差 ) \n* 在 1小时 内,Lucy 共处理了 "+getLucyRespHandlerStr+"次 请求💫,其中详细数据如下:\n\n"+getZlibWord+getWebStatusCount+"\n* Title Server 爆炸 容易造成数据获取失败\n* Zlib 3% Loss 以下则 基本上可以正常游玩\n* 10% Loss 则会有明显断网现象(请准备小黑屋工具)\n* 30% Loss 则无法正常游玩(即使使用小黑屋工具) ")
getRealStatus := "\n以下数据来源于mai机台的数据反馈\n"
ctx.SendPlainMessage(true, "* Zlib 压缩跳过率可以很好的反馈当前 MaiNet (Wahlap Service) 当前负载的情况,根据样本 + Lucy处理情况 来判断 \n* 错误率收集则来源于 机台游玩数据,反应各地区真实mai游玩错误情况 \n* 在 1小时 内,Lucy 共处理了 "+getLucyRespHandlerStr+"次 请求💫,其中详细数据如下:\n\n"+getZlibWord+getRealStatus+"\n"+ConvertRealPlayWords(playerStatus)+"\n* Zlib 3% Loss 以下则 基本上可以正常游玩\n* 10% Loss 则会有明显断网现象(请准备小黑屋工具)\n* 30% Loss 则无法正常游玩(即使使用小黑屋工具) ")
case getSplitStringList[1] == "update":
getID, _ := toolchain.GetChatUserInfoID(ctx)
getMaiID := GetUserIDFromDatabase(getID)
Expand Down Expand Up @@ -607,11 +616,10 @@ func init() {
} else {
ctx.SendPlainMessage(true, "Lucy 查找了对应ID 在这个难度下没有发现数据~")
}
return

}
}
}

case getSplitStringList[1] == "aliasupdate":
if rei.SuperUserPermission(ctx) {
UpdateAliasPackage()
Expand Down Expand Up @@ -820,7 +828,7 @@ func CheckTheTicketIsValid(ticket string) bool {

// convert SongDataTo
func convert(listStruct UserMusicListStruct) []InnerStructChanger {

Check failure on line 830 in plugin/mai/main.go

View workflow job for this annotation

GitHub Actions / lint

undefined: UserMusicListStruct (typecheck)
getRequest, err := os.ReadFile(engine.DataFolder() + "music_data")
getRequest, err := os.ReadFile(engine.DataFolder() + "music_data") // be aware that this songdata need upgarde.
if err != nil {
panic(err)
}
Expand Down
77 changes: 45 additions & 32 deletions plugin/mai/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"image/png"
"io"
"log"
"math"
"net/http"
"os"
"strconv"
Expand Down Expand Up @@ -49,6 +50,16 @@ type WebPingStauts struct {
Status bool `json:"status"`
}

type RealConvertPlay struct {
ReturnValue []struct {
SkippedCount int `json:"skippedCount"`
RetriedCount int `json:"retriedCount"`
RetryCountSum int `json:"retryCountSum"`
TotalCount int `json:"totalCount"`
FailedCount int `json:"failedCount"`
} `json:"returnValue"`
}

type ZlibErrorStatus struct {
Full struct {
Field1 int `json:"10"`
Expand Down Expand Up @@ -635,36 +646,6 @@ func ReturnZlibError() ZlibErrorStatus {
return returnData
}

// ReturnWebStatus Get Web Uptime Status.
func ReturnWebStatus() WebPingStauts {
url := "https://maihook.lemonkoi.one/api/ping"
method := "GET"
client := &http.Client{}
req, err := http.NewRequest(method, url, nil)

if err != nil {
fmt.Println(err)
return WebPingStauts{}
}
req.Header.Add("Accept", "*/*")
req.Header.Add("Host", "maihook.lemonkoi.one")
req.Header.Add("Connection", "keep-alive")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return WebPingStauts{}
}
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return WebPingStauts{}
}
var returnData WebPingStauts
json.Unmarshal(body, &returnData)
return returnData
}

func ConvertZlib(value, total int) string {
if total == 0 {
return "0.000%"
Expand All @@ -673,6 +654,38 @@ func ConvertZlib(value, total int) string {
return fmt.Sprintf("%.3f%%", percentage)
}

func ConvertFloat(data float64) string {
return strconv.FormatFloat(data, 'f', 3, 64)
func ConvertRealPlayWords(retry RealConvertPlay) string {
var pickedWords string
var count = 0
var header = " - 错误率数据收集自机台的真实网络通信,可以反映舞萌 DX 的网络状况。\n"

for _, word := range retry.ReturnValue {
var timeCount int
var UserReturnLogs string
switch {
case count == 0:
timeCount = 10
case count == 1:
timeCount = 30
case count == 2:
timeCount = 60
}

if word.TotalCount < 20 {
UserReturnLogs = "没有收集到足够的数据进行分析~"
} else {
totalSuccess := word.TotalCount - word.FailedCount
skippedRate := float64(word.SkippedCount) / float64(totalSuccess) * 100
otherErrorRate := float64(word.RetryCountSum) / float64(totalSuccess+word.RetryCountSum) * 100
overallErrorRate := (float64(word.SkippedCount+word.RetryCountSum) / float64(totalSuccess+word.RetryCountSum)) * 100
skippedRate = math.Round(skippedRate*100) / 100
otherErrorRate = math.Round(otherErrorRate*100) / 100
overallErrorRate = math.Round(overallErrorRate*100) / 100
UserReturnLogs = fmt.Sprintf("共 %d 个成功的请求中,有 %d 次未压缩(%.2f%%),有 %d 个请求共 %d 次其他错误(%.2f%%),整体错误率为 %.2f%%。", totalSuccess, word.SkippedCount, skippedRate, word.RetriedCount, word.RetryCountSum, otherErrorRate, overallErrorRate)
}
pickedWords = pickedWords + fmt.Sprintf("\n - 在 %d 分钟内%s", timeCount, UserReturnLogs)
count = count + 1

}
return header + pickedWords + "\n"
}

0 comments on commit 7cc5d66

Please sign in to comment.