Skip to content

Commit

Permalink
+ catch peaks based on current raw statistics
Browse files Browse the repository at this point in the history
+ allow to load savepoints via load button
  • Loading branch information
chrxh committed Nov 4, 2024
1 parent de6899f commit 45fd846
Show file tree
Hide file tree
Showing 16 changed files with 188 additions and 95 deletions.
10 changes: 9 additions & 1 deletion source/EngineInterface/RawStatisticsData.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "EngineInterface/EngineConstants.h"
#include "EngineInterface/Colors.h"


struct TimestepStatistics
{
ColorVector<int> numCells = {0, 0, 0, 0, 0, 0, 0};
Expand Down Expand Up @@ -55,3 +54,12 @@ struct RawStatisticsData
TimelineStatistics timeline;
HistogramData histogram;
};

inline double sumColorVector(ColorVector<double> const& v)
{
auto result = 0.0;
for (int i = 0; i < MAX_COLORS; ++i) {
result += v[i];
}
return result;
};
30 changes: 30 additions & 0 deletions source/Gui/AlienImGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,10 @@ bool AlienImGui::Combo(ComboParameters& parameters, int& value, bool* enabled)
items[i] = parameters._values[i].c_str();
}

if (parameters._disabled) {
ImGui::BeginDisabled();
}

if (enabled) {
ImGui::Checkbox(("##checkbox" + parameters._name).c_str(), enabled);
ImGui::BeginDisabled(!(*enabled));
Expand Down Expand Up @@ -479,6 +483,10 @@ bool AlienImGui::Combo(ComboParameters& parameters, int& value, bool* enabled)
ImGui::EndDisabled();
}

if (parameters._disabled) {
ImGui::EndDisabled();
}

if (parameters._tooltip) {
AlienImGui::HelpMarker(*parameters._tooltip);
}
Expand All @@ -491,6 +499,10 @@ bool AlienImGui::Switcher(SwitcherParameters& parameters, int& value, bool* enab
{
ImGui::PushID(parameters._name.c_str());

if (parameters._disabled) {
ImGui::BeginDisabled();
}

//enable button
if (enabled) {
ImGui::Checkbox("##checkbox", enabled);
Expand Down Expand Up @@ -542,6 +554,9 @@ bool AlienImGui::Switcher(SwitcherParameters& parameters, int& value, bool* enab
if (enabled) {
ImGui::EndDisabled();
}
if (parameters._disabled) {
ImGui::EndDisabled();
}

if (parameters._tooltip) {
AlienImGui::HelpMarker(*parameters._tooltip);
Expand Down Expand Up @@ -1174,6 +1189,21 @@ bool AlienImGui::Button(ButtonParameters const& parameters)
return result;
}

bool AlienImGui::ActionButton(ActionButtonParameters const& parameters)
{
ImGui::PushStyleColor(ImGuiCol_Text, Const::ActionButtonTextColor.Value);
ImGui::PushStyleColor(ImGuiCol_Button, Const::ActionButtonBackgroundColor.Value);
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, Const::ActionButtonHoveredColor.Value);
auto result = ImGui::Button(parameters._buttonText.c_str());
ImGui::PopStyleColor(3);

if (parameters._tooltip) {
AlienImGui::HelpMarker(*parameters._tooltip);
}

return result;
}

void AlienImGui::Spinner(SpinnerParameters const& parameters)
{
static std::optional<std::chrono::steady_clock::time_point> spinnerRefTimepoint;
Expand Down
9 changes: 9 additions & 0 deletions source/Gui/AlienImGui.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ class AlienImGui
{
MEMBER_DECLARATION(ComboParameters, std::string, name, "");
MEMBER_DECLARATION(ComboParameters, float, textWidth, 100);
MEMBER_DECLARATION(ComboParameters, bool, disabled, false);
MEMBER_DECLARATION(ComboParameters, std::optional<int>, defaultValue, std::nullopt);
MEMBER_DECLARATION(ComboParameters, std::vector<std::string>, values, std::vector<std::string>());
MEMBER_DECLARATION(ComboParameters, std::optional<std::string>, tooltip, std::nullopt);
Expand All @@ -190,6 +191,7 @@ class AlienImGui
MEMBER_DECLARATION(SwitcherParameters, std::string, name, "");
MEMBER_DECLARATION(SwitcherParameters, float, width, 0);
MEMBER_DECLARATION(SwitcherParameters, float, textWidth, 100);
MEMBER_DECLARATION(SwitcherParameters, bool, disabled, false);
MEMBER_DECLARATION(SwitcherParameters, std::optional<int>, defaultValue, std::nullopt);
MEMBER_DECLARATION(SwitcherParameters, std::vector<std::string>, values, std::vector<std::string>());
MEMBER_DECLARATION(SwitcherParameters, std::optional<std::string>, tooltip, std::nullopt);
Expand Down Expand Up @@ -311,6 +313,13 @@ class AlienImGui
};
static bool Button(ButtonParameters const& parameters);

struct ActionButtonParameters
{
MEMBER_DECLARATION(ActionButtonParameters, std::string, buttonText, "");
MEMBER_DECLARATION(ActionButtonParameters, std::optional<std::string>, tooltip, std::nullopt);
};
static bool ActionButton(ActionButtonParameters const& parameters);

struct SpinnerParameters
{
MEMBER_DECLARATION(SpinnerParameters, RealVector2D, pos, RealVector2D());
Expand Down
64 changes: 45 additions & 19 deletions source/Gui/AutosaveWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
#include "Base/StringHelper.h"
#include "PersisterInterface/SavepointTableService.h"
#include "PersisterInterface/SerializerService.h"
#include "PersisterInterface/TaskProcessor.h"

#include "AlienImGui.h"
#include "FileTransferController.h"
#include "GenericMessageDialog.h"
#include "OverlayController.h"
#include "StyleRepository.h"
#include "Viewport.h"
#include "PersisterInterface/TaskProcessor.h"

namespace
{
Expand Down Expand Up @@ -46,8 +47,8 @@ void AutosaveWindow::initIntern(SimulationFacade simulationFacade, PersisterFaca
_origDirectory = GlobalSettings::get().getValue("windows.autosave.directory", (std::filesystem::current_path() / Const::BasePath).string());
_directory = _origDirectory;

_origCatchPeak = GlobalSettings::get().getValue("windows.autosave.catch peak", _origCatchPeak);
_catchPeak = _origCatchPeak;
_origCatchPeaks = GlobalSettings::get().getValue("windows.autosave.catch peaks", _origCatchPeaks);
_catchPeaks = _origCatchPeaks;

_lastAutosaveTimepoint = std::chrono::steady_clock::now();
_lastPeakTimepoint = std::chrono::steady_clock::now();
Expand All @@ -66,7 +67,7 @@ void AutosaveWindow::shutdownIntern()
GlobalSettings::get().setValue("windows.autosave.mode", _saveMode);
GlobalSettings::get().setValue("windows.autosave.number of files", _numberOfFiles);
GlobalSettings::get().setValue("windows.autosave.directory", _directory);
GlobalSettings::get().setValue("windows.autosave.catch peak", _origCatchPeak);
GlobalSettings::get().setValue("windows.autosave.catch peaks", _catchPeaks);
}

void AutosaveWindow::processIntern()
Expand Down Expand Up @@ -122,7 +123,7 @@ void AutosaveWindow::processToolbar()
ImGui::EndDisabled();

ImGui::SameLine();
ImGui::BeginDisabled(_savepointTable->isEmpty());
ImGui::BeginDisabled(!_savepointTable.has_value() || _savepointTable->isEmpty());
if (AlienImGui::ToolbarButton(ICON_FA_BROOM)) {
GenericMessageDialog::get().yesNo("Delete", "Do you really want to delete the all savepoints?", [&]() { scheduleCleanup(); });
}
Expand All @@ -146,14 +147,13 @@ void AutosaveWindow::processTable()
| ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_NoBordersInBody | ImGuiTableFlags_ScrollY | ImGuiTableFlags_ScrollX;

if (ImGui::BeginTable("Save files", 4, flags, ImVec2(0, 0), 0.0f)) {
ImGui::TableSetupColumn("No", ImGuiTableColumnFlags_NoSort | ImGuiTableColumnFlags_WidthFixed, scale(30.0f));
ImGui::TableSetupColumn("Simulation", ImGuiTableColumnFlags_NoSort | ImGuiTableColumnFlags_WidthFixed, scale(140.0f));
ImGui::TableSetupColumn("Timestamp", ImGuiTableColumnFlags_NoSort | ImGuiTableColumnFlags_WidthFixed, scale(140.0f));
ImGui::TableSetupColumn("Project name", ImGuiTableColumnFlags_NoSort | ImGuiTableColumnFlags_WidthFixed, scale(200.0f));
ImGui::TableSetupColumn("Time step", ImGuiTableColumnFlags_DefaultSort | ImGuiTableColumnFlags_WidthFixed, scale(100.0f));
ImGui::TableSetupColumn("Peak value", ImGuiTableColumnFlags_DefaultSort | ImGuiTableColumnFlags_WidthFixed, scale(200.0f));
ImGui::TableSetupScrollFreeze(0, 1);
ImGui::TableHeadersRow();

auto sequenceNumberAtFrom = _savepointTable->getSequenceNumber();
ImGuiListClipper clipper;
clipper.Begin(_savepointTable->getSize());
while (clipper.Step()) {
Expand All @@ -164,8 +164,18 @@ void AutosaveWindow::processTable()
ImGui::PushID(row);
ImGui::TableNextRow(0, scale(ImGui::GetTextLineHeightWithSpacing()));

// project name
ImGui::TableNextColumn();
AlienImGui::Text(std::to_string(sequenceNumberAtFrom - row));
if (entry->state == SavepointState_Persisted) {
auto triggerLoadSavepoint = AlienImGui::ActionButton(AlienImGui::ActionButtonParameters().buttonText(ICON_FA_DOWNLOAD));
AlienImGui::Tooltip("Load savepoint", false);
if (triggerLoadSavepoint) {
onLoadSavepoint(entry);
}

ImGui::SameLine();
AlienImGui::Text(entry->name);
}

ImGui::SameLine();
auto selected = _selectedEntry == entry;
Expand All @@ -177,6 +187,7 @@ void AutosaveWindow::processTable()
_selectedEntry = selected ? entry : nullptr;
}

// timestamp
ImGui::TableNextColumn();
if (entry->state == SavepointState_InQueue) {
AlienImGui::Text("In queue");
Expand All @@ -191,14 +202,21 @@ void AutosaveWindow::processTable()
AlienImGui::Text("Error");
}

// timestep
ImGui::TableNextColumn();
if (entry->state == SavepointState_Persisted) {
AlienImGui::Text(entry->name);
AlienImGui::Text(StringHelper::format(entry->timestep));
}

// peak
ImGui::TableNextColumn();
if (entry->state == SavepointState_Persisted) {
AlienImGui::Text(StringHelper::format(entry->timestep));
AlienImGui::Text(entry->peak);

if (!entry->peakType.empty()) {
ImGui::SameLine();
ImGui::PushStyleColor(ImGuiCol_Text, Const::BrowserResourcePropertiesTextColor.Value);
AlienImGui::Text(" (" + entry->peakType + ")");
ImGui::PopStyleColor();
}

ImGui::PopID();
Expand Down Expand Up @@ -229,16 +247,17 @@ void AutosaveWindow::processSettings()
_lastAutosaveTimepoint = std::chrono::steady_clock::now();
}
}
if (AlienImGui::Switcher(
AlienImGui::SwitcherParameters()
.name("Catch peak")
if (AlienImGui::Combo(
AlienImGui::ComboParameters()
.name("Catch peaks")
.textWidth(RightColumnWidth)
.defaultValue(_origCatchPeak)
.defaultValue(_origCatchPeaks)
.disabled(!_autosaveEnabled)
.values({
"None",
"Genome complexity variance",
}),
_catchPeak)) {
_catchPeaks)) {
_peakDeserializedSimulation->setDeserializedSimulation(DeserializedSimulation());
}

Expand Down Expand Up @@ -316,6 +335,11 @@ void AutosaveWindow::onDeleteSavepoint(SavepointEntry const& entry)
_selectedEntry.reset();
}

void AutosaveWindow::onLoadSavepoint(SavepointEntry const& entry)
{
FileTransferController::get().onOpenSimulation(entry->filename);
}

void AutosaveWindow::processCleanup()
{
if (_scheduleCleanup) {
Expand All @@ -335,11 +359,11 @@ void AutosaveWindow::processAutomaticSavepoints()

auto minSinceLastAutosave = std::chrono::duration_cast<std::chrono::minutes>(std::chrono::steady_clock::now() - _lastAutosaveTimepoint).count();
if (minSinceLastAutosave >= _autosaveInterval) {
onCreateSavepoint(_catchPeak != CatchPeak_None);
onCreateSavepoint(_catchPeaks != CatchPeaks_None);
_lastAutosaveTimepoint = std::chrono::steady_clock::now();
}

if (_catchPeak != CatchPeak_None) {
if (_catchPeaks != CatchPeaks_None) {
auto minSinceLastCatchPeak = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::steady_clock::now() - _lastPeakTimepoint).count();
if (minSinceLastCatchPeak >= 30) {
_peakProcessor->executeTask(
Expand Down Expand Up @@ -418,6 +442,8 @@ void AutosaveWindow::updateSavepoint(int row)
newEntry->timestamp = StringHelper::format(data.timestamp);
newEntry->name = data.projectName;
newEntry->filename = data.filename;
newEntry->peak = StringHelper::format(toFloat(sumColorVector(data.rawStatisticsData.timeline.timestep.genomeComplexityVariance)), 2);
newEntry->peakType = "genome complexity variance";
_peakDeserializedSimulation->setDeserializedSimulation(DeserializedSimulation());
}
}
Expand Down
13 changes: 7 additions & 6 deletions source/Gui/AutosaveWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class AutosaveWindow : public AlienWindow<SimulationFacade, PersisterFacade>

void onCreateSavepoint(bool usePeakSimulation);
void onDeleteSavepoint(SavepointEntry const& entry);
void onLoadSavepoint(SavepointEntry const& entry);

void scheduleDeleteNonPersistentSavepoint(std::vector<SavepointEntry> const& entries);
void processDeleteNonPersistentSavepoint();
Expand Down Expand Up @@ -74,14 +75,14 @@ class AutosaveWindow : public AlienWindow<SimulationFacade, PersisterFacade>

std::chrono::steady_clock::time_point _lastAutosaveTimepoint;

using CatchPeak = int;
enum CatchPeak_
using CatchPeaks = int;
enum CatchPeaks_
{
CatchPeak_None,
CatchPeak_Variance
CatchPeaks_None,
CatchPeaks_Variance
};
CatchPeak _origCatchPeak = CatchPeak_None;
CatchPeak _catchPeak = _origCatchPeak;
CatchPeaks _origCatchPeaks = CatchPeaks_None;
CatchPeaks _catchPeaks = _origCatchPeaks;
std::chrono::steady_clock::time_point _lastPeakTimepoint;
TaskProcessor _peakProcessor;
SharedDeserializedSimulation _peakDeserializedSimulation;
Expand Down
11 changes: 4 additions & 7 deletions source/Gui/BrowserWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -817,9 +817,8 @@ void BrowserWindow::processReactionList(NetworkResourceTreeTO const& treeTO)
{
if (treeTO->isLeaf()) {
auto& leaf = treeTO->getLeaf();
ImGui::PushStyleColor(ImGuiCol_Text, (ImU32)Const::BrowserDownloadButtonTextColor);
auto isAddReaction = processActionButton(ICON_FA_PLUS);
ImGui::PopStyleColor();

auto isAddReaction = AlienImGui::ActionButton(AlienImGui::ActionButtonParameters().buttonText(ICON_FA_PLUS));
AlienImGui::Tooltip("Add a reaction", false);
if (isAddReaction) {
_activateEmojiPopup = true;
Expand Down Expand Up @@ -1115,11 +1114,9 @@ void BrowserWindow::processEmojiButton(int emojiType)

void BrowserWindow::processDownloadButton(BrowserLeaf const& leaf)
{
ImGui::PushStyleColor(ImGuiCol_Text, (ImU32)Const::BrowserDownloadButtonTextColor);
auto downloadButtonResult = processActionButton(ICON_FA_DOWNLOAD);
auto isDownload = AlienImGui::ActionButton(AlienImGui::ActionButtonParameters().buttonText(ICON_FA_DOWNLOAD));
AlienImGui::Tooltip("Download", false);
ImGui::PopStyleColor();
if (downloadButtonResult) {
if (isDownload) {
onDownloadResource(leaf);
}
}
Expand Down
Loading

0 comments on commit 45fd846

Please sign in to comment.