Skip to content

Commit

Permalink
feature: kd calc
Browse files Browse the repository at this point in the history
  • Loading branch information
broccolai committed Mar 7, 2024
1 parent fd33f62 commit 9278f6d
Show file tree
Hide file tree
Showing 19 changed files with 427 additions and 37 deletions.
2 changes: 1 addition & 1 deletion astro.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export default defineConfig({
build: {
inlineStylesheets: 'always',
},
output: 'hybrid',
output: 'server',
});
Binary file modified bun.lockb
Binary file not shown.
42 changes: 21 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,33 @@
},
"type": "module",
"devDependencies": {
"@types/node": "^20.8.6",
"postcss": "^8.4.31"
"@types/node": "^20.11.25",
"postcss": "^8.4.35"
},
"dependencies": {
"@aminya/solid-icons": "^2.0.12",
"@astrojs/solid-js": "^3.0.2",
"@biomejs/biome": "^1.2.2",
"@fontsource/open-sans": "^5.0.15",
"@fontsource/pt-mono": "^5.0.8",
"@fortawesome/free-solid-svg-icons": "^6.4.2",
"@pandacss/astro": "^0.16.0",
"@pandacss/dev": "^0.16.0",
"@prisma/client": "5.4.2",
"@solid-primitives/event-listener": "^2.3.0",
"@solid-primitives/resize-observer": "^2.0.22",
"@solidjs/meta": "^0.28.6",
"@solidjs/router": "^0.8.3",
"@vanilla-extract/integration": "^6.2.2",
"astro": "^3.3.0",
"babel-preset-solid": "^1.8.0",
"@astrojs/solid-js": "^4.0.1",
"@biomejs/biome": "^1.5.3",
"@fontsource/open-sans": "^5.0.25",
"@fontsource/pt-mono": "^5.0.12",
"@fortawesome/free-solid-svg-icons": "^6.5.1",
"@pandacss/astro": "^0.25.0",
"@pandacss/dev": "^0.34.0",
"@prisma/client": "5.10.2",
"@solid-primitives/event-listener": "^2.3.3",
"@solid-primitives/resize-observer": "^2.0.25",
"@solidjs/meta": "^0.29.3",
"@solidjs/router": "^0.12.5",
"@vanilla-extract/integration": "^7.1.1",
"astro": "^4.4.13",
"babel-preset-solid": "^1.8.15",
"batch-request-js": "^2.0.2",
"bungie-api-ts": "^5.0.0",
"npm-check-updates": "^16.14.6",
"npm-check-updates": "^16.14.15",
"oxide.ts": "^1.1.0",
"prisma": "^5.4.2",
"solid-js": "^1.8.1",
"typescript": "^5.2.2"
"prisma": "^5.10.2",
"solid-js": "^1.8.15",
"typescript": "^5.4.2"
},
"engines": {
"node": ">=16.8"
Expand Down
3 changes: 0 additions & 3 deletions src/components/destiny/green-dot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ export const GreenDot = () => {
const duration = (endTime - startTime) / 1000;

setMatchesPlayed(activity.matches);

console.log('size', activity);
console.log(`printActivity took ${duration} seconds`);
};

return (
Expand Down
236 changes: 236 additions & 0 deletions src/components/destiny/kd.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
import { createSignal } from 'solid-js';
import { trialsStats } from 'src/service/api-layer';
import { DestinyAccount } from 'src/service/destiny/types';
import { PlayerStats } from '../../service/destiny/trials-report.ts';
import { Input } from '../individuals/input.tsx';
import { FullPageContent } from '../global/containers.tsx';
import { styled } from '@panda/jsx';
import { H3, REGULAR_FONTS } from '../global/typography.tsx';

interface RequirementCalculatorProps {
stats: PlayerStats;
}

const SectionContainer = styled('div', {
base: {
border: '2px solid black',
background: 'white',
width: '100%',
padding: '1rem',
fontFamily: REGULAR_FONTS,
fontSize: '1rem',
},
});

const GridContainer = styled('div', {
base: {
display: 'grid',
gridTemplateColumns: `repeat(2, 1fr)`,
gridGap: '1rem',
},
});

const CalcButton = styled('button', {
base: {
border: '1px solid black',
gridColumn: 'span 2',
backgroundColor: 'white',
padding: '0.25rem',
},
});

const InputContainer = styled('div', {
base: {
minWidth: 0,
},
});

const SpecialInput = styled('input', {
base: {
minWidth: 0,
width: '100%',
border: '1px solid black',
padding: '0.25rem',
appearance: 'textfield',
},
});

const RequirementCalculator = (props: RequirementCalculatorProps) => {
const [target, setTarget] = createSignal<number>(0);
const [average, setAverage] = createSignal<number>(0);

const [result, setResult] = createSignal<string>('???');

const updateResult = (event: SubmitEvent) => {
event.preventDefault();

const requiredTotalKillsForGoalKD = target() * props.stats.deaths;
const killDeficitToReachGoalKD = requiredTotalKillsForGoalKD - props.stats.kills;
const efficiencyImprovementNeeded = average() - target();
const adjustedKillsNeeded = killDeficitToReachGoalKD / efficiencyImprovementNeeded;
const result = adjustedKillsNeeded * average();

setResult(result.toString());
};

return (
<>
<SectionName>CALC</SectionName>
<SectionContainer>
<form onSubmit={updateResult}>
<GridContainer>
<InputContainer>
<SpecialInput
type='number'
placeholder='target'
required
value={target()}
onInput={(e) => setTarget(parseFloat(e.currentTarget.value))}
min={0.01}
step={0.01}
/>
<StatName>target kd</StatName>
</InputContainer>
<InputContainer>
<SpecialInput
type='number'
placeholder='average'
required
value={average()}
onInput={(e) => setAverage(parseFloat(e.currentTarget.value))}
min={0.01}
step={0.01}
/>
<StatName style={'text-align: right;'}>average kd</StatName>
</InputContainer>
<CalcButton>GO</CalcButton>
<div style='text-align: center; grid-column: span 2; margin: 0.5rem 0;'>
<div>{result()}</div>
<StatName>kills required</StatName>
</div>
</GridContainer>
</form>
</SectionContainer>
</>
);
};

const StyledPage = styled(FullPageContent, {
base: {
padding: '15vh 0',
},
});

const Title = styled('h1', {
base: {
margin: '4rem 0',
},
});

const Content = styled('div', {
base: {
display: 'flex',
justifyContent: 'normal',
flexDirection: 'column',
width: '20vw',
height: '100%',
},
});

export const KillDeath = () => {
const [user, setUser] = createSignal<string>('');
const [stats, setStats] = createSignal<PlayerStats | null>(null);

const loadPlayer = async (event: SubmitEvent) => {
event.preventDefault();

const [name, identifier] = user().split('#');

const account: DestinyAccount = {
name: name,
identifer: parseInt(identifier),
};

await loadStats(account);
};

const loadStats = async (account: DestinyAccount) => {
const stats = await trialsStats(account);

setStats(stats);
};

return (
<StyledPage>
<Content>
<SectionName>LOOKUP</SectionName>
<form onSubmit={loadPlayer} autocomplete='off'>
<Input id={'username'} label={'bungie id'} placeholder={'broccoli#0679'} signal={[user, setUser]} />
</form>

{stats() && <StatsDisplay stats={stats()!!} />}

{stats() && <RequirementCalculator stats={stats()!!} />}
</Content>
</StyledPage>
);
};

interface StatsDisplayProps {
stats: PlayerStats;
}

const SectionName = styled(H3, {
base: {
fontSize: '1.2rem',
color: 'black',
width: '100%',
textAlign: 'center',
padding: '0.5rem',
margin: '2rem 0 0',
},
});

const StatWrapper = styled('div', {
base: {},
});

interface StatDisplayProps {
align: 'left' | 'right';
data: string | number;
name: string;
}

const StatName = styled('div', {
base: {
fontSize: '0.8rem',
color: 'grey',
},
});

const StatDisplay = (props: StatDisplayProps) => {
return (
<StatWrapper style={`text-align: ${props.align}`}>
<div>{props.data}</div>
<StatName>{props.name}</StatName>
</StatWrapper>
);
};

const StatsDisplay = (props: StatsDisplayProps) => {
const kd = (props.stats.kills / props.stats.deaths).toFixed(3);

return (
<>
<SectionName>STATS</SectionName>
<SectionContainer>
<GridContainer>
<StatDisplay align='left' data={props.stats.displayName} name='name' />
<StatDisplay align='right' data={kd} name='kd' />
<StatDisplay align='left' data={props.stats.kills} name='kills' />
<StatDisplay align='right' data={props.stats.deaths} name='deaths' />
</GridContainer>
</SectionContainer>
</>
);
};
8 changes: 8 additions & 0 deletions src/components/global/containers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,11 @@ export const ChildFlexSection = styled(FlexSection, {
position: 'relative',
},
});

export const FullPageContent = styled(FlexSection, {
base: {
width: '100vw',
height: '100vh',
overflow: 'hidden',
},
});
13 changes: 11 additions & 2 deletions src/components/global/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,20 @@ const Right = styled('p', {

const FIRST_PANEL = 1;

const Header = () => {
interface HeaderProps {
alwaysShow: boolean;
title: string | undefined;
}

const Header = (props: HeaderProps) => {
let previousState = panelState();
const [show, setShow] = createSignal(false);

createEffect(() => {
if (props.alwaysShow) {
setShow(true);
}

const currentState = panelState();
const storedPanel = previousState.currentPanel;

Expand All @@ -46,7 +55,7 @@ const Header = () => {
return (
<PageBanner top={0}>
<PageBannerContent>
<Icon style={{ [showIcon.identifier]: show() ? '1' : '0' }}>josh</Icon>
<Icon style={{ [showIcon.identifier]: show() ? '1' : '0' }}>{props.title ?? 'josh'}</Icon>
<Right>
<WiDaySunny />
</Right>
Expand Down
4 changes: 3 additions & 1 deletion src/components/index/projects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const Container = styled(FlexSection, {
},
});

const Intro = () => <Container />;
const Intro = () => {
return <Container>{/*<For each={projects}>{(project, i) => <ProjectCard project={project} />}</For>*/}</Container>;
};

export default Intro;
Loading

0 comments on commit 9278f6d

Please sign in to comment.