Skip to content

Commit

Permalink
Merge pull request #11 from lucianavlop/price-chart-enhancements
Browse files Browse the repository at this point in the history
Simplifying logic on price chart
  • Loading branch information
lucianavlop authored May 15, 2023
2 parents 2b5bf45 + 21ae985 commit d62dad9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 27 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
## Description
A simple dashboard to display the PVPC electricity prices in Spain.

A dashboard to display the PVPC electricity prices in Spain.

## Stack
- ReactJS
- Material-UI
- Nginx

- ReactJS
- Material-UI
- Nginx

## API

Requires an instances on this [API](https://github.com/daithihearn/electricity-prices)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "daithi-dashboard",
"version": "0.1.0",
"version": "2.1.1",
"private": true,
"dependencies": {
"@emotion/react": "^11.10.6",
Expand Down
5 changes: 3 additions & 2 deletions public/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"short_name": "electricity-prices-dashboard",
"name": "A dashboard to display the PVPC electricity prices in Spain.",
"icons": [
{
"src": "favicon.ico",
Expand All @@ -18,6 +18,7 @@
"sizes": "512x512"
}
],
"version": "2.1.1",
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
Expand Down
23 changes: 3 additions & 20 deletions src/components/PriceChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,7 @@ const DailyChart: React.FC<DailyChartProps> = ({
}, [currentPriceLocation, theme])

const cheapPeriods = useMemo(() => {
if (!showCheapPeriod || prices.length <= 1)
return [
Array<null>(prices.length).fill(null),
Array<null>(prices.length).fill(null),
]
if (!showCheapPeriod || prices.length <= 1) return [[], []]

const cp = getTwoCheapestPeriods(prices, 3)

Expand All @@ -209,23 +205,10 @@ const DailyChart: React.FC<DailyChartProps> = ({
}, [prices, showCheapPeriod])

const expensivePeriod = useMemo(() => {
if (!showExpensivePeriod) return Array<null>(prices.length).fill(null)
if (!showExpensivePeriod) return []

const ep = getMostExpensivePeriod(prices, 3)
return prices.map(p => {
const priceHour = new Date(p.dateTime).getHours()
// If the dateTime of item is contained in ep, return the price, else return null
if (
ep.find(epItem => {
const cpHour = new Date(epItem.dateTime).getHours()
return cpHour === priceHour || cpHour + 1 === priceHour
})
) {
return p.price
} else {
return null
}
})
return filterAndPadPrices(prices, ep)
}, [prices, showExpensivePeriod])

const averageDataset = useMemo(
Expand Down

0 comments on commit d62dad9

Please sign in to comment.