mostrar colores y nombres de supermercados

This commit is contained in:
Cat /dev/Nulo 2023-12-23 21:13:06 -03:00
parent dac949cdd3
commit 106dee13ac

View file

@ -5,10 +5,29 @@
export let precios: Precio[]; export let precios: Precio[];
enum Supermercado {
Dia = "Dia",
Carrefour = "Carrefour",
Coto = "Coto",
}
const hosts: { [host: string]: Supermercado } = {
"diaonline.supermercadosdia.com.ar": Supermercado.Dia,
"www.carrefour.com.ar": Supermercado.Carrefour,
"www.cotodigital3.com.ar": Supermercado.Coto,
};
const colorBySupermercado: { [supermercado in Supermercado]: string } = {
[Supermercado.Dia]: "#d52b1e",
[Supermercado.Carrefour]: "#19549d",
[Supermercado.Coto]: "#e20025",
};
$: datasets = precios $: datasets = precios
.map((p) => new URL(p.url!).hostname) .map((p) => new URL(p.url!).hostname)
.filter(onlyUnique) .filter(onlyUnique)
.map((host) => { .map((host) => {
const supermercado = hosts[host];
const ps = precios const ps = precios
.filter((p) => new URL(p.url!).hostname === host) .filter((p) => new URL(p.url!).hostname === host)
.filter( .filter(
@ -16,7 +35,7 @@
p.precioCentavos !== null, p.precioCentavos !== null,
); );
return { return {
label: host, label: supermercado,
data: [ data: [
...ps.map((p) => ({ ...ps.map((p) => ({
x: p.fetchedAt, x: p.fetchedAt,
@ -30,7 +49,7 @@
], ],
fill: false, fill: false,
borderColor: `${host}`, borderColor: colorBySupermercado[supermercado],
tension: 0.1, tension: 0.1,
}; };
}); });