From 4c5cf2503ed1bd1e6632afa3f0fbe27360c18de8 Mon Sep 17 00:00:00 2001 From: jeefo Date: Fri, 31 Jan 2025 20:40:08 +0300 Subject: [PATCH] ctrl: allow to erasing training data leaving graph files --- inc/control.h | 1 + inc/storage.h | 2 +- src/control.cpp | 12 +++++++++++- src/storage.cpp | 13 +++++++++++-- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/inc/control.h b/inc/control.h index 8e873d2..b404160 100644 --- a/inc/control.h +++ b/inc/control.h @@ -118,6 +118,7 @@ private: int cmdNodeSave (); int cmdNodeLoad (); int cmdNodeErase (); + int cmdNodeEraseTraining (); int cmdNodeDelete (); int cmdNodeCheck (); int cmdNodeCache (); diff --git a/inc/storage.h b/inc/storage.h index dc98c48..42cf521 100644 --- a/inc/storage.h +++ b/inc/storage.h @@ -88,7 +88,7 @@ public: int32_t storageToBotFile (int32_t options); // remove all bot related files from disk - void unlinkFromDisk (); + void unlinkFromDisk (bool onlyTrainingData); public: // loading the graph may attempt to recurse loading, with converting or download, reset retry counter diff --git a/src/control.cpp b/src/control.cpp index bd1f868..5723fce 100644 --- a/src/control.cpp +++ b/src/control.cpp @@ -355,6 +355,7 @@ int BotControl::cmdNode () { "load", "help", "erase", + "erase_training", "fileinfo", "check" }; @@ -399,6 +400,7 @@ int BotControl::cmdNode () { addGraphCmd ("save", "save [noarguments]", "Save graph file to disk.", &BotControl::cmdNodeSave); addGraphCmd ("load", "load [noarguments]", "Load graph file from disk.", &BotControl::cmdNodeLoad); addGraphCmd ("erase", "erase [iamsure]", "Erases the graph file from disk.", &BotControl::cmdNodeErase); + addGraphCmd ("erase_training", "erase_training", "Erases the training data leaving graph files.", &BotControl::cmdNodeEraseTraining); addGraphCmd ("delete", "delete [nearest|index]", "Deletes single graph node from map.", &BotControl::cmdNodeDelete); addGraphCmd ("check", "check [noarguments]", "Check if graph working correctly.", &BotControl::cmdNodeCheck); addGraphCmd ("cache", "cache [nearest|index]", "Caching node for future use.", &BotControl::cmdNodeCache); @@ -616,7 +618,7 @@ int BotControl::cmdNodeErase () { // prevent accidents when graph are deleted unintentionally if (arg (iamsure) == "iamsure") { - bstor.unlinkFromDisk (); + bstor.unlinkFromDisk (false); } else { msg ("Please, append \"iamsure\" as parameter to get graph erased from the disk."); @@ -624,6 +626,14 @@ int BotControl::cmdNodeErase () { return BotCommandResult::Handled; } +int BotControl::cmdNodeEraseTraining () { + enum args { graph_cmd = 1, cmd }; + + bstor.unlinkFromDisk (true); + + return BotCommandResult::Handled; +} + int BotControl::cmdNodeDelete () { enum args { graph_cmd = 1, cmd, nearest }; diff --git a/src/storage.cpp b/src/storage.cpp index d93dd5e..6bed42f 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -390,14 +390,16 @@ int32_t BotStorage::storageToBotFile (int32_t options) { return BotFile::Graph; } -void BotStorage::unlinkFromDisk () { +void BotStorage::unlinkFromDisk (bool onlyTrainingData) { // this function removes graph file from the hard disk StringArray unlinkable {}; bots.kickEveryone (true); // if we're delete graph, delete all corresponding to it files - unlinkable.emplace (buildPath (BotFile::Graph)); // graph itself + if (!onlyTrainingData) { + unlinkable.emplace (buildPath (BotFile::Graph)); // graph itself + } unlinkable.emplace (buildPath (BotFile::Practice)); // corresponding to practice unlinkable.emplace (buildPath (BotFile::Vistable)); // corresponding to vistable unlinkable.emplace (buildPath (BotFile::Pathmatrix)); // corresponding to matrix @@ -412,6 +414,13 @@ void BotStorage::unlinkFromDisk () { } } graph.reset (); // re-initialize points + + if (onlyTrainingData) { + graph.loadGraphData (); + + // take bots back to game + cv_quota.revert (); + } } StringRef BotStorage::getRunningPath () {