Skip to content

Commit

Permalink
Starting to limit variable scope
Browse files Browse the repository at this point in the history
  • Loading branch information
steps39 committed Sep 27, 2024
1 parent 44fbc07 commit a085884
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 34 deletions.
6 changes: 3 additions & 3 deletions SedimentDataExplorer.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<head>
<meta charset="UTF-8">
<title>Sediment Template Data Explorer</title>
<title>Sediment Data Explorer</title>
<style>
.checkbox-container {
display: inline-block;
Expand All @@ -15,7 +15,7 @@

<body>
<div id="everything" style="display: none;">
<h1>Sediment Template Data Explorer - v0.20240925</h1>
<h1>Sediment Data Explorer - v0.20240926</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 All @@ -36,7 +36,7 @@ <h2>Select Data Sets</h2>
<input type="text" id="urlInputDD" placeholder="URL" onchange="importDredgeData()">
<!-- Would accept comma-separated URLs -->
<br>
<input type="text" id="mlApplications" placeholder="MLA ids comma-separated" onchange="closeCEFASSelection()">
<input type="text" id="mlApplications" placeholder="MLA ids comma-separated">
<button onclick="closeCEFASSelection()">Finish CEFAS Selection</button>
<br>
<label for="centreLatitude">Centre Latitude:</label>
Expand Down
4 changes: 2 additions & 2 deletions SedimentDataExplorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -892,10 +892,10 @@ function importData() {
//console.log(meas);
//for (const sheetName in meas) {
if (sheetName === 'PAH data') {
pahPostProcess(meas);
pahPostProcess(meas,dateSampled);
}
if (sheetName === 'PCB data') {
pcbPostProcess(meas);
pcbPostProcess(meas,dateSampled);
}
//}
return dateAnalysed;
Expand Down
4 changes: 2 additions & 2 deletions sdeDataUtilities.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function pcbPostProcess(newMeas) {
function pcbPostProcess(newMeas,dateSampled) {
sheetName = 'PCB data';
//console.log(newMeas);
mmeas = newMeas;
Expand Down Expand Up @@ -29,7 +29,7 @@ function pcbPostProcess(newMeas) {
sampleMeasurements[dateSampled][sheetName].congenerTest = sums;
}

function pahPostProcess(newMeas) {
function pahPostProcess(newMeas,dateSampled) {
sheetName = 'PAH data';
const chemicals = sampleMeasurements[dateSampled][sheetName].chemicals;
if ('Acenapthene' in chemicals) {
Expand Down
49 changes: 23 additions & 26 deletions sdeDredgeData.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,10 @@ console.log(mlaInput);


function extractDataFromSheet(sheetData, mlApplication) {
df = sheetData;
df = sheetData;
testDD = df.filter(row => row[CEFASmla] && row[CEFASmla].includes(mlApplication));
let uniqueSamples = {};
let uniqueRows = [];

testDD.forEach(row => {
let sampleName = row[CEFASsamplename];
if (sampleName && !uniqueSamples[sampleName]) {
Expand All @@ -236,30 +235,37 @@ df = sheetData;
sampleDate = parseDates(uniqueRows[0][CEFASsampledate]);
applicationNo = uniqueRows[0][CEFASmla];
dateSampled = sampleDate + ' d ' + applicationNo;
//console.log(dateSampled);
//console.log(dateSampled);
sampleInfo[dateSampled] = {};
sampleInfo[dateSampled]['Date Sampled'] = sampleDate;
sampleInfo[dateSampled]['Application number'] = applicationNo;
sampleInfo[dateSampled]['fileURL'] = CEFASfilename;
sampleInfo[dateSampled].position = {};
uniqueRows.forEach(row => {
sampleInfo[dateSampled].position[row[CEFASsamplename]] = { 'Position latitude': row[CEFASlatitude], 'Position longitude': row[CEFASlongitude],
'Sampling depth (m)': row[CEFASdepth] };
sampleInfo[dateSampled].position[row[CEFASsamplename]] = {
'Position latitude': row[CEFASlatitude], 'Position longitude': row[CEFASlongitude],
'Sampling depth (m)': row[CEFASdepth]
};
});
let meas = {};
if (!(dateSampled in sampleMeasurements)) {
meas = {};
} else {
meas = sampleMeasurements[dateSampled];
};
everything = testDD;
//meas = {};
testDD.forEach(row => {
chemicalAbr = row[CEFASchemical].trim();
let chemicalAbr = row[CEFASchemical].trim();
let sheetName = '';
if (chemicalAbr in ddLookup.sheet) {
sheetName = ddLookup.sheet[chemicalAbr];
chemicalName = ddLookup.chemical[chemicalAbr];
sample = row[CEFASsamplename];
concentration = parseFloat(row[CEFASconcentration]) * ddCorrection[sheetName];
let chemicalName = ddLookup.chemical[chemicalAbr];
let sample = row[CEFASsamplename];
if (chemicalName === 'totalHC') {
sheetName = 'PAH data';
} else {
sheetName = ddLookup.sheet[chemicalAbr];
}
let concentration = parseFloat(row[CEFASconcentration]) * ddCorrection[sheetName];
if (concentration === undefined) {
concentration = 0.0;
}
Expand All @@ -268,16 +274,14 @@ df = sheetData;
meas[sheetName].chemicals = {};
meas[sheetName].total = {};
//Populate chemicals as data could be missing some chemicals
// for ddLookup.chemical
// ddLookup.sheetName
expectedChemicals = Object.keys(ddLookup.sheet).filter(key => ddLookup.sheet[key] === sheetName);
for (let i = 0; i < expectedChemicals.length; i++) {
meas[sheetName].chemicals[ddLookup.chemical[expectedChemicals[i]]] = {};
meas[sheetName].chemicals[ddLookup.chemical[expectedChemicals[i]]].samples = {};
}
}
if (chemicalName === 'totalHC') {
if(!('totalHC' in meas[sheetName])) {
if (!('totalHC' in meas[sheetName])) {
meas[sheetName].totalHC = {};
}
meas[sheetName].totalHC[sample] = concentration;
Expand All @@ -294,22 +298,15 @@ df = sheetData;
}
}
});
if (sheetName == 'BDE data') {
console.log(meas);
}
expectedChemicals = Object.keys(ddLookup.sheet).filter(key => ddLookup.sheet[key] === sheetName);
for (let i = 0; i < expectedChemicals.length; i++) {
meas[sheetName].chemicals[ddLookup.chemical[expectedChemicals[i]]] = {};
meas[sheetName].chemicals[ddLookup.chemical[expectedChemicals[i]]].samples = {};
}

sampleMeasurements[dateSampled] = meas;
sampleMeasurements[dateSampled] = meas;
for (const sheetName in meas) {
if (sheetName === 'PAH data') {
pahPostProcess(meas[sheetName]);
//console.log(meas[sheetName]);
pahPostProcess(meas[sheetName], dateSampled);
//console.log(sampleMeasurements[dateSampled][sheetName]);
}
if (sheetName === 'PCB data') {
pcbPostProcess(meas[sheetName]);
pcbPostProcess(meas[sheetName], dateSampled);
}
}
// Read in date of analysis
Expand Down
2 changes: 1 addition & 1 deletion sdeSelections.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ function applySampleFilter() {
} else {
if (!(sheetName === 'Physical Data')) {
for (const sample in sampleInfo[dateSelected].position) {
console.log(dateSelected,'has no',sheetName,'so setting all false');
//console.log(dateSelected,'has no',sheetName,'so setting all false');
samplesToKeep[dateSelected + ': ' + sample] = false;
}
}
Expand Down

0 comments on commit a085884

Please sign in to comment.