Skip to content

Commit 1444ea3

Browse files
CopilotAlexLipp
andauthored
chore: remove debug logging and diagnostic endpoint
Agent-Logs-Url: https://github.com/JonnyDawe/UK-Sewage-Map/sessions/ba6f103e-8680-485f-8494-592f592c4ccc Co-authored-by: AlexLipp <10188895+AlexLipp@users.noreply.github.com>
1 parent a633c09 commit 1444ea3

2 files changed

Lines changed: 75 additions & 251 deletions

File tree

api/debug-scottish-water.ts

Lines changed: 0 additions & 132 deletions
This file was deleted.

src/components/Map/commands/AddDischargeSources/AddDischargeSourcesCommand.ts

Lines changed: 75 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -101,129 +101,90 @@ export class AddDischargeSourcesCommand implements MapCommand {
101101

102102
private async createScottishWaterLayer(): Promise<__esri.FeatureLayer | null> {
103103
const scottishWaterConfig = waterCompanyConfig['Scottish Water'];
104-
if (!scottishWaterConfig || scottishWaterConfig.apiType !== 'scottishwater') {
105-
console.warn('[ScottishWater] No config found or apiType is not "scottishwater"');
106-
return null;
107-
}
108-
109-
console.log(`[ScottishWater] Step 1: Fetching data from ${scottishWaterConfig.apiUrl}`);
104+
if (!scottishWaterConfig || scottishWaterConfig.apiType !== 'scottishwater') return null;
110105

111-
let response: Response;
112106
try {
113-
response = await fetch(scottishWaterConfig.apiUrl);
114-
} catch (fetchError) {
115-
console.error(
116-
'[ScottishWater] Step 1 FAILED: fetch() threw an error (likely CORS or network)',
117-
fetchError,
118-
);
119-
return null;
120-
}
121-
122-
console.log(`[ScottishWater] Step 2: HTTP ${response.status} ${response.statusText}`);
123-
if (!response.ok) {
124-
console.error(`[ScottishWater] Step 2 FAILED: non-OK HTTP status ${response.status}`);
125-
return null;
126-
}
107+
const response = await fetch(scottishWaterConfig.apiUrl);
108+
if (!response.ok) {
109+
console.error(`Failed to fetch Scottish Water data: HTTP ${response.status}`);
110+
return null;
111+
}
127112

128-
let data: unknown;
129-
try {
130-
data = await response.json();
131-
} catch (jsonError) {
132-
console.error('[ScottishWater] Step 3 FAILED: could not parse response as JSON', jsonError);
133-
return null;
134-
}
113+
const data: unknown = await response.json();
114+
const validated = validateScottishWaterApiResponse(data);
115+
if (!validated) {
116+
console.error('Scottish Water API response did not match expected schema');
117+
return null;
118+
}
135119

136-
console.log('[ScottishWater] Step 3: JSON parsed successfully; validating schema...');
137-
const validated = validateScottishWaterApiResponse(data);
138-
if (!validated) {
139-
console.error(
140-
'[ScottishWater] Step 3 FAILED: schema validation failed. First 500 chars of raw response:',
141-
JSON.stringify(data).slice(0, 500),
120+
const withCoords = validated.results.filter(
121+
(
122+
item,
123+
): item is typeof item & {
124+
DISCHARGE_OVERFLOW_LOCATION_LATITUDE: number;
125+
DISCHARGE_OVERFLOW_LOCATION_LONGITUDE: number;
126+
} =>
127+
item.DISCHARGE_OVERFLOW_LOCATION_LATITUDE != null &&
128+
item.DISCHARGE_OVERFLOW_LOCATION_LONGITUDE != null,
142129
);
143-
return null;
144-
}
145130

146-
console.log(`[ScottishWater] Step 4: ${validated.results.length} records from API`);
147-
148-
const withCoords = validated.results.filter(
149-
(
150-
item,
151-
): item is typeof item & {
152-
DISCHARGE_OVERFLOW_LOCATION_LATITUDE: number;
153-
DISCHARGE_OVERFLOW_LOCATION_LONGITUDE: number;
154-
} =>
155-
item.DISCHARGE_OVERFLOW_LOCATION_LATITUDE != null &&
156-
item.DISCHARGE_OVERFLOW_LOCATION_LONGITUDE != null,
157-
);
158-
const withoutCoords = validated.results.length - withCoords.length;
159-
console.log(
160-
`[ScottishWater] Step 4: ${withCoords.length} records have coordinates, ${withoutCoords} dropped (null lat/lon)`,
161-
);
162-
163-
if (withCoords.length === 0) {
164-
console.warn(
165-
'[ScottishWater] Step 4 FAILED: no records with valid coordinates — layer will not be added',
131+
if (withCoords.length === 0) return null;
132+
133+
const graphics = withCoords.map(
134+
(item, index) =>
135+
new Graphic({
136+
geometry: new Point({
137+
longitude: item.DISCHARGE_OVERFLOW_LOCATION_LONGITUDE,
138+
latitude: item.DISCHARGE_OVERFLOW_LOCATION_LATITUDE,
139+
spatialReference: { wkid: 4326 },
140+
}),
141+
attributes: {
142+
OBJECTID: index,
143+
ASSET_ID: item.ASSET_ID,
144+
ASSET_NAME: item.ASSET_NAME,
145+
OVERFLOW_STATUS_ID: item.OVERFLOW_STATUS_ID,
146+
RECEIVING_WATER: item.RECEIVING_WATER,
147+
OVERFLOW_START_DATETIME: item.OVERFLOW_START_DATETIME
148+
? new Date(item.OVERFLOW_START_DATETIME).getTime()
149+
: null,
150+
OVERFLOW_END_DATETIME: item.OVERFLOW_END_DATETIME
151+
? new Date(item.OVERFLOW_END_DATETIME).getTime()
152+
: null,
153+
},
154+
}),
166155
);
167-
return null;
168-
}
169156

170-
const graphics = withCoords.map(
171-
(item, index) =>
172-
new Graphic({
173-
geometry: new Point({
174-
longitude: item.DISCHARGE_OVERFLOW_LOCATION_LONGITUDE,
175-
latitude: item.DISCHARGE_OVERFLOW_LOCATION_LATITUDE,
176-
spatialReference: { wkid: 4326 },
177-
}),
178-
attributes: {
179-
OBJECTID: index,
180-
ASSET_ID: item.ASSET_ID,
181-
ASSET_NAME: item.ASSET_NAME,
182-
OVERFLOW_STATUS_ID: item.OVERFLOW_STATUS_ID,
183-
RECEIVING_WATER: item.RECEIVING_WATER,
184-
OVERFLOW_START_DATETIME: item.OVERFLOW_START_DATETIME
185-
? new Date(item.OVERFLOW_START_DATETIME).getTime()
186-
: null,
187-
OVERFLOW_END_DATETIME: item.OVERFLOW_END_DATETIME
188-
? new Date(item.OVERFLOW_END_DATETIME).getTime()
189-
: null,
157+
return new FeatureLayer({
158+
title: 'Scottish Water',
159+
id: this.generateLayerId('Scottish Water'),
160+
source: graphics,
161+
geometryType: 'point',
162+
spatialReference: { wkid: 4326 },
163+
objectIdField: 'OBJECTID',
164+
fields: [
165+
new Field({ name: 'OBJECTID', type: 'oid' }),
166+
new Field({ name: 'ASSET_ID', type: 'string' }),
167+
new Field({ name: 'ASSET_NAME', type: 'string' }),
168+
new Field({ name: 'OVERFLOW_STATUS_ID', type: 'integer' }),
169+
new Field({ name: 'RECEIVING_WATER', type: 'string' }),
170+
new Field({ name: 'OVERFLOW_START_DATETIME', type: 'date' }),
171+
new Field({ name: 'OVERFLOW_END_DATETIME', type: 'date' }),
172+
],
173+
outFields: ['*'],
174+
renderer: scottishWaterAlertStatusRenderer,
175+
popupTemplate: dischargePopupTemplate,
176+
popupEnabled: true,
177+
orderBy: [
178+
{
179+
valueExpression: scottishWaterAlertStatusSymbolArcade,
180+
order: 'descending',
190181
},
191-
}),
192-
);
193-
194-
console.log('[ScottishWater] Step 5: Sample graphic attributes:', graphics[0]?.attributes);
195-
console.log('[ScottishWater] Step 5: Building FeatureLayer with', graphics.length, 'graphics');
196-
197-
const layer = new FeatureLayer({
198-
title: 'Scottish Water',
199-
id: this.generateLayerId('Scottish Water'),
200-
source: graphics,
201-
geometryType: 'point',
202-
spatialReference: { wkid: 4326 },
203-
objectIdField: 'OBJECTID',
204-
fields: [
205-
new Field({ name: 'OBJECTID', type: 'oid' }),
206-
new Field({ name: 'ASSET_ID', type: 'string' }),
207-
new Field({ name: 'ASSET_NAME', type: 'string' }),
208-
new Field({ name: 'OVERFLOW_STATUS_ID', type: 'integer' }),
209-
new Field({ name: 'RECEIVING_WATER', type: 'string' }),
210-
new Field({ name: 'OVERFLOW_START_DATETIME', type: 'date' }),
211-
new Field({ name: 'OVERFLOW_END_DATETIME', type: 'date' }),
212-
],
213-
outFields: ['*'],
214-
renderer: scottishWaterAlertStatusRenderer,
215-
popupTemplate: dischargePopupTemplate,
216-
popupEnabled: true,
217-
orderBy: [
218-
{
219-
valueExpression: scottishWaterAlertStatusSymbolArcade,
220-
order: 'descending',
221-
},
222-
],
223-
});
224-
225-
console.log('[ScottishWater] Step 6: FeatureLayer created — adding to map');
226-
return layer;
182+
],
183+
});
184+
} catch (error) {
185+
console.error('Failed to load Scottish Water data:', error);
186+
return null;
187+
}
227188
}
228189

229190
async executeOnMap(map: EsriMap): Promise<ViewCommand> {
@@ -263,11 +224,6 @@ export class AddDischargeSourcesCommand implements MapCommand {
263224
visible: 'inherit',
264225
},
265226
});
266-
console.log('[ScottishWater] Step 7: Layer added to map and registered with layer manager');
267-
} else {
268-
console.warn(
269-
'[ScottishWater] createScottishWaterLayer() returned null — no Scottish Water layer on map',
270-
);
271227
}
272228

273229
return {

0 commit comments

Comments
 (0)