mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
working on integrating new EPC api into address2UPRN
This commit is contained in:
parent
077f14764b
commit
0955862973
8 changed files with 34 additions and 19 deletions
5
.github/workflows/deploy_fastapi_backend.yml
vendored
5
.github/workflows/deploy_fastapi_backend.yml
vendored
|
|
@ -51,6 +51,10 @@ jobs:
|
|||
id: set_auth_token
|
||||
run: echo "::set-output name=auth_token::${{ secrets[format('{0}_EPC_AUTH_TOKEN', github.ref_name)] }}"
|
||||
|
||||
- name: Set Open EPC API token
|
||||
id: set_open_epc_token
|
||||
run: echo "::set-output name=open_epc_token::${{ secrets[format('{0}_OPEN_EPC_API_TOKEN', github.ref_name)] }}"
|
||||
|
||||
# Store port, name and host in github secrets
|
||||
- name: Set DB credentials
|
||||
id: set_db_credentials
|
||||
|
|
@ -127,6 +131,7 @@ jobs:
|
|||
GOOGLE_SOLAR_API_KEY: ${{ steps.set_api_secrets.outputs.google_solar_api_key }}
|
||||
DOMAIN_NAME: ${{ steps.set_domain.outputs.domain }}
|
||||
EPC_AUTH_TOKEN: ${{ steps.set_auth_token.outputs.auth_token }}
|
||||
OPEN_EPC_API_TOKEN: ${{ steps.set_open_epc_token.outputs.open_epc_token }}
|
||||
DB_HOST: ${{ steps.set_db_credentials.outputs.db_host }}
|
||||
DB_PORT: ${{ steps.set_db_credentials.outputs.db_port }}
|
||||
DB_NAME: ${{ steps.set_db_credentials.outputs.db_name }}
|
||||
|
|
|
|||
1
.github/workflows/unit_tests.yml
vendored
1
.github/workflows/unit_tests.yml
vendored
|
|
@ -49,6 +49,7 @@ jobs:
|
|||
docker run --rm \
|
||||
--network host \
|
||||
-e EPC_AUTH_TOKEN=${{ secrets.DEV_EPC_AUTH_TOKEN }} \
|
||||
-e OPEN_EPC_API_TOKEN=${{ secrets.DEV_OPEN_EPC_API_TOKEN }} \
|
||||
-e HUBSPOT_API_KEY=${{ secrets.HUBSPOT_API_KEY }} \
|
||||
-e DB_HOST=localhost \
|
||||
-e DB_NAME=test \
|
||||
|
|
|
|||
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -292,3 +292,6 @@ pyrightconfig.json
|
|||
# playwright output
|
||||
*/pashub_fetcher/videos/*
|
||||
backlog/*
|
||||
|
||||
# Local Claude config files
|
||||
.claude/*
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
API_KEY = example-api-key
|
||||
ENVIRONMENT = local
|
||||
SECRET_KEY = YOUR_SECRET_KEY
|
||||
ALGORITHM = HS256
|
||||
ALGORITHM = HS256
|
||||
OPEN_EPC_API_TOKEN = your_token_here
|
||||
|
|
@ -14,27 +14,30 @@ from utils.s3 import (
|
|||
)
|
||||
from datetime import datetime
|
||||
|
||||
from backend.utils.addressMatch import AddressMatch, get_uprn_candidates, df_has_single_uprn, score_addresses
|
||||
from backend.utils.addressMatch import (
|
||||
AddressMatch,
|
||||
get_uprn_candidates,
|
||||
df_has_single_uprn,
|
||||
score_addresses,
|
||||
)
|
||||
|
||||
logger = setup_logger()
|
||||
|
||||
|
||||
EPC_AUTH_TOKEN = os.getenv(
|
||||
"EPC_AUTH_TOKEN",
|
||||
)
|
||||
OPEN_EPC_API_TOKEN = os.getenv("OPEN_EPC_API_TOKEN")
|
||||
|
||||
if EPC_AUTH_TOKEN is None:
|
||||
raise RuntimeError("EPC_AUTH_TOKEN not defined in env")
|
||||
if OPEN_EPC_API_TOKEN is None:
|
||||
raise RuntimeError("OPEN_EPC_API_TOKEN not defined in env")
|
||||
|
||||
|
||||
def get_epc_data_with_postcode(postcode: str) -> pd.DataFrame:
|
||||
from backend.epc_client.client import EpcClientService
|
||||
service = EpcClientService(auth_token=EPC_AUTH_TOKEN)
|
||||
|
||||
service = EpcClientService(auth_token=OPEN_EPC_API_TOKEN)
|
||||
results = service.search_by_postcode(postcode)
|
||||
return pd.DataFrame([
|
||||
{"address": r.address_line_1, "uprn": r.uprn}
|
||||
for r in results
|
||||
])
|
||||
return pd.DataFrame(
|
||||
[{"address": r.address_line_1, "uprn": r.uprn} for r in results]
|
||||
)
|
||||
|
||||
|
||||
def get_uprn_with_epc_df(
|
||||
|
|
@ -58,8 +61,8 @@ def get_uprn_with_epc_df(
|
|||
best_score = scored_df.iloc[0]["lexiscore"]
|
||||
|
||||
# # Return None if score is below threshold
|
||||
# if best_score < 0.7:
|
||||
# return None
|
||||
if best_score < 0.7:
|
||||
return None
|
||||
|
||||
# All rank-1 rows (possible draw)
|
||||
top_rank_df = scored_df[scored_df["lexirank"] == 1]
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ def test_uprn_resolution_matches_manual(
|
|||
postcode: str,
|
||||
expected_uprn: str,
|
||||
):
|
||||
from utils.logger import setup_logger
|
||||
|
||||
uprn = get_uprn(user_input, postcode)
|
||||
if uprn:
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ class Settings(BaseSettings):
|
|||
|
||||
# Third parties
|
||||
EPC_AUTH_TOKEN: str = "changeme"
|
||||
OPEN_EPC_API_TOKEN: str = "changeme"
|
||||
GOOGLE_SOLAR_API_KEY: str = "changeme"
|
||||
|
||||
# Database settings
|
||||
|
|
|
|||
10
conftest.py
10
conftest.py
|
|
@ -1,11 +1,9 @@
|
|||
import os
|
||||
from pathlib import Path
|
||||
from backend.app.config import get_settings
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
import os
|
||||
|
||||
# Load .env in conftest.py directory for local development
|
||||
load_dotenv()
|
||||
load_dotenv(Path(__file__).resolve().parent / "backend" / ".env")
|
||||
|
||||
DEFAULT_ENV = {
|
||||
"API_KEY": "test",
|
||||
|
|
@ -18,6 +16,10 @@ DEFAULT_ENV = {
|
|||
"EPC_AUTH_TOKEN",
|
||||
"test",
|
||||
), # overridden in GitHub Actions
|
||||
"OPEN_EPC_API_TOKEN": os.getenv(
|
||||
"OPEN_EPC_API_TOKEN",
|
||||
"test",
|
||||
), # overridden in GitHub Actions
|
||||
"GOOGLE_SOLAR_API_KEY": "test",
|
||||
"DB_HOST": "localhost",
|
||||
"DB_USERNAME": "test",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue