Skip to content

Issue 1217 - CSV Upload Validation Checks#1579

Open
kyle-parker-1500 wants to merge 45 commits into
OpenEnergyDashboard:developmentfrom
OscarAvilSal:final_checks_uploadMeters
Open

Issue 1217 - CSV Upload Validation Checks#1579
kyle-parker-1500 wants to merge 45 commits into
OpenEnergyDashboard:developmentfrom
OscarAvilSal:final_checks_uploadMeters

Conversation

@kyle-parker-1500
Copy link
Copy Markdown

@kyle-parker-1500 kyle-parker-1500 commented Feb 15, 2026

Description

Partly Addresses #1217

Type of change

Added validation checks for the following 6 fields within the uploadMeters.js file according to the note left on PR1403:

  1. Max Error: Max Error must be within the range of 0 to 75.
  2. Area Unit & Value: If area unit is none then area cannot be specified.
  3. Min & Max Dates: The max date cannot be before the min date & validate if they are dates.
  4. Duplicates: Duplicates within the range of 1 to 9.
  5. Reading Gap: Should be greater than or equal to 0.
  6. Reading Variation: Should be greater than or equal to 0.
  • Note merging this changes the database configuration.
  • This change requires a documentation update

Checklist

  • I have followed the OED pull request ideas
  • I have removed text in ( ) from the issue request
  • You acknowledge that every person contributing to this work has signed the OED Contributing License Agreement and each author is listed in the Description section.

Limitations

The branch which these changes were pushed on is around 300 commits behind the development branch. Also not all meters have checks being done on them, only those listed in PR1403 and those listed here. Destiny destinyveloz@msn.com, Oscar oaviles-saldana@csumb.edu, and I kylerparker1500@gmail.com are open to continue working on this issue.

Thank you to @SageMar and @cmatthews444 for writing the previous checks, much of our code was derived from what you wrote.

SageMar and others added 30 commits November 27, 2024 15:51
…ion for checking each value towards the bottom of the uploadMeters.js file as well as calling them when the submission is sent to the server
… made sure the correct data was being sent back to the client side
…csv-validation

Boolean value validations
Merge branch 'Issue1217-csv-validation' of https://github.com/SageMar/OED into Issue1217-csv-validation
…ecked, now it converts strings to ints and functions
…checked for validity before calling it to check min<max
@huss
Copy link
Copy Markdown
Member

huss commented Feb 17, 2026

@kyle-parker-1500 Thank you for this PR. I see the CLA box is checked in the description. Given this, could you help with these:

  • I could not find an entry for you in our CLA records. Could you either do it or let me know if you think our records are wrong.
  • Our CLA records are by GitHub ID. I found @DestinyVeloz & @OscarAvilSal who I think might be the two other people listed. Could you or the other people verify that I have the correct GitHub IDs.

Please let me know if anything is not clear or you have thoughts.

@kyle-parker-1500
Copy link
Copy Markdown
Author

Hi @huss ,
That may have been my fault. I use a very similar username that I may have typed in by accident. I resubmitted the CLA with my current GitHub ID so I'm hoping that works out. The other IDs are correct. Thank you!

@huss
Copy link
Copy Markdown
Member

huss commented Mar 1, 2026

@kyle-parker-1500, @DestinyVeloz & @OscarAvilSal: First I want to apologize for how long my response has taken during an usual time. Second, I have started to review the work but I need more time to do it well. Please let me know if these are an issue.

@kyle-parker-1500
Copy link
Copy Markdown
Author

@huss don't worry about it and take your time with the review! My team and I are ready and able to fix any issues you find.

Copy link
Copy Markdown
Member

@huss huss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks to @kyle-parker-1500, @DestinyVeloz & @OscarAvilSal for this contribution. Again, I'm sorry my comments took so long. I've provided a number of comments to think about. Some are about code from earlier work as I reviewed this PR. Some are more general changes. Given this, if you don't want to address any of those you can leave a comment and OED can decide how to deal with them. Finally, I have yet to do careful testing of uploads (waiting for more finalized code) nor check that every index into the meter array is correct (didn't want you to wait while I do all of those and the method may change so doing that later may be bettert). Please let me know if anything is not clear, you have thoughts or I can help in any way.

const readCsv = require('../pipeline-in-progress/readCsv');
const Unit = require('../../models/Unit');
const { normalizeBoolean } = require('./validateCsvUploadParams');
const { normalizeBoolean, MeterTimeSortTypesJS, MeterTimeSortTypesJS } = require('./validateCsvUploadParams');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is MeterTimeSortTypesJS included twice?

return { maxErrorMsg: msg, value: false };
}
}
return { maxErrorMsg: '', value: true };
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering about returning this as value: true in the case that it is a NaN above. It should be a number so should this case also fail? I think this applies to other new tests.


if (areaUnit && areaUnit.toLowerCase() === 'none') {
if(!isNaN(areaValue) && areaValue !== 0) {
msg = `Invalid area value in row ${rowIndex + 1}: area="${meter[9]}". ` + `Area must be empty when area unit is 'none'.`;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indenting seems off and is using spaces instead of tabs as OED wants.

I looks like the test is for a non-zero area value so I wonder if the msg should say that too.

* @param {express.Response} res
* @param {express.Request} req
* @param {express.Response} res
* @param {express.Request} req
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering about listing req & res twice as params since they are once in the function. I don't think you made this change but is from the original PR. Thoughts?

*/
function isValidTimeSort(timeSortValue) {
const validTimes = Object.values(MeterTimeSortTypesJS);
// must be one of the three values
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(old code) This is not correct as there are currently two values. I would put "must be one of the allowed enum values."

function validateVariation(meter, rowIndex){
const variationValue = Number(meter[15]);
if(!isNaN(variationValue)){
if(variationValue < 0)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please format so { is on same line as if statement.

if(!isNaN(variationValue)){
if(variationValue < 0)
{
throw new CSVPipelineError(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to other comment, this throws error inside check.

{
throw new CSVPipelineError(
`Invalid variation value in row ${rowIndex + 1}: VariationValue="${meter[15]}". ` +
`Variation Value must be a number larger than 0.`,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formally reading variation so should say that.

const variationInput = meter[15];
if (variationInput) {
if (!validateVariation(variationInput)) {
let msg = `For meter ${meter[0]} the Gap entry of ${variationInput} is invalid. Gap must be a number greater than 0.`;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See other function about not returning value. Also, the msg should not be referring to gap.

*/
function validateBooleanFields(meter, rowIndex) {
// all inputs that involve a true or false all being validated together.
const booleanFields = {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like defining the index via a key. I'm thinking it would be better to define them all at the start to isolate this ugly fact and to make it clearer what is being accessed since it would be by kay name. Then all the rest of the code gets rid of the index value and uses the key. This is a new change so let me know your thoughts and if you want to do this.

@huss huss mentioned this pull request May 20, 2026
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants