mirror of
https://github.com/fhswf/aki_prj23_transparenzregister.git
synced 2025-06-21 23:43:55 +02:00
Added location to person (#185)
This commit is contained in:
@ -145,12 +145,16 @@ def get_district_court_id(name: str, city: str | None, db: Session) -> int:
|
|||||||
|
|
||||||
@cached(
|
@cached(
|
||||||
cache=LRUCache(maxsize=2000),
|
cache=LRUCache(maxsize=2000),
|
||||||
key=lambda firstname, lastname, date_of_birth, db: hash(
|
key=lambda firstname, lastname, date_of_birth, location, db: hash(
|
||||||
(firstname, lastname, date_of_birth)
|
(firstname, lastname, date_of_birth)
|
||||||
),
|
),
|
||||||
) # type: ignore
|
) # type: ignore
|
||||||
def get_person_id(
|
def get_person_id(
|
||||||
firstname: str, lastname: str, date_of_birth: date | str | None, db: Session
|
firstname: str,
|
||||||
|
lastname: str,
|
||||||
|
date_of_birth: date | str | None,
|
||||||
|
location: dict[str, str],
|
||||||
|
db: Session,
|
||||||
) -> int:
|
) -> int:
|
||||||
"""Identifies the id of and court.
|
"""Identifies the id of and court.
|
||||||
|
|
||||||
@ -161,6 +165,7 @@ def get_person_id(
|
|||||||
firstname: The first name of the person.
|
firstname: The first name of the person.
|
||||||
lastname: The last name of the person.
|
lastname: The last name of the person.
|
||||||
date_of_birth: The date the person was born.
|
date_of_birth: The date the person was born.
|
||||||
|
location: A dict containing street, house_number, zip_code and city of where a person lives if known.
|
||||||
db: A session to connect to an SQL db via SQLAlchemy.
|
db: A session to connect to an SQL db via SQLAlchemy.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
@ -179,7 +184,8 @@ def get_person_id(
|
|||||||
) is not None:
|
) is not None:
|
||||||
return person_id
|
return person_id
|
||||||
person = entities.Person(
|
person = entities.Person(
|
||||||
firstname=firstname, lastname=lastname, date_of_birth=date_of_birth
|
firstname=firstname, lastname=lastname, date_of_birth=date_of_birth,
|
||||||
|
**(location | get_geocodes(location.get("zip_code"))), # type: ignore
|
||||||
)
|
)
|
||||||
db.add(person)
|
db.add(person)
|
||||||
db.commit()
|
db.commit()
|
||||||
@ -392,6 +398,7 @@ def add_person_relation(person: dict[str, Any], company_id: int, db: Session) ->
|
|||||||
person_id = get_person_id(
|
person_id = get_person_id(
|
||||||
**person["name"],
|
**person["name"],
|
||||||
date_of_birth=date_of_brith,
|
date_of_birth=date_of_brith,
|
||||||
|
location=person.get("location", {}),
|
||||||
db=db,
|
db=db,
|
||||||
)
|
)
|
||||||
except DataInvalidError:
|
except DataInvalidError:
|
||||||
|
@ -11,7 +11,7 @@ from loguru import logger
|
|||||||
def configer_logger(
|
def configer_logger(
|
||||||
*,
|
*,
|
||||||
level: Literal["info", "debug", "warning", "error"],
|
level: Literal["info", "debug", "warning", "error"],
|
||||||
path: str | Path,
|
path: str | Path | None,
|
||||||
) -> None:
|
) -> None:
|
||||||
...
|
...
|
||||||
|
|
||||||
|
@ -105,6 +105,14 @@ class Person(Base):
|
|||||||
date_of_birth = sa.Column(sa.Date, nullable=False)
|
date_of_birth = sa.Column(sa.Date, nullable=False)
|
||||||
works_for = sa.Column(sa.String(100), nullable=True)
|
works_for = sa.Column(sa.String(100), nullable=True)
|
||||||
|
|
||||||
|
street = sa.Column(sa.String(100), nullable=True)
|
||||||
|
house_number = sa.Column(sa.String(10), nullable=True)
|
||||||
|
zip_code = sa.Column(sa.String(5), nullable=True)
|
||||||
|
city = sa.Column(sa.String(100), nullable=True)
|
||||||
|
longitude = sa.Column(sa.Float, nullable=True)
|
||||||
|
latitude = sa.Column(sa.Float, nullable=True)
|
||||||
|
pos_accuracy = sa.Column(sa.Float, nullable=True)
|
||||||
|
|
||||||
|
|
||||||
AnnualFinanceStatement = type(
|
AnnualFinanceStatement = type(
|
||||||
"AnnualFinanceStatement",
|
"AnnualFinanceStatement",
|
||||||
|
@ -136,8 +136,8 @@ def full_db(empty_db: Session, finance_statements: list[dict[str, Any]]) -> Sess
|
|||||||
court_id=2,
|
court_id=2,
|
||||||
name="Some Company GmbH",
|
name="Some Company GmbH",
|
||||||
street="Sesamstr.",
|
street="Sesamstr.",
|
||||||
|
house_number="1",
|
||||||
zip_code="58644",
|
zip_code="58644",
|
||||||
house_number="4",
|
|
||||||
city="TV City",
|
city="TV City",
|
||||||
last_update=datetime.date.fromisoformat("2023-01-01"),
|
last_update=datetime.date.fromisoformat("2023-01-01"),
|
||||||
latitude=51.3246,
|
latitude=51.3246,
|
||||||
@ -154,8 +154,8 @@ def full_db(empty_db: Session, finance_statements: list[dict[str, Any]]) -> Sess
|
|||||||
court_id=1,
|
court_id=1,
|
||||||
name="Other Company GmbH",
|
name="Other Company GmbH",
|
||||||
street="Sesamstr.",
|
street="Sesamstr.",
|
||||||
|
house_number="2",
|
||||||
zip_code="58636",
|
zip_code="58636",
|
||||||
house_number="8",
|
|
||||||
city="TV City",
|
city="TV City",
|
||||||
last_update=datetime.date.fromisoformat("2023-01-01"),
|
last_update=datetime.date.fromisoformat("2023-01-01"),
|
||||||
latitude=51.38,
|
latitude=51.38,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
"""Tests for data elements."""
|
"""Tests for ui elements."""
|
||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
@ -31,7 +31,7 @@ def test_get_company_data(full_db: Session) -> None:
|
|||||||
1: "Some purpose",
|
1: "Some purpose",
|
||||||
},
|
},
|
||||||
"company_street": {0: "Sesamstr.", 1: "Sesamstr."},
|
"company_street": {0: "Sesamstr.", 1: "Sesamstr."},
|
||||||
"company_house_number": {0: "4", 1: "8"},
|
"company_house_number": {0: "1", 1: "2"},
|
||||||
"company_zip_code": {0: "58644", 1: "58636"},
|
"company_zip_code": {0: "58644", 1: "58636"},
|
||||||
"company_city": {0: "TV City", 1: "TV City"},
|
"company_city": {0: "TV City", 1: "TV City"},
|
||||||
"company_longitude": {0: 7.6968, 1: 7.7032},
|
"company_longitude": {0: 7.6968, 1: 7.7032},
|
||||||
|
@ -135,25 +135,52 @@ def test_get_district_court_id(name: str, city: str, id: int, full_db: Session)
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
("firstname", "surname", "date_str", "id"),
|
("firstname", "surname", "date_str", "location", "id"),
|
||||||
[
|
[
|
||||||
("Max", "Mustermann", "2023-01-01", 1),
|
("Max", "Mustermann", "2023-01-01", {"zip_code": "58644"}, 1),
|
||||||
("Sabine", "Mustermann", "2023-01-01", 2),
|
("Sabine", "Mustermann", "2023-01-01", {}, 2),
|
||||||
("Some Firstname", "Some Surname", "2023-01-01", 3),
|
("Some Firstname", "Some Surname", "2023-01-01", {}, 3),
|
||||||
("Some Firstname", "Some Surname", "2023-01-02", 4),
|
("Some Firstname", "Some Surname", "2023-01-02", {}, 4),
|
||||||
("Other Firstname", "Other Surname", "2023-01-02", 5),
|
(
|
||||||
("Does not exist", "Other Surname", "2023-01-02", 6),
|
"Other Firstname",
|
||||||
("Other Firstname", "Does not exists", "2023-01-02", 6),
|
"Other Surname",
|
||||||
("Other Firstname", "Other Surname", "1900-01-02", 6),
|
"2023-01-02",
|
||||||
|
{
|
||||||
|
"zip_code": "58636",
|
||||||
|
"city": "Iserlohn",
|
||||||
|
"street": "Sesamstraße",
|
||||||
|
"house_number": "62",
|
||||||
|
},
|
||||||
|
5,
|
||||||
|
),
|
||||||
|
("Does not exist", "Other Surname", "2023-01-02", {}, 6),
|
||||||
|
(
|
||||||
|
"Other Firstname",
|
||||||
|
"Does not exists",
|
||||||
|
"2023-01-02",
|
||||||
|
{
|
||||||
|
"zip_code": "58636",
|
||||||
|
"city": "Iserlohn",
|
||||||
|
"street": "Sesamstraße",
|
||||||
|
"house_number": "62",
|
||||||
|
},
|
||||||
|
6,
|
||||||
|
),
|
||||||
|
("Other Firstname", "Other Surname", "1900-01-02", {"zip_code": "58644"}, 6),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_get_person_id(
|
def test_get_person_id(
|
||||||
firstname: str, surname: str, date_str: str, id: int, full_db: Session
|
firstname: str,
|
||||||
|
surname: str,
|
||||||
|
date_str: str,
|
||||||
|
location: dict,
|
||||||
|
id: int,
|
||||||
|
full_db: Session,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Tests if a person id can be returned and the court automatically be added if not yet part of the db."""
|
"""Tests if a person id can be returned and the court automatically be added if not yet part of the db."""
|
||||||
assert (
|
assert (
|
||||||
data_transfer.get_person_id(
|
data_transfer.get_person_id(
|
||||||
firstname, surname, date.fromisoformat(date_str), full_db
|
firstname, surname, date.fromisoformat(date_str), location, full_db
|
||||||
)
|
)
|
||||||
== id
|
== id
|
||||||
)
|
)
|
||||||
@ -178,6 +205,7 @@ def test_get_person_id_value_check(
|
|||||||
firstname,
|
firstname,
|
||||||
surname,
|
surname,
|
||||||
date.fromisoformat(date_str) if date_str else None,
|
date.fromisoformat(date_str) if date_str else None,
|
||||||
|
{},
|
||||||
full_db,
|
full_db,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -640,33 +668,39 @@ def test_add_relationships_none(empty_relations: list, full_db: Session) -> None
|
|||||||
{
|
{
|
||||||
"name": {"firstname": "Second person", "lastname": "Köstser"},
|
"name": {"firstname": "Second person", "lastname": "Köstser"},
|
||||||
"date_of_birth": "1961-02-09",
|
"date_of_birth": "1961-02-09",
|
||||||
"location": {"city": "Stuttgart"},
|
"location": {"city": "Stuttgart", "house_number": "4"},
|
||||||
"role": "Geschäftsführer",
|
"role": "Geschäftsführer",
|
||||||
"type": CompanyRelationshipEnum.PERSON.value,
|
"type": CompanyRelationshipEnum.PERSON.value,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": {"firstname": "First Person", "lastname": "Jifpa"},
|
"name": {"firstname": "First Person", "lastname": "Jifpa"},
|
||||||
"date_of_birth": "1976-04-20",
|
"date_of_birth": "1976-04-20",
|
||||||
"location": {"city": "Stuttgart"},
|
"location": {
|
||||||
|
"city": "Stuttgart",
|
||||||
|
"street": "Sesamstraße",
|
||||||
|
"zip_code": "64287",
|
||||||
|
"house_number": "4",
|
||||||
|
},
|
||||||
"role": "Geschäftsführer",
|
"role": "Geschäftsführer",
|
||||||
"type": CompanyRelationshipEnum.PERSON.value,
|
"type": CompanyRelationshipEnum.PERSON.value,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": {"firstname": "", "lastname": "Jiapa"},
|
"name": {"firstname": "", "lastname": "Jiapa"},
|
||||||
"date_of_birth": "1976-04-20",
|
"date_of_birth": "1976-04-20",
|
||||||
"location": {"city": "Stuttgart"},
|
"location": {"city": "Stuttgart", "house_number": "5"},
|
||||||
"role": "Geschäftsführer",
|
"role": "Geschäftsführer",
|
||||||
"type": CompanyRelationshipEnum.PERSON.value,
|
"type": CompanyRelationshipEnum.PERSON.value,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": {"firstname": "Something", "lastname": ""},
|
"name": {"firstname": "Something", "lastname": ""},
|
||||||
"date_of_birth": "12i3u",
|
"date_of_birth": "12i3u",
|
||||||
"location": {"city": "Stuttgart"},
|
"location": {"city": "Stuttgart", "house_number": "4"},
|
||||||
"role": "Geschäftsführer",
|
"role": "Geschäftsführer",
|
||||||
"type": CompanyRelationshipEnum.PERSON.value,
|
"type": CompanyRelationshipEnum.PERSON.value,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": {"lastname": "Jipha"},
|
"name": {"lastname": "Jipha"},
|
||||||
|
"location": {"city": "Stuttgart"},
|
||||||
"date_of_birth": "1976-04-20",
|
"date_of_birth": "1976-04-20",
|
||||||
"type": CompanyRelationshipEnum.PERSON.value,
|
"type": CompanyRelationshipEnum.PERSON.value,
|
||||||
},
|
},
|
||||||
@ -697,7 +731,7 @@ def test_relationships(documents: list[dict[str, Any]], full_db: Session) -> Non
|
|||||||
"founding_date": {0: pd.Timestamp(date.fromisoformat("2010-08-07"))},
|
"founding_date": {0: pd.Timestamp(date.fromisoformat("2010-08-07"))},
|
||||||
"business_purpose": {0: 'Say "Hello World"', 1: "Some purpose"},
|
"business_purpose": {0: 'Say "Hello World"', 1: "Some purpose"},
|
||||||
"street": {0: "Sesamstr.", 1: "Sesamstr.", 2: None},
|
"street": {0: "Sesamstr.", 1: "Sesamstr.", 2: None},
|
||||||
"house_number": {0: "4", 1: "8"},
|
"house_number": {0: "1", 1: "2"},
|
||||||
"zip_code": {0: "58644", 1: "58636"},
|
"zip_code": {0: "58644", 1: "58636"},
|
||||||
"city": {0: "TV City", 1: "TV City"},
|
"city": {0: "TV City", 1: "TV City"},
|
||||||
"longitude": {0: 7.6968, 1: 7.7032},
|
"longitude": {0: 7.6968, 1: 7.7032},
|
||||||
@ -765,6 +799,13 @@ def test_relationships(documents: list[dict[str, Any]], full_db: Session) -> Non
|
|||||||
6: pd.Timestamp("1976-04-20 00:00:00"),
|
6: pd.Timestamp("1976-04-20 00:00:00"),
|
||||||
},
|
},
|
||||||
"works_for": {_: None for _ in range(7)},
|
"works_for": {_: None for _ in range(7)},
|
||||||
|
"street": {6: "Sesamstraße"},
|
||||||
|
"house_number": {5: "4", 6: "4"},
|
||||||
|
"zip_code": {6: "64287"},
|
||||||
|
"city": {5: "Stuttgart", 6: "Stuttgart"},
|
||||||
|
"longitude": {6: 8.6644},
|
||||||
|
"latitude": {6: 49.8676},
|
||||||
|
"pos_accuracy": {6: 4.0},
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user