Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/helpers/DownloadData.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import Icon from "./MaterialIcon.svelte";

export let dataDownloadUrl="https://github.com/onsdigital/cpi-items-actions/raw/main/datadownload.xlsx";
// export let dataDownloadUrl="/datadownload.xlsx";
</script>

<div class="">
Expand Down
24 changes: 17 additions & 7 deletions src/components/helpers/Summary.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let locale=formatDefaultLocale({
"currency": ["£", ""]
})
let currency=format("$,.2f")
let percentage=format('.0f')
let percentage=format('.1f')
let perchangeofbasket

$: if(data.length>0){
Expand All @@ -29,16 +29,18 @@ $: if(data.length>0){
totallastyear = data.filter(d=>d['pricelastyear']>0).reduce((acc,cur)=>acc+cur['pricelastyear'],0)
pricedifflastmonth=total-totalOfItemsAvailableLastMonth-totallastmonth
pricedifflastyear=total-totalOfItemsAvailableLastyear-totallastyear
// https://seanconnolly.dev/javascript-find-element-with-max-value
maxannualgrowth=data.reduce((prev,curr)=>{
return prev['Annual growth'] > curr['Annual growth'] ? prev : curr
})
const itemsWithAnnualGrowth = data.filter(d=>d['Annual growth']!=null)
maxannualgrowth = itemsWithAnnualGrowth.length > 0 ? itemsWithAnnualGrowth.reduce((prev,curr)=>{
return Math.abs(prev['Annual growth']) > Math.abs(curr['Annual growth']) ? prev : curr
}) : null
perchangeofbasket=100*pricedifflastyear/totallastyear
}

function lowercasefirstletter(string) {
return string.charAt(0).toLowerCase() + string.slice(1);
}

$: console.log('pricedifflastmonth', pricedifflastmonth)
</script>

<div class='background'>
Expand All @@ -63,7 +65,7 @@ function lowercasefirstletter(string) {
<div class='first-item'>
{#if data.length>5 && total<250}
<p class='s21'>
Comparing with items available, this was <span class='bold'>{currency(Math.abs(pricedifflastmonth))} {pricedifflastmonth>0 ? 'more' :' less'} than last month</span> and
Comparing with items available, this was <span class='bold'>{pricedifflastmonth===0 ? 'the same as' : `${currency(Math.abs(pricedifflastmonth))} ${pricedifflastmonth>0 ? 'more' :' less'} than`} last month</span> and
<span class='bold'>{currency(Math.abs(pricedifflastyear))} {pricedifflastyear>0 ? 'more' :' less'} than last year.</span> This was an annual <span class='bold'>{pricedifflastyear>0 ? 'increase' :' decrease'} of {percentage(Math.abs(100*pricedifflastyear/totallastyear))}%.</span>
</p>
{:else if data.length==1 & total > 0}
Expand Down Expand Up @@ -98,7 +100,7 @@ function lowercasefirstletter(string) {


</div>
{#if maxannualgrowth['Annual growth']!=null}
{#if maxannualgrowth?.['Annual growth']!=null}
<div id='category' class='dashtop'>
<p class='bold s16'>{maxannualgrowth['Category1']}</p>
<div class='hflex'>
Expand Down Expand Up @@ -148,6 +150,14 @@ function lowercasefirstletter(string) {
content:url("../../../basket.svg");
}

.groceries{
content:url("../../../basket.svg");
}

.tobacco{
content:url("../../../basket.svg");
}

.clothingandfootwear{
content:url("../../../clothing.svg");
}
Expand Down
Loading