Initial commit
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
*.o.*
|
||||
*.d.*
|
||||
*.a.*
|
||||
.*.swp
|
||||
.AppleDouble
|
||||
lib
|
||||
@@ -0,0 +1,3 @@
|
||||
[submodule "Makefiles"]
|
||||
path = Makefiles
|
||||
url = https://gogs.dierkse.nl/JDierkse/Makefiles
|
||||
@@ -0,0 +1,43 @@
|
||||
#include "DataId.h"
|
||||
#include <StringAlgorithm.h>
|
||||
|
||||
|
||||
namespace DataStorage {
|
||||
|
||||
DataId::DataId(const std::string& table) :
|
||||
m_table(table)
|
||||
{
|
||||
}
|
||||
|
||||
int DataId::Id() const
|
||||
{
|
||||
return GetId(m_table);
|
||||
}
|
||||
|
||||
std::string DataId::Table() const
|
||||
{
|
||||
return m_table;
|
||||
}
|
||||
|
||||
int DataId::GetId(const std::string& dataName) const
|
||||
{
|
||||
if (StringAlgorithm::iequals(dataName, "voltage"))
|
||||
return 0;
|
||||
|
||||
if (StringAlgorithm::iequals(dataName, "gas") ||
|
||||
StringAlgorithm::iequals(dataName, "intensity") ||
|
||||
StringAlgorithm::iequals(dataName, "power") ||
|
||||
StringAlgorithm::iequals(dataName, "pressure") ||
|
||||
StringAlgorithm::iequals(dataName, "state") ||
|
||||
StringAlgorithm::iequals(dataName, "temperature"))
|
||||
return 1;
|
||||
|
||||
if (StringAlgorithm::iequals(dataName, "humidity") ||
|
||||
StringAlgorithm::iequals(dataName, "setpoint") ||
|
||||
StringAlgorithm::iequals(dataName, "forecast"))
|
||||
return 2;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
} // namespace DataStorage
|
||||
@@ -0,0 +1,46 @@
|
||||
#include "DataStorageClient.h"
|
||||
#include "DataId.h"
|
||||
#include <MySQLClient.h>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
namespace DataStorage {
|
||||
|
||||
DataStorageClient::DataStorageClient(const std::shared_ptr<MySQL::MySQLClient>& pMySQLClient, const std::string& table) :
|
||||
m_pMySQLClient(pMySQLClient),
|
||||
m_table(table)
|
||||
{
|
||||
}
|
||||
|
||||
DataStorageClient::~DataStorageClient()
|
||||
{
|
||||
}
|
||||
|
||||
void DataStorageClient::LogValue(int deviceId, const std::string& dataName, int timestamp, int value)
|
||||
{
|
||||
int dataId = DataId(dataName).Id();
|
||||
|
||||
std::stringstream query;
|
||||
query << "INSERT INTO `" << m_table << "` (device_id, data_id, timestamp, value) VALUES (" << deviceId << "," << dataId << ",FROM_UNIXTIME(" << timestamp << ")," << value << ");";
|
||||
m_pMySQLClient->Execute(query.str());
|
||||
}
|
||||
|
||||
void DataStorageClient::LogValue(int deviceId, const std::string& dataName, int timestamp, double value)
|
||||
{
|
||||
int dataId = DataId(dataName).Id();
|
||||
|
||||
std::stringstream query;
|
||||
query << "INSERT INTO `" << m_table << "` (device_id, data_id, timestamp, value) VALUES (" << deviceId << "," << dataId << ",FROM_UNIXTIME(" << timestamp << ")," << value << ");";
|
||||
m_pMySQLClient->Execute(query.str());
|
||||
}
|
||||
|
||||
void DataStorageClient::LogValue(int deviceId, const std::string& dataName, int timestamp, const std::string& value)
|
||||
{
|
||||
int dataId = DataId(dataName).Id();
|
||||
|
||||
std::stringstream query;
|
||||
query << "INSERT INTO `" << m_table << "` (device_id, data_id, timestamp, value) VALUES (" << deviceId << "," << dataId << ",FROM_UNIXTIME(" << timestamp << "),\"" << value << "\");";
|
||||
m_pMySQLClient->Execute(query.str());
|
||||
}
|
||||
|
||||
} // namespace DataStorageClientImpl
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../Makefile
|
||||
@@ -0,0 +1,43 @@
|
||||
#include "Timespan.h"
|
||||
#include <StringAlgorithm.h>
|
||||
|
||||
|
||||
namespace DataStorage {
|
||||
|
||||
namespace Conversions {
|
||||
|
||||
Timespan::type Timespan(const std::string& timespan)
|
||||
{
|
||||
if (StringAlgorithm::iequals(timespan, "Day"))
|
||||
return Timespan::Day;
|
||||
else if (StringAlgorithm::iequals(timespan, "Week"))
|
||||
return Timespan::Week;
|
||||
else if (StringAlgorithm::iequals(timespan, "Month"))
|
||||
return Timespan::Month;
|
||||
else if (StringAlgorithm::iequals(timespan, "Year"))
|
||||
return Timespan::Year;
|
||||
else
|
||||
return Timespan::Unknown;
|
||||
}
|
||||
|
||||
std::string Timespan(Timespan::type timespan)
|
||||
{
|
||||
switch (timespan)
|
||||
{
|
||||
case Timespan::Day:
|
||||
return "Day";
|
||||
case Timespan::Week:
|
||||
return "Week";
|
||||
case Timespan::Month:
|
||||
return "Month";
|
||||
case Timespan::Year:
|
||||
return "Year";
|
||||
default:
|
||||
case Timespan::Unknown:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Conversions
|
||||
|
||||
} // namespace DataStorage
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../../Logging
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../../MySQL
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../../Utilities
|
||||
@@ -0,0 +1,21 @@
|
||||
#
|
||||
# Makefile.conf
|
||||
#
|
||||
|
||||
LFLAGS += -lUtilities
|
||||
LFLAGS += -L$(ROOTPATH)/Libraries/Utilities/lib/$(ARCH)
|
||||
CFLAGS += -I$(ROOTPATH)/Libraries/Utilities/include
|
||||
|
||||
LFLAGS += -lLogging
|
||||
LFLAGS += -L$(ROOTPATH)/Libraries/Logging/lib/$(ARCH)
|
||||
CFLAGS += -I$(ROOTPATH)/Libraries/Logging/include
|
||||
|
||||
LFLAGS += -lMySQL -lmysqlclient -lmysqlcppconn
|
||||
LFLAGS += -L$(ROOTPATH)/Libraries/MySQL/lib/$(ARCH)
|
||||
CFLAGS += -I$(ROOTPATH)/Libraries/MySQL/include
|
||||
|
||||
LFLAGS += -lDataStorage
|
||||
LFLAGS += -L$(ROOTPATH)/lib/$(ARCH)
|
||||
CFLAGS += -I$(ROOTPATH) -I$(ROOTPATH)/include
|
||||
|
||||
DEBUGDIR := .debug
|
||||
@@ -0,0 +1,17 @@
|
||||
#
|
||||
# Makefile.target
|
||||
#
|
||||
|
||||
DataStorage.a.$(ARCH) : $(OBJECTS)
|
||||
$(call build_target_library_arch,$@,$^)
|
||||
DataStorage.a:
|
||||
$(call build_target,$@)
|
||||
|
||||
test.$(ARCH): $(OBJECTS) Test/Test.o.$(ARCH) | DataStorage.a.$(ARCH)
|
||||
$(call build_target_arch,$@,$^)
|
||||
test:
|
||||
$(call build_target,$@)
|
||||
|
||||
.DEFAULT_GOAL := DataStorage.a
|
||||
|
||||
TARGETS += DataStorage.a test
|
||||
Submodule
+1
Submodule Makefiles added at cd9ef1a1b0
@@ -0,0 +1,26 @@
|
||||
#ifndef DATAID_H
|
||||
#define DATAID_H
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace DataStorage {
|
||||
|
||||
class DataId
|
||||
{
|
||||
public:
|
||||
DataId(const std::string& dataName);
|
||||
|
||||
int Id() const;
|
||||
std::string Table() const;
|
||||
|
||||
private:
|
||||
int GetId(const std::string& dataName) const;
|
||||
|
||||
private:
|
||||
std::string m_table;
|
||||
};
|
||||
|
||||
} // namespace DataStorage
|
||||
|
||||
#endif // DATAID_H
|
||||
@@ -0,0 +1,37 @@
|
||||
#ifndef DATASTORAGECLIENT_H
|
||||
#define DATASTORAGECLIENT_H
|
||||
|
||||
#include "Timespan.h"
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace MySQL {
|
||||
|
||||
class MySQLClient;
|
||||
|
||||
} // namespace MySQL
|
||||
|
||||
namespace DataStorage {
|
||||
|
||||
class DataStorageClientImpl;
|
||||
|
||||
class DataStorageClient
|
||||
{
|
||||
public:
|
||||
DataStorageClient(const std::shared_ptr<MySQL::MySQLClient>& pMySQLClient, const std::string& table);
|
||||
~DataStorageClient();
|
||||
|
||||
public:
|
||||
void LogValue(int deviceId, const std::string& dataName, int timestamp, int value);
|
||||
void LogValue(int deviceId, const std::string& dataName, int timestamp, double value);
|
||||
void LogValue(int deviceId, const std::string& dataName, int timestamp, const std::string& value);
|
||||
|
||||
private:
|
||||
std::shared_ptr<MySQL::MySQLClient> m_pMySQLClient;
|
||||
std::string m_table;
|
||||
};
|
||||
|
||||
} // namespace DataStorage
|
||||
|
||||
#endif // DATASTORAGECLIENT_H
|
||||
@@ -0,0 +1,30 @@
|
||||
#ifndef TIMESPAN_H
|
||||
#define TIMESPAN_H
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace DataStorage {
|
||||
|
||||
struct Timespan
|
||||
{
|
||||
enum type
|
||||
{
|
||||
Day = 24 * 60 * 60,
|
||||
Week = 7 * 24 * 60 * 60,
|
||||
Month = 31 * 24 * 60 * 60,
|
||||
Year = 365 * 24 * 60 * 60,
|
||||
Unknown
|
||||
};
|
||||
};
|
||||
|
||||
namespace Conversions {
|
||||
|
||||
Timespan::type Timespan(const std::string& timespan);
|
||||
std::string Timespan(Timespan::type timespan);
|
||||
|
||||
} // namespace Conversions
|
||||
|
||||
} // namespace DataStorage
|
||||
|
||||
#endif // TIMESPAN_H
|
||||
Reference in New Issue
Block a user