Skip to content

Commit 6b74380

Browse files
[seed] Fix false lexicon values
1 parent e88f249 commit 6b74380

1 file changed

Lines changed: 36 additions & 23 deletions

File tree

transfers/seed.py

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
# Core models
1515
from db.contact import Contact, ThingContactAssociation
16-
from db.location import Location
16+
from db.location import Location, LocationThingAssociation
1717
from db.thing import Thing
1818
from db.sensor import Sensor
1919
from db.deployment import Deployment
@@ -48,15 +48,16 @@ def seed_all(n=5):
4848
name=fake.name(),
4949
organization=fake.company(),
5050
role=random.choice(["Hydrologist", "Technician", "Geologist"]),
51-
contact_type="Person",
51+
contact_type="Primary",
5252
)
5353
s.add(c)
5454
contacts.append(c)
5555

5656
# 2. Locations
5757
for _ in range(n):
5858
loc = Location(
59-
name=fake.city(),
59+
elevation=round(fake.random_number(digits=3), 2),
60+
county=fake.city(),
6061
latitude=round(fake.latitude(), 6),
6162
longitude=round(fake.longitude(), 6),
6263
release_status="public",
@@ -73,26 +74,23 @@ def seed_all(n=5):
7374
if not parameters:
7475
raise RuntimeError("No parameters found — ensure init_parameter() ran.")
7576

76-
methods = s.scalars(select(AnalysisMethod)).all()
77-
if not methods:
78-
# Fallback — some environments might not have predefined methods
79-
print("⚠️ No analysis methods found, creating placeholder entries.")
80-
for m in ["ASTM-D1293", "EPA-150.1", "SM-4500-O"]:
81-
am = AnalysisMethod(
82-
analysis_method_code=m,
83-
analysis_method_name=f"Method {m}",
84-
analysis_method_type="Lab",
85-
source_organization="NMED",
86-
)
87-
s.add(am)
88-
s.flush()
89-
methods = s.scalars(select(AnalysisMethod)).all()
77+
method_codes = ["ASTM-D1293", "EPA-150.1", "SM-4500-O"]
78+
for m in method_codes:
79+
am = AnalysisMethod(
80+
analysis_method_code=m,
81+
analysis_method_name=f"Method {m}",
82+
analysis_method_type="Lab",
83+
source_organization="NMED",
84+
)
85+
s.add(am)
86+
methods.append(am)
87+
9088
s.flush()
9189

92-
# 4. Things (Water Wells) & ThingContactAssociation
90+
# 4. Things (Water Wells) & ThingContactAssociation & LocationThingAssociation
9391
for i in range(n):
9492
t = Thing(
95-
name=f"WELL-{i+1:04d}",
93+
name=f"WELL-{i + 1:04d}",
9694
thing_type="water well",
9795
first_visit_date=fake.date_between("-2y", "today"),
9896
well_depth=random.uniform(50, 500),
@@ -121,11 +119,24 @@ def seed_all(n=5):
121119
)
122120
s.add(assoc)
123121

122+
for loc in locations:
123+
assigned_things = random.sample(things, k=min(2, len(things)))
124+
for t in assigned_things:
125+
assoc = LocationThingAssociation(
126+
location_id=loc.id,
127+
thing_id=t.id,
128+
effective_start=datetime.utcnow(),
129+
effective_end=None,
130+
)
131+
s.add(assoc)
132+
124133
# 5. Sensors & Deployments
125134
for i in range(n):
126135
sn = Sensor(
127-
name=f"Sensor-{i+1}",
128-
sensor_type=random.choice(["Pressure", "Temperature"]),
136+
name=f"Sensor-{i + 1}",
137+
sensor_type=random.choice(
138+
["Pressure Transducer", "Barometer", "Acoustic Sounder"]
139+
),
129140
serial_no=fake.unique.bothify(text="SN-####"),
130141
)
131142
sensors.append(sn)
@@ -148,9 +159,11 @@ def seed_all(n=5):
148159
# 6. Samples & Observations
149160
for i in range(n):
150161
samp = Sample(
151-
sample_name=f"SMPL-{fake.random_int(1000,9999)}",
162+
sample_name=f"SMPL-{fake.random_int(1000, 9999)}",
152163
sample_matrix="water",
153-
sample_method="Grab",
164+
sample_method=fake.choice(
165+
["Electric tape measurement (E-probe)", "Steel-tape measurement"]
166+
),
154167
sample_date=fake.date_time_this_year(),
155168
)
156169
t = random.choice(things)

0 commit comments

Comments
 (0)