Skip to content

Commit 247d436

Browse files
committed
Added precinct class
1 parent 9abf8c1 commit 247d436

File tree

2 files changed

+33
-14
lines changed

2 files changed

+33
-14
lines changed

backend/database/models/types/location.py renamed to backend/database/models/location.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from neomodel import (
22
StructuredNode,
3+
StructuredRel,
34
StringProperty,
45
UniqueIdProperty,
56
RelationshipTo,
@@ -13,6 +14,8 @@ class Place(StructuredNode):
1314
"""
1415
Base class for all places. Adds the 'Place' label to all subclasses.
1516
"""
17+
# __abstract_node__ = True
18+
1619
uid = UniqueIdProperty()
1720
name = StringProperty(required=True) # Common property for all places
1821
coordinates = PointProperty(crs="wgs-84") # Spatial property for geographic coordinates
@@ -25,28 +28,43 @@ class State(Place):
2528
abbreviation = StringProperty(required=True, unique_index=True) # e.g., "IL"
2629

2730
# Relationships
28-
capital = RelationshipTo("City", "HAS_CAPITAL", cardinality=One) # A state has one capital city
29-
counties = RelationshipTo("County", "HAS_COUNTY") # A state contains multiple counties
31+
cities = RelationshipTo("City", "HAS_CITY")
32+
counties = RelationshipTo("County", "HAS_COUNTY")
3033

3134
def __repr__(self):
3235
return f"<State {self.name}>"
3336

3437

3538
class County(Place):
3639
# Relationships
37-
state = RelationshipFrom("State", "HAS_COUNTY") # A county belongs to a state
38-
cities = RelationshipTo("City", "HAS_CITY") # A county contains multiple cities
40+
state = RelationshipFrom("State", "HAS_COUNTY")
41+
cities = RelationshipTo("City", "HAS_CITY")
3942

4043
def __repr__(self):
4144
return f"<County {self.name}>"
4245

4346

4447
class City(Place):
45-
population = StringProperty() # Optional: population of the city
48+
population = StringProperty()
49+
50+
# Relationships
51+
state = RelationshipFrom("State", "HAS_CITY")
52+
county = RelationshipFrom("County", "HAS_CITY")
53+
54+
def __repr__(self):
55+
return f"<City {self.name}>"
56+
57+
58+
class Precinct(Place):
59+
"""
60+
Represents a precinct, which is a smaller administrative division within a city or county.
61+
"""
4662

4763
# Relationships
48-
state = RelationshipFrom("State", "HAS_CAPITAL") # A city can be the capital of a state
49-
county = RelationshipFrom("County", "HAS_CITY") # A city belongs to a county
64+
city = RelationshipFrom("City", "HAS_PRECINCT")
65+
county = RelationshipFrom("County", "HAS_PRECINCT")
66+
agency = RelationshipTo("Agency", "SERVED_BY") # Connects Precinct to Agency
67+
units = RelationshipTo("Unit", "PATROLLED_BY") # Connects Precinct to Unit
5068

5169
def __repr__(self):
52-
return f"<City {self.name}>"
70+
return f"<Precinct {self.name}>"

backend/tests/test_locations.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
22
from neomodel.contrib.spatial_properties import NeomodelPoint
3-
from backend.database.models.types.location import State, County, City, Place
3+
from backend.database.models.location import State, County, City, Place
4+
45

56
def test_create_state():
67
# Create a State node
@@ -31,12 +32,12 @@ def test_relationships():
3132
# Create relationships
3233
state.counties.connect(county)
3334
county.cities.connect(city)
34-
state.capital.connect(city)
35+
state.cities.connect(city)
3536

3637
# Verify relationships
3738
assert county in state.counties.all()
3839
assert city in county.cities.all()
39-
assert city in state.capital.all()
40+
assert city in state.cities.all()
4041

4142
def test_create_place_with_coordinates():
4243
coordinates = NeomodelPoint(latitude=41.8781, longitude=-87.6298, crs="wgs-84")
@@ -61,16 +62,16 @@ def test_relationships_with_coordinates():
6162
# Create relationships
6263
state.counties.connect(county)
6364
county.cities.connect(city)
64-
state.capital.connect(city)
65+
state.cities.connect(city)
6566

6667
# Verify relationships
6768
assert county in state.counties.all()
6869
assert city in county.cities.all()
69-
assert city in state.capital.all()
70+
assert city in state.cities.all()
7071

7172
# Verify spatial data
7273
assert state.coordinates.latitude == 40.6331
7374
assert state.coordinates.longitude == -89.3985
7475
assert county.coordinates.latitude == 41.7377
7576
assert county.coordinates.longitude == -87.6976
76-
assert city.coordinates.latitude == 41.8781
77+
assert city.coordinates.latitude == 41.8781

0 commit comments

Comments
 (0)