Skip to content

Commit

Permalink
regenerated ui
Browse files Browse the repository at this point in the history
  • Loading branch information
datadavev committed Jun 12, 2024
1 parent 12d854b commit d06caad
Show file tree
Hide file tree
Showing 37 changed files with 1,118 additions and 0 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions isamples_export_client/ui/_file/styles.9124d518.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* A crosshair cursor for leaflet
e.g.: L.DomUtil.addClass(map._container,'crosshair-cursor-enabled');
*/
.leaflet-container.crosshair-cursor-enabled {
cursor:crosshair;
}
66 changes: 66 additions & 0 deletions isamples_export_client/ui/_import/isclib.e38a39a7.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
Implements support for getting content from iSC
*/

import { JSONParser } from "../_npm/@streamparser/[email protected]/_esm.js";


export class iSC {
constructor(options = {}) {
const {
service = "https://central.isample.xyz/isamples_central/",
default_query = "*:*"
} = options;
this.service = new URL(service);
this.default_query = default_query;
}

async countRecords(q) {
const url = new URL("thing/select", this.service);
console.log(`Query string = ${q}`);
url.search = new URLSearchParams({
q: q,
rows:0,
wt:"json"
});
return fetch(url)
.then((response) => response.json())
.then((data) => {
const nrecs = data.response.numFound;
console.log(`n records = ${nrecs}`);
return nrecs;
})
.catch((e) => {
console.log(e);
})
}

async pointStreamGenerator(q, handler){
const url = new URL("thing/stream", this.service);
console.log(`Query string = ${q}`);
url.search = new URLSearchParams({
q: q,
rows:10,
fl:"source,id,x:producedBy_samplingSite_location_longitude,y:producedBy_samplingSite_location_latitude"
});
fetch(url)
.then(async (response) => {
const jsonparser = new JSONParser({
stringBufferSise: undefined,
paths: ['$.result-set.docs.*']
});
jsonparser.onValue = handler;
const reader = response.body.getReader();
while (true) {
const { done, value} = await reader.read();
if (done) {
break;
}
jsonparser.write(value);
}
})
.catch((e) => {
console.log(e);
})
}
}
94 changes: 94 additions & 0 deletions isamples_export_client/ui/_import/sample.da41fe32.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/**
* Implements a module for displaying sample locations on a leaflet map using the GL extension.
*
* The WebGL approach is preferred when a large number of features are to be rendered.
*/

export class Samples {

constructor(db) {
this._db = db;
}

async init(data_source_url){
await this._db.query("DROP TABLE IF EXISTS samples;")
let q = `CREATE TABLE samples AS SELECT * FROM '${data_source_url}'`;
if (data_source_url.endsWith(".jsonl")) {
q = `CREATE TABLE samples AS SELECT * FROM read_json_auto('${data_source_url}', format='newline_delimited')`;
}
if (data_source_url.includes(".parquet")) {
q = `CREATE TABLE samples AS SELECT * FROM read_parquet('${data_source_url}')`;
}
try {
return this._db.query(q);
} catch (e) {
console.log(e);
}
}

get totalRecords() {
const q = 'SELECT COUNT(*) as n FROM samples;';
return this._db.queryRow(q).then((res) => {
return res.n
}).catch((e) => {
console.log(e);
return 0;
});
}

async allRows(){
const q = 'SELECT sample_identifier as pid, label, source_collection FROM samples;';
return this._db.query(q);
}

async vocabularyTermCounts() {
const facet_field = "has_material_category"
const q = `WITH mcrows AS (
SELECT DISTINCT unnest(${facet_field}) AS mc
FROM samples
) SELECT count(*) AS n, source_collection, mcrows.mc
FROM samples
JOIN mcrows ON list_contains(${facet_field}, mcrows.mc)
GROUP BY source_collection, mcrows.mc
ORDER BY mcrows.mc ASC`;
return this._db.query(q);
}

async getRecordsByBB(bb) {
/*
Returns x,y,pid of samples within bounding box of
[min_x, min_y, max_x, max_y]
*/
const q = `select
produced_by.sampling_site.sample_location.longitude as x,
produced_by.sampling_site.sample_location.latitude as y,
source_collection as source,
sample_identifier as pid from samples
where x>=${bb[0]} and x<=${bb[2]} and y>=${bb[1]} and y<=${bb[2]};`;
return this._db.query(q);
}

async getRecord(pid) {
const q = "SELECT * FROM samples WHERE sample_identifier=?";
return this._db.query(q, pid);
}

async getRecordsById(pid) {
/*
Returns records that have the same location as the record with the specified identifier.
*/
// TODO: fuzziness should be a function of zoom level.
const dx = 0.001;
const dy = 0.001;
const q = `select sample_identifier, source_collection, label from samples s
inner join (select produced_by.sampling_site.sample_location.longitude as x,
produced_by.sampling_site.sample_location.latitude as y from samples
where sample_identifier='${pid}') sm
on s.produced_by.sampling_site.sample_location.longitude>=sm.x-${dx}
and s.produced_by.sampling_site.sample_location.longitude<=sm.x+${dx}
and produced_by.sampling_site.sample_location.latitude>=sm.y-${dy}
and produced_by.sampling_site.sample_location.latitude<=sm.y+${dy};`;
return this._db.query(q);
}
}

Large diffs are not rendered by default.

Loading

0 comments on commit d06caad

Please sign in to comment.