fix: return rocket progress as ratio
This commit is contained in:
parent
ca72ed3f97
commit
5296562391
@ -73,16 +73,16 @@ func pointerTimeValue(value *time.Time) time.Time {
|
|||||||
return *value
|
return *value
|
||||||
}
|
}
|
||||||
|
|
||||||
func decimalPercent(current, need int64) (string, int) {
|
func decimalPercent(current, need int64) (string, float64) {
|
||||||
if need <= 0 || current <= 0 {
|
if need <= 0 || current <= 0 {
|
||||||
return "0.0000", 0
|
return "0.0000", 0
|
||||||
}
|
}
|
||||||
percent := float64(current) * 100 / float64(need)
|
if current >= need {
|
||||||
display := int(math.Floor(percent))
|
return "1.0000", 1
|
||||||
if display > 100 {
|
|
||||||
display = 100
|
|
||||||
}
|
}
|
||||||
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 {
|
func parsePercent(value string) float64 {
|
||||||
|
|||||||
@ -422,7 +422,7 @@ type StatusResponse struct {
|
|||||||
CurrentEnergy int64 `json:"currentEnergy"`
|
CurrentEnergy int64 `json:"currentEnergy"`
|
||||||
NeedEnergy int64 `json:"needEnergy"`
|
NeedEnergy int64 `json:"needEnergy"`
|
||||||
EnergyPercent string `json:"energyPercent"`
|
EnergyPercent string `json:"energyPercent"`
|
||||||
DisplayPercent int `json:"displayPercent"`
|
DisplayPercent float64 `json:"displayPercent"`
|
||||||
LaunchCountdownSeconds int `json:"launchCountdownSeconds,omitempty"`
|
LaunchCountdownSeconds int `json:"launchCountdownSeconds,omitempty"`
|
||||||
Shake bool `json:"shake"`
|
Shake bool `json:"shake"`
|
||||||
PreviewRocketURL string `json:"previewRocketUrl,omitempty"`
|
PreviewRocketURL string `json:"previewRocketUrl,omitempty"`
|
||||||
|
|||||||
@ -182,7 +182,7 @@ func main() {
|
|||||||
|
|
||||||
mid, err := service.GetStatus(ctx, user, room.RoomID)
|
mid, err := service.GetStatus(ctx, user, room.RoomID)
|
||||||
must(err, "mid status")
|
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)))
|
secondPayload := mqEnvelope(giftPayload("LOCAL_VERIFY_TRACK_2", igniteUserID, room.RoomID, 80, now.Add(time.Second)))
|
||||||
second, err := service.ProcessGiftPayload(ctx, secondPayload)
|
second, err := service.ProcessGiftPayload(ctx, secondPayload)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user