Skip to content

Commit

Permalink
Data wrangle remove incomplete samples
Browse files Browse the repository at this point in the history
  • Loading branch information
steps39 committed Dec 16, 2024
1 parent 8de0ad7 commit e145f73
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 37 deletions.
2 changes: 1 addition & 1 deletion SedimentDataExplorer.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

<body>
<div id="everything" style="display: none;">
<h1>Sediment Data Explorer - v0.20241118</h1>
<h1>Sediment Data Explorer - v0.20241216</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
50 changes: 49 additions & 1 deletion sdeCalcs4Charts.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,50 @@
completeSample = {};
function wrangleData(){
completeSample = {};
for (ds in selectedSampleInfo) {
completeSample[ds] = {};
for (sample in selectedSampleInfo[ds].position){
completeSample[ds][sample] = true;
}
}
for (ds in selectedSampleInfo) {
for (ct in selectedSampleMeasurements[ds]) {
if (ct === 'Physical Data') {
for (sample in selectedSampleInfo[ds].position) {
if (selectedSampleMeasurements[ds][ct].samples[sample] === undefined) {
completeSample[ds][sample] = false;
}
}
} else {
for (sample in selectedSampleInfo[ds].position) {
for (chemical in selectedSampleInfo[ds].chemicals){
for (sample in selectedSampleInfo[ds].chemicals[chemical]) {
if (selectedSampleMeasurements[ds][ct].chemicals[chemical].samples[sample] === undefined) {
completeSample[ds][sample] = false;
}
}
}
}
}
}
}
selectedSamples = [];
for (ds in selectedSampleInfo) {
for (sample in selectedSampleInfo[ds].position){
if (completeSample[ds][sample]) {
selectedSamples.push(ds + ': ' + sample);
}
}
}
//console.log(selectedSamples);
//console.log('old',selectedSampleMeasurements);
selectedSampleMeasurements = getselectedSampleMeasurements(selectedSamples);
//console.log('new',selectedSampleMeasurements);
//console.log('old',selectedSampleInfo);
selectedSampleInfo = getSelectedSamples(selectedSamples);
//console.log('new',selectedSampleInfo);
}

function recalculateConcentration(meas) {
let allSizes = {};
let allChemicals = Object.keys(meas);
Expand Down Expand Up @@ -291,6 +338,7 @@ function dataForTotalScatterCharting(sheetName, chartType) {
//let xValue;
switch (chartType) {
case "totalArea":
//console.log(ds,s);
xValue = sampleMeasurements[ds]['Physical Data'].samples[s].totalArea;
break;

Expand All @@ -311,7 +359,7 @@ function dataForTotalScatterCharting(sheetName, chartType) {
y: currentChemical.samples[s]
};
if (!xValue) {
console.log('Total scatter charting not possible for ', chartType, ' as no data available');
console.log('Total scatter charting not possible for ', chartType, ' as no data available');
unitTitle = 'No data';
return { unitTitle };
}
Expand Down
20 changes: 12 additions & 8 deletions sdeCharts.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ function updateOptions() {

function updateChart(){
updateOptions();
wrangleData();



//console.log('UPDATECHART*******************');
if (lastInstanceNo > 0) {
const canvas = [];
Expand Down Expand Up @@ -276,7 +280,7 @@ fred=selectedMeas;
'chartContainer',
instanceNo
);

// }

if (sheetName == 'PAH data' && Object.keys(chemInfo).length != 0) {
const chemicalNames = Object.keys(chemInfo);
Expand All @@ -303,7 +307,7 @@ fred=selectedMeas;
if (sheetName === 'PAH data' && subsToDisplay['gorhamtest']) {
unitTitle = retData['unitTitle'];
selectedSums = sumsForGorhamCharting();
console.log('sumsForGorhamCharting selectedSums',selectedSums);
//console.log('sumsForGorhamCharting selectedSums',selectedSums);
//console.log(selectedSums);
instanceNo += 1;
displayGorhamTest(selectedSums, sheetName, instanceNo, unitTitle);
Expand Down Expand Up @@ -377,7 +381,7 @@ function displayScatterCharts(sheetName, chartType, subsKey, xAxisLabel, yAxisLa
// Fetch chart data
const retData = dataForTotalScatterCharting(sheetName, chartType.key);
const { unitTitle, scatterData, chemicalData, fitConcentration, fitPredictors } = retData;
console.log('dataForTotalScatterCharting scatterData, chemicalData ',scatterData, chemicalData);
//console.log('dataForTotalScatterCharting scatterData, chemicalData ',scatterData, chemicalData);
if (unitTitle === 'No data') {
return instanceNo
}
Expand Down Expand Up @@ -1272,13 +1276,13 @@ function displayGorhamTest(sums, sheetName, instanceNo, unitTitle) {

// const samples = Object.keys(cumWeights);
const samples = Object.keys(sums);
console.log(samples);
console.log(sums);
samples.forEach(sample => console.log(sample));
//console.log(samples);
//console.log(sums);
//samples.forEach(sample => console.log(sample));
const lmwSumData = samples.map(sample => sums[sample].lmwSum);
console.log(lmwSumData);
//console.log(lmwSumData);
const hmwSumData = samples.map(sample => sums[sample].hmwSum);
console.log(hmwSumData);
//console.log(hmwSumData);
datasets = [
{
label: 'LMW Sums',
Expand Down
12 changes: 8 additions & 4 deletions sdeMaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,12 +375,16 @@ fred = kmlLayer;
//console.log('lat,lon ',minLat,minLon, maxLat,maxLon);
}



var layerControl = L.control.layers(mapLayers, shapeOverlay).addTo(map);
layerControl.on("loaded", function(e) {
var bounds = L.latLngBounds();
/*for (let layerName in shapeOverlay) {
bounds.extend(shapeOverlay[layerName].getLatLng());
}*/
//map.fitBounds(bounds);
//map.fitBounds(shapeOverlay.getBounds());
/*layerControl.on("loaded", function(e) {
map.fitBounds(e.target.getBounds());map.fitBounds(e.target.getBounds());
});
});*/

/* fetch("https://northeastfc.uk/RiverTees/Planning/MLA_2015_00088/MLA_2015_00088-LOCATIONS.kml")
.then(function (response) {
Expand Down
31 changes: 8 additions & 23 deletions sdeSelections.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
/*<div id="datasetLabels" style="display: none;">
<form id="datasetLabels">
</form>
<button onclick="updateDatasetLabels()">Confirm Labels and Close</button>
<button onclick="closeDatasetLabels()">Cancel</button>
</div>
<div id="sampleLabels" style="display: none;">
<form id="sampleLabels">
</form>
<button onclick="updateSampleLabels()">Confirm Labels and Close</button>
<button onclick="closeSampleLabels()">Cancel</button>
</div>*/

function openDatasetLabels() {
const datasetLabels = document.getElementById('datasetLabels');
datasetLabels.style.display = 'block';
Expand Down Expand Up @@ -285,7 +271,6 @@ function openDatasetSelection(selectedSampleMeasurements) {

}


function yourapplyDatasetFilter() {
const sampleModal = document.getElementById('datasetModal');
sampleModal.style.display = 'none';
Expand Down Expand Up @@ -332,11 +317,6 @@ function yourapplyDatasetFilter() {
updateChart();
}






function applyDatasetFilter() {
const sampleModal = document.getElementById('datasetModal');
sampleModal.style.display = 'none';
Expand Down Expand Up @@ -640,7 +620,7 @@ function selectSamples() {

function getselectedSampleMeasurements(selectedSamples) {
selectedMeas = {};
//console.log(selectedSamples);
//console.log(selectedSamples);
for (dateSampled in sampleMeasurements) {
//console.log(dateSampled);
const chemicalTypes = Object.keys(sampleMeasurements[dateSampled]);
Expand All @@ -665,12 +645,17 @@ function getselectedSampleMeasurements(selectedSamples) {
//console.log('2 psd selectedMeas ',dateSampled,chemicalType,selectedMeas);
}
//console.log('3 psd selectedMeas ',dateSampled,chemicalType,sample,selectedMeas);
selectedMeas[dateSampled][chemicalType].samples[sample] = {};
selectedMeas[dateSampled][chemicalType].samples[sample].psd = sampleMeasurements[dateSampled][chemicalType].samples[sample].psd;
// selectedMeas[dateSampled][chemicalType].samples[sample] = {};
selectedMeas[dateSampled][chemicalType].samples[sample] = sampleMeasurements[dateSampled][chemicalType].samples[sample];
/* selectedMeas[dateSampled][chemicalType].samples[sample].psd = sampleMeasurements[dateSampled][chemicalType].samples[sample].psd;
selectedMeas[dateSampled][chemicalType].samples[sample].psdAreas = sampleMeasurements[dateSampled][chemicalType].samples[sample].psdAreas;
selectedMeas[dateSampled][chemicalType].samples[sample].splitAreas = sampleMeasurements[dateSampled][chemicalType].samples[sample].splitAreas;
selectedMeas[dateSampled][chemicalType].samples[sample].splitWeights = sampleMeasurements[dateSampled][chemicalType].samples[sample].splitWeights;
selectedMeas[dateSampled][chemicalType].samples[sample].totalArea = sampleMeasurements[dateSampled][chemicalType].samples[sample].totalArea;
selectedMeas[dateSampled][chemicalType].samples[sample].cumAreas = sampleMeasurements[dateSampled][chemicalType].samples[sample].cumAreas;
selectedMeas[dateSampled][chemicalType].samples[sample].cumWeights = sampleMeasurements[dateSampled][chemicalType].samples[sample].cumWeights;
selectedMeas[dateSampled][chemicalType].samples[sample].psdRelativeAreas = sampleMeasurements[dateSampled][chemicalType].samples[sample].psdRelativeAreas;
selectedMeas[dateSampled][chemicalType].samples[sample].splitRelativeAreas = sampleMeasurements[dateSampled][chemicalType].samples[sample].splitRelativeAreas;*/
}
}
}
Expand Down

0 comments on commit e145f73

Please sign in to comment.