Skip to content

Commit

Permalink
feat: Implement-service-type-labels
Browse files Browse the repository at this point in the history
  • Loading branch information
timriedl-sprinteins committed Jul 19, 2023
1 parent 18da7f4 commit 52aa7d3
Show file tree
Hide file tree
Showing 26 changed files with 462 additions and 240 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Changed
- changed service-type icons

### Added
- add serviceType Label

## Type Switcher [Unreleased]
## Documentation [Unreleased]

### Changed
- changed service-type icons

### Added
- add serviceType Label

## Type Switcher [0.0.15] - 2023-07-11
- select all checkbox
- styling enhancements
Expand Down
29 changes: 20 additions & 9 deletions packages/core/src/scd/scd-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,19 @@ export class SCDQueries {
return connections
}

public getBusesByIEDName(name: string): Set<string> {
public getSubnetworksByIEDName(name: string): Set<Element> {
const root = this.determineRoot()
const selector = `SCL > Communication > SubNetwork > ConnectedAP[iedName='${name}']`

const lnodes = Array.from(root.querySelectorAll(selector))
const connections = new Set<string>
const connectedAPs = Array.from(root.querySelectorAll(selector))
const connections = new Set<Element>

for (const lnode of lnodes) {
if (lnode != null){
const bay = lnode.closest("SubNetwork")
const bayName = bay?.getAttribute("name")
for (const connectedAP of connectedAPs) {
if (connectedAP != null){
const bay = connectedAP.closest("SubNetwork")

if (bayName != null)
connections.add(bayName)
if (bay != null)
connections.add(bay)
}
}

Expand All @@ -65,6 +64,14 @@ export class SCDQueries {
)
}

public searchGSEControlByIEDNameAndName(iedName: string, cbName: string, options?:CommonOptions): GSEControlElement {
return this.searchElement<GSEControlElement>(
`SCL > IED[name='${iedName}'] GSEControl[name='${cbName}']`,
["name", "datSet"],
options,
)[0]
}

public static SelectorInput = "Inputs"
public searchInputs(options?: CommonOptions): InputElement[] {
return this.searchElement<InputElement>(SCDQueries.SelectorInput,[],options)
Expand Down Expand Up @@ -343,5 +350,9 @@ export type InputExtRefElement = SCDElement & {
srcCBName: string,
}

export type InputExtRefElementWithDatSet = InputExtRefElement & {
datSet: string
}

export type Optional<T> = T | undefined
export type AttributeList<T extends SCDElement> = Exclude<keyof T, keyof SCDElement>
66 changes: 45 additions & 21 deletions packages/core/src/use-cases/uc-communication-information.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MessageType } from "../scd"
import type { IEDElement, InputExtRefElement, SCDQueries } from "../scd/scd-query"
import type { IEDElement, InputExtRefElement, InputExtRefElementWithDatSet, SCDQueries } from "../scd/scd-query"

/**
* The name is temporary, rename it if you have a better one
Expand Down Expand Up @@ -46,21 +46,28 @@ export class UCCommunicationInformation {
return baysWithIEDs
}

public IEDCommInfosByBus(): Map<string, IEDCommInfo[]> {
public IEDCommInfosBySubnetworkBus(): Map<string, IEDCommInfo[]> {
const ieds = this.IEDCommInfos()

const busesWithIEDs = new Map<string, IEDCommInfo[]>()
ieds.forEach((ied) => {
const busNames = this.scdQueries.getBusesByIEDName(ied.iedName)
const subnetworks = this.scdQueries.getSubnetworksByIEDName(ied.iedName)

busNames.forEach((busName) => {
subnetworks.forEach((subnetwork) => {
let setList: IEDCommInfo[] | undefined = []

if (!busesWithIEDs.has(busName))
busesWithIEDs.set(busName, [])
const subnetworkName = subnetwork.getAttribute("name")

if (subnetworkName !== null) {

if (!busesWithIEDs.has(subnetworkName))
busesWithIEDs.set(subnetworkName, [])

setList = busesWithIEDs.get(subnetworkName)
setList?.push(ied)

}

setList = busesWithIEDs.get(busName)
setList?.push(ied)
})
})

Expand All @@ -77,6 +84,8 @@ export class UCCommunicationInformation {
name: info.name,
targetIEDName: info.clientIEDName,
serviceType: MessageType.MMS,
serviceCbName: "MMS",
serviceDatSet: "not implemented yet",
})
}

Expand All @@ -95,7 +104,7 @@ export class UCCommunicationInformation {
* an therefore not compatible with Sampled Measured Values and MMS (ReportControls)
* So we deprecate this function and rewrite it in a more general way
*
* @deprecated
* deprecated
* @param ied
* @returns
*/
Expand Down Expand Up @@ -147,8 +156,21 @@ export class UCCommunicationInformation {
private findReceivedMessages(ied: IEDElement ): ReceivedMessage[] {
const inputs = this.scdQueries.searchInputs({ root: ied.element })
const extRefs = inputs.map(input => this.scdQueries.searchExtRef({ root: input.element })).flat()

const messages = groupInputExtRefElementsByIedNameServiceTypeAndSrcCBName(extRefs)

const extRefsWithConnectionID = extRefs.map((el) => {
const iedName = el.iedName
const srcCBName = el.srcCBName
const connection = this.scdQueries.searchGSEControlByIEDNameAndName(iedName, srcCBName)
const datSet = connection?.datSet

const newInput: InputExtRefElementWithDatSet = {
...el,
datSet: datSet,
}
return newInput
})

const messages = groupInputExtRefElementsByIedNameServiceTypeAndSrcCBName(extRefsWithConnectionID)

return messages
}
Expand All @@ -167,7 +189,6 @@ export class UCCommunicationInformation {
name: reportControl.name,
})
}

}

return controls
Expand Down Expand Up @@ -204,27 +225,30 @@ export type PublishedMessage_V2 = {
name: string
targetIEDName: string
serviceType: string
serviceDatSet: string
serviceCbName: string
}

export type ReceivedMessage = {
iedName: string // to show
serviceType: string // to filter
srcCBName: string // to show
data: InputExtRefElement[]
datSet: string // to show
data: InputExtRefElementWithDatSet[]
}


type TempKey = {iedName: string, serviceType: string, srcCBName: string}
type TempKey = {iedName: string, serviceType: string, srcCBName: string, datSet: string}
export function groupInputExtRefElementsByIedNameServiceTypeAndSrcCBName(
elements: InputExtRefElement[],
elements: InputExtRefElementWithDatSet[],
): ReceivedMessage[] {

const indexed: { [key: string]: {elements:InputExtRefElement[], key: TempKey} } = {}
const indexed: { [key: string]: {elements:InputExtRefElementWithDatSet[], key: TempKey} } = {}
for (const element of elements) {
if(element.iedName === ""){ continue }

const key = `${element.iedName}_${element.serviceType}_${element.srcCBName}`
const tempKey = {iedName: element.iedName, serviceType: element.serviceType, srcCBName: element.srcCBName}
const key = `${element.iedName}_${element.serviceType}_${element.srcCBName}_${element.datSet}`
const tempKey = {iedName: element.iedName, serviceType: element.serviceType, srcCBName: element.srcCBName, datSet: element.datSet}

if (!indexed[key]) {
indexed[key] = {elements: [], key: tempKey}
Expand All @@ -236,10 +260,10 @@ export function groupInputExtRefElementsByIedNameServiceTypeAndSrcCBName(
const grouped: ReceivedMessage[] = []

for (const obj of Object.values(indexed)) {
const {iedName, serviceType, srcCBName} = obj.key
const {iedName, serviceType, srcCBName, datSet} = obj.key

grouped.push({ iedName, serviceType, srcCBName, data: obj.elements })
grouped.push({ iedName, serviceType, srcCBName, datSet, data: obj.elements })
}

return grouped
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<script lang="ts">
import { Example } from "../../internal"
import { IEDAccordion } from "."
import type { IEDNode } from "../../diagram"
import type { ServiceObject } from "../../../plugins/communication-explorer/sidebar/ied-accordion"
const exampleValues: IEDNode[] | undefined = []
const exampleValues: ServiceObject[] | undefined = []
</script>

<Example name={"closed"}>
<div class="max-width-300px">
<IEDAccordion
color={"--color-message-goose"}
label={"Label of GOOSE ?Disc_QB1 / XSWI 1?"}
affectedIEDs={exampleValues}
serviceType={"Label of GOOSE ?Disc_QB1 / XSWI 1?"}
affectedIEDObjects={exampleValues}
/>
</div>
</Example>
Expand All @@ -21,8 +21,8 @@
<IEDAccordion
color={"--color-message-goose"}
open={true}
label={"Label of GOOSE ?Disc_QB1 / XSWI 1?"}
affectedIEDs={exampleValues}
serviceType={"Label of GOOSE ?Disc_QB1 / XSWI 1?"}
affectedIEDObjects={exampleValues}
/>
</div>
</Example>
Expand All @@ -32,8 +32,8 @@
<IEDAccordion
color={"--color-message-goose"}
open={true}
label={"Label of GOOSE ?Disc_QB1 / XSWI 1?"}
affectedIEDs={[]}
serviceType={"Label of GOOSE ?Disc_QB1 / XSWI 1?"}
affectedIEDObjects={[]}
/>
</div>
</Example>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
<script lang="ts">
import type { IEDNode } from "../../diagram"
import type { ServiceObject } from "../../../plugins/communication-explorer/sidebar/ied-accordion"
import IconArrowDropDown from "../../icons/icon-arrow-drop-down.svelte"
import Icons from "../../icons/icons.svelte"
export let open = false
export let label: string
export let affectedIEDs: IEDNode[] = []
export let serviceType: string
export let serviceLabel: string | undefined = ""
export let affectedIEDObjects: ServiceObject[] = []
export let color: string
$: affectedIEDs = affectedIEDObjects.map((el) => {
return el.node
})
</script>

<div class="accordion">
<div class="accordion" >
<details bind:open>
<summary style="border-color: var({color})" class="summary">
<div class="infoblock-headline">
{#if label === "GOOSE"}
{#if serviceType === "GOOSE"}
<Icons size={"normal"} name={"tscdGooseIcon"} />
{:else if label === "Sampled Values"}
{:else if serviceType === "Sampled Values"}
<Icons size={"normal"} name={"tscdSvIcon"} />
{:else if label === "MMS"}
{:else if serviceType === "MMS"}
<Icons size={"normal"} name={"tscdMmsIcon"} />
{:else if label === "Unknown"}
{:else if serviceType === "Unknown"}
<Icons size={"normal"} name={"unknownIcon"} />
{/if}
<span class="label">{label}</span>
<span class="label">{serviceType} - {serviceLabel}</span>
<div class="icon">
<IconArrowDropDown />
</div>
Expand All @@ -31,8 +36,8 @@
<div class="accordion-open">
<hr class="dashed-line" />
<div class="infomation-block">
<div>ID:</div>
<div>MessageType: {label}</div>
<div>Label: {serviceLabel}</div>
<div>MessageType: {serviceType}</div>
</div>

<hr class="seperation-line" />
Expand Down Expand Up @@ -63,9 +68,8 @@
.infoblock-headline {
display: flex;
align-items: center;
gap: 0.5rem;
gap: .5rem;
width: 100%;
.label {
flex-grow: 1;
}
Expand Down
18 changes: 11 additions & 7 deletions packages/uilib/src/lib/components/diagram/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,27 @@
]
iedInfos[0].received.push({
iedName: iedInfos[1].iedName,
iedName: iedInfos[1].iedName,
serviceType: "GOOSE",
srcCBName: "Dataset_1",
srcCBName: "Dataset_1",
data: [],
})
datSet: ""
})
iedInfos[2].received.push({
iedName: iedInfos[3].iedName,
iedName: iedInfos[3].iedName,
serviceType: "SMV",
srcCBName: "Dataset_1",
srcCBName: "Dataset_1",
data: [],
})
datSet: ""
})
iedInfos[4].published.push({
id: "1",
name: "name",
targetIEDName: iedInfos[5].iedName,
serviceType: "MMS",
})
serviceDatSet: "",
serviceCbName: ""
})
let rootNode: RootNode
$: {
Expand Down
Loading

0 comments on commit 52aa7d3

Please sign in to comment.