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
This commit is contained in:
Noe 2024-07-02 16:53:51 +02:00
parent 816fb51dda
commit 3610421c7f
11 changed files with 110 additions and 80 deletions

View File

@ -5,12 +5,22 @@ using InnovEnergy.App.Backend.Relations;
namespace InnovEnergy.App.Backend.Database; 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) private static Boolean Insert(Object obj)
{ {
var success = Connection.Insert(obj) > 0; var success = Connection.Insert(obj) > 0;
if(success) BackupDatabase(); if (success)
{
_backupCounter++;
if (_backupCounter > 100)
{
_backupCounter = 0;
BackupDatabase();
}
}
return success; return success;
} }

View File

@ -9,12 +9,23 @@ namespace InnovEnergy.App.Backend.Database;
public static partial class Db public static partial class Db
{ {
private static void Backup()
{
_backupCounter++;
if (_backupCounter > 100)
{
_backupCounter = 0;
BackupDatabase();
}
}
public static Boolean Delete(Folder folder) public static Boolean Delete(Folder folder)
{ {
var deleteSuccess= RunTransaction(DeleteFolderAndAllItsDependencies); var deleteSuccess= RunTransaction(DeleteFolderAndAllItsDependencies);
if (deleteSuccess) if (deleteSuccess)
{ {
BackupDatabase(); Backup();
} }
return deleteSuccess; return deleteSuccess;
@ -39,8 +50,9 @@ public static partial class Db
public static Boolean Delete(Error errorToDelete) public static Boolean Delete(Error errorToDelete)
{ {
var deleteSuccess = RunTransaction(DeleteError); var deleteSuccess = RunTransaction(DeleteError);
if (deleteSuccess) if (deleteSuccess)
BackupDatabase(); Backup();
return deleteSuccess; return deleteSuccess;
@ -54,7 +66,7 @@ public static partial class Db
{ {
var deleteSuccess = RunTransaction(DeleteAction); var deleteSuccess = RunTransaction(DeleteAction);
if (deleteSuccess) if (deleteSuccess)
BackupDatabase(); Backup();
return deleteSuccess; return deleteSuccess;
@ -68,7 +80,7 @@ public static partial class Db
{ {
var deleteSuccess = RunTransaction(DeleteWarning); var deleteSuccess = RunTransaction(DeleteWarning);
if (deleteSuccess) if (deleteSuccess)
BackupDatabase(); Backup();
return deleteSuccess; return deleteSuccess;
@ -82,7 +94,7 @@ public static partial class Db
{ {
var deleteSuccess = RunTransaction(DeleteCsvTimestampToDelete); var deleteSuccess = RunTransaction(DeleteCsvTimestampToDelete);
if (deleteSuccess) if (deleteSuccess)
BackupDatabase(); Backup();
return deleteSuccess; return deleteSuccess;
@ -96,7 +108,7 @@ public static partial class Db
{ {
var deleteSuccess = RunTransaction(DeleteInstallationAndItsDependencies); var deleteSuccess = RunTransaction(DeleteInstallationAndItsDependencies);
if (deleteSuccess) if (deleteSuccess)
BackupDatabase(); Backup();
return deleteSuccess; return deleteSuccess;
@ -118,7 +130,7 @@ public static partial class Db
{ {
var deleteSuccess = RunTransaction(DeleteUserAndHisDependencies); var deleteSuccess = RunTransaction(DeleteUserAndHisDependencies);
if (deleteSuccess) if (deleteSuccess)
BackupDatabase(); Backup();
return deleteSuccess; return deleteSuccess;
Boolean DeleteUserAndHisDependencies() Boolean DeleteUserAndHisDependencies()
@ -138,7 +150,7 @@ public static partial class Db
{ {
var delete = Sessions.Delete(s => s.Id == session.Id) > 0; var delete = Sessions.Delete(s => s.Id == session.Id) > 0;
if (delete) if (delete)
BackupDatabase(); Backup();
return delete; return delete;
} }

View File

@ -8,7 +8,7 @@ public static partial class Db
private static Boolean Update(Object obj) private static Boolean Update(Object obj)
{ {
var success = Connection.Update(obj) > 0; var success = Connection.Update(obj) > 0;
if(success) BackupDatabase(); if(success) Backup();
return success; return success;
} }

View File

@ -68,8 +68,8 @@ public static class Aggregator
dailyAggregatedData.Save("DailyData"); dailyAggregatedData.Save("DailyData");
if (await dailyAggregatedData.PushToS3()) if (await dailyAggregatedData.PushToS3())
{ {
DeleteHourlyData("HourlyData",currentTime.ToUnixTime()); //DeleteHourlyData("HourlyData",currentTime.ToUnixTime());
AggregatedData.DeleteDailyData("DailyData"); //AggregatedData.DeleteDailyData("DailyData");
} }
} }

View File

@ -25,20 +25,20 @@ for ip_address in "${ip_addresses_usb0[@]}"; do
echo "Deployed and ran commands on $ip_address" echo "Deployed and ran commands on $ip_address"
done done
#
#for ip_address in "${ip_addresses_usb1[@]}"; do for ip_address in "${ip_addresses_usb1[@]}"; do
#
# ssh "$username"@"$ip_address" "cd /opt/victronenergy/serial-starter && echo '$root_password' | ./stop-tty.sh ttyUSB1" 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":/opt/victronenergy/dbus-fzsonick-48tl/"
# scp "dbus-fzsonick-48tl.py" "root@"$ip_address":/data/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" ssh "$username"@"$ip_address" "cd /opt/victronenergy/serial-starter && echo '$root_password' | ./start-tty.sh ttyUSB1"
#
#
# echo "Deployed and ran commands on $ip_address" echo "Deployed and ran commands on $ip_address"
#done done
#

View File

@ -1,6 +1,6 @@
export function formatPowerForGraph(value, magnitude): { value: number } { export function formatPowerForGraph(value, magnitude): { value: number } {
if (isNaN(value)) { if (isNaN(value) || value === null) {
return null; return { value: 0 };
} }
const prefixes = ['', 'k', 'M', 'G', 'T']; const prefixes = ['', 'k', 'M', 'G', 'T'];

View File

@ -300,10 +300,7 @@ export const getChartOptions = (
}, },
labels: { labels: {
formatter: function (value: number) { formatter: function (value: number) {
return formatPowerForGraph( return formatPowerForGraph(value, 0).value.toString();
value,
chartInfo.magnitude
).value.toString();
} }
} }
}, },

View File

@ -482,20 +482,22 @@ function Overview(props: OverviewProps) {
<FormattedMessage id="lastweek" defaultMessage="Last week" /> <FormattedMessage id="lastweek" defaultMessage="Last week" />
</Button> </Button>
{/*<Button*/} {aggregatedData && (
{/* variant="contained"*/} <Button
{/* onClick={handleSetDate}*/} variant="contained"
{/* disabled={loading}*/} onClick={handleSetDate}
{/* sx={{*/} disabled={loading}
{/* marginTop: '20px',*/} sx={{
{/* marginLeft: '10px',*/} marginTop: '20px',
{/* backgroundColor: dateOpen ? '#808080' : '#ffc04d',*/} marginLeft: '10px',
{/* color: '#000000',*/} backgroundColor: dateOpen ? '#808080' : '#ffc04d',
{/* '&:hover': { bgcolor: '#f7b34d' }*/} color: '#000000',
{/* }}*/} '&:hover': { bgcolor: '#f7b34d' }
{/*>*/} }}
{/* <FormattedMessage id="lastmonth" defaultMessage="Set Date" />*/} >
{/*</Button>*/} <FormattedMessage id="set_date" defaultMessage="Set Date" />
</Button>
)}
</Grid> </Grid>
<Grid <Grid

View File

@ -319,22 +319,22 @@ function SalidomoOverview(props: salidomoOverviewProps) {
</LocalizationProvider> </LocalizationProvider>
)} )}
<Grid container> <Grid container>
{/*<Grid item xs={6} md={6}>*/} <Grid item xs={6} md={6}>
{/* <Button*/} <Button
{/* variant="contained"*/} variant="contained"
{/* onClick={handleSetDate}*/} onClick={handleSetDate}
{/* disabled={loading}*/} disabled={loading}
{/* sx={{*/} sx={{
{/* marginTop: '20px',*/} marginTop: '20px',
{/* marginLeft: '10px',*/} marginLeft: '10px',
{/* backgroundColor: dateOpen ? '#808080' : '#ffc04d',*/} backgroundColor: dateOpen ? '#808080' : '#ffc04d',
{/* color: '#000000',*/} color: '#000000',
{/* '&:hover': { bgcolor: '#f7b34d' }*/} '&:hover': { bgcolor: '#f7b34d' }
{/* }}*/} }}
{/* >*/} >
{/* <FormattedMessage id="lastmonth" defaultMessage="Set Date" />*/} <FormattedMessage id="set_date" defaultMessage="Set Date" />
{/* </Button>*/} </Button>
{/*</Grid>*/} </Grid>
<Grid <Grid
container container

View File

@ -136,7 +136,7 @@ function PvView(props: PvViewProps) {
align="center" align="center"
sx={{ width: '10%', fontWeight: 'bold', color: 'black' }} sx={{ width: '10%', fontWeight: 'bold', color: 'black' }}
> >
{'String ' + pv.PvId} {'AMPT ' + pv.PvId}
</TableCell> </TableCell>
<TableCell <TableCell

View File

@ -129,9 +129,6 @@ export const transformInputToBatteryViewData = async (
let initialiation = true; let initialiation = true;
//console.log(start_time);
//console.log(end_time);
let timestampArray: CsvTimestamp[] = []; let timestampArray: CsvTimestamp[] = [];
let adjustedTimestampArray = []; let adjustedTimestampArray = [];
const timestampPromises = []; const timestampPromises = [];
@ -196,18 +193,20 @@ export const transformInputToBatteryViewData = async (
.split(','); .split(',');
//Initialize the chartData structure based on the node names extracted from the first result //Initialize the chartData structure based on the node names extracted from the first result
let old_length = pathsToSave.length;
if (battery_nodes.length > old_length) {
battery_nodes.forEach((node) => {
if (!pathsToSave.includes('Node' + node)) {
pathsToSave.push('Node' + node);
}
});
}
if (initialiation) { if (initialiation) {
initialiation = false; initialiation = false;
battery_nodes.forEach((node) => {
pathsToSave.push('Node' + node);
});
categories.forEach((category) => { categories.forEach((category) => {
chartData[category].data = []; chartData[category].data = [];
pathsToSave.forEach((path) => {
chartData[category].data[path] = { name: path, data: [] };
});
chartOverview[category] = { chartOverview[category] = {
magnitude: 0, magnitude: 0,
unit: '', 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 ( for (
let category_index = 0; let category_index = 0;
category_index < pathCategories.length; category_index < pathCategories.length;
@ -224,7 +233,7 @@ export const transformInputToBatteryViewData = async (
) { ) {
let category = categories[category_index]; 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]; let path = pathsToSearch[j] + pathCategories[category_index];
if (result[path]) { if (result[path]) {
@ -242,7 +251,10 @@ export const transformInputToBatteryViewData = async (
value.value value.value
]); ]);
} else { } 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 timestampArray: CsvTimestamp[] = [];
let adjustedTimestampArray = []; let adjustedTimestampArray = [];
const timestampPromises = []; const timestampPromises = [];