From 2c52875854d85de5688016615ff8f40b3087547f Mon Sep 17 00:00:00 2001 From: wtks <30363887+wtks@users.noreply.github.com> Date: Fri, 6 Dec 2024 22:40:12 +0900 Subject: [PATCH] =?UTF-8?q?total=5Fdistance=E3=81=AE=E5=8F=8D=E6=98=A0?= =?UTF-8?q?=E3=81=8C=E9=81=85=E3=81=84=E3=83=87=E3=83=BC=E3=82=BF=E3=81=8C?= =?UTF-8?q?=E3=81=82=E3=82=8A=E3=81=BE=E3=81=99=E3=82=A8=E3=83=A9=E3=83=BC?= =?UTF-8?q?=E3=81=AE=E3=83=90=E3=82=B0=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bench/benchmarker/world/chair_routes.go | 12 ++++++++++++ bench/benchmarker/world/owner.go | 9 +++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/bench/benchmarker/world/chair_routes.go b/bench/benchmarker/world/chair_routes.go index d6943242..e53d7eed 100644 --- a/bench/benchmarker/world/chair_routes.go +++ b/bench/benchmarker/world/chair_routes.go @@ -152,3 +152,15 @@ func (r *ChairLocation) GetCoordByTime(t time.Time) Coordinate { } return r.Initial } + +func (r *ChairLocation) GetLocationEntryByTime(t time.Time) *LocationEntry { + r.mu.RLock() + defer r.mu.RUnlock() + + for _, entry := range slices.Backward(r.history) { + if entry.ServerTime.Valid && !entry.ServerTime.Time.After(t) { + return entry + } + } + return nil +} diff --git a/bench/benchmarker/world/owner.go b/bench/benchmarker/world/owner.go index 93902443..da889ef9 100644 --- a/bench/benchmarker/world/owner.go +++ b/bench/benchmarker/world/owner.go @@ -79,11 +79,12 @@ func (p *Owner) Tick(ctx *Context) error { return WrapCodeError(ErrorCodeFailedToGetOwnerChairs, err) } + baseTime := time.Now() res, err := p.Client.GetOwnerChairs(ctx, &GetOwnerChairsRequest{}) if err != nil { return WrapCodeError(ErrorCodeFailedToGetOwnerChairs, err) } - if err := p.ValidateChairs(res); err != nil { + if err := p.ValidateChairs(res, baseTime); err != nil { return WrapCodeError(ErrorCodeIncorrectOwnerChairsData, err) } } else if ctx.CurrentTime()%LengthOfHour == LengthOfHour-1 { @@ -201,7 +202,7 @@ func (p *Owner) ValidateSales(until time.Time, serverSide *GetOwnerSalesResponse return nil } -func (p *Owner) ValidateChairs(serverSide *GetOwnerChairsResponse) error { +func (p *Owner) ValidateChairs(serverSide *GetOwnerChairsResponse, baseTime time.Time) error { if p.ChairDB.Len() != len(serverSide.Chairs) { return fmt.Errorf("オーナーの椅子の数が一致していません") } @@ -222,8 +223,8 @@ func (p *Owner) ValidateChairs(serverSide *GetOwnerChairsResponse) error { // return fmt.Errorf("activeが一致しないデータがあります (id: %s, got: %v, want: %v)", chair.ServerID, data.Active, !data.Active) //} if data.TotalDistanceUpdatedAt.Valid { - lastMovedAt, ok := chair.Location.LastMovedAt() - if ok && data.TotalDistanceUpdatedAt.Time.Sub(lastMovedAt) > 3*time.Second { + lastMoved := chair.Location.GetLocationEntryByTime(baseTime) + if lastMoved != nil && lastMoved.ServerTime.Time.Sub(data.TotalDistanceUpdatedAt.Time) > 3*time.Second { return fmt.Errorf("total_distanceの反映が遅いデータがあります (id: %s)", chair.ServerID) } want := chair.Location.TotalTravelDistanceUntil(data.TotalDistanceUpdatedAt.Time)