Browse Source

docs in db. We can now Line pad around next_quit_panel.

Steve Thielemann 4 years ago
parent
commit
a2b393de51
4 changed files with 49 additions and 1 deletions
  1. 41 0
      db.cpp
  2. 1 0
      db.h
  3. 5 0
      main.cpp
  4. 2 1
      play.cpp

+ 41 - 0
db.cpp

@@ -199,6 +199,12 @@ std::vector<scores_details> DBData::getScoresOnDay(time_t date) {
   return scores;
 }
 
+/**
+ * @brief Gets scores, time_t is day, vector has user and scores sorted highest
+ * to lowest.
+ *
+ * @return std::map<time_t, std::vector<scores_data>>
+ */
 std::map<time_t, std::vector<scores_data>> DBData::getScores(void) {
   std::map<time_t, std::vector<scores_data>> scores;
   try {
@@ -243,6 +249,41 @@ std::map<time_t, std::vector<scores_data>> DBData::getScores(void) {
   return scores;
 }
 
+/**
+ * @brief When has the user played?
+ *
+ * This returns a map of date (time_t), and number of hands played on that date.
+ *
+ * @return std::map<time_t, int>
+ */
+std::map<time_t, int> DBData::whenPlayed(void) {
+  // select "date", count(hand) from scores where username='?' group by
+  // "date";
+  std::map<time_t, int> plays;
+  try {
+    SQLite::Statement stmt(db, "SELECT \"date\", COUNT(hand) FROM scores WHERE "
+                               "username='?' GROUP BY \"date\";");
+    stmt.bind(1, user);
+
+    while (stmt.executeStep()) {
+      plays[stmt.getColumn(0)] = stmt.getColumn(1);
+    }
+  } catch (std::exception &e) {
+    if (get_logger) {
+      get_logger() << "whenPlayed(): " << std::endl;
+      get_logger() << "SQLite exception: " << e.what() << std::endl;
+    }
+    plays.clear();
+  }
+  return plays;
+}
+
+/**
+ * @brief This will expire out old scores
+ *
+ * @todo implement, but don't throw away high scores.
+ *
+ */
 void DBData::expireScores(void) {}
 
 /**

+ 1 - 0
db.h

@@ -50,6 +50,7 @@ public:
   void expireScores(void);
 
   int handsPlayedOnDay(time_t day);
+  std::map<time_t, int> whenPlayed(void);
 };
 
 void normalizeDate(time_t &tt, int hour = 2);

+ 5 - 0
main.cpp

@@ -690,6 +690,11 @@ int main(int argc, char *argv[]) {
     update_config = true;
   }
 
+  if (!config["makeup_per_day"]) {
+    config["makeup_per_day"] = 5;
+    update_config = true;
+  }
+
   /*
     if (config["hands_per_day"]) {
       get_logger() << "hands_per_day: " << config["hands_per_day"].as<int>()

+ 2 - 1
play.cpp

@@ -967,8 +967,9 @@ std::unique_ptr<door::Panel> PlayCards::make_next_panel(void) {
       commandLineRender(bracketColor, innerColor, outerColor);
   door::Line nextLine(text, W);
   nextLine.setRender(textRender);
-  // nextLine.setPadding(" ", panelColor);
+  nextLine.setPadding("  ", panelColor);
   nextLine.setUpdater(nextUpdate);
+  nextLine.fit();
   p->addLine(std::make_unique<door::Line>(nextLine));
   return p;
 }