Skip to content

Commit f2d0ba4

Browse files
authored
Merge pull request #652 from SlideRuleEarth/carlos-dev
Carlos dev
2 parents b301bbf + 11b9bab commit f2d0ba4

File tree

6 files changed

+96
-35
lines changed

6 files changed

+96
-35
lines changed

web-client/src/db/SlideRuleDb.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ export class SlideRuleDexie extends Dexie {
805805
throw error;
806806
} finally {
807807
const endTime = performance.now(); // End time
808-
console.log(`SlideRuleDb.getFilename |${fn}| for ${reqId} took ${endTime - startTime} milliseconds.`);
808+
//console.log(`SlideRuleDb.getFilename |${fn}| for ${reqId} took ${endTime - startTime} milliseconds.`);
809809
}
810810
return fn;
811811
}

web-client/src/stores/activeTabStore.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { type ElevationDataItem } from '@/utils/SrMapUtils';
21
import { defineStore } from 'pinia';
32
import { ref, computed } from 'vue';
43

web-client/src/stores/atlChartFilterStore.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ export const useAtlChartFilterStore = defineStore('atlChartFilter', {
6969
},
7070
getSelectedOverlayedReqIds() {
7171
const selectedOverlayedReqIds = this.selectedOverlayedReqIds;
72-
console.log('getSelectedOverlayedReqIds:', selectedOverlayedReqIds, 'length:', selectedOverlayedReqIds.length);
72+
//console.log('getSelectedOverlayedReqIds:', selectedOverlayedReqIds, 'length:', selectedOverlayedReqIds.length);
7373
return selectedOverlayedReqIds;
7474
},
7575
setSelectedOverlayedReqIds(selectedOverlayedReqIds: number[]) {
76-
console.log('setSelectedOverlayedReqIds old:',this.selectedOverlayedReqIds,'new:', selectedOverlayedReqIds);
77-
console.log('setSelectedOverlayedReqIds old len:',this.selectedOverlayedReqIds.length,'new len:', selectedOverlayedReqIds.length);
76+
//console.log('setSelectedOverlayedReqIds old:',this.selectedOverlayedReqIds,'new:', selectedOverlayedReqIds);
77+
//console.log('setSelectedOverlayedReqIds old len:',this.selectedOverlayedReqIds.length,'new len:', selectedOverlayedReqIds.length);
7878
this.selectedOverlayedReqIds = selectedOverlayedReqIds;
7979
},
8080
appendToSelectedOverlayedReqIds(reqId: number) {

web-client/src/utils/SrDuckDbUtils.ts

Lines changed: 87 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -320,26 +320,77 @@ export const getColsForRgtYatcFromFile = async (
320320
}
321321
};
322322

323-
export const duckDbReadAndUpdateElevationData = async (req_id: number,layerName:string): Promise<ElevationDataItem | null> => {
323+
export async function getRepresentativeElevationPointForReq(
324+
req_id: number
325+
): Promise<ElevationDataItem | null> {
326+
const start = performance.now();
327+
try {
328+
const fileName = await indexedDb.getFilename(req_id);
329+
const duckDbClient = await createDuckDbClient();
330+
await duckDbClient.insertOpfsParquet(fileName);
331+
332+
const fns = useFieldNameStore();
333+
const rgtCol = fns.getUniqueTrkFieldName(req_id);
334+
const cycleCol = fns.getUniqueOrbitIdFieldName(req_id);
335+
const spotCol = fns.getUniqueSpotIdFieldName(req_id);
336+
337+
const esc = duckDbClient.escape;
338+
339+
const sql = `
340+
WITH top_combo AS (
341+
SELECT ${esc(rgtCol)} AS rgt, ${esc(cycleCol)} AS cycle, ${esc(spotCol)} AS spot
342+
FROM '${fileName}'
343+
GROUP BY ${esc(rgtCol)}, ${esc(cycleCol)}, ${esc(spotCol)}
344+
ORDER BY COUNT(*) DESC
345+
LIMIT 1
346+
)
347+
SELECT t.*
348+
FROM '${fileName}' t
349+
JOIN top_combo tc
350+
ON t.${esc(rgtCol)} = tc.rgt
351+
AND t.${esc(cycleCol)} = tc.cycle
352+
AND t.${esc(spotCol)} = tc.spot
353+
LIMIT 1;
354+
`;
355+
356+
const q = await duckDbClient.query(sql);
357+
for await (const chunk of q.readRows()) {
358+
if (chunk.length > 0) return chunk[0] as ElevationDataItem;
359+
}
360+
return null;
361+
} catch (err) {
362+
console.error("getRepresentativeElevationPointForReq error:", err);
363+
return null;
364+
} finally {
365+
console.log(
366+
"getRepresentativeElevationPointForReq took",
367+
(performance.now() - start).toFixed(1),
368+
"ms"
369+
);
370+
}
371+
}
372+
373+
374+
export const duckDbReadAndUpdateElevationData = async (req_id: number, layerName: string): Promise<ElevationDataItem | null> => {
324375
console.log('duckDbReadAndUpdateElevationData req_id:', req_id);
325-
const startTime = performance.now(); // Start time
376+
const startTime = performance.now();
326377

327378
let firstRec: ElevationDataItem | null = null;
328379
let numRows = 0;
329380
let srViewName = await indexedDb.getSrViewName(req_id);
330-
381+
331382
if (!srViewName || srViewName === '' || srViewName === 'Global') {
332383
srViewName = 'Global Mercator Esri';
333384
console.error(`HACK ALERT!! inserting srViewName:${srViewName} for reqId:${req_id}`);
334385
}
335386

336387
const projName = srViews.value[srViewName].projectionName;
337-
388+
338389
if (!req_id) {
339390
console.error('duckDbReadAndUpdateElevationData Bad req_id:', req_id);
340391
return null;
341392
}
342-
393+
343394
const pntData = useAnalysisMapStore().getPntDataByReqId(req_id.toString());
344395
pntData.isLoading = true;
345396

@@ -348,23 +399,37 @@ export const duckDbReadAndUpdateElevationData = async (req_id: number,layerName:
348399
console.error('duckDbReadAndUpdateElevationData req_id:', req_id, ' status is error SKIPPING!');
349400
return null;
350401
}
351-
const mission = useFieldNameStore().getMissionForReqId(req_id);
352402

353403
const duckDbClient = await createDuckDbClient();
354404
const filename = await indexedDb.getFilename(req_id);
355405
await duckDbClient.insertOpfsParquet(filename);
356406

407+
// ─────────────────────────────────────────────────────────
408+
// NEW: pick representative point from top (rgt,cycle,spot)
409+
// default: median by x-axis (falls back internally)
410+
// alternative: pass "strongest"
411+
// ─────────────────────────────────────────────────────────
412+
try {
413+
const rep = await getRepresentativeElevationPointForReq(req_id);
414+
if (rep) {
415+
firstRec = rep; // <- set early; we still build/render the layer from chunks below
416+
}
417+
} catch (e) {
418+
console.warn('Representative point selection failed; will fall back to first clickable row:', e);
419+
}
420+
357421
let rows: ElevationDataItem[] = [];
358422
let positions: SrPosition[] = []; // Precompute positions
359-
const pntData = useAnalysisMapStore().getPntDataByReqId(req_id.toString());
360-
pntData.totalPnts = 0;
361-
pntData.currentPnts = 0;
423+
const pntDataLocal = useAnalysisMapStore().getPntDataByReqId(req_id.toString());
424+
pntDataLocal.totalPnts = 0;
425+
pntDataLocal.currentPnts = 0;
426+
362427
try {
363428
const sample_fraction = await computeSamplingRate(req_id);
364429
const result = await duckDbClient.queryChunkSampled(`SELECT * FROM read_parquet('${filename}')`, sample_fraction);
365430

366431
if (result.totalRows) {
367-
pntData.totalPnts =result.totalRows;
432+
pntDataLocal.totalPnts = result.totalRows;
368433
} else if (result.schema === undefined) {
369434
console.warn('duckDbReadAndUpdateElevationData totalRows and schema are undefined result:', result);
370435
}
@@ -375,24 +440,23 @@ export const duckDbReadAndUpdateElevationData = async (req_id: number,layerName:
375440
if (!done && value) {
376441
rows = value as ElevationDataItem[];
377442
numRows = rows.length;
378-
pntData.currentPnts = numRows;
379-
//console.log('duckDbReadAndUpdateElevationData rows:', rows);
380-
// **Find the first valid elevation point**
381-
firstRec = rows.find(isClickable) || null;
382-
if(!firstRec){
383-
console.warn('duckDbReadAndUpdateElevationData find(isClickable) firstRec is null');
384-
if(rows.length > 0) {
443+
pntDataLocal.currentPnts = numRows;
444+
445+
// Fallback if representative point was not found
446+
if (!firstRec) {
447+
firstRec = rows.find(isClickable) || null;
448+
if (!firstRec && rows.length > 0) {
385449
firstRec = rows[0];
386450
}
387451
}
452+
388453
if (firstRec) {
389-
// Precompute position data for all rows
390454
const lat_fieldname = useFieldNameStore().getLatFieldName(req_id);
391455
const lon_fieldname = useFieldNameStore().getLonFieldName(req_id);
392456
positions = rows.map(d => [
393457
d[lon_fieldname],
394458
d[lat_fieldname],
395-
0 // always make this 0 so the tracks are flat
459+
0 // keep tracks flat
396460
] as SrPosition);
397461
} else {
398462
console.warn(`No valid elevation points found in ${numRows} rows.`);
@@ -413,14 +477,12 @@ export const duckDbReadAndUpdateElevationData = async (req_id: number,layerName:
413477

414478
if (summary?.extHMean) {
415479
useCurReqSumStore().setSummary({
416-
req_id: req_id,
480+
req_id,
417481
extLatLon: summary.extLatLon,
418482
extHMean: summary.extHMean,
419483
numPoints: summary.numPoints
420484
});
421-
//console.log('duckDbReadAndUpdateElevationData',height_fieldname,'positions:', positions);
422485
updateDeckLayerWithObject(layerName, rows, summary.extHMean, height_fieldname, positions, projName);
423-
424486
} else {
425487
console.error('duckDbReadAndUpdateElevationData summary is undefined');
426488
}
@@ -431,9 +493,9 @@ export const duckDbReadAndUpdateElevationData = async (req_id: number,layerName:
431493
console.error('duckDbReadAndUpdateElevationData error:', error);
432494
throw error;
433495
} finally {
434-
const pntData = useAnalysisMapStore().getPntDataByReqId(req_id.toString());
435-
pntData.isLoading = false;
436-
const endTime = performance.now(); // End time
496+
const pntDataFinal = useAnalysisMapStore().getPntDataByReqId(req_id.toString());
497+
pntDataFinal.isLoading = false;
498+
const endTime = performance.now();
437499
console.log(`duckDbReadAndUpdateElevationData for ${req_id} took ${endTime - startTime} milliseconds.`);
438500
return { firstRec, numRows };
439501
}

web-client/src/utils/SrMapUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ export function createDeckLayer(
776776
};
777777

778778
const layer = new ScatterplotLayer(layerProps as any);
779-
console.log(`createDeckLayer took ${performance.now() - startTime} ms.`);
779+
//console.log(`createDeckLayer took ${performance.now() - startTime} ms.`);
780780
return layer;
781781
}
782782

web-client/src/utils/plotUtils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -594,10 +594,10 @@ async function getSeriesFor(reqIdStr:string,isOverlay=false) : Promise<SrScatter
594594
const existingColumns = await duckDbClient.queryForColNames(fileName);
595595
const all_y = chartStore.getYDataOptions(reqIdStr);
596596
const y = all_y.filter(col => existingColumns.includes(col));
597-
console.log('all_y:', all_y);
598-
console.log('existingColumns:', existingColumns);
599-
console.log('Filtered y:', y);
600-
console.log('getSeriesFor Using y:',y);
597+
// console.log('all_y:', all_y);
598+
// console.log('existingColumns:', existingColumns);
599+
// console.log('Filtered y:', y);
600+
// console.log('getSeriesFor Using y:',y);
601601
if(y.length != all_y.length){
602602
console.warn(`getSeriesFor ${reqIdStr} y length mismatch: all_y.length=${all_y.length}, existingColumns.length=${existingColumns.length}, y.length=${y.length}`);
603603
}

0 commit comments

Comments
 (0)