Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions pocs/petrinaut-hazel/src/main/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,19 @@ const isValidNetDefinition = (
/**
* Converts SimulationState to a 2D array format.
* Each step becomes an array of objects with placeId, marking, and placeLabel.
*
* Marking is also converted to a representation of an association list.
*/
const simulationStateTo2DArray = (
const simulationStateToHazelFormat = (
simulationState: SimulationState,
): HazelSimulationState => {
return simulationState.map((step) => {
return Object.entries(step).map(([placeId, { marking, placeLabel }]) => ({
placeId,
marking,
marking: Object.entries(marking).map(([tokenId, count]) => ({
0: tokenId,
1: count,
})),
placeLabel,
}));
});
Expand All @@ -77,7 +82,7 @@ const convertSimulationStateForHazel = (
return undefined;
}

return simulationStateTo2DArray(simulationState);
return simulationStateToHazelFormat(simulationState);
};

/**
Expand All @@ -95,8 +100,6 @@ export const App = () => {
id,
codec: "json",
onInit: (value) => {
console.log("Received value", value);

try {
const parsedValue = JSON.parse(value);

Expand All @@ -123,7 +126,6 @@ export const App = () => {

const reportSimulationState = useCallback(
(simulationState: SimulationState) => {
console.log("Simulation state reported");
setSimulationState(simulationState);

setSyntax({
Expand Down
14 changes: 9 additions & 5 deletions pocs/petrinaut-hazel/src/main/app/use-hazel-integration.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import type {
PetriNetDefinitionObject,
TokenCounts,
} from "@hashintel/petrinaut";
import type { PetriNetDefinitionObject } from "@hashintel/petrinaut";
import { useCallback, useEffect, useState } from "react";

export type MessageToHazel =
Expand Down Expand Up @@ -40,7 +37,14 @@ type HazelIntegrationConfig = {
};

export type HazelSimulationState = Array<
Array<{ placeId: string; marking: TokenCounts; placeLabel: string }>
Array<{
placeId: string;
/**
* Marking represented as a association list where the tokenId is the key and the count is the value, represented in the format Hazel expects.
*/
marking: Array<{ 0: string; 1: number }>;
placeLabel: string;
}>
>;

export type HazelValue = {
Expand Down