diff options
Diffstat (limited to 'app/models.js')
| -rw-r--r-- | app/models.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/app/models.js b/app/models.js index b4584f7..e3f6381 100644 --- a/app/models.js +++ b/app/models.js @@ -712,10 +712,52 @@ export class Filters { 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; /** @type {string[]} */ 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.minArea = Math.min(...areas) || 0; + this.maxArea = Math.max(...areas) || defaultArea; + + this.minLot = Math.min(...lots) || 0; + this.maxLot = Math.max(...lots) || defaultLot; + + // 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); + } } export class Collection { |
