-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Demo 1. In one console: ``` scripts/play.sh -i data/scenarios/Challenges/bridge-building.yaml ``` 2. In another console: ``` scripts/gen/goals-graph.sh ``` 3. View `goals.svg`: ![goals](https://github.com/user-attachments/assets/d6114c27-fde2-41ce-8c65-c52d3a9707de)
- Loading branch information
Showing
4 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash -ex | ||
|
||
cd $(git rev-parse --show-toplevel) | ||
|
||
curl -s http://localhost:5357/goals/render | dot -Tsvg -o goals.svg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
-- | | ||
-- SPDX-License-Identifier: BSD-3-Clause | ||
module Swarm.Web.GraphRender where | ||
|
||
import Control.Lens ((^.), (^..)) | ||
import Data.Map qualified as M | ||
import Data.Maybe (fromMaybe) | ||
import Data.Text qualified as T | ||
import Swarm.Game.Scenario.Objective | ||
import Swarm.Game.Scenario.Objective.Graph | ||
import Text.Dot | ||
|
||
renderGoalsGraph :: ObjectiveCompletion -> String | ||
renderGoalsGraph oc = | ||
showDot nlg | ||
where | ||
edgeLookup = M.fromList $ map (\x@(_, b, _) -> (b, x)) edges | ||
nlg = | ||
netlistGraph | ||
(\k -> maybe mempty (\(a, _, _) -> [("label", T.unpack $ fromMaybe "<?>" $ a ^. objectiveId)]) $ M.lookup k edgeLookup) | ||
(\k -> maybe mempty (\(_, _, c) -> c) $ M.lookup k edgeLookup) | ||
([(a, a) | (_, a, _) <- edges]) | ||
|
||
edges = makeGraphEdges objs | ||
objs = oc ^.. allObjectives |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters