aboutsummaryrefslogtreecommitdiffstats
path: root/app/models.js
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--app/models.js48
1 files changed, 25 insertions, 23 deletions
diff --git a/app/models.js b/app/models.js
index e3f6381..6ad5636 100644
--- a/app/models.js
+++ b/app/models.js
@@ -708,7 +708,10 @@ export class House {
}
export class Filters {
- constructor() {
+ /**
+ * @param {House[]} houses
+ */
+ constructor(houses) {
this.minPrice = 0;
this.maxPrice = Number.POSITIVE_INFINITY;
this.minYear = 1800;
@@ -717,46 +720,45 @@ export class Filters {
this.maxArea = Number.POSITIVE_INFINITY;
this.minLot = 0;
this.maxLot = Number.POSITIVE_INFINITY;
+ this.updateRanges(houses);
/** @type {string[]} */
this.districts = [];
}
+ reset() {
+ this.minPrice = 0;
+ this.maxPrice = Number.POSITIVE_INFINITY;
+ this.minYear = 1800;
+ this.maxYear = Number.POSITIVE_INFINITY;
+ this.minArea = 0;
+ this.maxArea = Number.POSITIVE_INFINITY;
+ this.minLot = 0;
+ this.maxLot = Number.POSITIVE_INFINITY;
+ this.districts = [];
+ }
+
/**
* Update filter ranges based on house data
* @param {House[]} houses
*/
updateRanges(houses) {
- if (!houses || houses.length === 0) return;
-
const prices = houses.map((h) => h.price).filter((p) => p > 0);
const years = houses.map((h) => h.constructionYear).filter((y) => y && y > 0);
const areas = houses.map((h) => h.livingArea).filter((a) => a && a > 0);
const lots = houses.map((h) => h.totalArea).filter((l) => l && l > 0);
- // Set reasonable defaults if no data
- const defaultPrice = 500000;
- const defaultYear = new Date().getFullYear();
- const defaultArea = 200;
- const defaultLot = 1000;
-
// Update min/max values, ensuring they're reasonable
- this.minPrice = Math.min(...prices) || 0;
- this.maxPrice = Math.max(...prices) || defaultPrice;
-
- this.minYear = Math.min(...years) || 1800;
- this.maxYear = Math.max(...years) || defaultYear;
+ this.minPrice = Math.min(...prices);
+ this.maxPrice = Math.max(...prices);
- this.minArea = Math.min(...areas) || 0;
- this.maxArea = Math.max(...areas) || defaultArea;
+ this.minYear = Math.min(...years);
+ this.maxYear = Math.max(...years);
- this.minLot = Math.min(...lots) || 0;
- this.maxLot = Math.max(...lots) || defaultLot;
+ this.minArea = Math.min(...areas);
+ this.maxArea = Math.max(...areas);
- // Ensure min doesn't exceed max
- this.minPrice = Math.min(this.minPrice, this.maxPrice);
- this.minYear = Math.min(this.minYear, this.maxYear);
- this.minArea = Math.min(this.minArea, this.maxArea);
- this.minLot = Math.min(this.minLot, this.maxLot);
+ this.minLot = Math.min(...lots);
+ this.maxLot = Math.max(...lots);
}
}