Skip to content

Commit

Permalink
feat: adjust club averages to show deviation
Browse files Browse the repository at this point in the history
  • Loading branch information
thraizz committed Aug 8, 2024
1 parent 1d33195 commit 95daa71
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 16 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = {
"warn",
{ allowConstantExport: true },
],
"@typescript-eslint/no-explicit-any": "off",
"prettier/prettier": "error",
},
};
26 changes: 15 additions & 11 deletions src/components/ClubStats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,14 @@ export const ClubStats = ({ average }: { average: AveragedSwing }) => {
0
).toPrecision(3) + "m",
},
// {
// name: "Deviation Distance",
// stat:
// (
// average?.["Total Deviation Distance"] ||
// average?.["Gesamtabweichungsdistanz"] ||
// 0
// ).toPrecision(3) + "m",
// },
{
name: "Smash Factor",
stat: (average?.["Smash Factor"] || 0).toPrecision(2),
name: "Deviation Distance",
stat: getDeviationString(average),
},
// {
// name: "Smash Factor",
// stat: (average?.["Smash Factor"] || 0).toPrecision(2),
// },
],
[average],
);
Expand Down Expand Up @@ -66,3 +61,12 @@ export const ClubStats = ({ average }: { average: AveragedSwing }) => {
</div>
);
};

const getDeviationString = (average: AveragedSwing) => {
const deviation =
average?.["Total Deviation Distance"] ||
average?.["Gesamtabweichungsdistanz"] ||
0;

return deviation > 0 ? `${deviation}m left` : `${Math.abs(deviation)}m right`;
};
2 changes: 1 addition & 1 deletion src/components/panels/Last30DaysAverages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useAveragedSwings } from "../../utils/calculateAverages";
import { ClubStats } from "../ClubStats";
import { IQRNote } from "../IQRNote";

export const Last30DaysAverages = () => {
export const AverageOverview = () => {
const averages = useAveragedSwings();

return (
Expand Down
12 changes: 10 additions & 2 deletions src/provider/SettingsContext.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { PropsWithChildren, createContext, useState } from "react";

import { ClubAverageStat } from "./settings.utils";

export type SettingsType = {
useIQR: boolean;
useAboveAverageShots: boolean;
clubAverageStats: ClubAverageStat[];
};

interface SettingsContextProps {
Expand All @@ -11,14 +14,19 @@ interface SettingsContextProps {
}

export const SettingsContext = createContext<SettingsContextProps>({
settings: { useIQR: false, useAboveAverageShots: false },
setSettings: () => {},
settings: {
useIQR: false,
useAboveAverageShots: false,
clubAverageStats: [] as any,
},
setSettings: () => { },
});

export const SettingsProvider = ({ children }: PropsWithChildren) => {
const [settings, setSettings] = useState<SettingsType>({
useIQR: false,
useAboveAverageShots: false,
clubAverageStats: ["CARRY_DISTANCE"],
});

return (
Expand Down
8 changes: 8 additions & 0 deletions src/provider/settings.utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const CLUB_AVERAGE_STATS = [
"CARRY_DISTANCE",
"TOTAL_DISTANCE",
"TOTAL_DEVIATION_DISTANCE",
"SMASH_FACTOR",
];

export type ClubAverageStat = (typeof CLUB_AVERAGE_STATS)[number];
4 changes: 2 additions & 2 deletions src/views/Dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Link } from "react-router-dom";
import { BasePageLayout } from "../components/base/BasePageLayout";
import { Last30DaysAverages } from "../components/panels/Last30DaysAverages";
import { AverageOverview } from "../components/panels/Last30DaysAverages";
import { SettingsForm } from "../components/panels/SettingsForm";
import { useSelectedSessions } from "../hooks/useSelectedSessions";
import { dashboardRoutes } from "../routes";
Expand All @@ -10,7 +10,7 @@ export const Dashboard = () => (
<SettingsForm />
<NoSessionSelectedHint />
<div className="rounded-md bg-white p-4">
<Last30DaysAverages />
<AverageOverview />
</div>
<div className="flex gap-4">
<Link to={dashboardRoutes.visualization} className="btn">
Expand Down

0 comments on commit 95daa71

Please sign in to comment.