Skip to content

Commit

Permalink
+ timestamp for peak save corrected
Browse files Browse the repository at this point in the history
+ reset peak simulation after save
  • Loading branch information
chrxh committed Nov 3, 2024
1 parent 04e604a commit de6899f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 23 deletions.
39 changes: 22 additions & 17 deletions source/Gui/AutosaveWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ void AutosaveWindow::processSettings()
_lastAutosaveTimepoint = std::chrono::steady_clock::now();
}
}
AlienImGui::Switcher(
if (AlienImGui::Switcher(
AlienImGui::SwitcherParameters()
.name("Catch peak")
.textWidth(RightColumnWidth)
Expand All @@ -238,7 +238,9 @@ void AutosaveWindow::processSettings()
"None",
"Genome complexity variance",
}),
_catchPeak);
_catchPeak)) {
_peakDeserializedSimulation->setDeserializedSimulation(DeserializedSimulation());
}

if (AlienImGui::InputText(
AlienImGui::InputTextParameters().name("Directory").textWidth(RightColumnWidth).defaultValue(_origDirectory).folderButton(true),
Expand Down Expand Up @@ -285,7 +287,7 @@ void AutosaveWindow::onCreateSavepoint(bool usePeakSimulation)
}

PersisterRequestId requestId;
if (usePeakSimulation) {
if (usePeakSimulation && !_peakDeserializedSimulation->isEmpty()) {
auto senderInfo = SenderInfo{.senderId = SenderId{AutosaveSenderId}, .wishResultData = true, .wishErrorInfo = true};
auto saveData = SaveDeserializedSimulationRequestData{
.filename = _directory, .sharedDeserializedSimulation = _peakDeserializedSimulation, .generateNameFromTimestep = true};
Expand Down Expand Up @@ -337,20 +339,22 @@ void AutosaveWindow::processAutomaticSavepoints()
_lastAutosaveTimepoint = std::chrono::steady_clock::now();
}

auto minSinceLastCatchPeak = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::steady_clock::now() - _lastPeakTimepoint).count();
if (minSinceLastCatchPeak >= 60) {
_peakProcessor->executeTask(
[&](auto const& senderId) {
return _persisterFacade->scheduleGetPeakSimulation(
SenderInfo{.senderId = senderId, .wishResultData = false, .wishErrorInfo = true},
GetPeakSimulationRequestData{
.peakDeserializedSimulation = _peakDeserializedSimulation,
.zoom = Viewport::get().getZoomFactor(),
.center = Viewport::get().getCenterInWorldPos()});
},
[&](auto const& requestId) {},
[](auto const& errors) { GenericMessageDialog::get().information("Error", errors); });
_lastPeakTimepoint = std::chrono::steady_clock::now();
if (_catchPeak != CatchPeak_None) {
auto minSinceLastCatchPeak = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::steady_clock::now() - _lastPeakTimepoint).count();
if (minSinceLastCatchPeak >= 30) {
_peakProcessor->executeTask(
[&](auto const& senderId) {
return _persisterFacade->scheduleGetPeakSimulation(
SenderInfo{.senderId = senderId, .wishResultData = false, .wishErrorInfo = true},
GetPeakSimulationRequestData{
.peakDeserializedSimulation = _peakDeserializedSimulation,
.zoom = Viewport::get().getZoomFactor(),
.center = Viewport::get().getCenterInWorldPos()});
},
[&](auto const& requestId) {},
[](auto const& errors) { GenericMessageDialog::get().information("Error", errors); });
_lastPeakTimepoint = std::chrono::steady_clock::now();
}
}
}

Expand Down Expand Up @@ -414,6 +418,7 @@ void AutosaveWindow::updateSavepoint(int row)
newEntry->timestamp = StringHelper::format(data.timestamp);
newEntry->name = data.projectName;
newEntry->filename = data.filename;
_peakDeserializedSimulation->setDeserializedSimulation(DeserializedSimulation());
}
}
if (requestState.value() == PersisterRequestState::Error) {
Expand Down
7 changes: 3 additions & 4 deletions source/PersisterImpl/PersisterWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ _PersisterWorker::PersisterRequestResultOrError _PersisterWorker::processRequest
deserializedSimulation.auxiliaryData.simulationParameters = _simulationFacade->getSimulationParameters();
deserializedSimulation.auxiliaryData.timestep = static_cast<uint32_t>(_simulationFacade->getCurrentTimestep());
deserializedSimulation.mainData = _simulationFacade->getClusteredSimulationData();
requestData.peakDeserializedSimulation->set(std::move(deserializedSimulation));
requestData.peakDeserializedSimulation->setDeserializedSimulation(std::move(deserializedSimulation));
}
return std::make_shared<_GetPeakSimulationRequestResult>(request->getRequestId(), GetPeakSimulationResultData());
} catch (...) {
Expand All @@ -657,8 +657,7 @@ _PersisterWorker::PersisterRequestResultOrError _PersisterWorker::processRequest

auto const& requestData = request->getData();

auto timestamp = std::chrono::system_clock::now();
auto deserializedData = requestData.sharedDeserializedSimulation->get();
auto deserializedData = requestData.sharedDeserializedSimulation->getDeserializedSimulation();

auto filename = requestData.filename;
if (requestData.generateNameFromTimestep) {
Expand All @@ -674,7 +673,7 @@ _PersisterWorker::PersisterRequestResultOrError _PersisterWorker::processRequest
.filename = filename,
.projectName = deserializedData.auxiliaryData.simulationParameters.projectName,
.timestep = deserializedData.auxiliaryData.timestep,
.timestamp = timestamp});
.timestamp = requestData.sharedDeserializedSimulation->getTimestamp()});
} catch (...) {
return std::make_shared<_PersisterRequestError>(
request->getRequestId(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#pragma once

#include <filesystem>
#include <chrono>

struct SaveDeserializedSimulationResultData
{
std::filesystem::path filename;
Expand Down
19 changes: 17 additions & 2 deletions source/PersisterInterface/SharedDeserializedSimulation.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <mutex>
#include <chrono>

#include "DeserializedSimulation.h"

Expand All @@ -16,20 +17,34 @@ class _SharedDeserializedSimulation
return _deserializedSimulation.statistics.back();
}

void set(DeserializedSimulation&& value)
void setDeserializedSimulation(DeserializedSimulation&& value)
{
std::lock_guard lock(_mutex);
_deserializedSimulation = std::move(value);
_timestamp = std::chrono::system_clock::now();
}

DeserializedSimulation get() const
DeserializedSimulation getDeserializedSimulation() const
{
std::lock_guard lock(_mutex);
return _deserializedSimulation;
}

std::chrono::system_clock::time_point getTimestamp() const
{
std::lock_guard lock(_mutex);
return _timestamp;
}

bool isEmpty() const
{
std::lock_guard lock(_mutex);
return _deserializedSimulation.mainData.isEmpty();
}

private:
mutable std::mutex _mutex;
DeserializedSimulation _deserializedSimulation;
std::chrono::system_clock::time_point _timestamp;
};
using SharedDeserializedSimulation = std::shared_ptr<_SharedDeserializedSimulation>;

0 comments on commit de6899f

Please sign in to comment.