|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- #pragma once
- #include <memory>
- #include <vector>
- #include "PublisherData.h"
- #include <map>
- #include <chrono>
- #include <optional>
- #include <regex>
- #include <atomic>
- #include "ModbusDataPOC.h"
- #include "ModbusDataBender.h"
- #include "ts_map.h"
- #include "cappedstorage.h"
-
- const Eigen::MatrixXd dummyMat(0,0);
- const Eigen::VectorXd dummyVec(0);
-
-
- struct SavedData{
- Category cat;
- std::vector<uint16_t> data;
-
- SavedData(const Category c, const std::vector<uint16_t> d){
- cat = c;
- data = d;
- }
- friend std::ostream& operator<<(std::ostream& os, const SavedData& savedData);
-
- };
-
-
-
- class PublisherInterface;
-
- constexpr auto READ_BUFFER_SIZE = 4096;
-
- typedef std::vector<std::vector<float>> float_matrix;
- //Type for one dimensional permanent double values
- typedef ts_map<ModbusRegister, CappedStorage> permanent_data;
-
- using namespace std::chrono;
-
- class DataModel
- {
- public:
- //Sigleton Methods
- static std::unique_ptr<DataModel>& Instance();
- static void Destroy();
- static void Create();
-
- ~DataModel();
-
- //save Data inside application
- void savePublishedData(PublisherData&&);
-
- void makePermanent(ModbusRegister reg, bool biased);
-
- void saveModbusParameter(ParameterSpecification param);
-
- //getter
- std::vector<u_int> getSavedPublishedDataIndexes(const u_int id, const seconds newerThan);
-
-
- //---local file storage methods---
- //Stores in-programm data to local file system
- bool flush(std::stringstream &ss);
-
- uintmax_t readLogFile(std::stringstream& ss, long long fromTime);
-
- //Reads in from all files their content to ss, or a certain file, specified by its index
- //TODO: define readSince to read al data after that time point
- //size_t readSingleFile(std::stringstream& ss, const size_t index);
- uintmax_t readFromAllFiles(std::stringstream& ss, std::chrono::system_clock::time_point readSince = std::chrono::system_clock::from_time_t(0));
- uintmax_t readAllDataFiles(std::stringstream& ss);
-
- unsigned long removeStoredData(seconds olderThan);
- unsigned long removeStoredData();
-
- //saves collected data after a certain amount of time points
- void checkForFlushData();
-
- unsigned long long getStartTime(const unsigned int id);
- unsigned long long getStartTime();
- const char* getDataDir() { return dataDir; }
- const std::regex& getRegexPatternFile() { return regexPatternFile; }
-
- constexpr unsigned long long duration_to_sec_long(const std::chrono::system_clock::duration& t);
- constexpr unsigned long long timepoint_to_sec_long(const std::chrono::system_clock::time_point& t);
-
- const ts_map<ModbusRegister, SavedData> &getPublisherData() const;
- CappedStorage* getPermanentData(ModbusRegister reg);
-
- std::stringstream &readTemporaryData(std::stringstream &buffer);
- std::stringstream &readPermanentData(std::stringstream &buffer, bool retain);
- ts_queue<ParameterSpecification> &getAlerts();
-
- private:
- //Register to enqueue data wich are stored permanently
- permanent_data permanentStorage;
- //Temporary storage of the last readed parameter
- ts_map<ModbusRegister, SavedData> temporaryStorage;
- //Temporary saved alerts
- ts_queue<ParameterSpecification> alerts;
-
- static long permanentParamHistory;
- static int narrowBlock;
-
- const std::regex regexPatternFile = std::regex("data_\\w+");
- const std::string logFileName = "data_analysis.log";
- const std::string dateFormatLogger = "%Y-%m-%d %H:%M:%S";
- u_int nrOfDataPoints = 0;
-
- //static instance which can be accessed by calling DataModel::Instance()
- static std::unique_ptr<DataModel> instance;
-
- //local directory path to the data storage
- const char* dataDir = "data/";
- const char* logDir = "log/";
-
-
- //Data from publishers, one elemt in outer vector for one id
- //Each id consists of a vector of PublisherData (use map to make the id become a unique key)
-
-
-
- //ostream operators (read and write dataModel data from streams)
- friend std::ostream& operator<<(std::ostream& os, DataModel& dataModel);
- friend std::istream& operator>>(std::istream& is, DataModel& dataModel);
- };
|