Skip to content

Commit 8b63371

Browse files
committed
Bugfix: coil code import from json
1 parent b8e1b14 commit 8b63371

File tree

4 files changed

+97
-9
lines changed

4 files changed

+97
-9
lines changed

src/dsf/mobility/RoadNetwork.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,16 @@ namespace dsf::mobility {
247247
name,
248248
geometry));
249249
// Check if there is coilcode property
250-
if (!edge_properties.at_key("coilcode").error() &&
251-
edge_properties["coilcode"].has_value()) {
252-
if (edge_properties["coilcode"].is_string()) {
253-
std::string strCoilCode{edge_properties["coilcode"].get_string().value()};
250+
if (!edge_properties.at_key("coilcode").error()) {
251+
auto const& epCoilCode = edge_properties["coilcode"];
252+
if (epCoilCode.is_string()) {
253+
std::string strCoilCode{epCoilCode.get_string().value()};
254254
addCoil(edge_id, strCoilCode);
255-
} else if (edge_properties["coilcode"].is_number()) {
256-
std::string strCoilCode =
257-
std::to_string(edge_properties["coilcode"].get_uint64());
255+
} else if (epCoilCode.is_uint64()) {
256+
std::string strCoilCode = std::to_string(epCoilCode.get_uint64());
257+
addCoil(edge_id, strCoilCode);
258+
} else if (epCoilCode.is_int64()) {
259+
std::string strCoilCode = std::to_string(epCoilCode.get_int64());
258260
addCoil(edge_id, strCoilCode);
259261
} else {
260262
spdlog::warn("Invalid coilcode for edge {}, adding default", edge_id);

webapp/index.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,13 @@
5454

5555
<!-- Slider for time step -->
5656
<div class="slider-container">
57-
<!-- <label for="timeSlider">TimeStamp</label> -->
57+
<div class="slider-controls">
58+
<button id="playBtn" title="Play/Pause"></button>
59+
<div class="fps-control">
60+
<label for="fpsInput">FPS:</label>
61+
<input type="number" id="fpsInput" value="10" min="1" max="60" />
62+
</div>
63+
</div>
5864
<input type="range" id="timeSlider" min="0" step="300" value="0" />
5965
<span id="timeLabel">N/A</span>
6066
</div>

webapp/script.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,12 @@ loadDataBtn.addEventListener('click', async function() {
658658
// Set up the time slider based on the density data's maximum time value
659659
const timeSlider = document.getElementById('timeSlider');
660660
const timeLabel = document.getElementById('timeLabel');
661+
const playBtn = document.getElementById('playBtn');
662+
const fpsInput = document.getElementById('fpsInput');
663+
664+
let isPlaying = false;
665+
let playInterval = null;
666+
661667
// Dynamically determine dt from the first two density datapoints
662668
let dt = 300;
663669
if (densities.length > 1) {
@@ -668,6 +674,44 @@ loadDataBtn.addEventListener('click', async function() {
668674
timeSlider.step = dt;
669675
timeLabel.textContent = `${formatTime(timeStamp)}`;
670676

677+
function togglePlay() {
678+
isPlaying = !isPlaying;
679+
playBtn.textContent = isPlaying ? '⏸' : '▶';
680+
681+
if (isPlaying) {
682+
const fps = parseInt(fpsInput.value) || 10;
683+
const interval = 1000 / fps;
684+
685+
playInterval = setInterval(() => {
686+
let currentValue = parseInt(timeSlider.value);
687+
let maxValue = parseInt(timeSlider.max);
688+
689+
if (currentValue >= maxValue) {
690+
currentValue = 0; // Loop back to start
691+
} else {
692+
currentValue += dt;
693+
}
694+
695+
timeSlider.value = currentValue;
696+
// Trigger input event manually
697+
timeSlider.dispatchEvent(new Event('input'));
698+
}, interval);
699+
} else {
700+
clearInterval(playInterval);
701+
playInterval = null;
702+
}
703+
}
704+
705+
playBtn.addEventListener('click', togglePlay);
706+
707+
fpsInput.addEventListener('change', () => {
708+
if (isPlaying) {
709+
// Restart with new FPS
710+
togglePlay(); // Stop
711+
togglePlay(); // Start
712+
}
713+
});
714+
671715
// Update the visualization when the slider value changes
672716
timeSlider.addEventListener('input', function() {
673717
const index = Math.floor(parseInt(timeSlider.value) / dt);

webapp/styles.css

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,40 @@ body, html {
183183
.settings button:hover {
184184
background: #e8e8e8;
185185
}
186-
186+
187+
.slider-controls {
188+
display: flex;
189+
align-items: center;
190+
justify-content: space-between;
191+
margin-bottom: 5px;
192+
}
193+
194+
#playBtn {
195+
background: none;
196+
border: 1px solid #ccc;
197+
border-radius: 4px;
198+
cursor: pointer;
199+
font-size: 16px;
200+
padding: 2px 8px;
201+
width: 30px;
202+
height: 30px;
203+
display: flex;
204+
align-items: center;
205+
justify-content: center;
206+
}
207+
208+
#playBtn:hover {
209+
background: #f0f0f0;
210+
}
211+
212+
.fps-control {
213+
display: flex;
214+
align-items: center;
215+
font-size: 12px;
216+
}
217+
218+
.fps-control input {
219+
width: 40px;
220+
margin-left: 5px;
221+
padding: 2px;
222+
}

0 commit comments

Comments
 (0)