From 3610421c7f81ad9dc10790dfc7bdffa9ea06aede Mon Sep 17 00:00:00 2001 From: Noe Date: Tue, 2 Jul 2024 16:53:51 +0200 Subject: [PATCH] Added DBbackup optimization Fixed problem with weekly aggregated data axis scale Updated PvView Fixed bug in Salidomo when the controller cannot identify the correct number of batteries --- csharp/App/Backend/Database/Create.cs | 14 ++++++- csharp/App/Backend/Database/Delete.cs | 28 +++++++++---- csharp/App/Backend/Database/Update.cs | 2 +- .../src/AggregationService/Aggregator.cs | 4 +- .../update_all_venus_installations.sh | 28 ++++++------- .../src/Resources/formatPower.tsx | 4 +- .../dashboards/Overview/chartOptions.tsx | 5 +-- .../content/dashboards/Overview/overview.tsx | 30 +++++++------- .../dashboards/Overview/salidomoOverview.tsx | 32 +++++++-------- .../src/content/dashboards/PvView/PvView.tsx | 2 +- .../frontend-marios2/src/interfaces/Chart.tsx | 41 +++++++++++-------- 11 files changed, 110 insertions(+), 80 deletions(-) diff --git a/csharp/App/Backend/Database/Create.cs b/csharp/App/Backend/Database/Create.cs index b84dabcea..e39bc5172 100644 --- a/csharp/App/Backend/Database/Create.cs +++ b/csharp/App/Backend/Database/Create.cs @@ -5,12 +5,22 @@ using InnovEnergy.App.Backend.Relations; namespace InnovEnergy.App.Backend.Database; -public static partial class Db +public static partial class Db { + private static int _backupCounter = 0; private static Boolean Insert(Object obj) { var success = Connection.Insert(obj) > 0; - if(success) BackupDatabase(); + if (success) + { + _backupCounter++; + if (_backupCounter > 100) + { + _backupCounter = 0; + BackupDatabase(); + } + } + return success; } diff --git a/csharp/App/Backend/Database/Delete.cs b/csharp/App/Backend/Database/Delete.cs index 09d361b88..578e8c612 100644 --- a/csharp/App/Backend/Database/Delete.cs +++ b/csharp/App/Backend/Database/Delete.cs @@ -9,12 +9,23 @@ namespace InnovEnergy.App.Backend.Database; public static partial class Db { + + + private static void Backup() + { + _backupCounter++; + if (_backupCounter > 100) + { + _backupCounter = 0; + BackupDatabase(); + } + } public static Boolean Delete(Folder folder) { var deleteSuccess= RunTransaction(DeleteFolderAndAllItsDependencies); if (deleteSuccess) { - BackupDatabase(); + Backup(); } return deleteSuccess; @@ -39,8 +50,9 @@ public static partial class Db public static Boolean Delete(Error errorToDelete) { var deleteSuccess = RunTransaction(DeleteError); + if (deleteSuccess) - BackupDatabase(); + Backup(); return deleteSuccess; @@ -54,7 +66,7 @@ public static partial class Db { var deleteSuccess = RunTransaction(DeleteAction); if (deleteSuccess) - BackupDatabase(); + Backup(); return deleteSuccess; @@ -68,7 +80,7 @@ public static partial class Db { var deleteSuccess = RunTransaction(DeleteWarning); if (deleteSuccess) - BackupDatabase(); + Backup(); return deleteSuccess; @@ -82,7 +94,7 @@ public static partial class Db { var deleteSuccess = RunTransaction(DeleteCsvTimestampToDelete); if (deleteSuccess) - BackupDatabase(); + Backup(); return deleteSuccess; @@ -96,7 +108,7 @@ public static partial class Db { var deleteSuccess = RunTransaction(DeleteInstallationAndItsDependencies); if (deleteSuccess) - BackupDatabase(); + Backup(); return deleteSuccess; @@ -118,7 +130,7 @@ public static partial class Db { var deleteSuccess = RunTransaction(DeleteUserAndHisDependencies); if (deleteSuccess) - BackupDatabase(); + Backup(); return deleteSuccess; Boolean DeleteUserAndHisDependencies() @@ -138,7 +150,7 @@ public static partial class Db { var delete = Sessions.Delete(s => s.Id == session.Id) > 0; if (delete) - BackupDatabase(); + Backup(); return delete; } diff --git a/csharp/App/Backend/Database/Update.cs b/csharp/App/Backend/Database/Update.cs index 1c75504f9..1528530ff 100644 --- a/csharp/App/Backend/Database/Update.cs +++ b/csharp/App/Backend/Database/Update.cs @@ -8,7 +8,7 @@ public static partial class Db private static Boolean Update(Object obj) { var success = Connection.Update(obj) > 0; - if(success) BackupDatabase(); + if(success) Backup(); return success; } diff --git a/csharp/App/SaliMax/src/AggregationService/Aggregator.cs b/csharp/App/SaliMax/src/AggregationService/Aggregator.cs index 8a6a0ea70..f05649ccc 100644 --- a/csharp/App/SaliMax/src/AggregationService/Aggregator.cs +++ b/csharp/App/SaliMax/src/AggregationService/Aggregator.cs @@ -68,8 +68,8 @@ public static class Aggregator dailyAggregatedData.Save("DailyData"); if (await dailyAggregatedData.PushToS3()) { - DeleteHourlyData("HourlyData",currentTime.ToUnixTime()); - AggregatedData.DeleteDailyData("DailyData"); + //DeleteHourlyData("HourlyData",currentTime.ToUnixTime()); + //AggregatedData.DeleteDailyData("DailyData"); } } diff --git a/firmware/Venus_Release/VenusReleaseFiles/dbus-fzsonick-48tl/update_all_venus_installations.sh b/firmware/Venus_Release/VenusReleaseFiles/dbus-fzsonick-48tl/update_all_venus_installations.sh index 76a9c0a31..d28de40ae 100755 --- a/firmware/Venus_Release/VenusReleaseFiles/dbus-fzsonick-48tl/update_all_venus_installations.sh +++ b/firmware/Venus_Release/VenusReleaseFiles/dbus-fzsonick-48tl/update_all_venus_installations.sh @@ -25,20 +25,20 @@ for ip_address in "${ip_addresses_usb0[@]}"; do echo "Deployed and ran commands on $ip_address" done -# -#for ip_address in "${ip_addresses_usb1[@]}"; do -# -# ssh "$username"@"$ip_address" "cd /opt/victronenergy/serial-starter && echo '$root_password' | ./stop-tty.sh ttyUSB1" -# -# scp "dbus-fzsonick-48tl.py" "root@"$ip_address":/opt/victronenergy/dbus-fzsonick-48tl/" -# scp "dbus-fzsonick-48tl.py" "root@"$ip_address":/data/dbus-fzsonick-48tl/" -# -# ssh "$username"@"$ip_address" "cd /opt/victronenergy/serial-starter && echo '$root_password' | ./start-tty.sh ttyUSB1" -# -# -# echo "Deployed and ran commands on $ip_address" -#done -# + +for ip_address in "${ip_addresses_usb1[@]}"; do + + ssh "$username"@"$ip_address" "cd /opt/victronenergy/serial-starter && echo '$root_password' | ./stop-tty.sh ttyUSB1" + + scp "dbus-fzsonick-48tl.py" "root@"$ip_address":/opt/victronenergy/dbus-fzsonick-48tl/" + scp "dbus-fzsonick-48tl.py" "root@"$ip_address":/data/dbus-fzsonick-48tl/" + + ssh "$username"@"$ip_address" "cd /opt/victronenergy/serial-starter && echo '$root_password' | ./start-tty.sh ttyUSB1" + + + echo "Deployed and ran commands on $ip_address" +done + diff --git a/typescript/frontend-marios2/src/Resources/formatPower.tsx b/typescript/frontend-marios2/src/Resources/formatPower.tsx index ae957bce0..4f5a3ede0 100644 --- a/typescript/frontend-marios2/src/Resources/formatPower.tsx +++ b/typescript/frontend-marios2/src/Resources/formatPower.tsx @@ -1,6 +1,6 @@ export function formatPowerForGraph(value, magnitude): { value: number } { - if (isNaN(value)) { - return null; + if (isNaN(value) || value === null) { + return { value: 0 }; } const prefixes = ['', 'k', 'M', 'G', 'T']; diff --git a/typescript/frontend-marios2/src/content/dashboards/Overview/chartOptions.tsx b/typescript/frontend-marios2/src/content/dashboards/Overview/chartOptions.tsx index 956a343e8..17499c5fe 100644 --- a/typescript/frontend-marios2/src/content/dashboards/Overview/chartOptions.tsx +++ b/typescript/frontend-marios2/src/content/dashboards/Overview/chartOptions.tsx @@ -300,10 +300,7 @@ export const getChartOptions = ( }, labels: { formatter: function (value: number) { - return formatPowerForGraph( - value, - chartInfo.magnitude - ).value.toString(); + return formatPowerForGraph(value, 0).value.toString(); } } }, diff --git a/typescript/frontend-marios2/src/content/dashboards/Overview/overview.tsx b/typescript/frontend-marios2/src/content/dashboards/Overview/overview.tsx index 762a608e5..86e899b37 100644 --- a/typescript/frontend-marios2/src/content/dashboards/Overview/overview.tsx +++ b/typescript/frontend-marios2/src/content/dashboards/Overview/overview.tsx @@ -482,20 +482,22 @@ function Overview(props: OverviewProps) { - {/**/} - {/* */} - {/**/} + {aggregatedData && ( + + )} )} - {/**/} - {/* */} - {/* */} - {/* */} - {/**/} + + + - {'String ' + pv.PvId} + {'AMPT ' + pv.PvId} old_length) { + battery_nodes.forEach((node) => { + if (!pathsToSave.includes('Node' + node)) { + pathsToSave.push('Node' + node); + } + }); + } + if (initialiation) { initialiation = false; - - battery_nodes.forEach((node) => { - pathsToSave.push('Node' + node); - }); categories.forEach((category) => { chartData[category].data = []; - pathsToSave.forEach((path) => { - chartData[category].data[path] = { name: path, data: [] }; - }); - chartOverview[category] = { magnitude: 0, unit: '', @@ -217,6 +216,16 @@ export const transformInputToBatteryViewData = async ( }); } + if (battery_nodes.length > old_length) { + categories.forEach((category) => { + pathsToSave.forEach((path) => { + if (pathsToSave.indexOf(path) >= old_length) { + chartData[category].data[path] = { name: path, data: [] }; + } + }); + }); + } + for ( let category_index = 0; category_index < pathCategories.length; @@ -224,7 +233,7 @@ export const transformInputToBatteryViewData = async ( ) { let category = categories[category_index]; - for (let j = 0; j < pathsToSearch.length; j++) { + for (let j = 0; j < pathsToSave.length; j++) { let path = pathsToSearch[j] + pathCategories[category_index]; if (result[path]) { @@ -242,7 +251,10 @@ export const transformInputToBatteryViewData = async ( value.value ]); } else { - //data[path].push([adjustedTimestamp, null]); + // chartData[category].data[pathsToSave[j]].data.push([ + // adjustedTimestampArray[i], + // null + // ]); } } } @@ -368,9 +380,6 @@ export const transformInputToDailyData = async ( }; }); - //console.log(start_time); - //console.log(end_time); - let timestampArray: CsvTimestamp[] = []; let adjustedTimestampArray = []; const timestampPromises = [];