diff --git a/typescript/frontend-marios2/src/content/dashboards/Installations/fetchData.tsx b/typescript/frontend-marios2/src/content/dashboards/Installations/fetchData.tsx index 6fb612b6e..9f69c4fe5 100644 --- a/typescript/frontend-marios2/src/content/dashboards/Installations/fetchData.tsx +++ b/typescript/frontend-marios2/src/content/dashboards/Installations/fetchData.tsx @@ -110,7 +110,8 @@ export const fetchDataJson = ( export const fetchAggregatedDataJson = ( date: string, - s3Credentials?: I_S3Credentials + s3Credentials?: I_S3Credentials, + product?: number ): Promise> => { const s3Path = `${date}.json`; @@ -128,7 +129,12 @@ export const fetchAggregatedDataJson = ( if (r.status === 404) { return Promise.resolve(FetchResult.notAvailable); } else if (r.status === 200) { - const jsontext = await r.text(); // Assuming the server returns the Base64 encoded ZIP file as text + const jsontext = await r.text(); + + if (product === 2) { + return parseSinexcelAggregatedData(jsontext); + } + const contentEncoding = r.headers.get('content-type'); if (contentEncoding != 'application/base64; charset=utf-8') { @@ -142,7 +148,6 @@ export const fetchAggregatedDataJson = ( const zip = await JSZip.loadAsync(byteArray); // Assuming the CSV file is named "data.csv" inside the ZIP archive const jsonContent = await zip.file('data.json').async('text'); - //console.log(jsonContent); return JSON.parse(jsonContent); } else { return Promise.resolve(FetchResult.notAvailable); @@ -154,6 +159,24 @@ export const fetchAggregatedDataJson = ( } }; +const parseSinexcelAggregatedData = (jsontext: string): any => { + const lines = jsontext.trim().split('\n'); + for (const line of lines) { + const entry = JSON.parse(line); + if (entry.Type === 'Daily') { + return { + PvPower: entry.DailySelfGeneratedElectricity ?? 0, + GridImportPower: entry.DailyElectricityPurchased ?? 0, + GridExportPower: -(entry.DailyElectricityFed ?? 0), + ChargingBatteryPower: entry.BatteryDailyChargeEnergy ?? 0, + DischargingBatteryPower: -(entry.BatteryDailyDischargeEnergy ?? 0), + LoadPowerConsumption: entry.DailyLoadPowerConsumption ?? 0 + }; + } + } + return FetchResult.notAvailable; +}; + //-------------------------------------------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------------------------------------------- diff --git a/typescript/frontend-marios2/src/content/dashboards/Overview/overview.tsx b/typescript/frontend-marios2/src/content/dashboards/Overview/overview.tsx index f413f20bc..9d1be1dc7 100644 --- a/typescript/frontend-marios2/src/content/dashboards/Overview/overview.tsx +++ b/typescript/frontend-marios2/src/content/dashboards/Overview/overview.tsx @@ -33,6 +33,7 @@ import { ProductIdContext } from '../../../contexts/ProductIdContextProvider'; interface OverviewProps { s3Credentials: I_S3Credentials; id: number; + device?: number; } const computeLast7Days = (): string[] => { @@ -210,11 +211,19 @@ function Overview(props: OverviewProps) { }> = transformInputToAggregatedDataJson( props.s3Credentials, dayjs().subtract(1, 'week'), - dayjs() + dayjs(), + product ); resultPromise .then((result) => { + if (result.dateList.length === 0) { + setDateSelectionError(intl.formatMessage({ id: 'noDataForDateRange' })); + setErrorDateModalOpen(true); + setLoading(false); + return; + } + const powerDifference = []; for ( let i = 0; @@ -320,11 +329,19 @@ function Overview(props: OverviewProps) { }> = transformInputToAggregatedDataJson( props.s3Credentials, startDate, - endDate + endDate, + product ); resultPromise .then((result) => { + if (result.dateList.length === 0) { + setDateSelectionError(intl.formatMessage({ id: 'noDataForDateRange' })); + setErrorDateModalOpen(true); + setLoading(false); + return; + } + const powerDifference = []; for ( @@ -524,6 +541,7 @@ function Overview(props: OverviewProps) { > + {props.device !== 3 && ( + )} - {/*{aggregatedData && (*/} - {/*)}*/} + {!(aggregatedData && product === 2) && ( - + )} + + {aggregatedData && product === 2 && ( + + + + + + + + + + + + + + + + + )} + {dailyData && ( } /> diff --git a/typescript/frontend-marios2/src/interfaces/Chart.tsx b/typescript/frontend-marios2/src/interfaces/Chart.tsx index 1ea3d49e3..7a331de8e 100644 --- a/typescript/frontend-marios2/src/interfaces/Chart.tsx +++ b/typescript/frontend-marios2/src/interfaces/Chart.tsx @@ -41,6 +41,7 @@ export interface chartAggregatedDataInterface { gridImportPower: { name: string; data: number[] }; gridExportPower: { name: string; data: number[] }; heatingPower: { name: string; data: number[] }; + acLoad: { name: string; data: number[] }; } export interface chartDataInterface { @@ -604,6 +605,10 @@ export const transformInputToDailyDataJson = async ( '(' + prefixes[chartOverview['pvProduction'].magnitude] + 'W' + ')'; chartOverview.dcBusVoltage.unit = '(' + prefixes[chartOverview['dcBusVoltage'].magnitude] + 'V' + ')'; + chartOverview.ACLoad.unit = + '(' + prefixes[chartOverview['ACLoad'].magnitude] + 'W' + ')'; + chartOverview.DCLoad.unit = + '(' + prefixes[chartOverview['DCLoad'].magnitude] + 'W' + ')'; chartOverview.overview = { magnitude: Math.max( @@ -655,7 +660,8 @@ const fetchJsonDataForOneTime = async ( export const transformInputToAggregatedDataJson = async ( s3Credentials: I_S3Credentials, start_date: dayjs.Dayjs, - end_date: dayjs.Dayjs + end_date: dayjs.Dayjs, + product?: number ): Promise<{ chartAggregatedData: chartAggregatedDataInterface; chartOverview: overviewInterface; @@ -676,7 +682,8 @@ export const transformInputToAggregatedDataJson = async ( 'ChargingBatteryPower', 'GridImportPower', 'GridExportPower', - 'HeatingPower' + 'HeatingPower', + 'LoadPowerConsumption' ]; const categories = [ @@ -698,7 +705,8 @@ export const transformInputToAggregatedDataJson = async ( heatingPower: { name: 'Heating Energy', data: [] }, dcDischargingPower: { name: 'Discharging Battery Energy', data: [] }, gridImportPower: { name: 'Grid Import Energy', data: [] }, - gridExportPower: { name: 'Grid Export Energy', data: [] } + gridExportPower: { name: 'Grid Export Energy', data: [] }, + acLoad: { name: 'AC Load', data: [] } }; const chartOverview: overviewInterface = { @@ -727,8 +735,11 @@ export const transformInputToAggregatedDataJson = async ( const timestampPromises = []; while (currentDay.isBefore(end_date)) { + const dateFormat = product === 2 + ? currentDay.format('DDMMYYYY') + : currentDay.format('YYYY-MM-DD'); timestampPromises.push( - fetchAggregatedDataJson(currentDay.format('YYYY-MM-DD'), s3Credentials) + fetchAggregatedDataJson(dateFormat, s3Credentials, product) ); currentDay = currentDay.add(1, 'day'); } @@ -857,6 +868,16 @@ export const transformInputToAggregatedDataJson = async ( max: overviewData['GridImportPower'].max }; + path = 'LoadPowerConsumption'; + chartAggregatedData.acLoad.data = data[path]; + + chartOverview.ACLoad = { + magnitude: overviewData['LoadPowerConsumption'].magnitude, + unit: '(kWh)', + min: overviewData['LoadPowerConsumption'].min, + max: overviewData['LoadPowerConsumption'].max + }; + chartOverview.overview = { magnitude: 0, unit: '(kWh)',