@@ -34,7 +34,7 @@ def get_update_type(self) -> UpdateType:
3434 return UpdateType .CCS_PUBLISHED
3535
3636 def get_update_url (self , last_update_dt ) -> str :
37- return f"https://data.seattle.gov/api/id/m33m-84uk.json?$query=select * where (`posted_date` > '{ last_update_dt .isoformat ()} ') order by `posted_date` desc"
37+ return f"https://data.seattle.gov/api/id/m33m-84uk.json?$query=select * where (`posted_date` > '{ last_update_dt .date (). isoformat ()} ') order by `posted_date` desc"
3838
3939 def process_case (self , case , update_dt ) -> Update :
4040 # Response:
@@ -66,12 +66,12 @@ def process_case(self, case, update_dt) -> Update:
6666
6767 result = find_case (update .case_num )
6868 if result :
69- update .officers = result .officers
7069 update .allegations = result .allegations
7170 else :
72- update .officers = []
7371 update .allegations = []
7472
73+ update .officers = []
74+
7575 return update
7676
7777 def process (self , data , update_dt ) -> List [Update ]:
@@ -83,60 +83,85 @@ def get_update_type(self) -> UpdateType:
8383 return UpdateType .COMPLAINT_FILED
8484
8585 def get_update_url (self , last_update_dt ) -> str :
86- return f"https://data.seattle.gov/api/id/pafy-bfmu .json?$query=select * where ((`task_creation_date ` > '{ last_update_dt .isoformat ()} ') and (upper(`status_description`) = upper('OPA Intake'))) order by `task_creation_date ` desc"
86+ return f"https://data.seattle.gov/api/id/hyay-5x7b .json?$query=select * where (`received_date ` > '{ last_update_dt .date (). isoformat ()} ') order by `received_date ` desc"
8787
88- def process_complaint (self , complaint , update_dt ) -> Update :
88+ def process_complaint (self , case_num , rows , update_dt ) -> Update :
8989 # Response:
9090 # [
9191 # {
92- # "opa_case_number":"2022OPA-0134",
93- # "status":"Done",
94- # "status_description":"OPA Intake",
95- # "due_date":"2022-05-20T00:00:00.000",
96- # "completed_date":"2022-05-04T00:00:00.000",
97- # "task_creation_date":"2022-05-03T00:00:00.000",
98- # "due_date_2":"2022-05-20T00:00:00.000",
99- # "completed_date_2":"2022-05-04T00:00:00.000",
100- # "task_creation_date_2":"2022-05-03T00:00:00.000",
101- # "currentstatus":"Done"
92+ # "unique_id":"65217-98589-69722-1595-26426",
93+ # "file_number":"2021OPA-0452",
94+ # "incident_number":"65217",
95+ # "occurred_date":"2021-10-03T00:00:00.000",
96+ # "received_date":"2021-10-04T00:00:00.000",
97+ # "incident_precinct":"-",
98+ # "incident_beat":"-",
99+ # "source":"SPD - Forwarded",
100+ # "incident_type":"OPA Investigation",
101+ # "allegation":"Professionalism",
102+ # "disposition":"-",
103+ # "discipline":"-",
104+ # "named_employee_id":"1595",
105+ # "named_employee_race":"Asian",
106+ # "named_employee_gender":"M",
107+ # "named_employee_age_at":"38",
108+ # "named_employee_title_at":"ACTING POLICE SERGEANT",
109+ # "named_employee_squad_at":"SOUTH PCT 3RD W - R/S RELIEF",
110+ # "complainant_number":"26426",
111+ # "complainant_gender":"Male",
112+ # "complainant_race":"White",
113+ # "complainant_age_complaint":"34",
114+ # "case_status":"Active",
115+ # "finding":"-",
116+ # "investigation_begin_date":"2021-10-03T00:00:00.000",
117+ # "investigation_end_date":"2022-05-01T00:00:00.000"
102118 # },
103119 # ...
120+ # ]
121+ officers = set ()
122+ allegations = set ()
123+ disposition = set ()
124+
125+ for row in rows :
126+ allegations .add (validate (row ["allegation" ], Regexps .STRING , "Unknown" ))
127+ disposition .add (validate (row ["disposition" ], Regexps .STRING , "Unknown" ))
128+
104129 update = Update ()
105- update .case_num = validate (
106- complaint ["opa_case_number" ], Regexps .CASE_NUM , "Invalid case number"
107- )
130+ update .allegations = list (allegations )
131+ update .case_num = validate (case_num , Regexps .CASE_NUM , "Invalid case number" )
108132 update .create_date = update_dt
109133 update .event_date = parser .parse (
110- validate (
111- complaint ["task_creation_date" ],
112- Regexps .TIMESTAMP ,
113- "1970-01-01T00:00:00" ,
114- )
134+ validate (rows [0 ]["received_date" ], Regexps .TIMESTAMP , None )
115135 )
136+ update .officers = list (officers )
116137 update .type = self .get_update_type ()
117138
118- result = find_case (update .case_num )
119- if result :
120- update .allegations = result .allegations
121- update .disposition = result .disposition
122- update .officers = result .officers
139+ if len (disposition ) == 1 :
140+ update .disposition = "" .join (disposition )
123141 else :
124- update .allegations = []
125- update .disposition = ""
126- update .officers = []
142+ update .disposition = "Partially Sustained"
127143
128144 return update
129145
130146 def process (self , data , update_dt ) -> List [Update ]:
131- return [self .process_complaint (complaint , update_dt ) for complaint in data ]
147+ # Since this dataset lists one allegation per row, we need to aggregate by case number
148+ def key_by_case (d ):
149+ return d ["file_number" ]
150+
151+ data = sorted (data , key = key_by_case )
152+ cases = {k : list (v ) for k , v in itertools .groupby (data , key = key_by_case )}
153+ return [
154+ self .process_complaint (case_num , rows , update_dt )
155+ for case_num , rows in cases .items ()
156+ ]
132157
133158
134159class ClosedInvestigationUpdater (Updater ):
135160 def get_update_type (self ) -> UpdateType :
136161 return UpdateType .INVESTIGATION_CLOSED
137162
138163 def get_update_url (self , last_update_dt ) -> str :
139- return f"https://data.seattle.gov/api/id/99yi-dthu .json?$query=select * where (`investigation_end_date` > '{ last_update_dt .isoformat ()} ') order by `investigation_end_date` desc"
164+ return f"https://data.seattle.gov/api/id/hyay-5x7b .json?$query=select * where (`investigation_end_date` > '{ last_update_dt . date () .isoformat ()} ') order by `investigation_end_date` desc"
140165
141166 def process_case (self , case_num , rows , update_dt ) -> Update :
142167 # Response:
@@ -176,7 +201,6 @@ def process_case(self, case_num, rows, update_dt) -> Update:
176201 disposition = set ()
177202
178203 for row in rows :
179- officers .add (validate (row ["named_employee_id" ], Regexps .SERIAL , "Unknown" ))
180204 allegations .add (validate (row ["allegation" ], Regexps .STRING , "Unknown" ))
181205 disposition .add (validate (row ["disposition" ], Regexps .STRING , "Unknown" ))
182206
0 commit comments