Skip to content

Commit

Permalink
#1088 explore new rodars data
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielwol committed Oct 28, 2024
1 parent 51be370 commit af506fb
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
27 changes: 27 additions & 0 deletions events/rodars/rodars_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import struct
from io import BytesIO

class Coordinates:
def __init__(self, longitude, latitude):
self.longitude = longitude
self.latitude = latitude

@classmethod
def from_binary(cls, br):
# Read longitude and latitude as doubles (8 bytes each)
longitude, latitude = struct.unpack('dd', br.read(16))
return cls(longitude, latitude)

def geometry_from_bytes(geo_bytes):
# Initialize a stream to read binary data from the byte array
with BytesIO(geo_bytes) as ms:
# Read the first 4 bytes for the integer (len in C#)
len_val = struct.unpack('i', ms.read(4))[0]
coordinates_list = []

# Iterate and unpack each pair of doubles as coordinates
for _ in range(len_val):
coordinates = Coordinates.from_binary(ms)
coordinates_list.append(coordinates)

return coordinates_list
60 changes: 60 additions & 0 deletions events/rodars/rodars_new.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
WITH issues AS (
--select the most recent version of each issue
SELECT DISTINCT ON (divisionid, issueid)
divisionid,
issueid,
timestamputc,
issuetype,
description,
priority,
proposedstarttimestamputc,
proposedendtimestamputc,
earlyendtimestamputc,
status,
timeoption
FROM public.issuedata
WHERE divisionid = 8048 --rodars new
ORDER BY divisionid, issueid, timestamputc DESC
)

SELECT
issues.divisionid,
issues.issueid,
issues.timestamputc,
issues.issuetype,
issues.description,
issues.priority,
issues.proposedstarttimestamputc,
issues.proposedendtimestamputc,
issues.earlyendtimestamputc,
issues.status,
issues.timeoption,
issuelocationnew.locationindex,
issuelocationnew.mainroadname,
issuelocationnew.fromroadname,
issuelocationnew.toroadname,
issuelocationnew.direction,
issuelocationnew.lanesaffected,
issuelocationnew.geometry,
issuelocationnew.streetnumber,
issuelocationnew.locationtype,
issuelocationnew.groupid,
issuelocationnew.groupdescription,
issueconfig.sourceid,
issueconfig.starttimestamputc,
issueconfig.endtimestamputc,
issueconfig.kmpost,
issueconfig.managementurl,
issueconfig.cancellationstatus,
issueconfig.closeissueonplannedendtime,
issueconfig.plannedstartadvancenoticeseconds,
issueconfig.plannedendadvancenoticeseconds,
issueconfig.locationdescriptionoverwrite,
issueconfig.startissueonplannedstarttime,
issueconfig.startstatus,
issueconfig.updateremindernoticeseconds
FROM public.issues
LEFT JOIN public.issuelocationnew USING (divisionid, issueid, timestamputc)
LEFT JOIN public.issueconfig USING (divisionid, issueid)
ORDER BY issueid DESC
LIMIT 1000

0 comments on commit af506fb

Please sign in to comment.