Prechádzať zdrojové kódy

Updated density line parsing.

Set trigger on something more specific.
In tests, output << what you're testing against.
(On failure, it prints those values out.  Which test failed?)
Steve Thielemann 3 rokov pred
rodič
commit
072dc68f84
2 zmenil súbory, kde vykonal 41 pridanie a 33 odobranie
  1. 36 28
      director.cpp
  2. 5 5
      test-director.cpp

+ 36 - 28
director.cpp

@@ -215,7 +215,7 @@ void Director::server_line(const std::string &line,
     if (startswith(line, " Items     Status  Trading % of max OnBoard"))
       SL_parser = SF_portline;
     */
-    if (in(line, "==>")) SL_parser = SF_densityline;
+    if (endswith(line, "Relative Density Scan")) SL_parser = SF_densityline;
     if (startswith(line, "Sector  : ")) SL_parser = SF_sectorline;
     if (line == ": ") SL_parser = SF_cimline;
     if (line == "<Info>") SL_parser = SF_infoline;
@@ -838,6 +838,8 @@ void Director::SL_densityline(const std::string &line) {
     SL_parser = nullptr;
     return;
   }
+
+  /*
   // Ensure this really is a density scan and not something else
   if (!in(line, "Sector") || !in(line, "Warps") || !in(line, "NavHaz") ||
       !in(line, "Anom")) {
@@ -848,6 +850,8 @@ void Director::SL_densityline(const std::string &line) {
   if (not galaxy.meta["density"]) {
     galaxy.meta["density"] = YAML::Node();
   }
+  */
+
   /*
    0         1   2                3  4     5 6    7      8     9     10   11 12
   "Sector    55  ==>              0  Warps : 4    NavHaz :     0%    Anom : No"
@@ -857,34 +861,38 @@ void Director::SL_densityline(const std::string &line) {
   "Sector 55 ==> 0 Warps 4 NavHaz 0 Anom No"
   "Sector 223 ==> 0 Warps 3 NavHaz 0 Anom No"
   */
-  std::string work = line;
-  replace(work, ":", "");
-  bool known = !in(work, "(");
-  replace(work, "(", "");
-  replace(work, ")", "");
-  replace(work, "%", "");
-  std::vector<std::string> dense = split(work);
-  // Parse our data
-  int sector = std::stoi(dense.at(1));
-  int density = std::stoi(dense.at(3));
-  int warps = std::stoi(dense.at(5));
-  int navhaz = std::stoi(dense.at(7));
-  bool anom = in(dense.at(9), "Yes");
-  // Commit data
-  BUGZ_LOG(warning) << "densityline: {sector=" << sector
-                    << " density=" << density << " warps=" << warps
-                    << " navhaz=" << navhaz << " anom=" << anom
-                    << " known=" << known << "}";
-  if (galaxy.meta["density"][sector]) {
-    galaxy.meta["density"][sector] = YAML::Node();
+  if (in(line, "==>")) {
+    std::string work = line;
+    replace(work, ":", "");
+    bool known = !in(work, "(");
+    replace(work, "(", "");
+    replace(work, ")", "");
+    replace(work, "%", "");
+    std::vector<std::string> dense = split(work);
+    // Parse our data
+    int sector = std::stoi(dense.at(1));
+    int density = std::stoi(dense.at(3));
+    int warps = std::stoi(dense.at(5));
+    int navhaz = std::stoi(dense.at(7));
+    bool anom = in(dense.at(9), "Yes");
+    // Commit data
+    BUGZ_LOG(warning) << "densityline: {sector=" << sector
+                      << " density=" << density << " warps=" << warps
+                      << " navhaz=" << navhaz << " anom=" << anom
+                      << " known=" << known << "}";
+    /*
+    if (galaxy.meta["density"][sector]) {
+      galaxy.meta["density"][sector] = YAML::Node();
+    }
+    */
+    galaxy.meta["density"][sector]["density"] = density;
+    galaxy.meta["density"][sector]["warps"] = warps;
+    galaxy.meta["density"][sector]["navhaz"] = navhaz;
+    galaxy.meta["density"][sector]["anom"] = anom;
+    galaxy.meta["density"][sector]["known"] = known;
+    // Add a check to see if density is greater than 500
+    // Add datetime stamp
   }
-  galaxy.meta["density"][sector]["density"] = density;
-  galaxy.meta["density"][sector]["warps"] = warps;
-  galaxy.meta["density"][sector]["navhaz"] = navhaz;
-  galaxy.meta["density"][sector]["anom"] = anom;
-  galaxy.meta["density"][sector]["known"] = known;
-  // Add a check to see if density is greater than 500
-  // Add datetime stamp
 }
 
 void Director::SL_portline(const std::string &line) {

+ 5 - 5
test-director.cpp

@@ -156,15 +156,15 @@ TEST(director, director_parsing_density) {
   for (auto sector : sectors) {
     // GTEST_COUT << "Testing Sector " << sector << std::endl;
     EXPECT_EQ(dir.galaxy.meta["density"][sector]["density"].as<int>(),
-              sector_data[sector]["density"].as<int>());
+              sector_data[sector]["density"].as<int>()) << "Sector " << sector << " density";
     EXPECT_EQ(dir.galaxy.meta["density"][sector]["warps"].as<int>(),
-              sector_data[sector]["warps"].as<int>());
+              sector_data[sector]["warps"].as<int>()) << "Sector " << sector << " warps";
     EXPECT_EQ(dir.galaxy.meta["density"][sector]["navhaz"].as<int>(),
-              sector_data[sector]["navhaz"].as<int>());
+              sector_data[sector]["navhaz"].as<int>()) << "Sector " << sector << " navhaz";
     EXPECT_EQ(dir.galaxy.meta["density"][sector]["anom"].as<bool>(),
-              sector_data[sector]["anom"].as<bool>());
+              sector_data[sector]["anom"].as<bool>()) << "Sector " << sector << " anom";
     EXPECT_EQ(dir.galaxy.meta["density"][sector]["known"].as<bool>(),
-              sector_data[sector]["known"].as<bool>());
+              sector_data[sector]["known"].as<bool>()) << "Sector " << sector << " known";
   }
 }