Enhance Docker and Compose configurations; add health check endpoint and caching improvements

- Updated Dockerfile to include FINN_CACHE_PATH and create data directory.
- Modified docker-compose.prod.yml to expose port 8010 and adjust resource limits.
- Updated docker-compose.yml to include FINN_CACHE_PATH and ensure proper port mapping.
- Added health check endpoint in http_server.py for container orchestration.
- Improved caching logic in analysis.py and service.py for similar units.
- Refined scoring.py with updated scoring model and constants for better accuracy.

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
Ole
2026-05-26 12:10:00 +00:00
parent d3f4bfa838
commit 46fd22c277
7 changed files with 315 additions and 233 deletions
+16 -10
View File
@@ -5,6 +5,7 @@ import logging
from . import ad as ad_module
from . import cache, eiendom_no, scoring, search
from .config import (
EIENDOM_NO_CACHE_TTL_HOURS,
FINN_CACHE_PATH,
FINN_CACHE_TTL_AD_HOURS,
FINN_DETAIL_LIMIT,
@@ -102,16 +103,21 @@ async def analyze_ad(
cache.save_eiendom_unit(conn, enriched)
if enriched:
# EiendomUnit.unit_vector is NOT populated by get_unit / enrich -- the
# field comes back None. Reading enriched.unit_vector directly leaves
# this block dead and similar_units permanently empty. Build the vector
# from the unit fields instead (fall back to the field if a future
# endpoint ever populates it).
vector = enriched.unit_vector or eiendom_no.build_unit_vector(enriched)
if vector:
# No dedicated cache table for similar units (per PRD) -- fetch
# fresh each call, consistent with service.get_or_fetch_similar_units.
similar_units = await eiendom_no.get_similar_units(vector)
# Check cache for similar units first. The cache uses (unit_code,
# listing_status) as the key, so we must look it up by unit_code.
similar_units = cache.get_similar_units(
conn, enriched.unit_code, "RECENTLY_SOLD", ttl_hours=EIENDOM_NO_CACHE_TTL_HOURS
)
if not similar_units:
# Cache miss: build the vector and fetch fresh from Eiendom.no
# (unit_vector field from get_unit is None; build locally)
vector = enriched.unit_vector or eiendom_no.build_unit_vector(enriched)
if vector:
similar_units = await eiendom_no.get_similar_units(vector)
# Save to cache
if similar_units:
cache.save_similar_units(conn, enriched.unit_code, "RECENTLY_SOLD", similar_units)
scores = scoring.score_ad(finn_ad, enriched, similar_units)
categories = scoring.classify_ad(scores)