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;
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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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");
}
}

View File

@ -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

View File

@ -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'];

View File

@ -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();
}
}
},

View File

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

View File

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

View File

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

View File

@ -129,9 +129,6 @@ export const transformInputToBatteryViewData = async (
let initialiation = true;
//console.log(start_time);
//console.log(end_time);
let timestampArray: CsvTimestamp[] = [];
let adjustedTimestampArray = [];
const timestampPromises = [];
@ -196,18 +193,20 @@ export const transformInputToBatteryViewData = async (
.split(',');
//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) {
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 = [];