Skip to content

Commit c5d2beb

Browse files
committed
setup: ask for usage stats
1 parent 74f6c3f commit c5d2beb

File tree

4 files changed

+63
-12
lines changed

4 files changed

+63
-12
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ To install or update LODA, please follow the [installation instructions](https:/
1010

1111
* Retrieve OEIS files from cache on API server
1212

13+
### Enhancements
14+
15+
* Improve setup: ask for usage statistics and clean up existing settings.
16+
1317
## v22.1.9
1418

1519
### Bugfixes

src/include/setup.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ MiningMode convertStrToMiningMode(const std::string& str);
1414

1515
class Setup {
1616
public:
17+
static const std::string LODA_SUBMIT_CPU_HOURS;
18+
1719
static std::string getLodaHomeNoCheck();
1820

1921
static const std::string& getLodaHome();
@@ -87,6 +89,7 @@ class Setup {
8789
static bool checkEnvVars();
8890
static bool checkMiningMode();
8991
static bool checkSubmittedBy();
92+
static bool checkUsageStats();
9093
static bool checkMaxMemory();
9194
static bool checkUpdateInterval();
9295
static bool checkMaxLocalProgramAge();

src/miner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ void Miner::checkRegularTasks() {
172172
if (cpuhours_scheduler.isTargetReached()) {
173173
cpuhours_scheduler.reset();
174174
if (mining_mode != MINING_MODE_LOCAL &&
175-
Setup::getSetupFlag("LODA_SUBMIT_CPU_HOURS", true)) {
175+
Setup::getSetupFlag(Setup::LODA_SUBMIT_CPU_HOURS, false)) {
176176
api_client->postCPUHour();
177177
}
178178
}

src/setup.cpp

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
#include "util.hpp"
1212
#include "web_client.hpp"
1313

14+
const std::string Setup::LODA_SUBMIT_CPU_HOURS("LODA_SUBMIT_CPU_HOURS");
15+
16+
// TODO: use a singlton of Setup
1417
std::string Setup::LODA_HOME;
1518
std::string Setup::OEIS_HOME;
1619
std::string Setup::PROGRAMS_HOME;
@@ -304,23 +307,29 @@ void Setup::runWizard() {
304307
if (!checkMiningMode()) {
305308
return;
306309
}
307-
if (!checkSubmittedBy()) {
308-
return;
310+
if (MINING_MODE == MINING_MODE_CLIENT) {
311+
if (!checkSubmittedBy()) {
312+
return;
313+
}
314+
if (!checkUsageStats()) {
315+
return;
316+
}
309317
}
310-
311318
std::cout << "Configure advanced settings? (y/N) ";
312319
std::getline(std::cin, line);
313320
std::cout << std::endl;
314-
if (line == "y" || line == "Y") {
321+
if (line == "y" || line == "Y" || line == "yes") {
315322
if (!checkMaxInstances()) {
316323
return;
317324
}
318325
if (!checkMaxMemory()) {
319326
return;
320327
}
321-
if (!checkUpdateInterval()) {
322-
return;
323-
}
328+
// since we get the oeis data from the API server, we don't need to
329+
// configure this anymore
330+
// if (!checkUpdateInterval()) {
331+
// return;
332+
// }
324333
#ifdef STD_FILESYSTEM
325334
if (getMiningMode() == MINING_MODE_CLIENT && !checkMaxLocalProgramAge()) {
326335
return;
@@ -543,7 +552,7 @@ bool Setup::checkMiningMode() {
543552
return false;
544553
}
545554
SETUP["LODA_MINING_MODE"] = convertMiningModeToStr(mode);
546-
MINING_MODE = UNDEFINED_INT; // reset cached value
555+
MINING_MODE = mode;
547556
std::cout << std::endl;
548557
return true;
549558
}
@@ -610,9 +619,9 @@ bool Setup::checkSubmittedBy() {
610619
<< std::endl
611620
<< "at https://loda-lang.org and the programs repository at"
612621
<< std::endl
613-
<< "https://github.com/loda-lang/loda-programs. If you like,"
622+
<< "https://github.com/loda-lang/loda-programs." << std::endl
614623
<< std::endl
615-
<< "enter your name below, or \"none\" to not include it:"
624+
<< "Enter your name, or \"none\" to not include it in programs:"
616625
<< std::endl;
617626
std::cout << "[" << submitted_by << "] ";
618627
std::getline(std::cin, submitted_by);
@@ -627,11 +636,46 @@ bool Setup::checkSubmittedBy() {
627636
return true;
628637
}
629638

639+
bool Setup::checkUsageStats() {
640+
std::cout << "To estimate the required server capacity, the LODA miner"
641+
<< std::endl
642+
<< "can send basic, anonymous usage statistics. Specifically,"
643+
<< std::endl
644+
<< "a running miner instance would send the value 1 to the"
645+
<< std::endl
646+
<< "API server once per hour. This data is used to determine"
647+
<< std::endl
648+
<< "the total number of active miners. There are no IDs or other"
649+
<< std::endl
650+
<< "data sent to the server. You can still mine without it."
651+
<< std::endl
652+
<< std::endl
653+
<< "Do you want to send this basic usage statisics? ";
654+
bool flag = getSetupFlag(LODA_SUBMIT_CPU_HOURS, false);
655+
if (flag) {
656+
std::cout << "(Y/n) ";
657+
} else {
658+
std::cout << "(y/N) ";
659+
}
660+
std::string line;
661+
std::getline(std::cin, line);
662+
std::cout << std::endl;
663+
if (!line.empty()) {
664+
if (line == "y" || line == "Y" || line == "yes") {
665+
SETUP[LODA_SUBMIT_CPU_HOURS] = "yes";
666+
} else {
667+
SETUP[LODA_SUBMIT_CPU_HOURS] = "no";
668+
}
669+
}
670+
return true;
671+
}
672+
630673
bool Setup::checkMaxMemory() {
631674
std::string line;
632675
std::cout << "Enter the maximum memory usage per miner instance in MB."
633676
<< std::endl
634-
<< "The default value is " << DEFAULT_MAX_PHYSICAL_MEMORY << " MB."
677+
<< "The recommended range is " << DEFAULT_MAX_PHYSICAL_MEMORY
678+
<< " - " << (DEFAULT_MAX_PHYSICAL_MEMORY * 2) << " MB."
635679
<< std::endl;
636680
int64_t max_memory = getMaxMemory() / (1024 * 1024);
637681
std::cout << "[" << max_memory << "] ";

0 commit comments

Comments
 (0)