You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
3.2 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import {RANGE_FILTERS_KEYS} from "./stores/usePendingPointsFilters.js";
export function download(filename, data) {
const downloadLink = window.document.createElement("a");
downloadLink.href = window.URL.createObjectURL(
new Blob([data], {
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
})
);
downloadLink.download = filename;
document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);
}
var chars = {"Ё":"YO","Й":"I","Ц":"TS","У":"U","К":"K","Е":"E","Н":"N","Г":"G","Ш":"SH","Щ":"SCH","З":"Z","Х":"H","Ъ":"'","ё":"yo","й":"i","ц":"ts","у":"u","к":"k","е":"e","н":"n","г":"g","ш":"sh","щ":"sch","з":"z","х":"h","ъ":"'","Ф":"F","Ы":"I","В":"V","А":"A","П":"P","Р":"R","О":"O","Л":"L","Д":"D","Ж":"ZH","Э":"E","ф":"f","ы":"i","в":"v","а":"a","п":"p","р":"r","о":"o","л":"l","д":"d","ж":"zh","э":"e","Я":"Ya","Ч":"CH","С":"S","М":"M","И":"I","Т":"T","Ь":"'","Б":"B","Ю":"YU","я":"ya","ч":"ch","с":"s","м":"m","и":"i","т":"t","ь":"'","б":"b","ю":"yu"," ":""};
export function transliterate(word){
return word.split('').map(function (char) {
return chars[char] || char;
}).join("");
}
export function getFilteredGroups(categories) {
if (!categories) return [];
return categories
.filter((category) => category.visible)
.map((category) => {
return {
...category,
groups: [...category.groups.filter((group) => group.visible)],
}
})
}
export function fieldHasChanged(filters, ranges, filterKey) {
const r = ranges[filterKey]
const gtValue = filters[`${filterKey}__gt`];
const gtInitial = r ? r[0] : 0 ;
const ltValue = filters[`${filterKey}__lt`];
const ltInitial =r ? r[1] : 0;
const result = !(gtValue === gtInitial && ltValue === ltInitial)
return {
result,
gtValue,
ltValue,
}
}
export const doesMatchFilter = (filters, ranges, feature) => {
const { prediction, categories, region } = filters;
const {
prediction_current,
category,
area,
district,
area_id,
district_id,
} = feature.properties;
const doesMatchPredictionFilter =
prediction_current >= prediction[0] &&
prediction_current <= prediction[1];
const doesMatchCategoriesFilter =
categories.length > 0 ? categories.includes(category) : true;
const doesMatchOtherFilters = () => {
let res = true;
RANGE_FILTERS_KEYS.map((filterKey) => {
if (fieldHasChanged(filters, ranges, filterKey) && res) {
res =
feature.properties[filterKey] >= filters[`${filterKey}__gt`] &&
feature.properties[filterKey] <= filters[`${filterKey}__lt`];
}
});
return res;
}
const doesMatchRegionFilter = () => {
if (!region) return true;
if (region.type === "ao") {
return (district ?? district_id) === region.id;
} else {
return (area ?? area_id) === region.id;
}
};
return (
doesMatchPredictionFilter &&
doesMatchCategoriesFilter &&
doesMatchRegionFilter() &&
doesMatchOtherFilters()
);
};
export const isNil = (value) =>
value === undefined || value === null || value === "";