-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
81 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1,89 @@ | ||
import fs from 'node:fs/promises'; | ||
import { access, writeFileSync, readFileSync } from 'node:fs'; | ||
|
||
|
||
|
||
import fs from "node:fs/promises"; | ||
import { access, writeFileSync, readFileSync } from "node:fs"; | ||
|
||
function createOrUpdateDataChart(file, source) { | ||
|
||
|
||
//read last crux | ||
|
||
const url = new URL(source, | ||
import.meta.url); | ||
const json = readFileSync(url, 'utf-8'); | ||
const data = JSON.parse(json); | ||
|
||
// update or create | ||
access(file, (err) => { | ||
if (err) { | ||
const newData = prepareEmptyDataForChart(data); | ||
|
||
let ds = JSON.stringify(newData); | ||
writeFileSync(file, ds); | ||
console.log("created"); | ||
} else { | ||
|
||
const url = new URL(file, | ||
import.meta.url); | ||
const json = readFileSync(url, 'utf-8'); | ||
const allFCP = JSON.parse(json); | ||
|
||
const updateAllFCP = updateCharData(data, allFCP); | ||
let ns = JSON.stringify(updateAllFCP); | ||
writeFileSync(file, ns); | ||
console.log("updated") | ||
} | ||
}); | ||
//read last crux | ||
|
||
const url = new URL(source, import.meta.url); | ||
const json = readFileSync(url, "utf-8"); | ||
const data = JSON.parse(json); | ||
|
||
// update or create | ||
access(file, (err) => { | ||
if (err) { | ||
const newData = prepareEmptyDataForChart(data); | ||
|
||
let ds = JSON.stringify(newData); | ||
writeFileSync(file, ds); | ||
console.log("created"); | ||
} else { | ||
const url = new URL(file, import.meta.url); | ||
const json = readFileSync(url, "utf-8"); | ||
const allFCP = JSON.parse(json); | ||
|
||
const updateAllFCP = updateCharData(data, allFCP); | ||
let ns = JSON.stringify(updateAllFCP); | ||
writeFileSync(file, ns); | ||
console.log("updated"); | ||
} | ||
}); | ||
} | ||
|
||
function getMetric(data, metric) { | ||
const dataConverted = data.metrics.map(item => { | ||
let obj = item[metric]; | ||
obj.url = item.url.replace("https://", ""); | ||
return obj | ||
}); | ||
|
||
let metricByUrl = {} | ||
dataConverted.forEach(item => { | ||
metricByUrl[item.url] = item.p75 | ||
}); | ||
return metricByUrl | ||
|
||
const dataConverted = data.metrics.map((item) => { | ||
let obj = item[metric] || {}; | ||
obj.url = item.url.replace("https://", ""); | ||
return obj; | ||
}); | ||
|
||
let metricByUrl = {}; | ||
dataConverted.forEach((item) => { | ||
metricByUrl[item.url] = item.p75; | ||
}); | ||
return metricByUrl; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
// push new data to data chart | ||
function updateCharData(data, dataFromFile) { | ||
Object.keys(dataFromFile).forEach((metric) => { | ||
const metricData = getMetric(data, metric); | ||
|
||
Object.keys(dataFromFile).forEach(metric => { | ||
const metricData = getMetric(data, metric); | ||
|
||
dataFromFile[metric].series.map(item => { | ||
item.data.push(metricData[item.name]); | ||
return item; | ||
}); | ||
dataFromFile[metric].categories.push(data.params.date); | ||
}) | ||
return dataFromFile; | ||
dataFromFile[metric].series.map((item) => { | ||
item.data.push(metricData[item.name]); | ||
return item; | ||
}); | ||
dataFromFile[metric].categories.push(data.params.date); | ||
}); | ||
return dataFromFile; | ||
} | ||
|
||
|
||
//prepare data for chart for the first time | ||
function prepareEmptyDataForChart(data) { | ||
|
||
let tmpl = {}; | ||
|
||
["FCP", "LCP", "INP", "CLS","TTFB"].forEach(metric => { | ||
tmpl[metric] = { | ||
"series": [], | ||
"categories": [] | ||
}; | ||
const metricData = getMetric(data, metric); | ||
Object.keys(metricData).forEach(url => { | ||
tmpl[metric].series.push({ | ||
"name": url, | ||
"data": [metricData[url]] | ||
}) | ||
}); | ||
tmpl[metric].categories.push(data.params.date) | ||
let tmpl = {}; | ||
|
||
["FCP", "LCP", "INP", "CLS", "TTFB"].forEach((metric) => { | ||
tmpl[metric] = { | ||
series: [], | ||
categories: [], | ||
}; | ||
const metricData = getMetric(data, metric); | ||
Object.keys(metricData).forEach((url) => { | ||
tmpl[metric].series.push({ | ||
name: url, | ||
data: [metricData[url]], | ||
}); | ||
}); | ||
tmpl[metric].categories.push(data.params.date); | ||
}); | ||
|
||
return tmpl | ||
return tmpl; | ||
} | ||
|
||
|
||
|
||
createOrUpdateDataChart('public/data-chart/crux-origin-all.json', 'src/_data/ecommerce-pl-origin.json'); | ||
createOrUpdateDataChart('public/data-chart/crux-home-all.json', 'src/_data/ecommerce-pl-url.json') | ||
createOrUpdateDataChart( | ||
"public/data-chart/crux-origin-all.json", | ||
"src/_data/ecommerce-pl-origin.json" | ||
); | ||
createOrUpdateDataChart( | ||
"public/data-chart/crux-home-all.json", | ||
"src/_data/ecommerce-pl-url.json" | ||
); |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"params":{"formFactor":"PHONE","origin":true,"collectionPeriod":{"firstDate":{"year":2024,"month":8,"day":21},"lastDate":{"year":2024,"month":9,"day":17}},"date":"20.09.2024"},"metrics":[{"url":"allegrolokalnie.pl","CLS":{"histogram":[91.9,6.03,2.07],"p75":"0.00","rank":"good"},"FCP":{"histogram":[94.13,3.82,2.05],"p75":1025,"rank":"good"},"FID":{"histogram":[],"p75":"-","rank":"-"},"LCP":{"histogram":[90.25,6.66,3.08],"p75":1635,"rank":"good"},"TTFB":{"histogram":[85.64,12.39,1.97],"p75":663,"rank":"good"},"INP":{"histogram":[86.3,10.9,2.8],"p75":144,"rank":"good"},"minimalGood":85.64},{"url":"www.amazon.pl","CLS":{"histogram":[76.38,19.95,3.67],"p75":"0.09","rank":"good"},"FCP":{"histogram":[89.14,7.36,3.5],"p75":1219,"rank":"good"},"FID":{"histogram":[],"p75":"-","rank":"-"},"LCP":{"histogram":[91.18,6.12,2.71],"p75":1652,"rank":"good"},"TTFB":{"histogram":[82.45,13.65,3.9],"p75":639,"rank":"good"},"INP":{"histogram":[86.11,11.71,2.18],"p75":145,"rank":"good"},"minimalGood":76.38},{"url":"www.doz.pl","CLS":{"histogram":[91.68,7.23,1.09],"p75":"0.04","rank":"good"},"FCP":{"histogram":[88.71,7.62,3.67],"p75":1236,"rank":"good"},"FID":{"histogram":[],"p75":"-","rank":"-"},"LCP":{"histogram":[91.94,5.4,2.65],"p75":1496,"rank":"good"},"TTFB":{"histogram":[87,10.26,2.74],"p75":588,"rank":"good"},"INP":{"histogram":[74.57,20.53,4.9],"p75":202,"rank":"average"},"minimalGood":74.57},{"url":"allegro.pl","CLS":{"histogram":[95.87,2.24,1.89],"p75":"0.00","rank":"good"},"FCP":{"histogram":[90.24,7.35,2.41],"p75":1333,"rank":"good"},"FID":{"histogram":[],"p75":"-","rank":"-"},"LCP":{"histogram":[92.51,5.12,2.38],"p75":1566,"rank":"good"},"TTFB":{"histogram":[70.83,26.14,3.03],"p75":862,"rank":"average"},"INP":{"histogram":[83.02,14.62,2.36],"p75":163,"rank":"good"},"minimalGood":70.83},{"url":"pl.aliexpress.com","CLS":{"histogram":[70.35,22.24,7.41],"p75":"0.13","rank":"average"},"FCP":{"histogram":[86.79,8.89,4.31],"p75":1281,"rank":"good"},"FID":{"histogram":[],"p75":"-","rank":"-"},"LCP":{"histogram":[90.07,6.38,3.55],"p75":1502,"rank":"good"},"TTFB":{"histogram":[73.29,20.14,6.58],"p75":838,"rank":"average"},"INP":{"histogram":[75.31,21.26,3.43],"p75":199,"rank":"good"},"minimalGood":70.35},{"url":"www.mediaexpert.pl","CLS":{"histogram":[84.95,7.88,7.17],"p75":"0.05","rank":"good"},"FCP":{"histogram":[85.04,9.04,5.92],"p75":1218,"rank":"good"},"FID":{"histogram":[],"p75":"-","rank":"-"},"LCP":{"histogram":[83.51,9.99,6.5],"p75":1879,"rank":"good"},"TTFB":{"histogram":[81.02,10.93,8.05],"p75":614,"rank":"good"},"INP":{"histogram":[68.18,23.94,7.88],"p75":237,"rank":"average"},"minimalGood":68.18},{"url":"www.euro.com.pl","CLS":{"histogram":[79.6,9.58,10.82],"p75":"0.06","rank":"good"},"FCP":{"histogram":[82.83,11.67,5.51],"p75":1522,"rank":"good"},"FID":{"histogram":[],"p75":"-","rank":"-"},"LCP":{"histogram":[88.09,7.3,4.61],"p75":1772,"rank":"good"},"TTFB":{"histogram":[70.28,24.7,5.02],"p75":882,"rank":"average"},"INP":{"histogram":[63.31,26.03,10.66],"p75":269,"rank":"average"},"minimalGood":63.31},{"url":"modivo.pl","CLS":{"histogram":[87.51,2.94,9.55],"p75":"0.00","rank":"good"},"FCP":{"histogram":[83.14,12.67,4.19],"p75":1562,"rank":"good"},"FID":{"histogram":[],"p75":"-","rank":"-"},"LCP":{"histogram":[84.03,10.02,5.94],"p75":2009,"rank":"good"},"TTFB":{"histogram":[58.94,35.49,5.57],"p75":1026,"rank":"average"},"INP":{"histogram":[56.63,30.52,12.85],"p75":313,"rank":"average"},"minimalGood":56.63},{"url":"www.empik.com","CLS":{"histogram":[65.87,18.13,16],"p75":"0.16","rank":"average"},"FCP":{"histogram":[80.31,13.63,6.06],"p75":1597,"rank":"good"},"FID":{"histogram":[],"p75":"-","rank":"-"},"LCP":{"histogram":[76.56,14.08,9.36],"p75":2407,"rank":"good"},"TTFB":{"histogram":[60.23,28.81,10.96],"p75":1147,"rank":"average"},"INP":{"histogram":[53.04,35.41,11.54],"p75":315,"rank":"average"},"minimalGood":53.04},{"url":"eobuwie.com.pl","CLS":{"histogram":[88.23,2.88,8.88],"p75":"0.00","rank":"good"},"FCP":{"histogram":[83.97,11.98,4.05],"p75":1528,"rank":"good"},"FID":{"histogram":[],"p75":"-","rank":"-"},"LCP":{"histogram":[84.76,9.16,6.08],"p75":1988,"rank":"good"},"TTFB":{"histogram":[76.12,19.76,4.13],"p75":781,"rank":"good"},"INP":{"histogram":[50.59,31.57,17.84],"p75":370,"rank":"average"},"minimalGood":50.59},{"url":"m.ceneo.pl","CLS":{"histogram":[97.2,1.25,1.55],"p75":"0.00","rank":"good"},"FCP":{"histogram":[93.83,4.12,2.05],"p75":960,"rank":"good"},"FID":{"histogram":[],"p75":"-","rank":"-"},"LCP":{"histogram":[95.6,2.6,1.8],"p75":1053,"rank":"good"},"TTFB":{"histogram":[85.12,11.95,2.93],"p75":592,"rank":"good"},"INP":{"histogram":[46.16,41.22,12.62],"p75":352,"rank":"average"},"minimalGood":46.16},{"url":"erli.pl","CLS":{"histogram":[78.92,6.09,14.99],"p75":"0.06","rank":"good"},"FCP":{"histogram":[83.31,11.56,5.14],"p75":1503,"rank":"good"},"FID":{"histogram":[],"p75":"-","rank":"-"},"LCP":{"histogram":[84.95,8.9,6.14],"p75":1908,"rank":"good"},"TTFB":{"histogram":[85.24,11.36,3.4],"p75":622,"rank":"good"},"INP":{"histogram":[37.01,40.58,22.41],"p75":466,"rank":"average"},"minimalGood":37.01},{"url":"www.castorama.pl","CLS":{"histogram":[68.6,6.14,25.26],"p75":"0.26","rank":"poor"},"FCP":{"histogram":[71.07,19.29,9.64],"p75":1989,"rank":"average"},"FID":{"histogram":[],"p75":"-","rank":"-"},"LCP":{"histogram":[65.89,21.11,13],"p75":2943,"rank":"average"},"TTFB":{"histogram":[49.98,34.66,15.36],"p75":1285,"rank":"average"},"INP":{"histogram":[34.19,26.66,39.15],"p75":773,"rank":"poor"},"minimalGood":34.19}]} | ||
{"params":{"formFactor":"PHONE","origin":true,"collectionPeriod":{"firstDate":{"year":2024,"month":8,"day":24},"lastDate":{"year":2024,"month":9,"day":20}},"date":"22.09.2024"},"metrics":[{"url":"allegrolokalnie.pl","CLS":{"histogram":[92.12,5.82,2.06],"p75":"0.00","rank":"good"},"FCP":{"histogram":[94.3,3.77,1.93],"p75":1029,"rank":"good"},"LCP":{"histogram":[90.5,6.35,3.15],"p75":1627,"rank":"good"},"TTFB":{"histogram":[85.72,12.38,1.9],"p75":667,"rank":"good"},"INP":{"histogram":[86.83,10.55,2.62],"p75":143,"rank":"good"},"minimalGood":85.72},{"url":"www.amazon.pl","CLS":{"histogram":[76.38,19.97,3.65],"p75":"0.09","rank":"good"},"FCP":{"histogram":[89.24,7.33,3.43],"p75":1215,"rank":"good"},"LCP":{"histogram":[91.22,6.11,2.66],"p75":1654,"rank":"good"},"TTFB":{"histogram":[82.37,13.53,4.09],"p75":639,"rank":"good"},"INP":{"histogram":[86.26,11.57,2.17],"p75":144,"rank":"good"},"minimalGood":76.38},{"url":"www.doz.pl","CLS":{"histogram":[91.53,7.34,1.13],"p75":"0.04","rank":"good"},"FCP":{"histogram":[88.71,7.69,3.6],"p75":1236,"rank":"good"},"LCP":{"histogram":[91.87,5.38,2.76],"p75":1496,"rank":"good"},"TTFB":{"histogram":[86.95,10.34,2.71],"p75":589,"rank":"good"},"INP":{"histogram":[74.63,20.46,4.91],"p75":201,"rank":"average"},"minimalGood":74.63},{"url":"pl.aliexpress.com","CLS":{"histogram":[72.07,20.52,7.41],"p75":"0.11","rank":"average"},"FCP":{"histogram":[86.88,8.8,4.32],"p75":1271,"rank":"good"},"LCP":{"histogram":[89.6,6.86,3.55],"p75":1531,"rank":"good"},"TTFB":{"histogram":[74.05,19.43,6.52],"p75":821,"rank":"average"},"INP":{"histogram":[75.45,21.15,3.4],"p75":197,"rank":"good"},"minimalGood":72.07},{"url":"allegro.pl","CLS":{"histogram":[95.8,2.34,1.86],"p75":"0.00","rank":"good"},"FCP":{"histogram":[90.25,7.25,2.5],"p75":1329,"rank":"good"},"LCP":{"histogram":[92.32,5.23,2.45],"p75":1564,"rank":"good"},"TTFB":{"histogram":[70.97,26.11,2.92],"p75":858,"rank":"average"},"INP":{"histogram":[83.31,14.53,2.17],"p75":163,"rank":"good"},"minimalGood":70.97},{"url":"www.mediaexpert.pl","CLS":{"histogram":[85.08,7.66,7.26],"p75":"0.05","rank":"good"},"FCP":{"histogram":[85.08,9.04,5.88],"p75":1215,"rank":"good"},"LCP":{"histogram":[83.6,9.96,6.44],"p75":1870,"rank":"good"},"TTFB":{"histogram":[81.16,10.89,7.95],"p75":613,"rank":"good"},"INP":{"histogram":[68.93,23.58,7.49],"p75":233,"rank":"average"},"minimalGood":68.93},{"url":"www.euro.com.pl","CLS":{"histogram":[79.46,9.79,10.75],"p75":"0.06","rank":"good"},"FCP":{"histogram":[83.26,11.33,5.4],"p75":1508,"rank":"good"},"LCP":{"histogram":[88.33,7.13,4.54],"p75":1755,"rank":"good"},"TTFB":{"histogram":[71.2,23.88,4.91],"p75":867,"rank":"average"},"INP":{"histogram":[63.68,26.08,10.25],"p75":265,"rank":"average"},"minimalGood":63.68},{"url":"modivo.pl","CLS":{"histogram":[87.6,3.07,9.33],"p75":"0.00","rank":"good"},"FCP":{"histogram":[82.36,13.13,4.51],"p75":1585,"rank":"good"},"LCP":{"histogram":[83.87,10.17,5.96],"p75":2025,"rank":"good"},"TTFB":{"histogram":[58.77,35.65,5.58],"p75":1028,"rank":"average"},"INP":{"histogram":[56.76,30.36,12.89],"p75":311,"rank":"average"},"minimalGood":56.76},{"url":"www.empik.com","CLS":{"histogram":[65.67,18.27,16.07],"p75":"0.16","rank":"average"},"FCP":{"histogram":[79.78,13.88,6.35],"p75":1606,"rank":"good"},"LCP":{"histogram":[76.52,14.09,9.39],"p75":2411,"rank":"good"},"TTFB":{"histogram":[60.13,28.52,11.35],"p75":1150,"rank":"average"},"INP":{"histogram":[52.98,35.55,11.47],"p75":315,"rank":"average"},"minimalGood":52.98},{"url":"eobuwie.com.pl","CLS":{"histogram":[88.38,2.87,8.76],"p75":"0.00","rank":"good"},"FCP":{"histogram":[84.3,11.81,3.89],"p75":1524,"rank":"good"},"LCP":{"histogram":[85.11,9.06,5.83],"p75":1976,"rank":"good"},"TTFB":{"histogram":[76.24,19.59,4.16],"p75":779,"rank":"good"},"INP":{"histogram":[52.31,31.39,16.3],"p75":346,"rank":"average"},"minimalGood":52.31},{"url":"m.ceneo.pl","CLS":{"histogram":[97.18,1.24,1.58],"p75":"0.00","rank":"good"},"FCP":{"histogram":[93.83,4.11,2.06],"p75":958,"rank":"good"},"LCP":{"histogram":[95.56,2.68,1.76],"p75":1052,"rank":"good"},"TTFB":{"histogram":[85.22,11.89,2.89],"p75":591,"rank":"good"},"INP":{"histogram":[46.36,41.06,12.58],"p75":350,"rank":"average"},"minimalGood":46.36},{"url":"erli.pl","CLS":{"histogram":[78.81,6.08,15.11],"p75":"0.07","rank":"good"},"FCP":{"histogram":[83.41,11.45,5.14],"p75":1501,"rank":"good"},"LCP":{"histogram":[85,8.88,6.12],"p75":1910,"rank":"good"},"TTFB":{"histogram":[85.39,11.33,3.28],"p75":620,"rank":"good"},"INP":{"histogram":[36.51,40.71,22.78],"p75":470,"rank":"average"},"minimalGood":36.51},{"url":"www.castorama.pl","CLS":{"histogram":[69.08,6.24,24.68],"p75":"0.23","rank":"average"},"FCP":{"histogram":[71.03,19.42,9.56],"p75":1982,"rank":"average"},"LCP":{"histogram":[66.26,21.45,12.29],"p75":2909,"rank":"average"},"TTFB":{"histogram":[50.48,34.09,15.43],"p75":1273,"rank":"average"},"INP":{"histogram":[35.11,26.66,38.23],"p75":757,"rank":"poor"},"minimalGood":35.11}]} |
Oops, something went wrong.