diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 83e0c13..f1d4d3d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -7,6 +7,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED True) configure_file(CMakeConfig.h.in CMakeConfig.h) -add_executable(chia-log-analysis main.cpp InputHandler.cpp) +add_executable(chia-log-analysis main.cpp InputHandler.cpp TimeAndDate.cpp) target_include_directories(chia-log-analysis PUBLIC "${PROJECT_BINARY_DIR}") \ No newline at end of file diff --git a/src/TimeAndDate.cpp b/src/TimeAndDate.cpp new file mode 100644 index 0000000..373c0eb --- /dev/null +++ b/src/TimeAndDate.cpp @@ -0,0 +1,38 @@ +// Convert date and time strings to a friendlier format for .csv files + +#include "TimeAndDate.h" +#include + +using namespace std; + +const map MONTHS = { + {"Jan", "01"}, + {"Feb", "02"}, + {"Mar", "03"}, + {"Apr", "04"}, + {"May", "05"}, + {"Jun", "06"}, + {"Jul", "07"}, + {"Aug", "08"}, + {"Sep", "09"}, + {"Oct", "10"}, + {"Nov", "11"}, + {"Dec", "12"} +}; + +// Converts a date string to the format YYYY-MM-DD hh:mm:ss +string TimeAndDate::FormatDate(string date_str) { + string rtn_str = ""; + + rtn_str.append(date_str.substr(20, 4)); // Year + rtn_str.append("-"); + rtn_str.append(MONTHS.at(date_str.substr(4, 3))); // Month + rtn_str.append("-"); + string day = date_str.substr(8, 2); // Day + if (day[0] == ' ') + day[0] = '0'; + rtn_str.append(day); + rtn_str.append(date_str.substr(10, 9)); // Time + + return rtn_str; +} \ No newline at end of file diff --git a/src/TimeAndDate.h b/src/TimeAndDate.h new file mode 100644 index 0000000..69b7762 --- /dev/null +++ b/src/TimeAndDate.h @@ -0,0 +1,12 @@ +#ifndef TIME_AND_DATE_H +#define TIME_AND_DATE_H + +#include +#include + +class TimeAndDate { + public: + static std::string FormatDate(std::string date_str); +}; + +#endif /* TIME_AND_DATE_H */ diff --git a/src/main.cpp b/src/main.cpp index 4c9c566..1e0c047 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,6 @@ // Chia Log Analysis by Drew M. Johnson // Authored 4/11/2021 -// Last updated 5/10/2021 +// Last updated 5/19/2021 // // This program prompts the user for two file locations if not provided: // 1) The location to read Chia plotter logs from @@ -14,6 +14,7 @@ #include #include "InputHandler.h" #include "Patterns.h" +#include "TimeAndDate.h" using namespace std; @@ -86,7 +87,7 @@ int main(int argc, char* argv[]) { out_file << match.str(1) << "," << match.str(2) << ","; found_flags[ff_i] = true; } else if (!found_flags[++ff_i] && regex_search(current_line, match, patterns::START_DATE)) { - out_file << match.str(1) << ","; + out_file << TimeAndDate::FormatDate(match.str(1)) << ","; found_flags[ff_i] = true; } else if (!found_flags[++ff_i] && regex_search(current_line, match, patterns::PHASE_1)) { out_file << match.str(1) << ",";