Skip to content

Commit

Permalink
Merge branch 'main' into post-message-client-ride
Browse files Browse the repository at this point in the history
  • Loading branch information
imamiya-masaki committed Dec 6, 2024
2 parents 6cd7253 + 62739c0 commit 5ca8c44
Show file tree
Hide file tree
Showing 38 changed files with 349 additions and 206 deletions.
7 changes: 1 addition & 6 deletions bench/benchmarker/scenario/scenario.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,7 @@ LOOP:
}

if s.world.Time%world.LengthOfHour == 0 {
if num := s.world.NotInvitedUserCount.Load(); num > 0 {
s.contestantLogger.Info(fmt.Sprintf("これまでに地域内の評判によって%d人が新規登録しました", num))
}
if num := s.world.InvitedUserCount.Load(); num > 0 {
s.contestantLogger.Info(fmt.Sprintf("これまでに既存ユーザーの招待経由で%d人が新規登録しました", num))
}
s.contestantLogger.Info(fmt.Sprintf("これまでに地域内の評判によって%d人、既存ユーザーの招待経由で%d人が新規登録しました", s.world.NotInvitedUserCount.Load(), s.world.InvitedUserCount.Load()))
if num := s.world.LeavedUserCount.Load(); num > 0 {
s.contestantLogger.Warn(fmt.Sprintf("これまでに低評価なライドによって%d人が利用をやめました", num))
}
Expand Down
4 changes: 4 additions & 0 deletions bench/benchmarker/world/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ const (
ErrorCodeWrongNearbyChairs
// ErrorCodeLackOfNearbyChairs 取得した付近の椅子情報が足りません
ErrorCodeLackOfNearbyChairs
// ErrorCodeMatchingTimeout マッチングに時間がかかりすぎです
ErrorCodeMatchingTimeout
)

var CriticalErrorCodes = map[ErrorCode]bool{
Expand All @@ -83,6 +85,7 @@ var CriticalErrorCodes = map[ErrorCode]bool{
ErrorCodeChairAlreadyHasRequest: true,
ErrorCodeIncorrectAmountOfFareCharged: true,
ErrorCodeUncontrollableRequestReceived: true,
ErrorCodeMatchingTimeout: true,
}

var ErrorTexts = map[ErrorCode]string{
Expand Down Expand Up @@ -113,6 +116,7 @@ var ErrorTexts = map[ErrorCode]string{
ErrorCodeChairReceivedDataIsWrong: "椅子が受け取った通知の内容が想定と異なります",
ErrorCodeWrongNearbyChairs: "取得した付近の椅子情報に不備があります",
ErrorCodeLackOfNearbyChairs: "付近の椅子情報が想定よりも3つ以上足りていません",
ErrorCodeMatchingTimeout: "ライドが長時間マッチングされませんでした",
}

type codeError struct {
Expand Down
7 changes: 5 additions & 2 deletions bench/benchmarker/world/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ type Request struct {
CompletedAt int64
// ServerCompletedAt サーバー側で記録されている完了時間
ServerCompletedAt time.Time

// BenchRequestedAt ベンチがライドのリクエストを送って成功した時間
BenchRequestedAt time.Time
// BenchMatchedAt ベンチがAcceptのリクエストを送って成功した時間
BenchMatchedAt time.Time

Expand Down Expand Up @@ -138,8 +141,8 @@ func (r *Request) CalculateEvaluation() Evaluation {
}
{
// 乗車待ち時間評価
if r.StartPoint.V.DistanceTo(r.PickupPoint) < 25 {
// 割り当てられた椅子が自分の場所から距離25以内
if r.StartPoint.V.DistanceTo(r.PickupPoint) < 10*r.Chair.Model.Speed {
// 割り当てられた椅子が自分の場所から距離10*椅子スピード以内
result.Dispatch = true
}
}
Expand Down
7 changes: 5 additions & 2 deletions bench/benchmarker/world/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,10 @@ func (u *User) Tick(ctx *Context) error {
switch u.Request.Statuses.User {
case RequestStatusMatching:
// マッチングされるまで待機する
// 一向にマッチングされない場合は、このユーザーの行動はハングする
break
// 30秒待ってもマッチされない場合は、サービスとして重大な問題があるのでクリティカルエラーとして落とす
if time.Now().Sub(u.Request.BenchRequestedAt) >= 30*time.Second {
return CodeError(ErrorCodeMatchingTimeout)
}

case RequestStatusDispatching:
// 椅子が到着するまで待つ
Expand Down Expand Up @@ -352,6 +354,7 @@ func (u *User) CreateRequest(ctx *Context) error {
return WrapCodeError(ErrorCodeFailedToCreateRequest, err)
}
req.ServerID = res.ServerRequestID
req.BenchRequestedAt = time.Now()
u.Request = req
u.RequestHistory = append(u.RequestHistory, req)
u.World.RequestDB.Create(req)
Expand Down
31 changes: 17 additions & 14 deletions bench/benchmarker/world/world.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,6 @@ func (w *World) checkNearbyChairsResponse(baseTime time.Time, current Coordinate
if current.DistanceTo(chair.Coordinate) > distance {
return fmt.Errorf("ID:%sの椅子は指定の範囲内にありません", chair.ID)
}
entries := c.Location.GetPeriodsByCoord(chair.Coordinate)
if len(entries) == 0 {
return fmt.Errorf("ID:%sの椅子はレスポンスされた座標に過去存在したことがありません", chair.ID)
}
for _, req := range c.RequestHistory.BackwardIter() {
if req.BenchMatchedAt.After(baseTime.Add(-3 * time.Second)) {
// nearbychairsのリクエストを送った3秒前以降にマッチされている場合は許容する
Expand All @@ -354,17 +350,24 @@ func (w *World) checkNearbyChairsResponse(baseTime time.Time, current Coordinate
}
break
}

if !lo.SomeBy(entries, func(entry GetPeriodsByCoordResultEntry) bool {
if !entry.Until.Valid {
// untilが無い場合は今もその位置にいることになるので、最新
return true
if !c.Location.Current().Equals(chair.Coordinate) {
// 最新の座標ではないなら過去を遡る
entries := c.Location.GetPeriodsByCoord(chair.Coordinate)
if len(entries) == 0 {
return fmt.Errorf("ID:%sの椅子はレスポンスされた座標に過去存在したことがありません", chair.ID)
} else {
if !lo.SomeBy(entries, func(entry GetPeriodsByCoordResultEntry) bool {
if !entry.Until.Valid {
// untilが無い場合は今もその位置にいることになるので、最新
return true
}
// untilがある場合は今より3秒以内にその位置にいればOK
return baseTime.Sub(entry.Until.Time) <= 3*time.Second
}) {
// ソフトエラーとして処理する
errs = append(errs, fmt.Errorf("ID:%sの椅子は直近に指定の範囲内にありません", chair.ID))
}
}
// untilがある場合は今より3秒以内にその位置にいればOK
return baseTime.Sub(entry.Until.Time) <= 3*time.Second
}) {
// ソフトエラーとして処理する
errs = append(errs, fmt.Errorf("ID:%sの椅子は直近に指定の範囲内にありません", chair.ID))
}
checked[chair.ID] = true
}
Expand Down
19 changes: 19 additions & 0 deletions frontend/app/components/icon/account-switch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { ComponentProps, FC } from "react";
import colors from "tailwindcss/colors";

export const AccountSwitchIcon: FC<ComponentProps<"svg">> = (props) => {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
height="24px"
width="24px"
viewBox="0 -960 960 960"
fill={colors.neutral[500]}
{...props}
>
<path d="M160-160v-80h110l-16-14q-52-46-73-105t-21-119q0-111 66.5-197.5T400-790v84q-72 26-116 88.5T240-478q0 45 17 87.5t53 78.5l10 10v-98h80v240H160Zm400-10v-84q72-26 116-88.5T720-482q0-45-17-87.5T650-648l-10-10v98h-80v-240h240v80H690l16 14q49 49 71.5 106.5T800-482q0 111-66.5 197.5T560-170Z" />
</svg>
);
};

// https://github.com/google/material-design-icons/blob/master/LICENSE
19 changes: 19 additions & 0 deletions frontend/app/components/icon/account.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { ComponentProps, FC } from "react";
import colors from "tailwindcss/colors";

export const AccountIcon: FC<ComponentProps<"svg">> = (props) => {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
height="24px"
width="24px"
viewBox="0 -960 960 960"
fill={colors.neutral[500]}
{...props}
>
<path d="M234-276q51-39 114-61.5T480-360q69 0 132 22.5T726-276q35-41 54.5-93T800-480q0-133-93.5-226.5T480-800q-133 0-226.5 93.5T160-480q0 59 19.5 111t54.5 93Zm246-164q-59 0-99.5-40.5T340-580q0-59 40.5-99.5T480-720q59 0 99.5 40.5T620-580q0 59-40.5 99.5T480-440Zm0 360q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q53 0 100-15.5t86-44.5q-39-29-86-44.5T480-280q-53 0-100 15.5T294-220q39 29 86 44.5T480-160Zm0-360q26 0 43-17t17-43q0-26-17-43t-43-17q-26 0-43 17t-17 43q0 26 17 43t43 17Zm0-60Zm0 360Z" />
</svg>
);
};

// https://github.com/google/material-design-icons/blob/master/LICENSE
2 changes: 1 addition & 1 deletion frontend/app/components/icon/chair.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const Chair: FC<
{
chairType: (typeof ChairTypes)[number];
} & ComponentProps<"svg">
> = function ({ chairType, ...props }) {
> = ({ chairType, ...props }) => {
const { bodyColor, windowColor, wheelColor } = chairType;
return (
<svg
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/components/icon/copy.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ComponentProps, FC } from "react";

export const CopyIcon: FC<ComponentProps<"svg">> = function (props) {
export const CopyIcon: FC<ComponentProps<"svg">> = (props) => {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/components/icon/desktop.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ComponentProps, FC } from "react";
import colors from "tailwindcss/colors";

export const DesktopIcon: FC<ComponentProps<"svg">> = function (props) {
export const DesktopIcon: FC<ComponentProps<"svg">> = (props) => {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/components/icon/history.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ComponentProps, FC } from "react";
import colors from "tailwindcss/colors";

export const HistoryIcon: FC<ComponentProps<"svg">> = function (props) {
export const HistoryIcon: FC<ComponentProps<"svg">> = (props) => {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/components/icon/human.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ComponentProps, FC } from "react";
import colors from "tailwindcss/colors";

export const HumanIcon: FC<ComponentProps<"svg">> = function (props) {
export const HumanIcon: FC<ComponentProps<"svg">> = (props) => {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/components/icon/isuride.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ComponentProps, FC } from "react";

export const IsurideIcon: FC<ComponentProps<"svg">> = function (props) {
export const IsurideIcon: FC<ComponentProps<"svg">> = (props) => {
return (
<svg
viewBox="0 0 163.15 219.74"
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/components/icon/mobile.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ComponentProps, FC } from "react";
import colors from "tailwindcss/colors";

export const MobileIcon: FC<ComponentProps<"svg">> = function (props) {
export const MobileIcon: FC<ComponentProps<"svg">> = (props) => {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/components/icon/money.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ComponentProps, FC } from "react";
import colors from "tailwindcss/colors";

export const MoneyIcon: FC<ComponentProps<"svg">> = function (props) {
export const MoneyIcon: FC<ComponentProps<"svg">> = (props) => {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/components/icon/schedule.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ComponentProps, FC } from "react";
import colors from "tailwindcss/colors";

export const ScheduleIcon: FC<ComponentProps<"svg">> = function (props) {
export const ScheduleIcon: FC<ComponentProps<"svg">> = (props) => {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { NavLink } from "@remix-run/react";
import type { ComponentProps, FC } from "react";
import { AccountIcon } from "~/components/icon/account";
import { HistoryIcon } from "~/components/icon/history";
import { IsurideIcon } from "~/components/icon/isuride";

Expand All @@ -20,6 +21,11 @@ const MenuList = [
link: "/client/history",
label: "HISTORY",
},
{
icon: AccountIcon,
link: "/client/user",
label: "USER",
},
] as const satisfies NavigationMenu[];

export const FooterNavigation: FC = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ const ChairProgress: FC<{
destLoc?: Coordinate;
}> = ({ model, rideStatus, pickupLoc, destLoc, currentLoc }) => {
const startLoc = useMemo(() => {
return rideStatus !== undefined ? getSimulatorStartCoordinate() : null;
return typeof rideStatus !== "undefined"
? getSimulatorStartCoordinate()
: null;
}, [rideStatus]);

const progressToPickup: number = useMemo(() => {
Expand Down Expand Up @@ -175,37 +177,36 @@ const ChairProgress: FC<{
);
};

const ChairDetailInfo = memo(
function ChairDetailInfo({
chairModel,
chairName,
rideStatus,
}: {
chairModel: string;
chairName: string;
rideStatus: RideStatus;
}) {
return chairModel && chairName && rideStatus ? (
<div className="flex items-center space-x-4">
<ChairIcon model={chairModel} className="size-12 shrink-0" />
<div className="space-y-0.5 w-full">
<Text bold>{chairName}</Text>
<Text className="text-xs text-neutral-500">{chairModel}</Text>
<SimulatorChairRideStatus currentStatus={rideStatus} />
</div>
</div>
) : null;
},
(prev, next) =>
prev.chairModel === next.chairModel &&
prev.chairName === next.chairName &&
prev.rideStatus === next.rideStatus,
);

export const SimulatorChairDisplay: FC = () => {
const { data, chair } = useSimulatorContext();
const rideStatus = useMemo(() => data?.status ?? "MATCHING", [data]);

const ChairDetailInfo = memo(
function ChairDetailInfo({
chairModel,
chairName,
rideStatus,
}: {
chairModel: string;
chairName: string;
rideStatus: RideStatus;
}) {
return chairModel && chairName && rideStatus ? (
<div className="flex items-center space-x-4">
<ChairIcon model={chairModel} className="size-12 shrink-0" />
<div className="space-y-0.5 w-full">
<Text bold>{chairName}</Text>
<Text className="text-xs text-neutral-500">{chairModel}</Text>
<SimulatorChairRideStatus currentStatus={rideStatus} />
</div>
</div>
) : null;
},
(prev, next) =>
prev.chairModel === next.chairModel &&
prev.chairName === next.chairName &&
prev.rideStatus === next.rideStatus,
);

return (
<div className="bg-white rounded shadow px-6 py-4 w-full">
{chair ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const DateInput: FC<DateInputProps> = ({
type="date"
id={id}
className={twMerge(
"mt-1 w-full border border-neutral-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 px-3 py-2",
"mt-1 px-5 py-3 w-full border border-neutral-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",
className,
)}
{...props}
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/components/primitives/form/toggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const Toggle: FC<Props> = ({
"peer-checked:translate-x-7 peer-checked:border-emerald-500",
!disabled && "cursor-pointer",
)}
></label>
/>
</div>
);
};
4 changes: 2 additions & 2 deletions frontend/app/components/primitives/modal/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const Modal = forwardRef<{ close: () => void }, ModalProps>(
className={twMerge(
"fixed bottom-0 left-0 right-0 h-[90vh] bg-white rounded-t-3xl shadow-lg transition-transform duration-300 ease-in-out z-50 md:max-w-screen-md mx-auto",
center &&
"top-1/2 -translate-y-1/2 max-h-[50vh] rounded-3xl transition duration-300 ease-out",
"top-1/2 -translate-y-1/2 max-h-[50vh] rounded-3xl p-3 transition duration-300 ease-out",
className,
)}
ref={sheetRef}
Expand All @@ -65,7 +65,7 @@ export const Modal = forwardRef<{ close: () => void }, ModalProps>(
}}
{...props}
>
<div className={"px-6 py-3 md:px-10 md:py-6 h-full"}>{children}</div>
<div className={"p-6 md:p-10 h-full"}>{children}</div>
</div>
</>
);
Expand Down
Loading

0 comments on commit 5ca8c44

Please sign in to comment.