Skip to content

Commit

Permalink
Change format of *Start date* data
Browse files Browse the repository at this point in the history
Fixes #9
  • Loading branch information
Pengor committed May 20, 2021
1 parent 198168b commit 6f8506d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
38 changes: 38 additions & 0 deletions src/TimeAndDate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Convert date and time strings to a friendlier format for .csv files

#include "TimeAndDate.h"
#include <ctime>

using namespace std;

const map<string,string> 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;
}
12 changes: 12 additions & 0 deletions src/TimeAndDate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef TIME_AND_DATE_H
#define TIME_AND_DATE_H

#include <string>
#include <map>

class TimeAndDate {
public:
static std::string FormatDate(std::string date_str);
};

#endif /* TIME_AND_DATE_H */
5 changes: 3 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -14,6 +14,7 @@
#include <filesystem>
#include "InputHandler.h"
#include "Patterns.h"
#include "TimeAndDate.h"

using namespace std;

Expand Down Expand Up @@ -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) << ",";
Expand Down

0 comments on commit 6f8506d

Please sign in to comment.