hops
TimestampRecorder.hpp
Go to the documentation of this file.
1 #ifndef HOPS_TIMESTAMPRECORDER_HPP
2 #define HOPS_TIMESTAMPRECORDER_HPP
3 
4 #include "../../FileWriter/FileWriter.hpp"
9 #include "../../Utility/Data.hpp"
10 
11 #include <chrono>
12 #include <memory>
13 #include <stdexcept>
14 #include <vector>
15 
16 namespace hops {
17  template<typename MarkovChainImpl>
18  class TimestampRecorder : public MarkovChainImpl {
19  public:
20  explicit TimestampRecorder(const MarkovChainImpl &markovChainImpl) : MarkovChainImpl(markovChainImpl) {
21  records = std::make_shared<std::vector<long>>();
22  }
23 
24  void installDataObject(ChainData& chainData) {
25  chainData.setTimestamps(records);
27  MarkovChainImpl::installDataObject(chainData);
28  }
29  }
30 
31  void writeRecordsToFile(const FileWriter *const fileWriter) const {
32  fileWriter->write("timestamps", *records);
34  MarkovChainImpl::writeRecordsToFile(fileWriter);
35  }
36  };
37 
38  [[nodiscard]] std::vector<long> getTimestampRecords() const {
39  return *records;
40  }
41 
42  void storeRecord() {
43  records->emplace_back(
44  std::chrono::duration_cast<std::chrono::milliseconds>(
45  std::chrono::high_resolution_clock::now().time_since_epoch()
46  ).count()
47  );
48 
50  MarkovChainImpl::storeRecord();
51  }
52  }
53 
54  void clearRecords() {
55  records->clear();
57  MarkovChainImpl::clearRecords();
58  }
59  }
60 
61  private:
62  std::shared_ptr<std::vector<long>> records;
63  };
64 }
65 
66 #endif //HOPS_TIMESTAMPRECORDER_HPP
hops::TimestampRecorder::TimestampRecorder
TimestampRecorder(const MarkovChainImpl &markovChainImpl)
Definition: TimestampRecorder.hpp:20
hops::IsClearRecordsAvailable
Definition: IsClearRecordsAvailable.hpp:8
hops::TimestampRecorder::storeRecord
void storeRecord()
Definition: TimestampRecorder.hpp:42
IsInstallDataObjectAvailable.hpp
IsClearRecordsAvailable.hpp
IsStoreRecordAvailable.hpp
hops::IsInstallDataObjectAvailable
Definition: IsInstallDataObjectAvailable.hpp:9
hops::TimestampRecorder
Definition: TimestampRecorder.hpp:18
hops::TimestampRecorder::installDataObject
void installDataObject(ChainData &chainData)
Definition: TimestampRecorder.hpp:24
hops::IsWriteRecordsToFileAvailable
Definition: IsWriteRecordsToFileAvailable.hpp:9
hops::TimestampRecorder::getTimestampRecords
std::vector< long > getTimestampRecords() const
Definition: TimestampRecorder.hpp:38
hops::FileWriter::write
virtual void write(const std::string &description, const std::vector< float > &records) const =0
Writes records.
hops::ChainData
Definition: ChainData.hpp:12
hops::ChainData::setTimestamps
void setTimestamps(const std::shared_ptr< std::vector< long >> timestamps)
Definition: ChainData.hpp:57
hops::IsStoreRecordAvailable
Definition: IsStoreRecordAvailable.hpp:8
hops::FileWriter
Definition: FileWriter.hpp:9
hops
Definition: CsvReader.hpp:8
IsWriteRecordsToFileAvailable.hpp
hops::TimestampRecorder::clearRecords
void clearRecords()
Definition: TimestampRecorder.hpp:54
hops::TimestampRecorder::writeRecordsToFile
void writeRecordsToFile(const FileWriter *const fileWriter) const
Definition: TimestampRecorder.hpp:31