Skip to content

Commit

Permalink
Layers in maps - flakey where datasets are complete
Browse files Browse the repository at this point in the history
  • Loading branch information
steps39 committed Nov 19, 2024
1 parent cab27b3 commit df790f3
Show file tree
Hide file tree
Showing 7 changed files with 664 additions and 176 deletions.
13 changes: 12 additions & 1 deletion SedimentDataExplorer.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<body>
<div id="everything" style="display: none;">
<h1>Sediment Data Explorer - v0.20241102</h1>
<h1>Sediment Data Explorer - v0.20241118</h1>
MMO Templates -
<input type="file" id="fileInput" multiple onchange="importData()"> <!-- Allow multiple file selection -->
<input type="text" id="urlInput" placeholder="Enter comma-separated URLs" onchange="importData()">
Expand Down Expand Up @@ -209,6 +209,11 @@ <h2>Select Chemicals</h2>
<input type="radio" name="sorting" id="longitude" value="longitude"> Longitude
<input type="radio" name="sorting" id="latitude" value="latitude"> Latitude
<input type="radio" name="sorting" id="totalarea" value="totalarea"> Total surface area of particles
<input type="radio" name="sorting" id="lmw" value="lmw"> LMW PAHs Gorham-Test sum
<input type="radio" name="sorting" id="hww" value="hmw"> HMW PAHs Gorham-Test sum
<input type="radio" name="sorting" id="totalhc" value="totalhc"> Total hydrocarbon
<input type="radio" name="sorting" id="ices7" value="ices7"> ICES7 PCBs sum
<input type="radio" name="sorting" id="allpcbs" value="allpcbs"> All PCBs sum
<input type="radio" name="sorting" id="silt" value="silt"> Weight fraction silt and clay
<input type="radio" name="sorting" id="siltsand" value="siltsand"> Weight fraction of silt, clay and fine sand
<input type="radio" name="sorting" id="sand" value="sand"> Weight fraction of sand
Expand All @@ -217,6 +222,11 @@ <h2>Select Chemicals</h2>
<input type="radio" name="sorting" id="datalongitude" value="datelongitude"> Date of sampling then longitude
<input type="radio" name="sorting" id="datelatitude" value="datelatitude"> Date of sampling then latitude
<input type="radio" name="sorting" id="datetotalarea" value="datetotalarea"> Date of sampling then total area
<input type="radio" name="sorting" id="datetotalhc" value="datetotalhc"> Date of sampling then total hydrocarbon
<input type="radio" name="sorting" id="datelmw" value="datelmw"> Date of sampling then LMW Gorham-Test sum
<input type="radio" name="sorting" id="datehmw" value="datehmw"> Date of sampling then HMW Gorham-Test sum
<input type="radio" name="sorting" id="dateices7" value="dateices7"> Date of sampling then ICES7 PCBs sum
<input type="radio" name="sorting" id="dateices7" value="dateallpcbs"> Date of sampling then All PCBs sum
</div>

<div>
Expand Down Expand Up @@ -268,6 +278,7 @@ <h2>Select Chemicals</h2>
<!-- Leaflet JavaScript -->
<script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.7.5/proj4.js"></script>
<script src="https://harrywood.co.uk/maps/examples/leaflet/leaflet-plugins/layer/vector/KML.js"></script>
<script src="os-transform.js"></script>
<script src="sdeDataUtilities.js"></script>
<script src="sdeDredgeData.js"></script>
Expand Down
64 changes: 41 additions & 23 deletions SedimentDataExplorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
subName = subChartNames[i];
subsToDisplay[sheetName] = true;
}
sortingOptions = ['normal', 'datelatitude', 'datelongitude', 'datetotalarea', 'latitude', 'longitude', 'totalarea', 'silt', 'siltsand', 'sand', 'gravel'];
sortingOptions = ['normal', 'datelatitude', 'datelongitude', 'datetotalarea', 'latitude', 'longitude', 'totalarea', 'silt', 'siltsand', 'sand', 'gravel',
'totalhc', 'lmw', 'hmw', 'ices7', 'allpcbs', 'datelmw', 'datehmw', 'dateices7', 'dateallpcbs'];
calcSheetNames = ['Physical Stats','PSA Charts','Metals calcs','PAH calcs','PCB calcs','BDE calcs','Organotin calcs','Organochlorine calcs'];
let map; // Declare map as a global variable
let fred;
Expand Down Expand Up @@ -285,7 +286,6 @@ for (i = 1; i < dataSheetNames.length; i++) {
}
}
}

updateChart();
};
reader.readAsText(file);
Expand Down Expand Up @@ -514,10 +514,12 @@ console.log('importChemInfo');
const df = XLSX.utils.sheet_to_json(sheetData, { header: 1 });
for (let r = 1; r < df.length; r++) {
const sample = df[r][0];
namedLocations[sample] = {};
namedLocations[sample].latitude = df[r][1];
namedLocations[sample].longitude = df[r][2];
console.log(sample,namedLocations[sample]);
//console.log('|',sample,'|',sample.trim(),'|');
cleanSample = sample.replace(/\s+/g, '').toLowerCase();
namedLocations[cleanSample] = {};
namedLocations[cleanSample].latitude = df[r][1];
namedLocations[cleanSample].longitude = df[r][2];
//console.log(sample,namedLocations[sample]);
}
console.log('End of processExcelLocations');
}
Expand All @@ -536,7 +538,7 @@ console.log('End of processExcelLocations');
for (let i = 0; i < sels.length; i++) {
console.log(i);
console.log(sels[i]);
const checkbox = document.getElementById(sels[i]);
const checkbox = document.getElementById(sels[i].toLowerCase());
checkbox.checked = true;
}
}
Expand Down Expand Up @@ -956,17 +958,22 @@ function processExcelData(data, url) {
if (!totalSum > 0 && !(sheetName === 'Physical Data')) {
return 'No data for ' + sheetName;
}
//console.log(dateSampled, sheetName, 'meas ', meas);
sampleMeasurements[dateSampled][sheetName] = meas;
const sums = {};
//console.log(meas);
//for (const sheetName in meas) {
if (sheetName === 'PAH data') {
pahPostProcess(meas, dateSampled);
}
if (sheetName === 'PCB data') {
pcbPostProcess(meas, dateSampled);
if (sheetName === 'Physical Data' && Object.keys(meas.samples).length === 0) {
return 'No data for ' + sheetName;
}
//console.log(dateSampled, sheetName, 'meas ', meas);
// if (!(meas.samples === undefined || meas.samples === null)) {
sampleMeasurements[dateSampled][sheetName] = meas;
const sums = {};
//console.log(meas);
//for (const sheetName in meas) {
if (sheetName === 'PAH data') {
pahPostProcess(meas, dateSampled);
}
if (sheetName === 'PCB data') {
pcbPostProcess(meas, dateSampled);
}
// }
//}
return dateAnalysed;
}
Expand Down Expand Up @@ -1086,11 +1093,16 @@ function processExcelData(data, url) {
//console.log(point);
if (point === null || point === undefined) {
// latitude and longitude aren't specified so try to retrieve latlon from previously entered locations
if (namedLocations[sample] !== null && namedLocations[sample] !== undefined) {
cleanSample = sample.replace(/\s+/g, '').toLowerCase();
console.log(sample,cleanSample);
if (cleanSample in namedLocations) {
// if (namedLocations[cleanSample] !== null && namedLocations[cleanSample] !== undefined) {
console.log('found');
point = {};
point['latitude'] = namedLocations[sample].latitude;
point['longitude'] = namedLocations[sample].longitude;
point['latitude'] = namedLocations[cleanSample].latitude;
point['longitude'] = namedLocations[cleanSample].longitude;
} else {
console.log('not found');
//console.log('lat and long undefined does not match', sample);
point = {};
point['latitude'] = undefined;
Expand Down Expand Up @@ -1136,9 +1148,11 @@ function processExcelData(data, url) {
newDateSampled = dateSampled;
//console.log(dateSampled,dateAnalysed);
if (dateSampled.includes('Missing')) {
newDateSampled = dateAnalysed + 'ADMSD';
// Date sampled is missing so include an M for missing and the analysis date
newDateSampled = dateAnalysed + 'M';
} else if (dateSampled > dateAnalysed) {
newDateSampled = dateAnalysed + 'ADBSD';
// Date sampled is later than date analysed so include an L for late and the analysis date
newDateSampled = dateAnalysed + 'L';
}
//Add in application number
//console.log(dateSampled,sampleInfo[dateSampled]);
Expand All @@ -1160,6 +1174,8 @@ function processExcelData(data, url) {
}
newDateSampled = newDateSampled + ' f ' + sampleInfo[dateSampled]['Application number'];
sampleInfo[newDateSampled] = sampleInfo[dateSampled];
sampleInfo[newDateSampled]['Date Sampled'] = newDateSampled;
sampleInfo[newDateSampled].label = newDateSampled;
delete sampleInfo[dateSampled];
sampleMeasurements[newDateSampled] = sampleMeasurements[dateSampled];
delete sampleMeasurements[dateSampled];
Expand Down Expand Up @@ -1442,8 +1458,10 @@ function removeButton(chartInstanceNo, buttonType) {
function chemicalTypeHasData(sheetName) {
chemicalTypeData = false;
for (const ds in selectedSampleMeasurements) {
console.log(ds);
console.log(ds, sheetName);
const chemicalTypes = Object.keys(selectedSampleMeasurements[ds]);
//console.log(ds, sheetName, chemicalTypes);
console.log(ds, sheetName, chemicalTypes);
if (chemicalTypes.includes(sheetName)) {
chemicalTypeData = true;
return chemicalTypeData;
Expand Down
Loading

0 comments on commit df790f3

Please sign in to comment.