Skip to content
This repository has been archived by the owner on Jan 3, 2025. It is now read-only.

Commit

Permalink
Merge pull request #34 from The-B1T-Foundation/added_metrics
Browse files Browse the repository at this point in the history
Added metrics & MT
  • Loading branch information
b1tflyyyy authored May 3, 2024
2 parents 1dbf523 + b19056b commit 98f2b36
Show file tree
Hide file tree
Showing 16 changed files with 491 additions and 16 deletions.
8 changes: 8 additions & 0 deletions source/business_logic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ set(MODEL_HEADERS
model/config/tg_config/tg_config_model.hpp
model/math_problem_game/math_problem_game_expression_model.hpp
model/config/english_words_info_api_config/english_words_info_api_config_model.hpp
model/metrics/metrics_model.hpp
model/config/tg_root_user_config/tg_root_user_config_model.hpp
)

set(MODEL_SOURCES
Expand All @@ -41,6 +43,8 @@ set(MODEL_SOURCES
model/config/tg_config/tg_config_model.cpp
model/math_problem_game/math_problem_game_expression_model.cpp
model/config/english_words_info_api_config/english_words_info_api_config_model.cpp
model/metrics/metrics_model.cpp
model/config/tg_root_user_config/tg_root_user_config_model.cpp
)

set(CONTROLLER_HEADERS
Expand All @@ -56,6 +60,8 @@ set(CONTROLLER_HEADERS
controller/api/base_api/base_api_controller.hpp
controller/api/english_words_info_api/english_words_info_api_controller.hpp
controller/config/english_words_info_api_config/english_words_info_api_config_controller.hpp
controller/db/metrics_db/metrics_db_controller.hpp
controller/config/tg_root_user_config/tg_root_user_config_controller.hpp
)

set(CONTROLLER_SOURCES
Expand All @@ -71,6 +77,8 @@ set(CONTROLLER_SOURCES
controller/api/base_api/base_api_controller.cpp
controller/api/english_words_info_api/english_words_info_api_controller.cpp
controller/config/english_words_info_api_config/english_words_info_api_config_controller.cpp
controller/db/metrics_db/metrics_db_controller.cpp
controller/config/tg_root_user_config/tg_root_user_config_controller.cpp
)

add_library(${LIBRARY_NAME} STATIC
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// MIT License

// Copyright (c) 2024 The B1T Foundation

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.


#include "tg_root_user_config_controller.hpp"

// ---------------------------------------------------------------------------------------------------------------------
std::optional<ATG_Root_User_Config> ATG_Root_User_Config_Controller::Load_Config()
{
char* tg_root_user{ std::getenv("TG_ROOT_USER") };
if (!tg_root_user)
{
return std::nullopt;
}

return ATG_Root_User_Config{ strtoll(tg_root_user, nullptr, 10) };
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// MIT License

// Copyright (c) 2024 The B1T Foundation

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.


#pragma once

#include <optional>
#include <cstdlib>

#include <model/config/tg_root_user_config/tg_root_user_config_model.hpp>

class ATG_Root_User_Config_Controller
{
public:
constexpr ATG_Root_User_Config_Controller() = default;
constexpr ~ATG_Root_User_Config_Controller() = default;

static std::optional<ATG_Root_User_Config> Load_Config();
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// MIT License

// Copyright (c) 2024 The B1T Foundation

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.


#include "metrics_db_controller.hpp"

// ---------------------------------------------------------------------------------------------------------------------
AMetrics_DB_Controller::AMetrics_DB_Controller(const ADB_Config& db_cfg) :
ABase_DB_Controller{ db_cfg, "metrics_data" }
{ }

// ---------------------------------------------------------------------------------------------------------------------
void AMetrics_DB_Controller::Set_Metrics(const SMetrics& metrics)
{
Exec_Query(std::format(R"(INSERT INTO {} (start_req, profile_req, pr_game_req, math_game_req, help_req, about_project_req, definition_req, date) VALUES ('{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}'))", Table_Name, metrics.Start_Request_Count, metrics.Profile_Request_Count, metrics.Pr_Game_Request_Count, metrics.Math_Game_Request_Count, metrics.Help_Request_Count, metrics.About_Project_Request_Count, metrics.Definition_Request_Count, metrics.Get_Current_Date()));
}

// ---------------------------------------------------------------------------------------------------------------------
SMetrics AMetrics_DB_Controller::Get_Metrics(std::int64_t metrics_id)
{
auto response{ Exec_Query(std::format(R"(SELECT start_req, profile_req, pr_game_req, math_game_req, help_req, about_project_req, definition_req, date FROM {} WHERE id = '{}')", Table_Name, metrics_id)) };
return SMetrics{ response[0][0].as<std::int64_t>(), response[0][1].as<std::int64_t>(), response[0][2].as<std::int64_t>(), response[0][3].as<std::int64_t>(), response[0][4].as<std::int64_t>(), response[0][5].as<std::int64_t>(), response[0][6].as<std::int64_t>(), response[0][7].as<std::string>() };
}

// ---------------------------------------------------------------------------------------------------------------------
std::int64_t AMetrics_DB_Controller::Get_Available_Metrics_Count()
{
auto response{ Exec_Query(std::format(R"(SELECT MAX(id) FROM {})", Table_Name)) };
return response[0][0].as<std::int64_t>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// MIT License

// Copyright (c) 2024 The B1T Foundation

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.


#pragma once

#include <controller/db/base_db/base_db_controller.hpp>
#include <model/metrics/metrics_model.hpp>

class AMetrics_DB_Controller : public ABase_DB_Controller
{
public:
explicit AMetrics_DB_Controller(const ADB_Config& db_cfg);
~AMetrics_DB_Controller() override = default;

void Set_Metrics(const SMetrics& metrics);
SMetrics Get_Metrics(std::int64_t metrics_id);
std::int64_t Get_Available_Metrics_Count();
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// MIT License

// Copyright (c) 2024 The B1T Foundation

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.


#include "tg_root_user_config_model.hpp"

// ---------------------------------------------------------------------------------------------------------------------
ATG_Root_User_Config::ATG_Root_User_Config(std::int64_t root_id) :
Root_Id{ root_id }
{ }

// ---------------------------------------------------------------------------------------------------------------------
std::int64_t ATG_Root_User_Config::Get_Root_Id() const
{
return Root_Id;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// MIT License

// Copyright (c) 2024 The B1T Foundation

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.


#pragma once

#include <cstdint>

class ATG_Root_User_Config
{
public:
explicit ATG_Root_User_Config(std::int64_t root_id);
constexpr ~ATG_Root_User_Config() = default;

[[nodiscard]] std::int64_t Get_Root_Id() const;

private:
std::int64_t Root_Id;
};
60 changes: 60 additions & 0 deletions source/business_logic/model/metrics/metrics_model.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// MIT License

// Copyright (c) 2024 The B1T Foundation

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.


#include "metrics_model.hpp"

// ---------------------------------------------------------------------------------------------------------------------
SMetrics::SMetrics() :
Start_Request_Count{}, Profile_Request_Count{}, Pr_Game_Request_Count{}, Math_Game_Request_Count{}, Help_Request_Count{}, About_Project_Request_Count{}, Definition_Request_Count{}, Current_Date{}
{ }

// ---------------------------------------------------------------------------------------------------------------------
SMetrics::SMetrics(std::int64_t start_request_count, std::int64_t profile_request_count, std::int64_t pr_game_request_count, std::int64_t math_game_request_count, std::int64_t help_request_count, std::int64_t about_project_request_count, std::int64_t definition_request_count, std::string current_date) :
Start_Request_Count{ start_request_count }, Profile_Request_Count{ profile_request_count }, Pr_Game_Request_Count{ pr_game_request_count }, Math_Game_Request_Count{ math_game_request_count }, Help_Request_Count{ help_request_count }, About_Project_Request_Count{ about_project_request_count }, Definition_Request_Count{ definition_request_count }, Current_Date{ std::move(current_date) }
{ }

// ---------------------------------------------------------------------------------------------------------------------
void SMetrics::Set_Current_Date()
{
std::chrono::system_clock::time_point time_point{ std::chrono::system_clock::now() };
Current_Date = std::format("{:%Y.%m.%d %H:%M}", time_point);
}

// ---------------------------------------------------------------------------------------------------------------------
const std::string& SMetrics::Get_Current_Date() const
{
return Current_Date;
}

// ---------------------------------------------------------------------------------------------------------------------
void SMetrics::Clear()
{
Start_Request_Count = 0;
Profile_Request_Count = 0;
Pr_Game_Request_Count = 0;
Math_Game_Request_Count = 0;
Help_Request_Count = 0;
About_Project_Request_Count = 0;
Definition_Request_Count = 0;
Current_Date = " ";
}
Loading

0 comments on commit 98f2b36

Please sign in to comment.