Skip to content

Commit

Permalink
Project footprint and energy density metrics.
Browse files Browse the repository at this point in the history
  • Loading branch information
James Karavakis committed Dec 9, 2022
1 parent efbca8f commit 9a364bd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function App() {
<Form>
<ContentContainer>
<Inputs />
<KeyMetrics footprint={10} price={2} energyDensity={3} />
<KeyMetrics />
</ContentContainer>
</Form>
</AppContainer>
Expand Down
18 changes: 8 additions & 10 deletions src/components/Project/Metric.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import styled from 'styled-components';
import { Text } from '@tesla/design-system-react';
import { useFormState } from 'informed';
import { calculateCost, numberWithCommas } from '../../functions';

interface KeyMetricsProps {
footprint: number;
price: number;
energyDensity: number;
}
import { calculateCost, calculateEnergy, calculateFootprint, numberWithCommas } from '../../functions';

const KeyMetricsBar = styled.div`
display: flex;
Expand Down Expand Up @@ -36,18 +30,22 @@ const MetricValue = styled.p`
color: #000000;
`;

export const KeyMetrics = ({footprint, price, energyDensity}: KeyMetricsProps) => {
export const KeyMetrics = () => {
const formState = useFormState();

const megapack = typeof formState.values.megapack === 'number' ? formState.values.megapack : 0;
const megapack2 = typeof formState.values.megapack2 === 'number' ? formState.values.megapack2 : 0;
const megapackXL = typeof formState.values.megapackXL === 'number' ? formState.values.megapackXL : 0;
const powerpack = typeof formState.values.powerpack ==='number' ? formState.values.powerpack : 0;

const total = megapack + megapack2 + megapackXL + powerpack;

const transformer = Math.floor(total/2) + (total % 2);

const totalCost = calculateCost({megapackXL, megapack2, megapack, powerpack, transformer});
const totalFootprint = calculateFootprint({megapackXL, megapack2, megapack, powerpack, transformer});
const totalEnergy = calculateEnergy({megapackXL, megapack2, megapack, powerpack, transformer});
const energyDensity = totalEnergy/totalFootprint ? Math.round(totalEnergy/totalFootprint * 10000)/10 : 0

return (
<KeyMetricsBar>
Expand All @@ -56,11 +54,11 @@ export const KeyMetrics = ({footprint, price, energyDensity}: KeyMetricsProps) =
<Text>Total Cost</Text>
</KeyMetric>
<KeyMetric>
<MetricValue>{price} sq ft</MetricValue>
<MetricValue>{numberWithCommas(totalFootprint)} sq ft</MetricValue>
<Text>Footprint</Text>
</KeyMetric>
<KeyMetric>
<MetricValue>{energyDensity} MWh/sq ft</MetricValue>
<MetricValue>{energyDensity} kWh/sq ft</MetricValue>
<Text>Energy Density</Text>
</KeyMetric>
</KeyMetricsBar>
Expand Down
24 changes: 24 additions & 0 deletions src/functions/Metrics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,28 @@ export const calculateCost = ({megapackXL, megapack2, megapack, powerpack, trans
const totalCost = megapackXLCost + megapack2Cost + megapackCost + powerpackCost + transformerCost;

return totalCost;
}

export const calculateFootprint = ({megapackXL, megapack2, megapack, powerpack, transformer}: ProductProps) => {
const megapackXLSize = megapackXL * products.megapackXL.size[0] * products.megapackXL.size[1];
const megapack2Size = megapack2 * products.megapack2.size[0] * products.megapack2.size[1];
const megapackSize = megapack * products.megapack.size[0] * products.megapack.size[1];
const powerpackSize = powerpack * products.powerpack.size[0] * products.powerpack.size[1];
const transformerSize = transformer * products.transformer.size[0] * products.transformer.size[1];

const totalSize = megapackXLSize + megapack2Size + megapackSize + powerpackSize + transformerSize;

return totalSize;
}

export const calculateEnergy = ({megapackXL, megapack2, megapack, powerpack, transformer}: ProductProps) => {
const megapackXLEnergy = megapackXL * products.megapackXL.energy;
const megapack2Energy = megapack2 * products.megapack2.energy;
const megapackEnergy = megapack * products.megapack.energy;
const powerpackEnergy = powerpack * products.powerpack.energy;
const transformerEnergy = transformer * products.transformer.energy;

const totalEnergy = megapackXLEnergy + megapack2Energy + megapackEnergy + powerpackEnergy + transformerEnergy;

return totalEnergy;
}

0 comments on commit 9a364bd

Please sign in to comment.