Update battery view for Salimax/SodistoreMax

Update Mainstats as well. We still do not have detailed battery view for SodistoreMax.
This commit is contained in:
Noe 2025-04-19 13:32:30 +02:00
parent bcde77c567
commit f3168e7215
6 changed files with 233 additions and 119 deletions

View File

@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React, { useContext, useEffect, useState } from 'react';
import {
Container,
Grid,
@ -26,12 +26,12 @@ import routes from '../../../Resources/routes.json';
import CircularProgress from '@mui/material/CircularProgress';
import MainStats from './MainStats';
import DetailedBatteryView from './DetailedBatteryView';
import { ProductIdContext } from '../../../contexts/ProductIdContextProvider';
interface BatteryViewProps {
values: JSONRecordData;
s3Credentials: I_S3Credentials;
installationId: number;
productNum: number;
connected: boolean;
}
@ -56,13 +56,7 @@ function BatteryView(props: BatteryViewProps) {
navigate(routes.mainstats);
};
// const findBatteryData = (batteryId: number) => {
// for (let i = 0; i < props.values.batteryView.length; i++) {
// if (props.values.batteryView[i].BatteryId == batteryId) {
// return props.values.batteryView[i];
// }
// }
// };
const { product, setProduct } = useContext(ProductIdContext);
useEffect(() => {
if (sortedBatteryView.length == 0) {
@ -191,26 +185,12 @@ function BatteryView(props: BatteryViewProps) {
s3Credentials={props.s3Credentials}
batteryData={battery}
installationId={props.installationId}
productNum={props.productNum}
productNum={product}
></DetailedBatteryView>
}
/>
)
)}
{/*{props.values.batteryView.map((battery) => (*/}
{/* <Route*/}
{/* key={routes.detailed_view + battery.BatteryId}*/}
{/* path={routes.detailed_view + battery.BatteryId}*/}
{/* element={*/}
{/* <DetailedBatteryView*/}
{/* s3Credentials={props.s3Credentials}*/}
{/* batteryData={findBatteryData(battery.BatteryId)}*/}
{/* installationId={props.installationId}*/}
{/* productNum={props.productNum}*/}
{/* ></DetailedBatteryView>*/}
{/* }*/}
{/* />*/}
{/*))}*/}
</Routes>
</Grid>
@ -266,7 +246,9 @@ function BatteryView(props: BatteryViewProps) {
textAlign: 'center'
}}
>
{battery.FwVersion}
{product == 0
? battery.FwVersion
: battery.BatteryDeligreenDataRecord.FwVersion}
</TableCell>
<TableCell
sx={{
@ -274,7 +256,9 @@ function BatteryView(props: BatteryViewProps) {
textAlign: 'center'
}}
>
{battery.Dc.Power + ' ' + 'W'}
{product == 0
? battery.Dc.Power + ' ' + 'W'
: battery.BatteryDeligreenDataRecord.Power + ' ' + 'W'}
</TableCell>
<TableCell
sx={{
@ -282,108 +266,192 @@ function BatteryView(props: BatteryViewProps) {
textAlign: 'center',
backgroundColor:
battery.Dc.Voltage < 44 || battery.Dc.Voltage > 57
product == 0
? battery.Dc.Voltage < 44 || battery.Dc.Voltage > 57
? '#FF033E'
: '#32CD32'
: battery.BatteryDeligreenDataRecord
.TotalBatteryVoltage < 44 ||
battery.BatteryDeligreenDataRecord
.TotalBatteryVoltage > 57
? '#FF033E'
: '#32CD32',
color: battery.Dc.Voltage ? 'black' : 'white'
color:
product === 0
? battery.Dc.Voltage
? 'black'
: 'white'
: battery.BatteryDeligreenDataRecord
.TotalBatteryVoltage
? 'black'
: 'white'
}}
>
{battery.Dc.Voltage + ' ' + 'V'}
{product === 0
? battery.Dc.Voltage + ' ' + 'V'
: battery.BatteryDeligreenDataRecord
.TotalBatteryVoltage +
' ' +
'V'}
</TableCell>
<TableCell
sx={{
width: '10%',
textAlign: 'center',
backgroundColor:
battery.Soc < 20
product === 0
? battery.Soc < 20
? '#FF033E'
: battery.Soc < 50
? '#ffbf00'
: '#32CD32'
: battery.BatteryDeligreenDataRecord.Soc < 20
? '#FF033E'
: battery.Soc < 50
: battery.BatteryDeligreenDataRecord.Soc < 50
? '#ffbf00'
: '#32CD32',
color: battery.Soc ? 'inherit' : 'white'
color:
product === 0
? battery.Soc
? 'inherit'
: 'white'
: battery.BatteryDeligreenDataRecord.Soc
? 'inherit'
: 'white'
}}
>
{battery.Soc + ' %'}
{product == 0
? battery.Soc + ' %'
: battery.BatteryDeligreenDataRecord.Soc + ' %'}
</TableCell>
<TableCell
sx={{
width: '10%',
textAlign: 'center',
backgroundColor:
battery.Temperatures.Cells.Average > 300
? '#FF033E'
: battery.Temperatures.Cells.Average > 280
? '#ffbf00'
: battery.Temperatures.Cells.Average < 245
? '#008FFB'
: '#32CD32'
sx={() => {
if (product === 0) {
const avg = battery.Temperatures.Cells.Average;
return {
width: '10%',
textAlign: 'center',
backgroundColor:
avg > 300
? '#FF033E'
: avg > 280
? '#ffbf00'
: avg < 245
? '#008FFB'
: '#32CD32'
};
} else {
const avg =
(battery.BatteryDeligreenDataRecord.TemperaturesList
.CellTemperature1 +
battery.BatteryDeligreenDataRecord
.TemperaturesList.CellTemperature2 +
battery.BatteryDeligreenDataRecord
.TemperaturesList.CellTemperature3 +
battery.BatteryDeligreenDataRecord
.TemperaturesList.CellTemperature4) /
4;
return {
width: '10%',
textAlign: 'center',
backgroundColor:
avg > 300
? '#FF033E'
: avg > 280
? '#ffbf00'
: avg < 245
? '#008FFB'
: '#32CD32'
};
}
}}
>
{battery.Temperatures.Cells.Average + ' °C'}
{product === 0
? battery.Temperatures.Cells.Average + ' °C'
: (
(battery.BatteryDeligreenDataRecord.TemperaturesList
.CellTemperature1 +
battery.BatteryDeligreenDataRecord
.TemperaturesList.CellTemperature2 +
battery.BatteryDeligreenDataRecord
.TemperaturesList.CellTemperature3 +
battery.BatteryDeligreenDataRecord
.TemperaturesList.CellTemperature4) /
4
).toFixed(1) + ' °C'}
</TableCell>
<TableCell
style={{
width: '20%',
textAlign: 'center',
padding: '8px',
fontWeight:
battery.Warnings !== '' ? 'bold' : 'inherit',
backgroundColor:
battery.Warnings === '' ? 'inherit' : '#ff9900',
color: battery.Warnings != '' ? 'black' : 'inherit'
}}
>
{battery.Warnings === '' ? (
'None'
) : battery.Warnings.toString().split('-').length > 1 ? (
<Link
style={{ color: 'black' }}
to={
currentLocation.pathname.substring(
0,
currentLocation.pathname.lastIndexOf('/') + 1
) +
routes.log +
'?open=warning'
}
{product === 0 && (
<>
<TableCell
style={{
width: '20%',
textAlign: 'center',
padding: '8px',
fontWeight:
battery.Warnings !== '' ? 'bold' : 'inherit',
backgroundColor:
battery.Warnings === '' ? 'inherit' : '#ff9900',
color: battery.Warnings !== '' ? 'black' : 'inherit'
}}
>
Multiple Warnings
</Link>
) : (
battery.Warnings
)}
</TableCell>
<TableCell
sx={{
width: '20%',
textAlign: 'center',
fontWeight: battery.Alarms !== '' ? 'bold' : 'inherit',
backgroundColor:
battery.Alarms === '' ? 'inherit' : '#FF033E',
color: battery.Alarms != '' ? 'black' : 'inherit'
}}
>
{battery.Alarms === '' ? (
'None'
) : battery.Alarms.toString().split('-').length > 1 ? (
<Link
style={{ color: 'black' }}
to={
currentLocation.pathname.substring(
0,
currentLocation.pathname.lastIndexOf('/') + 1
) +
routes.log +
'?open=error'
}
{battery.Warnings === '' ? (
'None'
) : battery.Warnings.toString().split('-').length >
1 ? (
<Link
style={{ color: 'black' }}
to={
currentLocation.pathname.substring(
0,
currentLocation.pathname.lastIndexOf('/') + 1
) +
routes.log +
'?open=warning'
}
>
Multiple Warnings
</Link>
) : (
battery.Warnings
)}
</TableCell>
<TableCell
sx={{
width: '20%',
textAlign: 'center',
fontWeight:
battery.Alarms !== '' ? 'bold' : 'inherit',
backgroundColor:
battery.Alarms === '' ? 'inherit' : '#FF033E',
color: battery.Alarms !== '' ? 'black' : 'inherit'
}}
>
Multiple Alarms
</Link>
) : (
battery.Alarms
)}
</TableCell>
{battery.Alarms === '' ? (
'None'
) : battery.Alarms.toString().split('-').length >
1 ? (
<Link
style={{ color: 'black' }}
to={
currentLocation.pathname.substring(
0,
currentLocation.pathname.lastIndexOf('/') + 1
) +
routes.log +
'?open=error'
}
>
Multiple Alarms
</Link>
) : (
battery.Alarms
)}
</TableCell>
</>
)}
</TableRow>
))}
</TableBody>

View File

@ -367,7 +367,15 @@ function MainStats(props: MainStatsProps) {
setStartDate(newDate);
}
}}
renderInput={(props) => <TextField {...props} />}
renderInput={(params) => (
<TextField
{...params}
sx={{
marginTop: 2, // Apply styles here
width: '100%' // Optional: You can adjust the width or other styling here
}}
/>
)}
/>
<DateTimePicker
@ -379,7 +387,15 @@ function MainStats(props: MainStatsProps) {
setEndDate(newDate);
}
}}
renderInput={(props) => <TextField {...props} />}
renderInput={(params) => (
<TextField
{...params}
sx={{
marginTop: 2, // Apply styles here
width: '100%' // Optional: You can adjust the width or other styling here
}}
/>
)}
/>
<div

View File

@ -427,7 +427,6 @@ function Installation(props: singleInstallationProps) {
values={values}
s3Credentials={s3Credentials}
installationId={props.current_installation.id}
productNum={props.current_installation.product}
connected={connected}
></BatteryView>
}

View File

@ -43,6 +43,31 @@ interface BatteryStrings {
}
export interface Device {
BatteryDeligreenDataRecord: {
BatteryCapacity: number;
BusCurrent: number;
BusVoltage: number;
CellVoltage: string;
FwVersion: number;
NumberOfCycles: number;
Power: number;
RatedCapacity: number;
ResidualCapacity: number;
Soc: number;
Soh: number;
TemperaturesList: {
CellTemperature1: number;
CellTemperature2: number;
CellTemperature3: number;
CellTemperature4: number;
EnvironmentTemperature: number;
PowerTemperature: number;
};
TotalBatteryVoltage: number;
};
Leds: Leds;
Eoc: boolean;
Soc: number;

View File

@ -29,10 +29,7 @@ function Topology(props: TopologyProps) {
const { product, setProduct } = useContext(ProductIdContext);
console.log('product VALUE IS ', product);
//console.log(props.values.DcDc.Dc.Battery.Voltage);
//console.log('product VALUE IS ', product);
const [showValues, setShowValues] = useState(false);
const handleSwitch = () => () => {

View File

@ -83,13 +83,22 @@ export const transformInputToBatteryViewDataJson = async (
const prefixes = ['', 'k', 'M', 'G', 'T'];
const MAX_NUMBER = 9999999;
const categories = ['Soc', 'Temperature', 'Power', 'Voltage', 'Current'];
const pathCategories = [
'.Soc',
'.Temperatures.Cells.Average',
'.Dc.Power',
'.Dc.Voltage',
'.Dc.Current'
];
const pathCategories =
product === 0
? [
'.Soc',
'.Temperatures.Cells.Average',
'.Dc.Power',
'.Dc.Voltage',
'.Dc.Current'
]
: [
'.BatteryDeligreenDataRecord.Soc',
'.BatteryDeligreenDataRecord.TemperaturesList.EnvironmentTemperature',
'.BatteryDeligreenDataRecord.Power',
'.BatteryDeligreenDataRecord.TotalBatteryVoltage',
'.BatteryDeligreenDataRecord.BusCurrent'
];
const pathsToSearch = [
'Battery.Devices.1',