This commit is contained in:
Noe 2023-06-30 16:15:41 +02:00
commit 869a83b799
26 changed files with 294 additions and 164 deletions

View File

@ -2,7 +2,7 @@
dotnet_version='net6.0'
salimax_ip= '10.2.3.104'
username='ie-entwicklung@'
username='ie-entwicklung'
set -e

View File

@ -0,0 +1,34 @@
#!/bin/bash
dotnet_version='net6.0'
salimax_ip='10.2.4.33'
username='ie-entwicklung'
set -e
echo -e "\n============================ Build ============================\n"
dotnet publish \
./SaliMax.csproj \
-p:PublishTrimmed=false \
-c Release \
-r linux-x64
echo -e "\n============================ Deploy ============================\n"
rsync -v \
./bin/Release/$dotnet_version/linux-x64/publish/* \
ie-entwicklung@10.2.4.33:~/salimax
echo -e "\n============================ Restart Salimax sevice ============================\n"
ssh -tt \
ie-entwicklung@10.2.4.33 \
sudo systemctl restart salimax.service
echo -e "\n============================ Print service output ============================\n"
ssh -tt \
ie-entwicklung@10.2.4.33 \
journalctl -f -u salimax.service

View File

@ -1,9 +1,8 @@
#!/bin/bash
dotnet_version='net6.0'
salimax_ip= '10.2.3.115'
username='ie-entwicklung@'
salimax_ip='10.2.3.115'
username='ie-entwicklung'
set -e

View File

@ -187,7 +187,7 @@ public static class Controller
if (statusRecord.Battery.Eoc)
{
"Batteries have reached EOC".Log();
"Batteries have reached EOC".LogInfo();
config.LastEoc = UnixTime.Now;
return false;
}

View File

@ -10,11 +10,18 @@ public static class Logger
private const Int32 MaxLogFileCount = 1000; // TODO: move to settings
private const String LogFilePath = "LogDirectory/log.txt"; // TODO: move to settings
// ReSharper disable once InconsistentNaming
private static readonly ILogger _logger = new CustomLogger(LogFilePath, MaxFileSizeBytes, MaxLogFileCount);
public static T Log<T>(this T t) where T : notnull
public static T LogInfo<T>(this T t) where T : notnull
{
// _logger.LogInformation(t.ToString()); // TODO: check warning
_logger.LogInformation(t.ToString()); // TODO: check warning
return t;
}
public static T LogDebug<T>(this T t) where T : notnull
{
_logger.LogDebug(t.ToString()); // TODO: check warning
return t;
}
}

View File

@ -36,20 +36,23 @@ internal static class Program
private static readonly Byte[] BatteryNodes = { 2, 3, 4, 5, 6 };
private const String BatteryTty = "/dev/ttyUSB0";
#if DEBUG
private static readonly TcpChannel TruConvertAcChannel = new TcpChannel("localhost", 5001);
private static readonly TcpChannel TruConvertDcChannel = new TcpChannel("localhost", 5002);
private static readonly TcpChannel GridMeterChannel = new TcpChannel("localhost", 5003);
private static readonly TcpChannel AcOutLoadChannel = new TcpChannel("localhost", 5004);
private static readonly TcpChannel AmptChannel = new TcpChannel("localhost", 5005);
private static readonly TcpChannel RelaysChannel = new TcpChannel("localhost", 5006);
private static readonly TcpChannel BatteriesChannel = new TcpChannel("localhost", 5007);
#else
private static readonly TcpChannel RelaysChannel = new TcpChannel("10.0.1.1", 502); // "192.168.1.242";
private static readonly TcpChannel TruConvertAcChannel = new TcpChannel("10.0.2.1", 502); // "192.168.1.2";
private static readonly TcpChannel TruConvertDcChannel = new TcpChannel("10.0.3.1", 502); // "192.168.1.3";
private static readonly TcpChannel GridMeterChannel = new TcpChannel("10.0.4.1", 502); // "192.168.1.241";
private static readonly TcpChannel AcOutLoadChannel = new TcpChannel("10.0.4.2", 502); // "192.168.1.241";
private static readonly TcpChannel AmptChannel = new TcpChannel("10.0.5.1", 502); // "192.168.1.249";
//private static readonly TcpChannel TruConvertAcChannel = new TcpChannel("localhost", 5001);
//private static readonly TcpChannel TruConvertDcChannel = new TcpChannel("localhost", 5002);
//private static readonly TcpChannel GridMeterChannel = new TcpChannel("localhost", 5003);
//private static readonly TcpChannel AcOutLoadChannel = new TcpChannel("localhost", 5004);
//private static readonly TcpChannel AmptChannel = new TcpChannel("localhost", 5005);
//private static readonly TcpChannel RelaysChannel = new TcpChannel("localhost", 5006);
//private static readonly TcpChannel BatteriesChannel = new TcpChannel("localhost", 5007);
private static readonly TcpChannel BatteriesChannel = new TcpChannel("localhost", 5007);
#endif
private static readonly S3Config S3Config = new S3Config
@ -165,7 +168,6 @@ internal static class Program
Console.WriteLine("press ctrl-C to stop");
while (true)
{
sd_notify(0, "WATCHDOG=1");
@ -181,15 +183,6 @@ internal static class Program
if (record.Relays is not null)
record.Relays.ToCsv().WriteLine();
var emuMeterRegisters = record.GridMeter;
if (emuMeterRegisters is not null)
{
emuMeterRegisters.Ac.Power.Active.WriteLine("Grid Active");
//emuMeterRegisters.Ac.Power.Reactive.WriteLine("Grid Reactive");
}
record.ControlConstants();
record.ControlSystemState();
@ -275,9 +268,22 @@ internal static class Program
var gridBox = TextBlock.AlignLeft(gridPowerByPhase).TitleBox("Grid");
var inverterBox = TextBlock.AlignLeft(inverterPowerByAcDc).TitleBox("Inverter");
var dcDcBox = TextBlock.AlignLeft(dc48Voltage).TitleBox("DC/DC");
var batteryBox = TextBlock.AlignLeft(batteryVoltage.ToDisplayString(), batterySoc.ToDisplayString(), batteryCurrent.ToDisplayString(), batteryTemp.ToDisplayString()).TitleBox("Battery");
var batteryAvgBox = TextBlock.AlignLeft(batteryVoltage.ToDisplayString(),
batterySoc.ToDisplayString(),
batteryCurrent.ToDisplayString(),
batteryTemp.ToDisplayString())
.TitleBox("Battery");
//////////////////// Batteries /////////////////////////
IReadOnlyList<TextBlock> batteryBoxes = s.Battery
.Devices
.Select(CreateIndividualBattery)
.ToArray(s.Battery.Devices.Count);
var individualBatteries = TextBlock.AlignLeft(batteryBoxes);
var totalBoxes = TextBlock.CenterVertical(gridBox,
gridBusFlow,
@ -291,11 +297,25 @@ internal static class Program
flowDcBusToDcDc,
dcDcBox,
flowDcDcToBattery,
batteryBox);
batteryAvgBox,
individualBatteries);
totalBoxes.WriteLine();
}
private static TextBlock CreateIndividualBattery(Battery48TlRecord battery, Int32 i)
{
var content = TextBlock.AlignLeft(battery.Dc.Voltage.ToDisplayString(),
battery.Soc.ToDisplayString(),
battery.Dc.Current.ToDisplayString(),
battery.Temperatures.Heating);
var box = content.TitleBox($"Battery {i + 1}");
var flow = Flow.Horizontal(battery.Dc.Power);
return TextBlock.CenterVertical(flow, box);
}
private static TextBlock ColumnBox(String pvTitle, String busTitle, String loadTitle, TextBlock dataBox)
{
return ColumnBox(pvTitle, busTitle, loadTitle, dataBox, 0);

View File

@ -18,7 +18,7 @@ public class RelaysDevice
}
catch (Exception e)
{
$"Failed to read from {nameof(RelaysDevice)}\n{e}".Log();
$"Failed to read from {nameof(RelaysDevice)}\n{e}".LogInfo();
// TODO: log
return null;
@ -33,7 +33,7 @@ public class RelaysDevice
}
catch (Exception e)
{
$"Failed to write to {nameof(RelaysDevice)}\n{e}".Log();
$"Failed to write to {nameof(RelaysDevice)}\n{e}".LogInfo();
}
}
}

View File

@ -31,11 +31,11 @@ public class Config //TODO: let IE choose from config files (Json) and connect t
LastEoc = UnixTime.Epoch,
PConstant = .5,
GridSetPoint = 0,
BatterySelfDischargePower = 200, // TODO: multiple batteries
BatterySelfDischargePower = 200, // TODO: multiple batteries // no need as we multiplied by the number of the batteries
HoldSocZone = 1, // TODO: find better name,
MinDcBusVoltage = 730,
MinDcBusVoltage = 690,
ReferenceDcBusVoltage = 750,
MaxDcBusVoltage = 770,
MaxDcBusVoltage = 810,
};
@ -50,7 +50,7 @@ public class Config //TODO: let IE choose from config files (Json) and connect t
}
catch (Exception e)
{
$"Failed to write config file {configFilePath}\n{e}".Log();
$"Failed to write config file {configFilePath}\n{e}".LogInfo();
throw;
}
}
@ -66,7 +66,7 @@ public class Config //TODO: let IE choose from config files (Json) and connect t
}
catch (Exception e)
{
$"Failed to read config file {configFilePath}, using default config\n{e}".Log();
$"Failed to read config file {configFilePath}, using default config\n{e}".LogInfo();
return Default;
}
}

View File

@ -6,7 +6,7 @@
<LangVersion>preview</LangVersion>
<IsTrimmable>true</IsTrimmable>
<ImplicitUsings>enable</ImplicitUsings>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<InvariantGlobalization>true</InvariantGlobalization>
<SuppressTrimAnalysisWarnings>false</SuppressTrimAnalysisWarnings>
<RootNamespace>Please.reload.the.project.Rider.is.stupid</RootNamespace>

View File

@ -1,7 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<!-- <Import Project="../../InnovEnergy.Lib.props"/>-->
<Import Project="../../../App/InnovEnergy.App.props" />
<Import Project="../../InnovEnergy.Lib.props"/>
<ItemGroup>
<ProjectReference Include="../../Protocols/Modbus/Modbus.csproj" />

View File

@ -1,8 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configurations>Debug;Release;Release-Server</Configurations>
<Platforms>AnyCPU;linux-arm</Platforms>
</PropertyGroup>
<Import Project="../../InnovEnergy.Lib.props" />
<ItemGroup>

View File

@ -1,7 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<!-- <Import Project="../../InnovEnergy.Lib.props" />-->
<Import Project="../../../App/InnovEnergy.App.props" />
<Import Project="../../InnovEnergy.Lib.props" />
<ItemGroup>
<ProjectReference Include="../../Protocols/Modbus/Modbus.csproj" />

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<!-- <Import Project="../../InnovEnergy.Lib.props" />-->
<Import Project="../../../App/InnovEnergy.App.props" />
<Import Project="../../InnovEnergy.Lib.props" />
<ItemGroup>
<ProjectReference Include="../../Protocols/Modbus/Modbus.csproj" />
<ProjectReference Include="../../StatusApi/StatusApi.csproj" />

View File

@ -1,7 +1,6 @@
using System.Diagnostics.CodeAnalysis;
using InnovEnergy.Lib.Devices.Battery48TL.DataTypes;
using InnovEnergy.Lib.Protocols.Modbus.Reflection.Attributes;
using InnovEnergy.Lib.SrcGen.Attributes;
namespace InnovEnergy.Lib.Devices.Battery48TL;
#pragma warning disable CS0169, CS0649

View File

@ -1,7 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<!-- <Import Project="../../InnovEnergy.Lib.props" />-->
<Import Project="../../../App/InnovEnergy.App.props" />
<Import Project="../../InnovEnergy.Lib.props" />
<ItemGroup>
<ProjectReference Include="../../Utils/Utils.csproj" />

View File

@ -1,14 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configurations>Debug;Release;Release-Server</Configurations>
<Platforms>AnyCPU;linux-arm</Platforms>
</PropertyGroup>
<Import Project="../InnovEnergy.Lib.props" />
<ItemGroup>
<ProjectReference Include="../Utils/Utils.csproj" />
<ProjectReference Include="../Time/Time.csproj" />
<ProjectReference Include="../SrcGen/SrcGen.csproj" />
</ItemGroup>
<!-- <Target Name="PreBuild" BeforeTargets="PreBuildEvent">-->

View File

@ -0,0 +1,15 @@
// TODO remove for .Net 7
namespace System.Runtime.CompilerServices
{
public class RequiredMemberAttribute : Attribute { }
public class CompilerFeatureRequiredAttribute : Attribute
{
public CompilerFeatureRequiredAttribute(string name) { }
}
}
namespace System.Diagnostics.CodeAnalysis
{
public class SetsRequiredMembersAttribute : Attribute { }
}

View File

@ -112,7 +112,7 @@ public class TextBlock
return new TextBlock(alignedLines);
}
public static TextBlock CenterHorizontal(params Object[] things)
public static TextBlock CenterHorizontal(IReadOnlyList<Object> things)
{
var lines = things
.SelectMany(GetLines)
@ -127,6 +127,10 @@ public class TextBlock
return new TextBlock(alignedLines);
}
public static TextBlock CenterHorizontal(params Object[] things)
{
return CenterHorizontal((IReadOnlyList<Object>)things);
}
public static TextBlock AlignTop(params Object[] things)
{

View File

@ -1,6 +1,6 @@
{
"sdk": {
"version": "6.0.0",
"version": "7.0.0",
"rollForward": "latestMajor",
"allowPrerelease": true
}

View File

@ -57,7 +57,8 @@
"@formatjs/cli": "^6.0.3",
"@types/react-plotly.js": "^2.6.0",
"@types/react-window": "^1.8.5",
"eslint-plugin-formatjs": "^4.10.1"
"eslint-plugin-formatjs": "^4.10.1",
"prettier": "^2.8.8"
}
},
"node_modules/@adobe/css-tools": {
@ -19743,6 +19744,21 @@
"node": ">=0.10.0"
}
},
"node_modules/prettier": {
"version": "2.8.8",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz",
"integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==",
"dev": true,
"bin": {
"prettier": "bin-prettier.js"
},
"engines": {
"node": ">=10.13.0"
},
"funding": {
"url": "https://github.com/prettier/prettier?sponsor=1"
}
},
"node_modules/pretty-bytes": {
"version": "5.6.0",
"resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-5.6.0.tgz",
@ -39706,6 +39722,12 @@
"resolved": "https://registry.npmjs.org/prepend-http/-/prepend-http-1.0.4.tgz",
"integrity": "sha512-PhmXi5XmoyKw1Un4E+opM2KcsJInDvKyuOumcjjw3waw86ZNjHwVUOOWLc4bCzLdcKNaWBH9e99sbWzDQsVaYg=="
},
"prettier": {
"version": "2.8.8",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz",
"integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==",
"dev": true
},
"pretty-bytes": {
"version": "5.6.0",
"resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-5.6.0.tgz",

View File

@ -85,6 +85,7 @@
"@formatjs/cli": "^6.0.3",
"@types/react-plotly.js": "^2.6.0",
"@types/react-window": "^1.8.5",
"eslint-plugin-formatjs": "^4.10.1"
"eslint-plugin-formatjs": "^4.10.1",
"prettier": "^2.8.8"
}
}

View File

@ -16,7 +16,7 @@ import { S3Access } from "../../../dataCache/S3/S3Access";
import DataCache, { FetchResult } from "../../../dataCache/dataCache";
import { LogContext } from "../../Context/LogContextProvider";
import { isDefined } from "../../../dataCache/utils/maybe";
import { Data, Layout, PlotRelayoutEvent } from "plotly.js";
import { Data, Icons, Layout, PlotRelayoutEvent, relayout } from "plotly.js";
import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs";
import { FormattedMessage } from "react-intl";
import DateRangePicker from "./DateRangePicker";
@ -45,6 +45,7 @@ export const fetchData = (
return Promise.resolve(FetchResult.notAvailable);
} else if (r.status === 200) {
const text = await r.text();
console.log("parsecsv", text, parseCsv(text));
return parseCsv(text);
} else {
console.error("unexpected status code");
@ -153,6 +154,7 @@ const ScalarGraph = () => {
const handleRelayout = useCallback(
(params: PlotRelayoutEvent) => {
console.log("relayout");
const xaxisRange0 = params["xaxis.range[0]"];
const xaxisRange1 = params["xaxis.range[1]"];
if (xaxisRange0 && xaxisRange1) {
@ -169,10 +171,10 @@ const ScalarGraph = () => {
if (checkedToggles.length > 0) {
const coordinateTimeSeries = transformToGraphData(timeSeries);
const visibleGraphs = Object.keys(coordinateTimeSeries).filter((path) => {
console.log("checkedToggles", coordinateTimeSeries, checkedToggles);
return checkedToggles.find((toggle) => toggle === path);
});
console.log("visibleGraphs", visibleGraphs);
if (visibleGraphs.length > 0) {
return (
<div style={{ marginTop: "20px" }}>
@ -185,6 +187,8 @@ const ScalarGraph = () => {
</LocalizationProvider>
{visibleGraphs.map((path) => {
const isScalar = isNumeric(coordinateTimeSeries[path].y[0]);
console.log("graphdata", timeSeries, coordinateTimeSeries);
const data = isScalar
? [
{
@ -202,7 +206,6 @@ const ScalarGraph = () => {
barnorm: "percent",
}
: {};
console.log("graphdata", coordinateTimeSeries);
return (
<Plot
key={path}
@ -227,6 +230,8 @@ const ScalarGraph = () => {
"select2d",
"pan2d",
"autoScale2d",
"resetScale2d",
"zoom2d",
],
}}
onRelayout={handleRelayout}

View File

@ -1,10 +1,14 @@
import {Box} from "@mui/material";
import {getBoxColor} from "../../../util/graph.util";
import { Box } from "@mui/material";
import { getBoxColor } from "../../../util/graph.util";
export interface BoxDataValue {
unit: string;
value: string | number;
}
export type BoxData = {
label: string;
values: (string | number)[];
unit: string;
values: BoxDataValue[];
};
export type TopologyBoxProps = {
@ -18,7 +22,7 @@ const isInt = (value: number) => {
export const BOX_SIZE = 85;
const TopologyBox = (props: TopologyBoxProps) => {
const {titleColor, boxColor} = getBoxColor(props.title);
const { titleColor, boxColor } = getBoxColor(props.title);
return (
<Box
sx={{
@ -54,19 +58,22 @@ const TopologyBox = (props: TopologyBoxProps) => {
>
{props.data && (
<>
{props.data.values.map((value, index) => {
{props.data.values.map((boxData, index) => {
console.log("boxData", boxData);
return (
<p
key={props.title + '-' + index}
style={{marginBlockStart: "0", marginBlockEnd: "2px"}}
key={props.title + "-" + index}
style={{ marginBlockStart: "0", marginBlockEnd: "2px" }}
// eslint-disable-next-line formatjs/no-literal-string-in-jsx
>{`${
props.data && props.data.values.length === 3
? "L" + (index + 1) + " "
: ""
}${
!isInt(Number(value)) ? Number(value).toPrecision(4) : value
}${props.data?.unit}`}</p>
!isInt(Number(boxData.value))
? Number(boxData.value).toPrecision(4)
: boxData.value
}${boxData.unit}`}</p>
);
})}
</>

View File

@ -43,9 +43,9 @@ const TopologyFlow = (props: TopologyFlowProps) => {
}}
>
{values
?.filter((value) => (value as number) !== 0)
?.filter((boxData) => (boxData.value as number) !== 0)
.map(
(value) => `${Math.round(value as number)} ${props.data?.unit}`
(boxData) => `${Math.round(boxData.value as number)} ${boxData.unit}`
)}
</p>
<div

View File

@ -5,7 +5,7 @@ import { SkipList } from "./skipList/skipList";
import { createDispatchQueue } from "./promiseQueue";
import { SkipListNode } from "./skipList/skipListNode";
import { RecordSeries } from "./data";
import { Maybe, isUndefined } from "./utils/maybe";
import { isUndefined, Maybe } from "./utils/maybe";
import { isNumber } from "./utils/runtimeTypeChecking";
import { CsvEntry } from "../util/graph.util";
@ -104,20 +104,24 @@ export default class DataCache<T extends Record<string, CsvEntry>> {
const n = after.index - t;
const pn = p + n;
let interpolated: Partial<Record<string, CsvEntry>> = {};
let interpolated: Record<string, CsvEntry> = {};
//What about string nodes? like Alarms
for (const k of Object.keys(dataBefore)) {
const beforeData = dataBefore[k].value;
const afterData = Number(dataAfter[k].value);
let foo = interpolated[k];
if (foo) {
foo.value = isNumber(beforeData)
? (beforeData * n + afterData * p) / pn
: n < p
? afterData
: beforeData;
const valueBefore = dataBefore[k].value;
const valueAfter = dataAfter[k]?.value as Maybe<number | string>;
let value: number | string;
if (isUndefined(valueAfter)) {
value = valueBefore;
} else if (isNumber(valueBefore) && isNumber(valueAfter)) {
value = (valueBefore * n + valueAfter * p) / pn;
} else {
value = n < p ? valueAfter : valueBefore;
}
interpolated[k] = { value, unit: dataBefore[k].unit };
}
return interpolated as T;

View File

@ -1,11 +1,12 @@
import { Datum, TypedArray } from "plotly.js";
import {
TreeElement,
} from "../components/Installations/Log/CheckboxTree";
import { TreeElement } from "../components/Installations/Log/CheckboxTree";
import { TimeRange, UnixTime } from "../dataCache/time";
import { DataPoint, DataRecord } from "../dataCache/data";
import { isDefined } from "../dataCache/utils/maybe";
import { BoxData } from "../components/Installations/Log/TopologyBox";
import {
BoxData,
BoxDataValue,
} from "../components/Installations/Log/TopologyBox";
export interface GraphCoordinates {
x: Datum[] | Datum[][] | TypedArray;
@ -30,6 +31,7 @@ export const createTimes = (
);
return roundedRange.sample(oneSpan);
};
export interface GraphData {
[path: string]: GraphCoordinates;
}
@ -95,6 +97,7 @@ interface BoxColor {
titleColor: string;
boxColor: string;
}
export const getBoxColor = (boxTitle?: string): BoxColor => {
switch (boxTitle) {
case "Grid":
@ -138,18 +141,33 @@ export const extractTopologyValues = (
const timeSeriesValue = timeSeriesData.value;
if (isDefined(timeSeriesValue)) {
return Object.keys(topologyPaths).reduce((acc, topologyKey) => {
let topologyValues: (string | number)[];
let topologyValues: BoxDataValue[];
const values = topologyPaths[topologyKey as keyof TopologyValues].map(
(topologyPath) => timeSeriesValue[topologyPath]
);
switch (topologyKey as keyof TopologyValues) {
case "gridToAcInConnection":
topologyValues = [
values.reduce((acc, curr) => Number(acc) + Number(curr.value), 0),
values.reduce(
(acc, curr) => {
return {
value: Number(acc.value) + Number(curr.value),
unit: acc.unit,
};
},
{ value: 0, unit: values[0].unit }
),
];
break;
default:
topologyValues = values.map((element) => element.value);
topologyValues = values
.filter((element) => element)
.map((element) => {
if (element) {
return { value: element.value, unit: element.unit };
}
return { value: 0, unit: "" };
});
}
return {
...acc,
@ -158,7 +176,6 @@ export const extractTopologyValues = (
label: topologyPaths[topologyKey as keyof TopologyValues][0]
.split("/")
.pop(),
unit: values[0].unit,
} as BoxData,
};
}, {} as TopologyValues);
@ -171,16 +188,22 @@ export const getHighestConnectionValue = (values: TopologyValues) =>
.filter((value) => value.includes("Connection"))
.reduce((acc, curr) => {
const value = Math.abs(
values[curr as keyof TopologyValues].values[0] as number
values[curr as keyof TopologyValues].values[0].value as number
);
return value > acc ? value : acc;
}, 0);
export const getAmount = (
highestConnectionValue: number,
values: (string | number)[]
values: BoxDataValue[]
) => {
return Math.abs(values[0] as number) / highestConnectionValue;
console.log(
"getamount",
Math.abs(values[0].value as number) / highestConnectionValue,
Math.abs(values[0].value as number),
highestConnectionValue
);
return Math.abs(values[0].value as number) / highestConnectionValue;
};
export interface CsvEntry {
@ -189,23 +212,26 @@ export interface CsvEntry {
}
export const parseCsv = (text: string): DataRecord => {
console.log("parseText", text);
const y = text
.split(/\r?\n/)
.filter((split) => split.length > 0)
.map((l) => {
return l.split(";");
});
const x = y
return y
.map((fields) => {
if (fields[0] === "/AcDc/Warnings")
console.log("warnings", fields[1], isNaN(+fields[1]));
if (fields[0].includes("LoadOnAcIsland")) {
console.log("fields", fields, {
[fields[0]]: { value: parseFloat(fields[1]), unit: fields[2] },
});
}
if (isNaN(Number(fields[1])) || fields[1] === "") {
return { [fields[0]]: { value: fields[1], unit: fields[2] } };
}
return { [fields[0]]: { value: parseFloat(fields[1]), unit: fields[2] } };
})
.reduce((acc, current) => ({ ...acc, ...current }), {} as DataRecord);
return x;
};
export const insertTreeElements = (