fix: return rocket progress as ratio

This commit is contained in:
hy001 2026-07-15 20:49:25 +08:00
parent ca72ed3f97
commit 5296562391
3 changed files with 8 additions and 8 deletions

View File

@ -73,16 +73,16 @@ func pointerTimeValue(value *time.Time) time.Time {
return *value
}
func decimalPercent(current, need int64) (string, int) {
func decimalPercent(current, need int64) (string, float64) {
if need <= 0 || current <= 0 {
return "0.0000", 0
}
percent := float64(current) * 100 / float64(need)
display := int(math.Floor(percent))
if display > 100 {
display = 100
if current >= need {
return "1.0000", 1
}
return fmt.Sprintf("%.4f", percent), display
// App 端按 0-1 比例换算百分比;截断而非四舍五入,避免未充满时提前显示 100%。
ratio := math.Floor(float64(current)/float64(need)*10000) / 10000
return fmt.Sprintf("%.4f", ratio), ratio
}
func parsePercent(value string) float64 {

View File

@ -422,7 +422,7 @@ type StatusResponse struct {
CurrentEnergy int64 `json:"currentEnergy"`
NeedEnergy int64 `json:"needEnergy"`
EnergyPercent string `json:"energyPercent"`
DisplayPercent int `json:"displayPercent"`
DisplayPercent float64 `json:"displayPercent"`
LaunchCountdownSeconds int `json:"launchCountdownSeconds,omitempty"`
Shake bool `json:"shake"`
PreviewRocketURL string `json:"previewRocketUrl,omitempty"`

View File

@ -182,7 +182,7 @@ func main() {
mid, err := service.GetStatus(ctx, user, room.RoomID)
must(err, "mid status")
assert(mid.CurrentLevel == 1 && mid.CurrentEnergy == 60 && mid.DisplayPercent == 60, "mid status mismatch")
assert(mid.CurrentLevel == 1 && mid.CurrentEnergy == 60 && mid.DisplayPercent == 0.6, "mid status mismatch")
secondPayload := mqEnvelope(giftPayload("LOCAL_VERIFY_TRACK_2", igniteUserID, room.RoomID, 80, now.Add(time.Second)))
second, err := service.ProcessGiftPayload(ctx, secondPayload)