Skip to content

Commit

Permalink
Implement basic scores table for single shooter with navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
Howler Monkey committed Feb 24, 2024
1 parent 071a97d commit a50fee9
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 23 deletions.
14 changes: 6 additions & 8 deletions api/src/classifiers.api.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import _ from "lodash";
import memoize from "memoize";

import { divShortToRuns } from "./dataUtil/classifiers.js";
import {
divShortToRuns,
basicInfoForClassifier,
} from "./dataUtil/classifiers.js";
import { divIdToShort } from "./dataUtil/divisions.js";
import { HF, N, Percent, PositiveOrMinus1 } from "./dataUtil/numbers.js";
import { shooterShortInfo } from "./dataUtil/shooters.js";
Expand Down Expand Up @@ -338,13 +341,8 @@ export const extendedInfoForClassifier = memoize(
{ cacheKey: ([c, division]) => c.classifier + ":" + division }
);

export const basicInfoForClassifier = (c) => ({
id: c.id,
code: c.classifier,
name: c.name,
scoring: c.scoring,
});

export const classifiers = classifiersData.classifiers;
/** whitelist for wsb downloads */
export const classifierNumbers = classifiers.map((cur) => cur.classifier);

export { basicInfoForClassifier };
22 changes: 22 additions & 0 deletions api/src/dataUtil/classifiers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,28 @@ import lo from "../../../data/merged.active.limitedoptics.json" assert { type: "
import pcc from "../../../data/merged.active.pcc.json" assert { type: "json" };
import { byMemberNumber } from "./byMemberNumber.js";

import classifiersData from "../../../data/classifiers/classifiers.json" assert { type: "json" };

export const basicInfoForClassifier = (c) => ({
id: c.id,
code: c.classifier,
name: c.name,
scoring: c.scoring,
});

export const basicInfoForClassifierCode = (number) => {
if (!number) {
return {};
}
const c = classifiersData.classifiers.find(
(cur) => cur.classifier === number
);
if (!c) {
return {};
}
return basicInfoForClassifier(c);
};

// fucking github and its fucking 50Mb file limitation
const ltd = [...limited1, ...limited2];

Expand Down
7 changes: 4 additions & 3 deletions api/src/dataUtil/shooters.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import one from "../../../data/mergedArray.classifications.1.json" assert { type: "json" };
import two from "../../../data/mergedArray.classifications.2.json" assert { type: "json" };
export const all = [...one, ...two];
import { Percent, PositiveOrMinus1 } from "./numbers.js";
import { N, Percent, PositiveOrMinus1 } from "./numbers.js";

import { divIdToShort } from "./divisions.js";
import { divShortToShooterToRuns } from "./classifiers.js";
Expand Down Expand Up @@ -175,8 +175,10 @@ const shootersFullForDivision = (division) =>
division,
});
const curPercent = PositiveOrMinus1(Percent(run.hf, hhf));
const percentMinusCurPercent =
curPercent >= 0 ? N(run.percent - curPercent) : -1;

return { ...run, curPercent, index };
return { ...run, curPercent, percentMinusCurPercent, index };
}),
}));

Expand Down Expand Up @@ -207,7 +209,6 @@ export const shootersTableByMemberNumber = {
export const shooterChartData = ({ memberNumber, division, y }) => {
// monke done fucked up, monke doesn't know why it has to use [0], monke dum
let runs = shootersTableByMemberNumber[division][memberNumber][0].classifiers;

return runs
.map((run) => ({
x: run.sd,
Expand Down
19 changes: 14 additions & 5 deletions api/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ import {
shooterChartData,
} from "./dataUtil/shooters.js";

import {
basicInfoForClassifierCode,
basicInfoForClassifier,
} from "./dataUtil/classifiers.js";

import {
classifiers,
classifierNumbers,
basicInfoForClassifier,
extendedInfoForClassifier,
runsForDivisionClassifier,
chartData,
Expand Down Expand Up @@ -177,19 +181,24 @@ const start = async () => {
const { sort, order, page: pageString } = req.query;
const page = Number(pageString) || 1;

console.log("WTF");
const { classifiers, ...info } =
shootersTableByMemberNumber[division][memberNumber][0];
const data = multisort(
classifiers,
sort?.split?.(","),
order?.split?.(",")
);
).map((c) => ({
...c,
classifierInfo: basicInfoForClassifierCode(c?.classifier),
}));

return {
info,
classifiers: data.slice((page - 1) * PAGE_SIZE, page * PAGE_SIZE),
classifiersTotal: data.length,
classifiersPage: page,
classifiers: data,
// TODO: classifiers: data.slice((page - 1) * PAGE_SIZE, page * PAGE_SIZE),
// classifiersTotal: data.length,
// classifiersPage: page,
};
});
fastify.get("/api/shooters/:division/:memberNumber/chart", (req, res) => {
Expand Down
8 changes: 6 additions & 2 deletions web/src/components/ClassifierCell.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { Textfit } from "react-textfit";

export const ClassifierCell = ({ code, name, scoring }) => (
<div className="flex flex-column w-12rem">
export const ClassifierCell = ({ code, name, scoring, onClick }) => (
<div
className="flex flex-column w-12rem"
style={onClick ? { cursor: "pointer" } : {}}
onClick={onClick}
>
<div className="flex flex-row justify-content-between">
<div className="font-bold text-color-secondary">{code}</div>
<div className="text-xs text-color-secondary">{scoring}</div>
Expand Down
92 changes: 92 additions & 0 deletions web/src/pages/ShootersPage/components/ShooterRunsTable.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import _ from "lodash";
import { DataTable } from "primereact/datatable";
import { Column } from "primereact/column";
import { headerTooltipOptions } from "../../../components/Table";
import ClassifierCell from "../../../components/ClassifierCell";

// TODO: historical HHF, percentile
const ShooterRunsTable = ({
classifiers,
classifiersTotal,
classifiersPage,
onClassifierSelection,
onClubSelection,
}) => (
<DataTable
sortMode="multiple"
loading={!classifiers?.length}
stripedRows
/*lazy*/
value={(classifiers ?? []).map((c) => ({
...c,
sdUnix: new Date(c.sd).getTime(),
}))}
tableStyle={{ minWidth: "50rem" }}
/*
{...sortProps}
{...pageProps}
paginatorTemplate="FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink"
paginatorLeft={<h2>Scores</h2>}
paginatorRight={
<TableFilter
placeholder="Filter by Club or Shooter"
onFilterChange={(f) => setFilter(f)}
/>
}
totalRecords={runsTotal}
filterDisplay="row"
*/
>
{/* <Column field="sd" header="Date" />*/}
<Column
field="sdUnix"
header="Date"
sortable
body={(run) => new Date(run.sd).toLocaleDateString()}
/>
<Column
field="classifier"
header="Classifier"
sortable
bodyStyle={{ width: "12rem" }}
body={(run) =>
run.classifier ? (
<ClassifierCell
{...run.classifierInfo}
onClick={() => onClassifierSelection?.(run.classifier)}
/>
) : (
run.club_name
)
}
/>
<Column field="clubid" header="Club" sortable showFilterMenu={false} />
<Column field="hf" header="HF" sortable />
<Column
field="percent"
header="Percent"
sortable
headerTooltip="Classifier percentage for this score during the time that it was processed by USPSA. Maxes out at 100%."
headerTooltipOptions={headerTooltipOptions}
/>
<Column
field="curPercent"
header="Current Percent"
sortable
headerTooltip="What classifier percentage this score would've earned if it was submitted today, with Current HHFs."
headerTooltipOptions={headerTooltipOptions}
/>
<Column
field="percentMinusCurPercent"
header="Percent Change"
sortable
headerTooltip="Difference between calculated percent when run was submitted and what it would've been with current High Hit-Factor. \n Positive values mean classifier became harder, negative - easier."
headerTooltipOptions={headerTooltipOptions}
/>
<Column field="code" header="Flag" sortable />
<Column field="source" header="Source" sortable />
{/* TODO: <Column field="percentile" header="Percentile" sortable={false} /> */}
</DataTable>
);

export default ShooterRunsTable;
10 changes: 5 additions & 5 deletions web/src/pages/ShootersPage/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ShootersTable from "./components/ShootersTable";
import ShooterInfoTable from "./components/ShooterInfoTable";
import { useApi } from "../../utils/client";
import { divShortToLong } from "../../../../api/src/dataUtil/divisions";
import ShooterRunsTable from "./components/ShooterRunsTable";

// TODO: shooters table for single classifier? # attempts, low HF, high HF, same for percent, same for curPercent
// TODO: all classifiers total number of reshoots (non-uniqueness)
Expand Down Expand Up @@ -59,7 +60,8 @@ export const ShooterRunsAndInfo = ({
memberNumber,
onBackToShooters,
}) => {
const { info } = useShooterTableData({
const navigate = useNavigate();
const { info, ...tableShit } = useShooterTableData({
division,
memberNumber,
});
Expand Down Expand Up @@ -89,15 +91,13 @@ export const ShooterRunsAndInfo = ({
</div>
</div>

{/*
<RunsTable
{...useRunsTableDataResults}
<ShooterRunsTable
{...tableShit}
onClassifierSelection={(number) =>
navigate(`/classifiers/${division}/${number}`)
}
onClubSelection={(club) => navigate("/clubs/" + club)}
/>
*/}
</>
);
};
Expand Down

0 comments on commit a50fee9

Please sign in to comment.