-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip * faster switching by allocating a new reducer queue * make mermaid part of parsers * recursive eventlogging * example of gantt * prettier * wip improv
- Loading branch information
Showing
24 changed files
with
532 additions
and
362 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 |
---|---|---|
|
@@ -3,6 +3,7 @@ build | |
install | ||
docs/html | ||
.vscode | ||
examples/flight/mermaid.html | ||
|
||
# Prerequisites | ||
*.d | ||
|
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 |
---|---|---|
@@ -1,12 +1,11 @@ | ||
#an app | ||
# an app | ||
find_package(spdlog REQUIRED) | ||
|
||
if(ASAN_BUILD AND NOT TSAN_BUILD) | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fsanitize=address,undefined -fno-omit-frame-pointer -O0") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fsanitize=address,undefined -fno-omit-frame-pointer -O0") | ||
elseif(TSAN_BUILD AND NOT ASAN_BUILD) | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fsanitize=thread -fno-omit-frame-pointer -O0") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fsanitize=thread -fno-omit-frame-pointer -O0") | ||
endif() | ||
|
||
add_executable(${PROJECT_NAME}_flight flight.cc) | ||
target_link_libraries(${PROJECT_NAME}_flight symmetri spdlog::spdlog) | ||
|
||
#install | ||
install(TARGETS ${PROJECT_NAME}_flight DESTINATION ${PROJECT_SOURCE_DIR}/install) |
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,22 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
</head> | ||
<body> | ||
<div id="gantt"> | ||
</div> | ||
<script src="https://code.jquery.com/jquery-3.7.0.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script> | ||
<script> | ||
$("#gantt").load("mermaid.html", function () { | ||
mermaid.initialize({ | ||
mermaid: { | ||
startOnLoad: false | ||
} | ||
}); | ||
window.mermaid.init(undefined, document.querySelectorAll('.mermaid')); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
Empty file.
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,54 @@ | ||
# Flight | ||
|
||
This is a little application that parses three Petri nets and uses multiple ways of composing to demonstrate the capabilities. It also demonstrates how to implement custom behavior for *fire*, *pause* and *cancel* using a user supplied class `Foo` in `transitions.hpp`. | ||
|
||
## installing | ||
|
||
You can build and install to a local `install`-directory: | ||
|
||
```bash | ||
mkdir build | ||
cd build | ||
cmake -DBUILD_EXAMPLES=ON -DBUILD_TESTING=OFF .. | ||
make | ||
``` | ||
|
||
You will also need a little local webserver if you want to visualize the Gantt-chart online. See below how it could look. In this example [live-server](https://github.com/tapio/live-server) is used because it has fancy hot reloading. | ||
|
||
You can run it like this: | ||
|
||
```bash | ||
live-server --port=8000 --open=./examples/flight/index.html --watch=./examples/flight & \ | ||
./build/examples/flight/symmetri_flight nets/PT1.pnml nets/PT2.pnml nets/PT3.pnml && \ | ||
fg | ||
``` | ||
|
||
And you should be able to watch [http://127.0.0.1:8000/examples/flight/](http://127.0.0.1:8000/examples/flight/) | ||
|
||
You can interact with the application through simple keys followed by an [enter] | ||
|
||
```bash | ||
input options: | ||
[p] - pause | ||
[r] - resume | ||
[x] - exit | ||
``` | ||
|
||
# Mermaid example | ||
|
||
```mermaid | ||
--- | ||
displayMode : compact | ||
--- | ||
gantt | ||
title A Gantt Diagram | ||
dateFormat x | ||
axisFormat %H:%M:%S | ||
section RootNet | ||
T0 :done, 2606109959,2606119999 | ||
T1 :done, 2606119999,2606125016 | ||
T2 :active, 2606125016,2606129933 | ||
section SubNet | ||
T0 :done, 2606109959,2606114979 | ||
T1 :done, 2606114980,2606119999 | ||
``` |
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
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
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,85 @@ | ||
#include <algorithm> | ||
#include <sstream> | ||
|
||
#include "symmetri/parsers.h" | ||
|
||
namespace symmetri { | ||
|
||
std::string mermaidFromEventlog(symmetri::Eventlog el) { | ||
auto now_timestamp = Clock::now(); | ||
el.erase(std::remove_if(el.begin(), el.end(), | ||
[](const auto &x) { | ||
return x.state == symmetri::State::Scheduled; | ||
}), | ||
el.end()); | ||
std::sort(el.begin(), el.end(), [](const auto &a, const auto &b) { | ||
if (a.case_id != b.case_id) { | ||
return a.case_id < b.case_id; | ||
} | ||
if (a.stamp != b.stamp) { | ||
return a.stamp < b.stamp; | ||
} | ||
if (a.transition != b.transition) { | ||
return a.transition < b.transition; | ||
} | ||
return false; | ||
}); | ||
|
||
if (el.empty()) { | ||
return ""; | ||
} | ||
|
||
std::stringstream mermaid; | ||
mermaid << "\n---\ndisplayMode : compact\n---\ngantt\ntitle A Gantt " | ||
"Diagram\ndateFormat x\naxisFormat \%H:\%M:\%S\n"; | ||
std::string current_section(""); | ||
for (auto it = el.begin(); std::next(it) != el.end(); it = std::next(it)) { | ||
const auto &start = *it; | ||
const auto &end = *std::next(it); | ||
auto id1 = start.case_id + start.transition; | ||
auto id2 = end.case_id + end.transition; | ||
if (start.state == symmetri::State::Started) { | ||
if (current_section != start.case_id) { | ||
current_section = start.case_id; | ||
mermaid << "section " << start.case_id << "\n"; | ||
} | ||
auto result = (end.state == symmetri::State::Error || | ||
end.state == symmetri::State::Deadlock) | ||
? "crit" | ||
: (end.state == symmetri::State::UserExit // Paused | ||
? "active" | ||
: "done"); // Completed | ||
|
||
mermaid | ||
<< start.transition << " :" << (id1 == id2 ? result : "active") | ||
<< ", " | ||
<< std::chrono::duration_cast<std::chrono::milliseconds>( | ||
start.stamp.time_since_epoch()) | ||
.count() | ||
<< ',' | ||
<< std::chrono::duration_cast<std::chrono::milliseconds>( | ||
(id1 == id2 ? end.stamp : now_timestamp).time_since_epoch()) | ||
.count() | ||
<< '\n'; | ||
} | ||
} | ||
|
||
// and check if the latest is an active transition | ||
const auto &start = el.back(); | ||
if (start.state == symmetri::State::Started) { | ||
mermaid << start.transition << " :" | ||
<< "active" | ||
<< ", " | ||
<< std::chrono::duration_cast<std::chrono::milliseconds>( | ||
start.stamp.time_since_epoch()) | ||
.count() | ||
<< ',' | ||
<< std::chrono::duration_cast<std::chrono::milliseconds>( | ||
now_timestamp.time_since_epoch()) | ||
.count() | ||
<< '\n'; | ||
} | ||
|
||
return mermaid.str(); | ||
} | ||
} // namespace symmetri |
Oops, something went wrong.