This commit is contained in:
MuslemRahimi 2025-03-01 12:27:53 +01:00
parent 447240b668
commit 2da4780576

View File

@ -1,44 +1,44 @@
export const listOfRelevantCountries = [ export const listOfRelevantCountries = [
{ USA: "United States" }, { US: "United States" },
{ CHN: "China" }, { CN: "China" },
{ CAN: "Canada" }, { CA: "Canada" },
{ GBR: "United Kingdom" }, { GB: "United Kingdom" },
{ JPN: "Japan" }, { JP: "Japan" },
{ ISR: "Israel" }, { IL: "Israel" },
{ BRA: "Brazil" }, { BR: "Brazil" },
{ FRA: "France" }, { FR: "France" },
{ IRL: "Ireland" }, { IE: "Ireland" },
{ DEU: "Germany" }, { DE: "Germany" },
{ MEX: "Mexico" }, { MX: "Mexico" },
{ IND: "India" }, { IN: "India" },
{ AUS: "Australia" }, { AU: "Australia" },
{ KOR: "South Korea" }, { KR: "South Korea" },
{ SWE: "Sweden" }, { SE: "Sweden" },
{ NLD: "Netherlands" }, { NL: "Netherlands" },
{ CHE: "Switzerland" }, { CH: "Switzerland" },
{ TWN: "Taiwan" }, { TW: "Taiwan" },
{ ZAF: "South Africa" }, { ZA: "South Africa" },
{ HKG: "Hong Kong" }, { HK: "Hong Kong" },
{ SGP: "Singapore" }, { SG: "Singapore" },
{ ARG: "Argentina" }, { AR: "Argentina" },
{ CHL: "Chile" }, { CL: "Chile" },
{ PHL: "Philippines" }, { PH: "Philippines" },
{ TUR: "Turkey" }, { TR: "Turkey" },
{ ITA: "Italy" }, { IT: "Italy" },
{ IDN: "Indonesia" }, { ID: "Indonesia" },
{ MYS: "Malaysia" }, { MY: "Malaysia" },
{ LUX: "Luxembourg" }, { LU: "Luxembourg" },
{ VNM: "Vietnam" }, { VN: "Vietnam" },
{ NZL: "New Zealand" }, { NZ: "New Zealand" },
{ DNK: "Denmark" }, { DK: "Denmark" },
{ NOR: "Norway" }, { NO: "Norway" },
{ FIN: "Finland" }, { FI: "Finland" },
{ RUS: "Russia" }, { RU: "Russia" },
{ ARE: "United Arab Emirates" }, { AE: "United Arab Emirates" },
]; ];
const countryMap = Object.fromEntries( const countryMap = Object.fromEntries(
listOfRelevantCountries.map((entry) => { listOfRelevantCountries?.map((entry) => {
const [code, name] = Object.entries(entry)[0]; const [code, name] = Object.entries(entry)[0];
return [name, code]; return [name, code];
}) })
@ -50,14 +50,14 @@ onmessage = async (event: MessageEvent) => {
// Separate importance filters and country filters // Separate importance filters and country filters
const importanceFilters = filterList.filter( const importanceFilters = filterList.filter(
(item) => typeof item === "number" && [1, 2, 3].includes(item as number) (item) => typeof item === "number" && [1, 2, 3]?.includes(item as number)
) as number[]; ) as number[];
const countryFilters = filterList.filter( const countryFilters = filterList?.filter(
(item) => typeof item === "string" (item) => typeof item === "string"
) as string[]; ) as string[];
// Map filterList country names to abbreviations // Map filterList country names to abbreviations
const filterCodes = countryFilters.map((name) => countryMap[name]) || []; const filterCodes = countryFilters?.map((name) => countryMap[name]) || [];
// Filter rawData based on the mapped country codes and importance // Filter rawData based on the mapped country codes and importance
const output = rawData?.map((subArray) => const output = rawData?.map((subArray) =>
@ -65,8 +65,8 @@ onmessage = async (event: MessageEvent) => {
const countryMatch = const countryMatch =
filterCodes.length === 0 || filterCodes.includes(item?.country); filterCodes.length === 0 || filterCodes.includes(item?.country);
const importanceMatch = const importanceMatch =
importanceFilters.length === 0 || importanceFilters?.length === 0 ||
importanceFilters.includes(item?.importance); importanceFilters?.includes(item?.importance);
return countryMatch && importanceMatch; return countryMatch && importanceMatch;
}) })
); );