Compare commits

..

No commits in common. "50435529a2b87756f21ba44d4d234cb7464ae44a" and "ee17ec7a55b9ac62a6070ae979c55fea9debe05e" have entirely different histories.

69
scl.py
View file

@ -260,7 +260,7 @@ def do_initial_post(
start_time: datetime, start_time: datetime,
estimated_restoration_time: datetime, estimated_restoration_time: datetime,
outage_geometries: shapely.MultiPolygon, outage_geometries: shapely.MultiPolygon,
) -> str: ) -> dict[str, str | None]:
post_id = None post_id = None
map_media_post = None map_media_post = None
area_text = str() area_text = str()
@ -311,7 +311,7 @@ Cause: {}
) )
post_id = post_result["id"] post_id = post_result["id"]
return post_id return {"post_id": post_id, "map_media_post_id": None}
class Base(DeclarativeBase): class Base(DeclarativeBase):
@ -326,6 +326,7 @@ class SclOutage(Base):
outage_user_id: Mapped[str] = mapped_column() outage_user_id: Mapped[str] = mapped_column()
most_recent_post_id: Mapped[Optional[str]] = mapped_column() most_recent_post_id: Mapped[Optional[str]] = mapped_column()
initial_post_id: Mapped[Optional[str]] = mapped_column() initial_post_id: Mapped[Optional[str]] = mapped_column()
map_media_post_id: Mapped[Optional[str]] = mapped_column()
last_updated_time: Mapped[datetime] = mapped_column() last_updated_time: Mapped[datetime] = mapped_column()
estimated_restoration_time: Mapped[datetime] = mapped_column() estimated_restoration_time: Mapped[datetime] = mapped_column()
cause: Mapped[str] = mapped_column() cause: Mapped[str] = mapped_column()
@ -340,7 +341,7 @@ class SclOutage(Base):
geometries_modified: Mapped[Optional[bool]] = mapped_column() geometries_modified: Mapped[Optional[bool]] = mapped_column()
def __repr__(self) -> str: def __repr__(self) -> str:
return f"SclOutage(scl_outage_id={self.scl_outage_id!r}, most_recent_post_id={self.most_recent_post_id!r}, initial_post_id={self.initial_post_id!r}, last_updated_time={self.last_updated_time!r}, no_longer_in_response_time={self.no_longer_in_response_time!r}, start_time={self.start_time!r}, num_people={self.num_people!r}, max_num_people={self.max_num_people!r}, neighborhood={self.neighborhood!r}, city={self.city!r}, outage_geometries={self.outage_geometries!r}, geometries_modified={self.geometries_modified!r})" return f"SclOutage(scl_outage_id={self.scl_outage_id!r}, most_recent_post_id={self.most_recent_post_id!r}, initial_post_id={self.initial_post_id!r}, map_media_post_id={self.map_media_post_id!r}, last_updated_time={self.last_updated_time!r}, no_longer_in_response_time={self.no_longer_in_response_time!r}, start_time={self.start_time!r}, num_people={self.num_people!r}, max_num_people={self.max_num_people!r}, neighborhood={self.neighborhood!r}, city={self.city!r}, outage_geometries={self.outage_geometries!r}, geometries_modified={self.geometries_modified!r})"
engine = create_engine("sqlite:///scl.db") engine = create_engine("sqlite:///scl.db")
@ -414,14 +415,7 @@ with Session(engine) as session:
existing_record.max_num_people = event["numPeople"] existing_record.max_num_people = event["numPeople"]
max_event_class = classify_event_size(existing_record.max_num_people) max_event_class = classify_event_size(existing_record.max_num_people)
if existing_record.outage_geometries != outage_geometries: if existing_record.outage_geometries != outage_geometries:
print( print("Geometries modified")
"Geometries modified. Equals: {}, DE-9IM: {}, Within: {}".format(
outage_geometries.equals(existing_record.outage_geometries),
outage_geometries.relate(existing_record.outage_geometries),
outage_geometries.within(existing_record.outage_geometries),
)
)
updated_properties.append("area") updated_properties.append("area")
existing_record.outage_geometries = outage_geometries existing_record.outage_geometries = outage_geometries
existing_record.geometries_modified = True existing_record.geometries_modified = True
@ -464,28 +458,30 @@ with Session(engine) as session:
print( print(
"Posting an event that grew above the threshold required to post" "Posting an event that grew above the threshold required to post"
) )
post_id = do_initial_post( initial_post_result = do_initial_post(
event, event,
event_class, event_class,
start_time, start_time,
estimated_restoration_time, estimated_restoration_time,
outage_geometries, outage_geometries,
) )
# TODO: It doesn't look like these would have been set- where? try:
# try: existing_record.neighborhood = initial_post_result[
# existing_record.neighborhood = initial_post_result[ "neighborhood"
# "neighborhood" ]
# ] except KeyError:
# except KeyError: pass
# pass
# try: try:
# existing_record.city = initial_post_result["city"] existing_record.city = initial_post_result["city"]
# except KeyError: except KeyError:
# pass pass
existing_record.initial_post_id = post_id existing_record.initial_post_id = initial_post_result["post_id"]
existing_record.most_recent_post_id = post_id existing_record.most_recent_post_id = initial_post_result["post_id"]
existing_record.map_media_post_id = initial_post_result[
"map_media_post_id"
]
else: else:
print("Existing record was found, and no properties were updated.") print("Existing record was found, and no properties were updated.")
session.commit() session.commit()
@ -493,6 +489,7 @@ with Session(engine) as session:
except NoResultFound: except NoResultFound:
print("Existing record not found") print("Existing record not found")
post_id = None post_id = None
map_media_post_id = None
neighborhood = None neighborhood = None
city = None city = None
if not event_class["is_postable"]: if not event_class["is_postable"]:
@ -502,30 +499,32 @@ with Session(engine) as session:
) )
) )
else: else:
post_id = do_initial_post( initial_post_result = do_initial_post(
event, event,
event_class, event_class,
start_time, start_time,
estimated_restoration_time, estimated_restoration_time,
outage_geometries, outage_geometries,
) )
post_id = initial_post_result["post_id"]
map_media_post_id = initial_post_result["map_media_post_id"]
# TODO: It doesn't look like these would have been set- where? try:
# try: neighborhood = initial_post_result["neighborhood"]
# neighborhood = initial_post_result["neighborhood"] except KeyError:
# except KeyError: pass
# pass
# try: try:
# city = initial_post_result["city"] city = initial_post_result["city"]
# except KeyError: except KeyError:
# pass pass
new_outage_record = SclOutage( new_outage_record = SclOutage(
scl_outage_id=event["id"], scl_outage_id=event["id"],
outage_user_id=event["identifier"], outage_user_id=event["identifier"],
most_recent_post_id=post_id, most_recent_post_id=post_id,
initial_post_id=post_id, initial_post_id=post_id,
map_media_post_id=map_media_post_id,
last_updated_time=last_updated_time, last_updated_time=last_updated_time,
estimated_restoration_time=estimated_restoration_time, estimated_restoration_time=estimated_restoration_time,
cause=event["cause"], cause=event["cause"],