Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 59 additions & 58 deletions src/client/app/components/CompareLineChartComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,15 @@ export default function CompareLineChartComponent() {
}

// Adding information to the shifted data so that it can be plotted on the same graph with current data
const shiftedLabel = translate('shifted');
const updateDataNew = dataNew.map(item => ({
...item,
name: 'Shifted ' + item.name,
name: `${shiftedLabel} ${item.name}`,
line: { ...item.line, color: '#1AA5F0' },
xaxis: 'x2',
text: Array.isArray(item.text)
? item.text.map(text => text.replace('<br>', '<br>Shifted '))
: item.text?.replace('<br>', '<br>Shifted ')
? item.text.map(text => text.replace('<br>', `<br>${shiftedLabel} `))
: item.text?.replace('<br>', `<br>${shiftedLabel} `)
}));

return (
Expand Down Expand Up @@ -177,67 +178,67 @@ export default function CompareLineChartComponent() {
}

</>

);

}

/**
* If the number of points differs for the original and shifted lines, the data will not appear at the same places horizontally.
* The time interval in the original and shifted line for the actual readings can have issues.
* While the requested time ranges should be the same, the actually returned readings may differ.
* This can happen if there are readings missing including start, end or between. If the number of readings vary then there is an issue.
* If not, it is unlikely but can happen if there are missing readings in both lines that do not align but there are the same number missing in both.
* This is an ugly edge case that OED is not going to try to catch now.
* Use the last index in Redux state as a proxy for the number since need that below.
* @param originalReading original data to compare
* @param shiftedReading shifted data to compare
*/
function checkReceivedData(originalReading: any, shiftedReading: any) {
let numberPointsSame = true;
if (originalReading.length !== shiftedReading.length) {
// If the number of points vary then then scales will not line up point by point. Warn the user.
numberPointsSame = false;
showWarnNotification(
`The original line has ${originalReading.length} readings but the shifted line has ${shiftedReading.length}`
+ ' readings which means the points will not align horizontally.'
);
}
// Now see if the original and shifted lines overlap.
if (moment(shiftedReading.at(-1).toString()) > moment(originalReading.at(0).toString())) {
showInfoNotification(
`The shifted line overlaps the original line starting at ${originalReading[0]}`,
toast.POSITION.TOP_RIGHT,
15000
);
}
/**
* If the number of points differs for the original and shifted lines, the data will not appear at the same places horizontally.
* The time interval in the original and shifted line for the actual readings can have issues.
* While the requested time ranges should be the same, the actually returned readings may differ.
* This can happen if there are readings missing including start, end or between. If the number of readings vary then there is an issue.
* If not, it is unlikely but can happen if there are missing readings in both lines that do not align but there are the same number missing in both.
* This is an ugly edge case that OED is not going to try to catch now.
* Use the last index in Redux state as a proxy for the number since need that below.
* @param originalReading original data to compare
* @param shiftedReading shifted data to compare
*/
function checkReceivedData(originalReading: any, shiftedReading: any) {
let numberPointsSame = true;
if (originalReading.length !== shiftedReading.length) {
// If the number of points vary then then scales will not line up point by point. Warn the user.
numberPointsSame = false;
showWarnNotification(
`${translate('compare.line.original.shifted.count.first')} ${originalReading.length} ` +
`${translate('compare.line.original.shifted.count.second')} ${shiftedReading.length} ` +
`${translate('compare.line.original.shifted.count.third')}`
);
}
// Now see if the original and shifted lines overlap.
if (moment(shiftedReading.at(-1).toString()) > moment(originalReading.at(0).toString())) {
showInfoNotification(
`${translate('compare.line.shifted.overlaps.start.prefix')} ${originalReading[0]}`,
toast.POSITION.TOP_RIGHT,
15000
);
}

// Now see if day of the week aligns.
// If the number of points is not the same then no horizontal alignment so do not tell user.
const firstOriginReadingDay = moment(originalReading.at(0)?.toString());
const firstShiftedReadingDay = moment(shiftedReading.at(0)?.toString());
if (numberPointsSame && firstOriginReadingDay.day() === firstShiftedReadingDay.day()) {
showInfoNotification('Days of week align (unless missing readings)',
toast.POSITION.TOP_RIGHT,
15000
);
}
// Now see if the month and day align. If the number of points is not the same then no horizontal
// alignment so do not tell user. Check if the first reading matches because only notify if this is true.
if (numberPointsSame && monthDateSame(firstOriginReadingDay, firstShiftedReadingDay)) {
// Loop over all readings but the first. Really okay to do first but just checked that one.
// Note length of original and shifted same so just use original.
let message = 'The month and day of the month align for the original and shifted readings';
for (let i = 1; i < originalReading.length; i++) {
if (!monthDateSame(moment(originalReading.at(i)?.toString()), moment(shiftedReading.at(i)?.toString()))) {
// Mismatch so inform user. Should be due to leap year crossing and differing leap year.
// Only tell first mistmatch
message += ` until original reading at date ${moment(originalReading.at(i)?.toString()).format('ll')}`;
break;
// Now see if day of the week aligns.
// If the number of points is not the same then no horizontal alignment so do not tell user.
const firstOriginReadingDay = moment(originalReading.at(0)?.toString());
const firstShiftedReadingDay = moment(shiftedReading.at(0)?.toString());
if (numberPointsSame && firstOriginReadingDay.day() === firstShiftedReadingDay.day()) {
showInfoNotification(translate('compare.line.days.align'),
toast.POSITION.TOP_RIGHT,
15000
);
}
// Now see if the month and day align. If the number of points is not the same then no horizontal
// alignment so do not tell user. Check if the first reading matches because only notify if this is true.
if (numberPointsSame && monthDateSame(firstOriginReadingDay, firstShiftedReadingDay)) {
// Loop over all readings but the first. Really okay to do first but just checked that one.
// Note length of original and shifted same so just use original.
let message = translate('compare.line.month.day.align');
for (let i = 1; i < originalReading.length; i++) {
if (!monthDateSame(moment(originalReading.at(i)?.toString()), moment(shiftedReading.at(i)?.toString()))) {
// Mismatch so inform user. Should be due to leap year crossing and differing leap year.
// Only tell first mistmatch
message += `${translate('compare.line.month.day.align.until.prefix')} ${moment(originalReading.at(i)?.toString()).format('ll')}`;
break;
}
}
showInfoNotification(message, toast.POSITION.TOP_RIGHT, 15000);
}
showInfoNotification(message, toast.POSITION.TOP_RIGHT, 15000);
}

}

/**
Expand Down
27 changes: 27 additions & 0 deletions src/client/app/translations/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,16 @@ const LocaleTranslationData = {
"select.shift.amount": "Select shift amount",
"select.unit": "Select Unit",
"shift.date.interval": "Shift Date Interval",
"shifted": "Shifted",
"shifted.data.crosses.leap.year.to.non.leap.year": "Shifted data crosses a leap year so the graph might not align appropriately",

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 cannot find where this is used.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

As far as I know, this line of code has been here since before I was working on it. Regardless, I deleted it.

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.

Thanks. I missed that you did not make the change.

"compare.line.original.shifted.count.first": "The original line has ",
"compare.line.original.shifted.count.second": " readings but the shifted line has ",
"compare.line.original.shifted.count.third": ", which means the points will not align horizontally.",
"compare.line.shifted.overlaps.start": "The shifted line overlaps the original line starting at {start}",
Comment thread
Nespina24 marked this conversation as resolved.
Outdated
"compare.line.shifted.overlaps.start.prefix": "The shifted line overlaps the original line starting at ",
"compare.line.days.align": "Days of week align (unless missing readings)",
"compare.line.month.day.align": "The month and day of the month align for the original and shifted readings",
"compare.line.month.day.align.until.prefix": " until original reading at date {date}",
"show": "Show",
"show.all.logs": "Show All Logs ",
"show.grid": "Show grid",
Expand Down Expand Up @@ -1073,7 +1082,16 @@ const LocaleTranslationData = {
"select.shift.amount": "Select shift amount\u{26A1}",
"select.unit": "Select Unit\u{26A1}",
"shift.date.interval": "Shift Date Interval\u{26A1}",
"shifted": "Shifted\u{26A1}",
"shifted.data.crosses.leap.year.to.non.leap.year": "Shifted data crosses a leap year so the graph might not align appropriately\u{26A1}",
"compare.line.original.shifted.count.first": "The original line has \u{26A1}",
"compare.line.original.shifted.count.second": " readings but the shifted line has \u{26A1}",
"compare.line.original.shifted.count.third": ", which means the points will not align horizontally.\u{26A1}",
"compare.line.shifted.overlaps.start": "The shifted line overlaps the original line starting at {start}\u{26A1}",
"compare.line.shifted.overlaps.start.prefix": "The shifted line overlaps the original line starting at \u{26A1}",
"compare.line.days.align": "Days of week align (unless missing readings)\u{26A1}",
"compare.line.month.day.align": "The month and day of the month align for the original and shifted readings\u{26A1}",
"compare.line.month.day.align.until.prefix": " until original reading at date {date}\u{26A1}",
"show": "Montrer",
"show.all.logs": "Show All Logs\u{26A1} ",
"show.grid": "Show grid\u{26A1}",
Expand Down Expand Up @@ -1661,7 +1679,16 @@ const LocaleTranslationData = {
"select.shift.amount": "Select shift amount\u{26A1}",
"select.unit": "Seleccionar unidad",
"shift.date.interval": "Shift Date Interval\u{26A1}",
"shifted": "Shifted\u{26A1}",
"shifted.data.crosses.leap.year.to.non.leap.year": "Shifted data crosses a leap year so the graph might not align appropriately\u{26A1}",
"compare.line.original.shifted.count.first": "The original line has \u{26A1}",
"compare.line.original.shifted.count.second": " readings but the shifted line has \u{26A1}",
"compare.line.original.shifted.count.third": ", which means the points will not align horizontally.\u{26A1}",
"compare.line.shifted.overlaps.start": "The shifted line overlaps the original line starting at {start}\u{26A1}",
"compare.line.shifted.overlaps.start.prefix": "The shifted line overlaps the original line starting at \u{26A1}",
"compare.line.days.align": "Days of week align (unless missing readings)\u{26A1}",
"compare.line.month.day.align": "The month and day of the month align for the original and shifted readings\u{26A1}",
"compare.line.month.day.align.until.prefix": " until original reading at date {date}\u{26A1}",
"show": "Mostrar",
"show.all.logs": "Show All Logs\u{26A1} ",
"show.grid": "Mostrar rejilla",
Expand Down
Loading