Compare commits
8 Commits
d41f11a333
...
test_sqlit
| Author | SHA1 | Date | |
|---|---|---|---|
| 6794dada92 | |||
| 6ff4a66551 | |||
| 45f73c721e | |||
| e99bd33985 | |||
| 40b2f963a6 | |||
| cc00586bc9 | |||
| d7ea0b99ac | |||
| 0dedb2d6b9 |
@@ -8,7 +8,11 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
|
|||||||
# set(CMAKE_VERBOSE_MAKEFILE ON)
|
# set(CMAKE_VERBOSE_MAKEFILE ON)
|
||||||
add_compile_options(-ggdb)
|
add_compile_options(-ggdb)
|
||||||
|
|
||||||
include_directories(external/include/)
|
include_directories(
|
||||||
|
external/include
|
||||||
|
shared/inc
|
||||||
|
)
|
||||||
|
|
||||||
link_libraries(
|
link_libraries(
|
||||||
${CMAKE_SOURCE_DIR}/external/libimgui.a
|
${CMAKE_SOURCE_DIR}/external/libimgui.a
|
||||||
${CMAKE_SOURCE_DIR}/external/libraylib.a
|
${CMAKE_SOURCE_DIR}/external/libraylib.a
|
||||||
@@ -18,50 +22,44 @@ link_libraries(
|
|||||||
m
|
m
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_library(shared STATIC
|
||||||
|
shared/src/canvas/BackGround.cpp
|
||||||
|
shared/src/canvas/BackGroundColors.cpp
|
||||||
|
shared/src/canvas/Canvas.cpp
|
||||||
|
shared/src/canvas/Tree.cpp
|
||||||
|
shared/src/values/Dna.cpp
|
||||||
|
shared/src/values/DnaManager.cpp
|
||||||
|
shared/src/values/mrand.cpp
|
||||||
|
shared/src/values/Similarity.cpp
|
||||||
|
shared/src/TcpSocket.cpp
|
||||||
|
shared/src/sql.cpp
|
||||||
|
shared/src/values/DnaDB.cpp
|
||||||
|
)
|
||||||
|
|
||||||
add_executable(app
|
add_executable(app
|
||||||
app/src/main.cpp
|
app/src/main.cpp
|
||||||
app/src/App.cpp
|
app/src/App.cpp
|
||||||
app/src/DnaStore.cpp
|
app/src/DnaStore.cpp
|
||||||
app/src/sys.cpp
|
app/src/sys.cpp
|
||||||
shared/src/canvas/BackGround.cpp
|
|
||||||
shared/src/canvas/BackGroundColors.cpp
|
|
||||||
shared/src/canvas/Canvas.cpp
|
|
||||||
shared/src/canvas/Tree.cpp
|
|
||||||
shared/src/values/Dna.cpp
|
|
||||||
shared/src/values/DnaManager.cpp
|
|
||||||
shared/src/values/mrand.cpp
|
|
||||||
shared/src/values/Similarity.cpp
|
|
||||||
shared/src/TcpSocket.cpp
|
|
||||||
)
|
)
|
||||||
# Add include directories
|
target_include_directories(app PRIVATE app/inc)
|
||||||
target_include_directories(app PRIVATE app/inc shared/inc )
|
target_link_libraries(app PRIVATE shared)
|
||||||
|
|
||||||
add_executable(server
|
add_executable(server
|
||||||
server/src/server.cpp
|
server/src/server.cpp
|
||||||
server/src/checker.cpp
|
server/src/checker.cpp
|
||||||
|
|
||||||
shared/src/sql.cpp
|
|
||||||
shared/src/TcpSocket.cpp
|
|
||||||
shared/src/values/Dna.cpp
|
|
||||||
shared/src/values/DnaManager.cpp
|
|
||||||
shared/src/values/mrand.cpp
|
|
||||||
)
|
)
|
||||||
# Add include directories
|
target_include_directories(server PRIVATE server/inc)
|
||||||
target_include_directories(server PRIVATE server/inc shared/inc)
|
target_link_libraries(server PRIVATE shared)
|
||||||
|
|
||||||
add_executable(view
|
add_executable(view
|
||||||
view/src/main.cpp
|
view/src/main.cpp
|
||||||
view/src/Vapp.cpp
|
view/src/Vapp.cpp
|
||||||
shared/src/canvas/BackGround.cpp
|
|
||||||
shared/src/canvas/BackGroundColors.cpp
|
|
||||||
shared/src/canvas/Canvas.cpp
|
|
||||||
shared/src/canvas/Tree.cpp
|
|
||||||
shared/src/values/Dna.cpp
|
|
||||||
shared/src/values/DnaManager.cpp
|
|
||||||
shared/src/values/mrand.cpp
|
|
||||||
shared/src/values/Similarity.cpp
|
|
||||||
|
|
||||||
shared/src/sql.cpp
|
|
||||||
)
|
)
|
||||||
# Add include directories
|
target_include_directories(view PRIVATE view/inc)
|
||||||
target_include_directories(view PRIVATE view/inc shared/inc)
|
target_link_libraries(view PRIVATE shared)
|
||||||
|
|
||||||
|
add_executable(slike
|
||||||
|
random/slike.cpp
|
||||||
|
)
|
||||||
|
target_link_libraries(slike PRIVATE shared)
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
#include <array>
|
#include <array>
|
||||||
#include "canvas/Canvas.hpp"
|
#include "canvas/Canvas.hpp"
|
||||||
#include "DnaStore.hpp"
|
#include "DnaStore.hpp"
|
||||||
|
|
||||||
class App
|
class App
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace DnaStore
|
namespace DnaStore
|
||||||
{
|
{
|
||||||
|
void init();
|
||||||
|
void deinit();
|
||||||
void load(DnaManagerData *data);
|
void load(DnaManagerData *data);
|
||||||
void saveData(DnaManagerData *data);
|
void saveData(DnaManagerData *data);
|
||||||
void saveVec(DnaManagerData *data);
|
void saveVec(DnaManagerData *data);
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ void App::init(int screenWidth, int screenHeight)
|
|||||||
this->screenWidth = screenWidth;
|
this->screenWidth = screenWidth;
|
||||||
this->screenHeight = screenHeight;
|
this->screenHeight = screenHeight;
|
||||||
this->canvas.init(screenWidth);
|
this->canvas.init(screenWidth);
|
||||||
|
DnaStore::init();
|
||||||
// int s = MeasureText("GEN 9999: 999/999", 20);
|
// int s = MeasureText("GEN 9999: 999/999", 20);
|
||||||
// TraceLog(LOG_INFO, "%d", s);
|
// TraceLog(LOG_INFO, "%d", s);
|
||||||
|
|
||||||
@@ -239,4 +239,5 @@ void App::deinit()
|
|||||||
UnloadRenderTexture(canvasTexure[i]);
|
UnloadRenderTexture(canvasTexure[i]);
|
||||||
}
|
}
|
||||||
canvas.deinit();
|
canvas.deinit();
|
||||||
|
DnaStore::deinit();
|
||||||
}
|
}
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "sys.hpp"
|
#include "sys.hpp"
|
||||||
#include "DnaStore.hpp"
|
#include "DnaStore.hpp"
|
||||||
#include "TcpSocket.hpp"
|
#include "TcpSocket.hpp"
|
||||||
|
#include "values/DnaDB.hpp"
|
||||||
|
|
||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
|
|
||||||
@@ -16,20 +17,31 @@
|
|||||||
#define DATA_FILE_NAME "DATA.bin"
|
#define DATA_FILE_NAME "DATA.bin"
|
||||||
#define VECTOR_FILE_NAME "VECTOR.bin"
|
#define VECTOR_FILE_NAME "VECTOR.bin"
|
||||||
#define GEN_FILE_PATTRN "gen/%04d.bin"
|
#define GEN_FILE_PATTRN "gen/%04d.bin"
|
||||||
#define HOST_NAME "petrovv.com"
|
#define HOST_NAME "localhost"
|
||||||
|
#define DB_NAME "data.db"
|
||||||
|
|
||||||
|
DnaDB dnaDB;
|
||||||
|
|
||||||
|
void DnaStore::init(){
|
||||||
|
const char* filename = sys::transformFilePath(DB_NAME);
|
||||||
|
dnaDB.init(filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DnaStore::deinit(){
|
||||||
|
dnaDB.deinit();
|
||||||
|
}
|
||||||
|
|
||||||
void DnaStore::load(DnaManagerData *data)
|
void DnaStore::load(DnaManagerData *data)
|
||||||
{
|
{
|
||||||
const char *dir = sys::transformFilePath("gen");
|
const char *dir = sys::transformFilePath("gen");
|
||||||
std::filesystem::create_directory(dir);
|
std::filesystem::create_directory(dir);
|
||||||
if (sys::fileExists(ID_FILE_NAME))
|
|
||||||
{
|
std::vector<int64_t> ids = dnaDB.getUserIds();
|
||||||
sys::loadDataFromFile(ID_FILE_NAME, &data->id, sizeof(int64_t));
|
if(!ids.empty()){
|
||||||
}
|
data->id = ids[0];
|
||||||
else
|
}else{
|
||||||
{
|
|
||||||
data->id = time(nullptr);
|
data->id = time(nullptr);
|
||||||
sys::saveDataToFile(ID_FILE_NAME, &data->id, sizeof(int64_t));
|
dnaDB.insertUser(data->id, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sys::fileExists(DATA_FILE_NAME))
|
if (sys::fileExists(DATA_FILE_NAME))
|
||||||
|
|||||||
77
random/build_sytem/build.cpp
Normal file
77
random/build_sytem/build.cpp
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
|
||||||
|
#define EXT_LINK
|
||||||
|
#define EXT_INC
|
||||||
|
#include "build.hpp"
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
|
std::vector<std::string> LINK = {"raylib/lib/libraylib.a"};
|
||||||
|
|
||||||
|
std::vector<std::string> RAYINCLUDE = {"-Iraylib/include"};
|
||||||
|
std::filesystem::path RAYLIB_DIR = "raylib";
|
||||||
|
|
||||||
|
bool build = false;
|
||||||
|
bool clear = false;
|
||||||
|
bool run = false;
|
||||||
|
|
||||||
|
int main(int argc, char const *argv[])
|
||||||
|
{
|
||||||
|
if (rebuild_my_self(__FILE__, argc, argv))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
for (int i = 1; i < argc; ++i)
|
||||||
|
{
|
||||||
|
if (!std::strcmp(argv[i], "opt"))
|
||||||
|
opt_flags = "-O3";
|
||||||
|
|
||||||
|
if (!std::strcmp(argv[i], "build"))
|
||||||
|
build = true;
|
||||||
|
|
||||||
|
if (!std::strcmp(argv[i], "run"))
|
||||||
|
run = true;
|
||||||
|
|
||||||
|
if (!std::strcmp(argv[i], "clear"))
|
||||||
|
{
|
||||||
|
clear_all_build();
|
||||||
|
clear = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (clear && !build)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!std::filesystem::is_directory(RAYLIB_DIR))
|
||||||
|
{
|
||||||
|
command = {"wget", "https://github.com/raysan5/raylib/releases/download/5.5/raylib-5.5_linux_amd64.tar.gz"};
|
||||||
|
run_command(command);
|
||||||
|
command = {"tar", "-xzvf", "raylib-5.5_linux_amd64.tar.gz"};
|
||||||
|
run_command(command);
|
||||||
|
std::filesystem::rename("raylib-5.5_linux_amd64", "raylib");
|
||||||
|
std::filesystem::remove_all("raylib-5.5_linux_amd64.tar.gz");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!std::filesystem::is_directory(RAYLIB_DIR))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
std::filesystem::create_directory(OBJ_DIR);
|
||||||
|
|
||||||
|
int res = compile_src_dir(RAYINCLUDE);
|
||||||
|
switch (res)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
compile_obj_dir(LINK);
|
||||||
|
break;
|
||||||
|
case -1:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!std::filesystem::exists(BUILD_FILE))
|
||||||
|
compile_obj_dir(LINK);
|
||||||
|
|
||||||
|
if (run)
|
||||||
|
{
|
||||||
|
run_main();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
408
random/build_sytem/build.hpp
Normal file
408
random/build_sytem/build.hpp
Normal file
@@ -0,0 +1,408 @@
|
|||||||
|
#include <cstdio>
|
||||||
|
#include <cstring>
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <list>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <fstream>
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
|
// #define EXT_ARGS
|
||||||
|
// #define EXT_LINK
|
||||||
|
// #define EXT_INC
|
||||||
|
// #define EXT_OBJ
|
||||||
|
// #define Werror
|
||||||
|
// #define Wextra
|
||||||
|
|
||||||
|
std::filesystem::path OBJ_DIR = "obj";
|
||||||
|
std::filesystem::path INC_DIR = "inc";
|
||||||
|
std::filesystem::path SRC_DIR = "src";
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
std::filesystem::path BUILD_FILE = "main.exe";
|
||||||
|
std::string cpp_compiler = "zig c++";
|
||||||
|
std::string c_compiler = "zig cc";
|
||||||
|
#else
|
||||||
|
std::filesystem::path BUILD_FILE = "main";
|
||||||
|
std::string cpp_compiler = "g++";
|
||||||
|
std::string c_compiler = "gcc";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
std::string opt_flags = "-ggdb";
|
||||||
|
std::vector<std::string> command;
|
||||||
|
|
||||||
|
enum class Color
|
||||||
|
{
|
||||||
|
black,
|
||||||
|
red,
|
||||||
|
green,
|
||||||
|
yellow,
|
||||||
|
blue,
|
||||||
|
purple,
|
||||||
|
cyan,
|
||||||
|
white,
|
||||||
|
reset,
|
||||||
|
};
|
||||||
|
|
||||||
|
void pick_color(Color color)
|
||||||
|
{
|
||||||
|
switch (color)
|
||||||
|
{
|
||||||
|
case Color::black:
|
||||||
|
printf("\033[0;30m");
|
||||||
|
break;
|
||||||
|
case Color::red:
|
||||||
|
printf("\033[0;31m");
|
||||||
|
break;
|
||||||
|
case Color::green:
|
||||||
|
printf("\033[0;32m");
|
||||||
|
break;
|
||||||
|
case Color::yellow:
|
||||||
|
printf("\033[0;33m");
|
||||||
|
break;
|
||||||
|
case Color::blue:
|
||||||
|
printf("\033[0;34m");
|
||||||
|
break;
|
||||||
|
case Color::purple:
|
||||||
|
printf("\033[0;35m");
|
||||||
|
break;
|
||||||
|
case Color::cyan:
|
||||||
|
printf("\033[0;36m");
|
||||||
|
break;
|
||||||
|
case Color::white:
|
||||||
|
printf("\033[0;37m");
|
||||||
|
break;
|
||||||
|
case Color::reset:
|
||||||
|
printf("\033[0m");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_command(std::vector<std::string> &arguments)
|
||||||
|
{
|
||||||
|
pick_color(Color::cyan);
|
||||||
|
for (auto &&i : arguments)
|
||||||
|
{
|
||||||
|
printf("%s ", i.c_str());
|
||||||
|
}
|
||||||
|
pick_color(Color::white);
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool run_command(std::vector<std::string> &arguments)
|
||||||
|
{
|
||||||
|
print_command(arguments);
|
||||||
|
std::string command = "";
|
||||||
|
|
||||||
|
for (auto &&i : arguments)
|
||||||
|
{
|
||||||
|
command += " " + i;
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::system(command.c_str()) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool check_if_rebuild(const std::filesystem::path &org_path, const std::filesystem::path &new_path)
|
||||||
|
{
|
||||||
|
if (!std::filesystem::exists(org_path))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!std::filesystem::exists(new_path))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
auto file_time_one = std::filesystem::last_write_time(org_path);
|
||||||
|
auto file_time_two = std::filesystem::last_write_time(new_path);
|
||||||
|
return file_time_one > file_time_two;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool try_remove(std::filesystem::path path)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
std::filesystem::remove(path);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (const std::exception &e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool rebuild_my_self(std::filesystem::path src_path, int argc, const char **exec_path)
|
||||||
|
{
|
||||||
|
std::filesystem::path exec = exec_path[0];
|
||||||
|
|
||||||
|
try_remove("old_build");
|
||||||
|
|
||||||
|
if (!check_if_rebuild(src_path, exec) && !check_if_rebuild(__FILE__, exec))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
std::filesystem::rename(exec, "old_build");
|
||||||
|
|
||||||
|
std::vector<std::string> input;
|
||||||
|
|
||||||
|
for (int i = 0; i < argc; ++i)
|
||||||
|
input.push_back(exec_path[i]);
|
||||||
|
|
||||||
|
std::vector<std::string> comand = {cpp_compiler, src_path.string(), "-o", exec_path[0], "-ggdb"};
|
||||||
|
if (!run_command(comand))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
printf("rebuild\n");
|
||||||
|
|
||||||
|
if (!run_command(input))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct all_in_directory
|
||||||
|
{
|
||||||
|
std::vector<std::filesystem::path> files;
|
||||||
|
std::vector<std::filesystem::path> dirs;
|
||||||
|
};
|
||||||
|
|
||||||
|
all_in_directory get_all_files_in_dir(std::filesystem::path directory_path)
|
||||||
|
{
|
||||||
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
|
all_in_directory dir;
|
||||||
|
if (!fs::is_directory(directory_path))
|
||||||
|
return dir;
|
||||||
|
|
||||||
|
std::list<fs::path> dirs;
|
||||||
|
dirs.push_back(directory_path);
|
||||||
|
dir.dirs.push_back(directory_path);
|
||||||
|
|
||||||
|
while (!dirs.empty())
|
||||||
|
{
|
||||||
|
for (const auto &entry : fs::directory_iterator(dirs.front()))
|
||||||
|
{
|
||||||
|
// Check if the entry is a regular file
|
||||||
|
if (fs::is_regular_file(entry))
|
||||||
|
{
|
||||||
|
dir.files.push_back(entry.path());
|
||||||
|
}
|
||||||
|
// Check if the entry is a directory
|
||||||
|
else if (fs::is_directory(entry))
|
||||||
|
{
|
||||||
|
dirs.push_back(entry.path());
|
||||||
|
dir.dirs.push_back(entry.path());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dirs.pop_front();
|
||||||
|
}
|
||||||
|
|
||||||
|
return dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> get_includes(const std::filesystem::path &path)
|
||||||
|
{
|
||||||
|
std::vector<std::string> ret;
|
||||||
|
|
||||||
|
std::ifstream ifs(path);
|
||||||
|
std::string line;
|
||||||
|
|
||||||
|
while (std::getline(ifs, line))
|
||||||
|
{
|
||||||
|
if (line.empty())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (line[0] != '#')
|
||||||
|
break;
|
||||||
|
|
||||||
|
// if include ends with " its my .h
|
||||||
|
if (line[line.size() - 1] == '\"')
|
||||||
|
{
|
||||||
|
// magic num 10 is lenOf(#include ") so start at 10 until end of
|
||||||
|
// line witch is len of line - 10 - 1 of cahar "
|
||||||
|
ret.push_back(line.substr(10, line.length() - 10 - 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void clear_all_build()
|
||||||
|
{
|
||||||
|
std::filesystem::remove_all(OBJ_DIR);
|
||||||
|
std::filesystem::remove_all(BUILD_FILE);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef EXT_INC
|
||||||
|
int compile_src_dir(std::vector<std::string> ext_inc)
|
||||||
|
#else
|
||||||
|
int compile_src_dir()
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
all_in_directory src_dir = get_all_files_in_dir(SRC_DIR);
|
||||||
|
all_in_directory obj_dir;
|
||||||
|
|
||||||
|
for (auto &&i : src_dir.dirs)
|
||||||
|
{
|
||||||
|
std::filesystem::create_directory(OBJ_DIR / i);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unordered_set<std::string> modified_heders;
|
||||||
|
all_in_directory inc_dir = get_all_files_in_dir(INC_DIR);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < inc_dir.files.size(); i++)
|
||||||
|
{
|
||||||
|
if (check_if_rebuild(inc_dir.files[i], BUILD_FILE))
|
||||||
|
{
|
||||||
|
std::string heder = inc_dir.files[i].string().substr(4);
|
||||||
|
modified_heders.insert(heder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
command.clear();
|
||||||
|
command.push_back(cpp_compiler);
|
||||||
|
command.push_back("-c");
|
||||||
|
int src_loc = command.size();
|
||||||
|
command.push_back("");
|
||||||
|
command.push_back("-o");
|
||||||
|
int obj_loc = command.size();
|
||||||
|
command.push_back("");
|
||||||
|
command.push_back(opt_flags);
|
||||||
|
|
||||||
|
#ifdef EXT_INC
|
||||||
|
command.insert(command.end(), ext_inc.begin(), ext_inc.end());
|
||||||
|
#endif
|
||||||
|
|
||||||
|
command.push_back("-I" + INC_DIR.string());
|
||||||
|
command.push_back("-std=c++20");
|
||||||
|
command.push_back("-Wall");
|
||||||
|
#ifdef Wextra
|
||||||
|
command.push_back("-Wextra");
|
||||||
|
#endif
|
||||||
|
#ifdef Werror
|
||||||
|
command.push_back("-Werror");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int build = 0;
|
||||||
|
for (auto &&i : src_dir.files)
|
||||||
|
{
|
||||||
|
std::filesystem::path tmp = i;
|
||||||
|
std::filesystem::path out = OBJ_DIR / tmp.replace_extension(".o");
|
||||||
|
bool reb = false;
|
||||||
|
// check if .cpp changed
|
||||||
|
if (check_if_rebuild(i, out))
|
||||||
|
reb = true;
|
||||||
|
|
||||||
|
// if .cpp didnt change check include files changed
|
||||||
|
if (!reb)
|
||||||
|
{
|
||||||
|
std::vector<std::string> incudes = get_includes(i);
|
||||||
|
for (auto &&j : incudes)
|
||||||
|
{
|
||||||
|
if (modified_heders.find(j) != modified_heders.end())
|
||||||
|
{
|
||||||
|
reb = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reb)
|
||||||
|
{
|
||||||
|
command[src_loc] = i.string();
|
||||||
|
command[obj_loc] = out.string();
|
||||||
|
if (!run_command(command))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
build = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return build;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(EXT_LINK)
|
||||||
|
bool compile_obj_dir(std::vector<std::string> ext_link)
|
||||||
|
#else
|
||||||
|
bool compile_obj_dir()
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
all_in_directory obj_dir = get_all_files_in_dir(OBJ_DIR);
|
||||||
|
|
||||||
|
command.clear();
|
||||||
|
command.push_back(cpp_compiler);
|
||||||
|
|
||||||
|
for (auto &&i : obj_dir.files)
|
||||||
|
{
|
||||||
|
command.push_back(i.string());
|
||||||
|
}
|
||||||
|
|
||||||
|
command.push_back(opt_flags);
|
||||||
|
command.push_back("-o");
|
||||||
|
command.push_back(BUILD_FILE.string());
|
||||||
|
|
||||||
|
#if defined(EXT_LINK)
|
||||||
|
command.insert(command.end(), ext_link.begin(), ext_link.end());
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return run_command(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(EXT_OBJ) && defined(EXT_INC)
|
||||||
|
void build_as_one(std::vector<std::string> ext_obj, std::vector<std::string> ext_inc)
|
||||||
|
#elif defined(EXT_OBJ)
|
||||||
|
void build_as_one(std::vector<std::string> ext_obj)
|
||||||
|
#elif defined(EXT_INC)
|
||||||
|
void build_as_one(std::vector<std::string> ext_inc)
|
||||||
|
#else
|
||||||
|
void build_as_one()
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
all_in_directory src_dir = get_all_files_in_dir(SRC_DIR);
|
||||||
|
|
||||||
|
command.clear();
|
||||||
|
command.push_back(cpp_compiler);
|
||||||
|
command.push_back("-o");
|
||||||
|
command.push_back(BUILD_FILE.string());
|
||||||
|
command.push_back(opt_flags);
|
||||||
|
|
||||||
|
#ifdef EXT_INC
|
||||||
|
command.insert(command.end(), ext_inc.begin(), ext_inc.end());
|
||||||
|
#endif
|
||||||
|
|
||||||
|
command.push_back("-I" + INC_DIR.string());
|
||||||
|
command.push_back("-std=c++20");
|
||||||
|
command.push_back("-Wall");
|
||||||
|
#ifdef Wextra
|
||||||
|
command.push_back("-Wextra");
|
||||||
|
#endif
|
||||||
|
#ifdef Werror
|
||||||
|
command.push_back("-Werror");
|
||||||
|
#endif
|
||||||
|
for (auto &&i : src_dir.files)
|
||||||
|
{
|
||||||
|
command.push_back(i.string());
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef EXT_OBJ
|
||||||
|
command.insert(command.end(), ext_obj.begin(), ext_obj.end());
|
||||||
|
#endif
|
||||||
|
run_command(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef EXT_ARGS
|
||||||
|
bool run_main(std::vector<std::string> ext_args)
|
||||||
|
#else
|
||||||
|
bool run_main()
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
command.clear();
|
||||||
|
#ifndef _WIN32
|
||||||
|
command.push_back("./" + BUILD_FILE.string());
|
||||||
|
#else
|
||||||
|
command.push_back(BUILD_FILE.string());
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef EXT_ARGS
|
||||||
|
command.insert(command.end(), ext_args.begin(), ext_args.end());
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return run_command(command);
|
||||||
|
}
|
||||||
147
random/slike.cpp
Normal file
147
random/slike.cpp
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
#include <raylib.h>
|
||||||
|
#include <raymath.h>
|
||||||
|
#include <cmath>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
Vector2 newPoint(Vector2 start, float len, float angleD){
|
||||||
|
float angleR = (angleD * PI) / 180; // radian
|
||||||
|
return {start.x + len * cos(angleR), start.y - len * sin(angleR)};
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawBranch(Vector2 startV, Vector2 endV, Color startC, Color endC, int startR, int endR){
|
||||||
|
float fstep = 0.05;
|
||||||
|
for (float i = 0; i < 1.05; i += fstep)
|
||||||
|
{
|
||||||
|
Vector2 point = Vector2Lerp(startV, endV, i);
|
||||||
|
Color color = ColorLerp(startC, endC, i);
|
||||||
|
int size = Lerp(startR, endR, i);
|
||||||
|
DrawCircleV(point, size, color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr float screenWidth = 800;
|
||||||
|
constexpr float screenHeight = 800;
|
||||||
|
|
||||||
|
constexpr float len = 300;
|
||||||
|
constexpr float angleD = 100;
|
||||||
|
constexpr Vector2 start = {screenWidth / 2, screenHeight - 100};
|
||||||
|
constexpr float radius = 20;
|
||||||
|
constexpr float radiusS = 80;
|
||||||
|
constexpr float radiusE = 60;
|
||||||
|
constexpr Color colorS = RED;
|
||||||
|
constexpr Color colorE = GREEN;
|
||||||
|
|
||||||
|
typedef void (*slika)();
|
||||||
|
|
||||||
|
int idx = 0;
|
||||||
|
|
||||||
|
std::vector<slika> v_slik = {
|
||||||
|
[]()
|
||||||
|
{
|
||||||
|
DrawCircleV(start, radius, BLACK);
|
||||||
|
},
|
||||||
|
|
||||||
|
[]()
|
||||||
|
{
|
||||||
|
Vector2 end = {start.x, start.y - len};
|
||||||
|
DrawCircleV(start, radius, BLACK);
|
||||||
|
DrawLineEx(start, end, 10, BLACK);
|
||||||
|
},
|
||||||
|
|
||||||
|
[]()
|
||||||
|
{
|
||||||
|
Vector2 end = newPoint(start, len, angleD);
|
||||||
|
DrawCircleV(start, radius, BLACK);
|
||||||
|
DrawLineEx(start, end, 10, BLACK);
|
||||||
|
DrawCircleV(end, radius, BLACK);
|
||||||
|
DrawCircleSectorLines(start, len / 3, 360 - angleD, 360, 30, BLACK);
|
||||||
|
},
|
||||||
|
|
||||||
|
[]()
|
||||||
|
{
|
||||||
|
Vector2 end = newPoint(start, len, angleD);
|
||||||
|
DrawCircleV(start, radius, BLACK);
|
||||||
|
DrawLineEx(start, end, 10, BLACK);
|
||||||
|
DrawCircleV(end, radius, BLACK);
|
||||||
|
DrawCircleLinesV(start, radiusS, BLACK);
|
||||||
|
DrawCircleLinesV(end, radiusE, BLACK);
|
||||||
|
},
|
||||||
|
|
||||||
|
[]()
|
||||||
|
{
|
||||||
|
Vector2 end = newPoint(start, len, angleD);
|
||||||
|
DrawLineEx(start, end, 10, BLACK);
|
||||||
|
DrawCircleV(start, radiusS, colorS);
|
||||||
|
DrawCircleV(end, radiusE, colorE);
|
||||||
|
},
|
||||||
|
|
||||||
|
[]()
|
||||||
|
{
|
||||||
|
Vector2 end = newPoint(start, len, angleD);
|
||||||
|
drawBranch(start, end, colorS, colorE, radiusS, radiusE);
|
||||||
|
},
|
||||||
|
|
||||||
|
[]()
|
||||||
|
{
|
||||||
|
Vector2 p = newPoint(start, len, angleD);
|
||||||
|
drawBranch(start, p, colorS, colorE, radiusS, radiusE);
|
||||||
|
Vector2 p1 = newPoint(p, len, 135);
|
||||||
|
Vector2 p2 = newPoint(p, len, 90);
|
||||||
|
Vector2 p3 = newPoint(p, len, 45);
|
||||||
|
DrawLineEx(p, p1, 10, BLACK);
|
||||||
|
DrawLineEx(p, p2, 10, BLACK);
|
||||||
|
DrawLineEx(p, p3, 10, BLACK);
|
||||||
|
DrawCircleV(p, radius, BLACK);
|
||||||
|
DrawCircleV(p1, radius, BLACK);
|
||||||
|
DrawCircleV(p2, radius, BLACK);
|
||||||
|
DrawCircleV(p3, radius, BLACK);
|
||||||
|
},
|
||||||
|
|
||||||
|
[]()
|
||||||
|
{
|
||||||
|
Vector2 p = newPoint(start, len, angleD);
|
||||||
|
drawBranch(start, p, colorS, colorE, radiusS, radiusE);
|
||||||
|
Vector2 p1 = newPoint(p, len, 135);
|
||||||
|
Vector2 p2 = newPoint(p, len, 90);
|
||||||
|
Vector2 p3 = newPoint(p, len, 45);
|
||||||
|
drawBranch(p, p1, colorE, BLUE, radiusE, 50);
|
||||||
|
drawBranch(p, p2, colorE, ORANGE, radiusE, 50);
|
||||||
|
drawBranch(p, p3, colorE, PURPLE, radiusE, 50);
|
||||||
|
},
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
InitWindow(screenWidth, screenHeight, "Slike");
|
||||||
|
SetTargetFPS(60);
|
||||||
|
|
||||||
|
while (!WindowShouldClose())
|
||||||
|
{
|
||||||
|
BeginDrawing();
|
||||||
|
if (IsKeyPressed(KEY_S))
|
||||||
|
{
|
||||||
|
TakeScreenshot(TextFormat("slika%.2d.png", idx));
|
||||||
|
}
|
||||||
|
if (IsKeyPressed(KEY_N))
|
||||||
|
{
|
||||||
|
idx++;
|
||||||
|
if (idx >= v_slik.size())
|
||||||
|
idx = v_slik.size() - 1;
|
||||||
|
}
|
||||||
|
if (IsKeyPressed(KEY_P))
|
||||||
|
{
|
||||||
|
idx--;
|
||||||
|
if (idx < 0)
|
||||||
|
idx = 0;
|
||||||
|
}
|
||||||
|
ClearBackground(WHITE);
|
||||||
|
v_slik[idx]();
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CloseWindow();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -32,8 +32,9 @@ private:
|
|||||||
Vector2 start = {0};
|
Vector2 start = {0};
|
||||||
std::list<DrawArgs> drawCalls;
|
std::list<DrawArgs> drawCalls;
|
||||||
|
|
||||||
void drawBranch();
|
void calculateBranch();
|
||||||
|
|
||||||
|
void drawBranch(Vector2 startPoint, Vector2 endPoint, Color startColor, Color endColor, float startThickness, float endThickness);
|
||||||
inline size_t getNumOfBranches(int dep);
|
inline size_t getNumOfBranches(int dep);
|
||||||
inline Color getStartColor(DrawArgs &arg);
|
inline Color getStartColor(DrawArgs &arg);
|
||||||
inline Color getEndColor(int dep, Color &start);
|
inline Color getEndColor(int dep, Color &start);
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ constexpr char DB_NAME[] = "data.db";
|
|||||||
struct sqlite3;
|
struct sqlite3;
|
||||||
struct sqlite3_stmt;
|
struct sqlite3_stmt;
|
||||||
|
|
||||||
#define SQLITE_ROW 100 /* sqlite3_step() has another row ready */
|
#define SQLITE_ROW 100 /* sqlite3_step() has another row ready */
|
||||||
#define SQL_DONE 101
|
#define SQL_DONE 101
|
||||||
#define SQL_NULL 5
|
#define SQL_NULL 5
|
||||||
#define SQLITE_OK 0
|
#define SQLITE_OK 0
|
||||||
@@ -44,6 +44,7 @@ namespace sql
|
|||||||
void init();
|
void init();
|
||||||
void shutdown();
|
void shutdown();
|
||||||
int open(const char *filename, sqlite3 **ppDb);
|
int open(const char *filename, sqlite3 **ppDb);
|
||||||
|
int exec(sqlite3 *db, const char *sql, int (*callback)(void *, int, char **, char **), void *first_arg, char **errmsg);
|
||||||
int prepare_v2(sqlite3 *db, const char *zSql, int nByte, sqlite3_stmt **pStmt, const char **pzTail);
|
int prepare_v2(sqlite3 *db, const char *zSql, int nByte, sqlite3_stmt **pStmt, const char **pzTail);
|
||||||
int bind_int64(sqlite3_stmt *pStmt, int column, int64_t value);
|
int bind_int64(sqlite3_stmt *pStmt, int column, int64_t value);
|
||||||
int step(sqlite3_stmt *pStmt);
|
int step(sqlite3_stmt *pStmt);
|
||||||
|
|||||||
20
shared/inc/values/DnaDB.hpp
Normal file
20
shared/inc/values/DnaDB.hpp
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#include <cinttypes>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
struct sqlite3;
|
||||||
|
|
||||||
|
class DnaDB
|
||||||
|
{
|
||||||
|
sqlite3 *db;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void init(const char *db_name = "data.db");
|
||||||
|
void deinit();
|
||||||
|
std::vector<int64_t> getUserIds();
|
||||||
|
int insertUser(int64_t id, int64_t max_gen);
|
||||||
|
int updateUser(int64_t id, int64_t max_gen);
|
||||||
|
|
||||||
|
void getGenerations();
|
||||||
|
void getLikesForGeneration();
|
||||||
|
void getVectorForGeneration();
|
||||||
|
};
|
||||||
@@ -7,9 +7,9 @@
|
|||||||
|
|
||||||
enum Liked
|
enum Liked
|
||||||
{
|
{
|
||||||
tbd,
|
tbd = 0,
|
||||||
yes,
|
yes = 1,
|
||||||
no
|
no = 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct UiUnit
|
struct UiUnit
|
||||||
|
|||||||
@@ -3,14 +3,14 @@
|
|||||||
|
|
||||||
namespace Similarity
|
namespace Similarity
|
||||||
{
|
{
|
||||||
// float euclidean_distance(Dna *d1, Dna *d2); direct distance betwen vector. wont give 0 and 1
|
float euclidean_distance(Dna *d1, Dna *d2);// direct distance betwen vector. wont give 0 and 1
|
||||||
// float dot_product(Dna *d1, Dna *d2); doent return betwen 0 to 1
|
float dot_minmax(Dna *d1, Dna *d2); // doent return betwen 0 to 1
|
||||||
// float cosine_similarity(Dna *d1, Dna *d2);
|
float cosine_similarity(Dna *d1, Dna *d2);
|
||||||
// float cosine_similarity_int(Dna *d1, Dna *d2);
|
float cosine_similarity_int(Dna *d1, Dna *d2);
|
||||||
float hamming_distance(Dna *d1, Dna *d2);
|
float hamming_distance(Dna *d1, Dna *d2);
|
||||||
float hamming_distance_without_seeds(Dna *d1, Dna *d2);
|
float hamming_distance_without_seeds(Dna *d1, Dna *d2);
|
||||||
// float jaccard_index(Dna *d1, Dna *d2); // primerja unio genov naprimer gleda ce je gen za nebo isti z genom za barvo za liste, to nerabimo
|
// float jaccard_index(Dna *d1, Dna *d2); // primerja unio genov naprimer gleda ce je gen za nebo isti z genom za barvo za liste, to nerabimo
|
||||||
// float levenshtein_distance(Dna *d1, Dna *d2); // odstranjen ker mi vrne iste podatke kot hamming distance ki je bolj enostaven za izracun
|
float levenshtein_distance(Dna *d1, Dna *d2); // odstranjen ker mi vrne iste podatke kot hamming distance ki je bolj enostaven za izracun
|
||||||
// float needleman_wunsch(Dna *d1, Dna *d2); used for bioinformatics and aligment. Dont need its aligned alredy
|
// float needleman_wunsch(Dna *d1, Dna *d2); used for bioinformatics and aligment. Dont need its aligned alredy
|
||||||
|
|
||||||
typedef float(simil_func)(Dna *d1, Dna *d2);
|
typedef float(simil_func)(Dna *d1, Dna *d2);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include "canvas/BackGround.hpp"
|
#include "canvas/BackGround.hpp"
|
||||||
#include "canvas/BackGroundColors.hpp"
|
#include "canvas/BackGroundColors.hpp"
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
#include <raymath.h>
|
#include <raymath.h>
|
||||||
|
#include <rlgl.h>
|
||||||
|
|
||||||
#define ITER_PER_FRAME 5000
|
#define ITER_PER_FRAME 5000
|
||||||
|
|
||||||
@@ -40,7 +41,7 @@ void Tree::init(int size)
|
|||||||
start.x = size / 2;
|
start.x = size / 2;
|
||||||
start.y = size;
|
start.y = size;
|
||||||
calculateLevels(size);
|
calculateLevels(size);
|
||||||
//texBunny = LoadTexture("dot.png"); // bug add deinit to unload texutre
|
// texBunny = LoadTexture("dot.png"); // bug add deinit to unload texutre
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tree::draw(Dna *dna)
|
void Tree::draw(Dna *dna)
|
||||||
@@ -56,7 +57,7 @@ bool Tree::tick()
|
|||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
while (!drawCalls.empty())
|
while (!drawCalls.empty())
|
||||||
{
|
{
|
||||||
drawBranch();
|
calculateBranch();
|
||||||
drawCalls.pop_front();
|
drawCalls.pop_front();
|
||||||
i++;
|
i++;
|
||||||
if (i >= ITER_PER_FRAME)
|
if (i >= ITER_PER_FRAME)
|
||||||
@@ -68,7 +69,7 @@ bool Tree::tick()
|
|||||||
|
|
||||||
// Private
|
// Private
|
||||||
|
|
||||||
void Tree::drawBranch()
|
void Tree::calculateBranch()
|
||||||
{
|
{
|
||||||
DrawArgs arg = drawCalls.front();
|
DrawArgs arg = drawCalls.front();
|
||||||
if (arg.dep == MAX_DEPTH)
|
if (arg.dep == MAX_DEPTH)
|
||||||
@@ -86,17 +87,14 @@ void Tree::drawBranch()
|
|||||||
|
|
||||||
Color colorStart = getStartColor(arg);
|
Color colorStart = getStartColor(arg);
|
||||||
Color colorEnd = getEndColor(arg.dep, colorStart);
|
Color colorEnd = getEndColor(arg.dep, colorStart);
|
||||||
|
// drawBranch(arg.start, end, colorStart, colorEnd, sizeStart, sizeEnd);
|
||||||
for (float i = 0; i < 1; i += fstep)
|
for (float i = 0; i < 1; i += fstep)
|
||||||
{
|
{
|
||||||
Vector2 point = Vector2Lerp(arg.start, end, i);
|
Vector2 point = Vector2Lerp(arg.start, end, i);
|
||||||
Color color = ColorLerp(colorStart, colorEnd, i);
|
Color color = ColorLerp(colorStart, colorEnd, i);
|
||||||
int size = Lerp(sizeStart, sizeEnd, i);
|
int size = Lerp(sizeStart, sizeEnd, i);
|
||||||
DrawCircleV(point, size, color);
|
DrawCircleV(point, size, color);
|
||||||
//DrawTextureEx(texBunny, point,0, ((float)size) / texBunny.height, color);
|
// DrawTextureEx(texBunny, point,0, ((float)size) / texBunny.height, color);
|
||||||
|
|
||||||
// use
|
|
||||||
// DrawRectangleGradientEx
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// add more branches to draw
|
// add more branches to draw
|
||||||
@@ -200,3 +198,51 @@ inline float Tree::getAngleVar(DrawArgs &arg)
|
|||||||
|
|
||||||
return angleVar;
|
return angleVar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Tree::drawBranch(Vector2 startPoint, Vector2 endPoint, Color startColor, Color endColor, float startThickness, float endThickness)
|
||||||
|
{
|
||||||
|
// Calculate the direction vector from startPoint to endPoint
|
||||||
|
Vector2 direction = {endPoint.x - startPoint.x, endPoint.y - startPoint.y};
|
||||||
|
|
||||||
|
// Normalize the direction vector
|
||||||
|
float length = sqrtf(direction.x * direction.x + direction.y * direction.y);
|
||||||
|
if (length == 0)
|
||||||
|
length = 1; // Avoid division by zero
|
||||||
|
Vector2 normalizedDir = {direction.x / length, direction.y / length};
|
||||||
|
|
||||||
|
// Calculate the perpendicular vector (rotate 90 degrees)
|
||||||
|
Vector2 perpendicular = {-normalizedDir.y, normalizedDir.x};
|
||||||
|
|
||||||
|
// Calculate the four vertices of the quadrilateral
|
||||||
|
Vector2 topLeft = {
|
||||||
|
startPoint.x + perpendicular.x * startThickness,
|
||||||
|
startPoint.y + perpendicular.y * startThickness};
|
||||||
|
Vector2 topRight = {
|
||||||
|
endPoint.x + perpendicular.x * endThickness,
|
||||||
|
endPoint.y + perpendicular.y * endThickness};
|
||||||
|
Vector2 bottomLeft = {
|
||||||
|
startPoint.x - perpendicular.x * startThickness,
|
||||||
|
startPoint.y - perpendicular.y * startThickness};
|
||||||
|
Vector2 bottomRight = {
|
||||||
|
endPoint.x - perpendicular.x * endThickness,
|
||||||
|
endPoint.y - perpendicular.y * endThickness};
|
||||||
|
|
||||||
|
// Draw the two triangles to form the quadrilateral
|
||||||
|
rlBegin(RL_TRIANGLES);
|
||||||
|
// First triangle
|
||||||
|
rlColor4ub(startColor.r, startColor.g, startColor.b, startColor.a);
|
||||||
|
rlVertex2f(topLeft.x, topLeft.y);
|
||||||
|
rlColor4ub(endColor.r, endColor.g, endColor.b, endColor.a);
|
||||||
|
rlVertex2f(topRight.x, topRight.y);
|
||||||
|
rlColor4ub(startColor.r, startColor.g, startColor.b, startColor.a);
|
||||||
|
rlVertex2f(bottomLeft.x, bottomLeft.y);
|
||||||
|
|
||||||
|
// Second triangle
|
||||||
|
rlColor4ub(startColor.r, startColor.g, startColor.b, startColor.a);
|
||||||
|
rlVertex2f(bottomLeft.x, bottomLeft.y);
|
||||||
|
rlColor4ub(endColor.r, endColor.g, endColor.b, endColor.a);
|
||||||
|
rlVertex2f(topRight.x, topRight.y);
|
||||||
|
rlColor4ub(endColor.r, endColor.g, endColor.b, endColor.a);
|
||||||
|
rlVertex2f(bottomRight.x, bottomRight.y);
|
||||||
|
rlEnd();
|
||||||
|
}
|
||||||
@@ -78,6 +78,10 @@ namespace sql
|
|||||||
{
|
{
|
||||||
return sqlite3_open(filename, ppDb);
|
return sqlite3_open(filename, ppDb);
|
||||||
}
|
}
|
||||||
|
int exec(sqlite3 *db, const char *sql, int (*callback)(void *, int, char **, char **), void *first, char **errmsg)
|
||||||
|
{
|
||||||
|
return sqlite3_exec(db, sql, callback, first, errmsg);
|
||||||
|
}
|
||||||
int prepare_v2(sqlite3 *db, const char *zSql, int nByte, sqlite3_stmt **pStmt, const char **pzTail)
|
int prepare_v2(sqlite3 *db, const char *zSql, int nByte, sqlite3_stmt **pStmt, const char **pzTail)
|
||||||
{
|
{
|
||||||
return sqlite3_prepare_v2(db, zSql, nByte, pStmt, pzTail);
|
return sqlite3_prepare_v2(db, zSql, nByte, pStmt, pzTail);
|
||||||
|
|||||||
69
shared/src/values/DnaDB.cpp
Normal file
69
shared/src/values/DnaDB.cpp
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
#include "values/DnaDB.hpp"
|
||||||
|
|
||||||
|
#include <sql.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void DnaDB::init(const char * db_name)
|
||||||
|
{
|
||||||
|
sql::init();
|
||||||
|
int res = sql::open(db_name, &db);
|
||||||
|
|
||||||
|
constexpr char create_user_table[] = "CREATE TABLE IF NOT EXISTS user_table ( ID INTEGER PRIMARY KEY, USER_ID INTEGER, MAX_GENERATION INTEGER);";
|
||||||
|
res = sql::exec(db, create_user_table, nullptr, nullptr, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DnaDB::deinit()
|
||||||
|
{
|
||||||
|
sql::close(db);
|
||||||
|
sql::shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<int64_t> DnaDB::getUserIds()
|
||||||
|
{
|
||||||
|
constexpr char sql[] = "SELECT USER_ID FROM user_table;";
|
||||||
|
sqlite3_stmt *stmt;
|
||||||
|
sql::prepare_v2(db, sql, -1, &stmt, nullptr);
|
||||||
|
std::vector<int64_t> ids;
|
||||||
|
while (sql::step(stmt) != SQL_DONE)
|
||||||
|
{
|
||||||
|
int64_t id = sql::column_int64(stmt, 0);
|
||||||
|
ids.push_back(id);
|
||||||
|
}
|
||||||
|
sql::finalize(stmt);
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DnaDB::insertUser(int64_t id, int64_t max_gen){
|
||||||
|
constexpr char sql[] = "INSERT INTO user_table (USER_ID, MAX_GENERATION) VALUES (?,?);";
|
||||||
|
sqlite3_stmt *stmt;
|
||||||
|
sql::prepare_v2(db, sql, -1, &stmt, nullptr);
|
||||||
|
sql::bind_int64(stmt, 1, id);
|
||||||
|
sql::bind_int64(stmt, 2, max_gen);
|
||||||
|
int ret = sql::step(stmt);
|
||||||
|
sql::finalize(stmt);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DnaDB::updateUser(int64_t id, int64_t max_gen){
|
||||||
|
constexpr char sql[] = "UPDATE user_table SET MAX_GENERATION = ? WHERE USER_ID = ?;";
|
||||||
|
sqlite3_stmt *stmt;
|
||||||
|
sql::prepare_v2(db, sql, -1, &stmt, nullptr);
|
||||||
|
sql::bind_int64(stmt, 1, max_gen);
|
||||||
|
sql::bind_int64(stmt, 2, id);
|
||||||
|
int ret = sql::step(stmt);
|
||||||
|
sql::finalize(stmt);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DnaDB::getGenerations()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void DnaDB::getLikesForGeneration()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void DnaDB::getVectorForGeneration()
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -1,56 +1,88 @@
|
|||||||
#include "values/Similarity.hpp"
|
#include "values/Similarity.hpp"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <numeric>
|
||||||
|
#include <raylib.h>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
namespace Similarity
|
namespace Similarity
|
||||||
{
|
{
|
||||||
|
|
||||||
|
float dot_minmax(Dna *d1, Dna *d2)
|
||||||
|
{
|
||||||
|
uint64_t max = sizeof(Dna) * 255 * 255;
|
||||||
|
uint8_t *a = (uint8_t *)d1;
|
||||||
|
uint8_t *b = (uint8_t *)d2;
|
||||||
|
uint32_t result = 0;
|
||||||
|
for (size_t i = 0; i < sizeof(Dna); ++i)
|
||||||
|
{
|
||||||
|
result += static_cast<uint32_t>(a[i]) * static_cast<uint32_t>(b[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result / (double)max;
|
||||||
|
}
|
||||||
|
|
||||||
|
float euclidean_distance(Dna *d1, Dna *d2)
|
||||||
|
{
|
||||||
|
uint8_t *a = (uint8_t *)d1;
|
||||||
|
uint8_t *b = (uint8_t *)d2;
|
||||||
|
float sum = 0.0f;
|
||||||
|
for (size_t i = 0; i < sizeof(Dna); ++i)
|
||||||
|
{
|
||||||
|
float diff = static_cast<float>(a[i]) - static_cast<float>(b[i]);
|
||||||
|
sum += diff * diff;
|
||||||
|
}
|
||||||
|
|
||||||
|
float distance = std::sqrt(sum);
|
||||||
|
float max_distance = 255.0f * std::sqrt(static_cast<float>(sizeof(Dna)));
|
||||||
|
return 1 - (distance / max_distance);
|
||||||
|
}
|
||||||
|
|
||||||
// todo: use int8_t insted of uint8_t and map data
|
// todo: use int8_t insted of uint8_t and map data
|
||||||
// 0 -> -128
|
// 0 -> -128
|
||||||
// 255 -> 127
|
// 255 -> 127
|
||||||
// int8_t = uint8_t - 128
|
// int8_t = uint8_t - 128
|
||||||
// float cosine_similarity(Dna *d1, Dna *d2)
|
float cosine_similarity(Dna *d1, Dna *d2)
|
||||||
// {
|
{
|
||||||
// uint8_t *d1a = (uint8_t *)d1;
|
uint8_t *d1a = (uint8_t *)d1;
|
||||||
// uint8_t *d2a = (uint8_t *)d2;
|
uint8_t *d2a = (uint8_t *)d2;
|
||||||
|
|
||||||
// float mag1 = 0.0f;
|
float mag1 = 0.0f;
|
||||||
// float mag2 = 0.0f;
|
float mag2 = 0.0f;
|
||||||
// float dot_prod = 0.0f;
|
float dot_prod = 0.0f;
|
||||||
// for (size_t i = 0; i < sizeof(Dna); i++)
|
for (size_t i = 0; i < sizeof(Dna); i++)
|
||||||
// {
|
{
|
||||||
// dot_prod += d1a[i] * d2a[i];
|
dot_prod += d1a[i] * d2a[i];
|
||||||
// mag1 += d1a[i] * d1a[i];
|
mag1 += d1a[i] * d1a[i];
|
||||||
// mag2 += d2a[i] * d2a[i];
|
mag2 += d2a[i] * d2a[i];
|
||||||
// }
|
}
|
||||||
// mag1 = sqrt(mag1);
|
mag1 = sqrt(mag1);
|
||||||
// mag2 = sqrt(mag2);
|
mag2 = sqrt(mag2);
|
||||||
|
|
||||||
// return dot_prod / (mag1 * mag2);
|
return dot_prod / (mag1 * mag2);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// float cosine_similarity_int(Dna *d1, Dna *d2)
|
float cosine_similarity_int(Dna *d1, Dna *d2)
|
||||||
// {
|
{
|
||||||
// auto map = [](uint8_t a) -> int8_t
|
auto map = [](uint8_t a) -> int8_t
|
||||||
// { return a - 128; };
|
{ return a - 128; };
|
||||||
|
uint8_t *d1a = (uint8_t *)d1;
|
||||||
// uint8_t *d1a = (uint8_t *)d1;
|
uint8_t *d2a = (uint8_t *)d2;
|
||||||
// uint8_t *d2a = (uint8_t *)d2;
|
float mag1 = 0.0f;
|
||||||
|
float mag2 = 0.0f;
|
||||||
// float mag1 = 0.0f;
|
float dot_prod = 0.0f;
|
||||||
// float mag2 = 0.0f;
|
for (size_t i = 0; i < sizeof(Dna); i++)
|
||||||
// float dot_prod = 0.0f;
|
{
|
||||||
// for (size_t i = 0; i < sizeof(Dna); i++)
|
int8_t a = map(d1a[i]);
|
||||||
// {
|
int8_t b = map(d2a[i]);
|
||||||
// int8_t a = map(d1a[i]);
|
dot_prod += a * b;
|
||||||
// int8_t b = map(d2a[i]);
|
mag1 += a * a;
|
||||||
// dot_prod += a * b;
|
mag2 += b * b;
|
||||||
// mag1 += a * a;
|
}
|
||||||
// mag2 += b * b;
|
mag1 = sqrt(mag1);
|
||||||
// }
|
mag2 = sqrt(mag2);
|
||||||
// mag1 = sqrt(mag1);
|
return dot_prod / (mag1 * mag2);
|
||||||
// mag2 = sqrt(mag2);
|
}
|
||||||
|
|
||||||
// return dot_prod / (mag1 * mag2);
|
|
||||||
// }
|
|
||||||
|
|
||||||
float hamming_distance(Dna *d1, Dna *d2)
|
float hamming_distance(Dna *d1, Dna *d2)
|
||||||
{
|
{
|
||||||
@@ -84,8 +116,45 @@ namespace Similarity
|
|||||||
return 1 - (distance / (end - start));
|
return 1 - (distance / (end - start));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *nameofFunc(simil_func f)
|
||||||
|
{
|
||||||
|
if (f == &Similarity::euclidean_distance)
|
||||||
|
{
|
||||||
|
return "eucl";
|
||||||
|
}
|
||||||
|
else if (f == &Similarity::dot_minmax)
|
||||||
|
{
|
||||||
|
return "dot";
|
||||||
|
}
|
||||||
|
else if (f == &Similarity::cosine_similarity)
|
||||||
|
{
|
||||||
|
return "cos";
|
||||||
|
}
|
||||||
|
else if (f == &Similarity::cosine_similarity_int)
|
||||||
|
{
|
||||||
|
return "cos_i";
|
||||||
|
}
|
||||||
|
else if (f == &Similarity::hamming_distance)
|
||||||
|
{
|
||||||
|
return "hamming_distance";
|
||||||
|
}
|
||||||
|
else if (f == &Similarity::hamming_distance_without_seeds)
|
||||||
|
{
|
||||||
|
return "hamming_distance_without_seeds";
|
||||||
|
}
|
||||||
|
else if (f == &Similarity::levenshtein_distance)
|
||||||
|
{
|
||||||
|
return "leven";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return "unknown nameofFunc";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
float calc_similarity(std::vector<Dna> &vec, simil_func f)
|
float calc_similarity(std::vector<Dna> &vec, simil_func f)
|
||||||
{
|
{
|
||||||
|
auto start = std::chrono::high_resolution_clock::now();
|
||||||
size_t num_pairs = (vec.size() * (vec.size() - 1)) / 2;
|
size_t num_pairs = (vec.size() * (vec.size() - 1)) / 2;
|
||||||
|
|
||||||
float total_similarity = 0.0;
|
float total_similarity = 0.0;
|
||||||
@@ -97,6 +166,47 @@ namespace Similarity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
float average_similarity = total_similarity / num_pairs;
|
float average_similarity = total_similarity / num_pairs;
|
||||||
|
|
||||||
|
auto stop = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
|
const auto int_ms = std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
|
||||||
|
|
||||||
return average_similarity * 100.0f;
|
return average_similarity * 100.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float levenshtein_distance(Dna *d1, Dna *d2)
|
||||||
|
{
|
||||||
|
size_t len = sizeof(Dna);
|
||||||
|
uint8_t *a = (uint8_t *)d1;
|
||||||
|
uint8_t *b = (uint8_t *)d2;
|
||||||
|
|
||||||
|
// Create a distance matrix
|
||||||
|
static std::vector<std::vector<uint32_t>> dp(len + 1, std::vector<uint32_t>(len + 1, 0));
|
||||||
|
|
||||||
|
// Initialize the first row and column
|
||||||
|
for (size_t i = 0; i <= len; ++i)
|
||||||
|
{
|
||||||
|
dp[i][0] = i;
|
||||||
|
}
|
||||||
|
for (size_t j = 0; j <= len; ++j)
|
||||||
|
{
|
||||||
|
dp[0][j] = j;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fill the distance matrix
|
||||||
|
for (size_t i = 1; i <= len; ++i)
|
||||||
|
{
|
||||||
|
for (size_t j = 1; j <= len; ++j)
|
||||||
|
{
|
||||||
|
uint32_t cost = (a[i - 1] == b[j - 1]) ? 0 : 1;
|
||||||
|
dp[i][j] = std::min({
|
||||||
|
dp[i - 1][j] + 1, // deletion
|
||||||
|
dp[i][j - 1] + 1, // insertion
|
||||||
|
dp[i - 1][j - 1] + cost // substitution
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 1 - (dp[len][len] / float(len + len));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
14
tmp.txt
Normal file
14
tmp.txt
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
eucl cos cos_i hamming dot leven
|
||||||
|
91 117 181 87 41 105799
|
||||||
|
60 78 305 250 40 100331
|
||||||
|
61 78 121 105 40 97438
|
||||||
|
66 81 124 106 40 97529
|
||||||
|
60 78 127 108 40 96296
|
||||||
|
62 85 131 104 39 96456
|
||||||
|
61 81 125 106 40 96510
|
||||||
|
61 81 125 103 40 97253
|
||||||
|
61 81 125 78 40 97409
|
||||||
|
60 82 125 103 40 99816
|
||||||
|
62 81 128 81 40 98978
|
||||||
|
68 81 126 58 40 98289
|
||||||
|
61 88 130 60 39 99663
|
||||||
@@ -11,10 +11,11 @@ enum DrawingStage
|
|||||||
drawTree,
|
drawTree,
|
||||||
drawBig,
|
drawBig,
|
||||||
calSim,
|
calSim,
|
||||||
|
save,
|
||||||
done,
|
done,
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr int numberOfFunc = 2;
|
constexpr int numberOfFunc = 6;
|
||||||
|
|
||||||
class Vapp
|
class Vapp
|
||||||
{
|
{
|
||||||
@@ -27,6 +28,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
bool showSelection;
|
bool showSelection;
|
||||||
bool showStats;
|
bool showStats;
|
||||||
|
bool saveToFile;
|
||||||
sqlite3 *db;
|
sqlite3 *db;
|
||||||
sqlite3_stmt *get_gen_num;
|
sqlite3_stmt *get_gen_num;
|
||||||
std::vector<int64_t> ids;
|
std::vector<int64_t> ids;
|
||||||
@@ -52,4 +54,5 @@ private:
|
|||||||
std::vector<std::array<float, numberOfFunc>> similTable;
|
std::vector<std::array<float, numberOfFunc>> similTable;
|
||||||
|
|
||||||
void setUpTable();
|
void setUpTable();
|
||||||
|
void drawToFile();
|
||||||
};
|
};
|
||||||
@@ -6,12 +6,13 @@
|
|||||||
#include <rlImGui.h>
|
#include <rlImGui.h>
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
const char select_user_id[] = "SELECT USER_ID FROM user_table GROUP BY USER_ID;";
|
const char select_user_id[] = "SELECT USER_ID FROM user_table GROUP BY USER_ID;";
|
||||||
|
|
||||||
constexpr int sizeOfCanvas = 1000;
|
constexpr int sizeOfCanvas = 1000;
|
||||||
|
|
||||||
void Vapp::init(char* filename)
|
void Vapp::init(char *filename)
|
||||||
{
|
{
|
||||||
bigTexture = LoadRenderTexture(sizeOfCanvas * 4, sizeOfCanvas * 4);
|
bigTexture = LoadRenderTexture(sizeOfCanvas * 4, sizeOfCanvas * 4);
|
||||||
treeTexture = LoadRenderTexture(sizeOfCanvas, sizeOfCanvas);
|
treeTexture = LoadRenderTexture(sizeOfCanvas, sizeOfCanvas);
|
||||||
@@ -100,11 +101,18 @@ void Vapp::update()
|
|||||||
break;
|
break;
|
||||||
case DrawingStage::calSim:
|
case DrawingStage::calSim:
|
||||||
|
|
||||||
simil[0] = Similarity::calc_similarity(manager.vector, Similarity::hamming_distance);
|
simil[0] = Similarity::calc_similarity(manager.vector, Similarity::euclidean_distance);
|
||||||
simil[1] = Similarity::calc_similarity(manager.vector, Similarity::hamming_distance_without_seeds);
|
simil[1] = Similarity::calc_similarity(manager.vector, Similarity::cosine_similarity);
|
||||||
|
simil[2] = Similarity::calc_similarity(manager.vector, Similarity::cosine_similarity_int);
|
||||||
|
simil[3] = Similarity::calc_similarity(manager.vector, Similarity::hamming_distance);
|
||||||
|
simil[4] = Similarity::calc_similarity(manager.vector, Similarity::levenshtein_distance);
|
||||||
|
simil[5] = Similarity::calc_similarity(manager.vector, Similarity::dot_minmax);
|
||||||
|
stageOfDrawing = DrawingStage::save;
|
||||||
|
break;
|
||||||
|
case DrawingStage::save:
|
||||||
|
if(saveToFile) drawToFile();
|
||||||
stageOfDrawing = DrawingStage::done;
|
stageOfDrawing = DrawingStage::done;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DrawingStage::done:
|
case DrawingStage::done:
|
||||||
enableAll = true;
|
enableAll = true;
|
||||||
break;
|
break;
|
||||||
@@ -132,6 +140,10 @@ void Vapp::draw()
|
|||||||
{
|
{
|
||||||
setUpTable();
|
setUpTable();
|
||||||
}
|
}
|
||||||
|
if(ImGui::MenuItem("Save to File", nullptr, saveToFile, true))
|
||||||
|
{
|
||||||
|
saveToFile = !saveToFile;
|
||||||
|
}
|
||||||
ImGui::EndMainMenuBar();
|
ImGui::EndMainMenuBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,13 +185,35 @@ void Vapp::draw()
|
|||||||
if (showStats)
|
if (showStats)
|
||||||
{
|
{
|
||||||
ImGui::Begin("Status", &showStats);
|
ImGui::Begin("Status", &showStats);
|
||||||
ImGui::LabelText("##sim1", "hamming_distance: %f", simil[0]);
|
ImGui::LabelText("##sim1", "euclidean_distance: %f", simil[0]);
|
||||||
ImGui::LabelText("##sim2", "hamming_distance_without_seeds: %f", simil[1]);
|
ImGui::LabelText("##sim2", "cosine_similarity: %f", simil[1]);
|
||||||
|
ImGui::LabelText("##sim3", "cosine_similarity_int: %f", simil[2]);
|
||||||
|
ImGui::LabelText("##sim4", "hamming_distance: %f", simil[3]);
|
||||||
|
ImGui::LabelText("##sim5", "levenshtein_distance: %f", simil[4]);
|
||||||
|
ImGui::LabelText("##sim6", "dot_minmax: %f", simil[5]);
|
||||||
|
|
||||||
const ImGuiTableFlags flags = ImGuiTableFlags_NoHostExtendX | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Resizable | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_ContextMenuInBody;
|
const ImGuiTableFlags flags = ImGuiTableFlags_NoHostExtendX | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Resizable | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_ContextMenuInBody;
|
||||||
const int columns = numberOfFunc + 1;
|
const int columns = numberOfFunc + 1;
|
||||||
if (ImGui::BeginTable("table1", columns, flags))
|
if (ImGui::BeginTable("table1", columns, flags))
|
||||||
{
|
{
|
||||||
|
|
||||||
|
ImGui::TableNextRow();
|
||||||
|
|
||||||
|
ImGui::TableSetColumnIndex(0);
|
||||||
|
ImGui::Text("index");
|
||||||
|
ImGui::TableSetColumnIndex(1);
|
||||||
|
ImGui::Text("euclidean_distance");
|
||||||
|
ImGui::TableSetColumnIndex(2);
|
||||||
|
ImGui::Text("cosine_similarity");
|
||||||
|
ImGui::TableSetColumnIndex(3);
|
||||||
|
ImGui::Text("cosine_similarity_int");
|
||||||
|
ImGui::TableSetColumnIndex(4);
|
||||||
|
ImGui::Text("hamming_distance");
|
||||||
|
ImGui::TableSetColumnIndex(5);
|
||||||
|
ImGui::Text("levenshtein_distance");
|
||||||
|
ImGui::TableSetColumnIndex(6);
|
||||||
|
ImGui::Text("dot_minmax");
|
||||||
|
|
||||||
for (int row = 0; row < similTable.size(); row++)
|
for (int row = 0; row < similTable.size(); row++)
|
||||||
{
|
{
|
||||||
ImGui::TableNextRow();
|
ImGui::TableNextRow();
|
||||||
@@ -277,7 +311,7 @@ void Vapp::setUpTable()
|
|||||||
UiUnit unit = DnaManager::next(&manager);
|
UiUnit unit = DnaManager::next(&manager);
|
||||||
if ((unit.index != pos))
|
if ((unit.index != pos))
|
||||||
{
|
{
|
||||||
// DOTO: SET ERROR
|
// TODO: SET ERROR
|
||||||
TraceLog(LOG_ERROR, "LOADING DNA");
|
TraceLog(LOG_ERROR, "LOADING DNA");
|
||||||
sql::finalize(get_gen_stmt);
|
sql::finalize(get_gen_stmt);
|
||||||
return;
|
return;
|
||||||
@@ -290,9 +324,13 @@ void Vapp::setUpTable()
|
|||||||
{
|
{
|
||||||
similTable.emplace_back();
|
similTable.emplace_back();
|
||||||
int s = similTable.size() - 1;
|
int s = similTable.size() - 1;
|
||||||
similTable[s][0] = Similarity::calc_similarity(manager.vector, Similarity::hamming_distance);
|
|
||||||
similTable[s][1] = Similarity::calc_similarity(manager.vector, Similarity::hamming_distance_without_seeds);
|
|
||||||
|
|
||||||
|
similTable[s][0] = Similarity::calc_similarity(manager.vector, Similarity::euclidean_distance);
|
||||||
|
similTable[s][1] = Similarity::calc_similarity(manager.vector, Similarity::cosine_similarity);
|
||||||
|
similTable[s][2] = Similarity::calc_similarity(manager.vector, Similarity::cosine_similarity_int);
|
||||||
|
similTable[s][3] = Similarity::calc_similarity(manager.vector, Similarity::hamming_distance);
|
||||||
|
similTable[s][4] = Similarity::calc_similarity(manager.vector, Similarity::levenshtein_distance);
|
||||||
|
similTable[s][5] = Similarity::calc_similarity(manager.vector, Similarity::dot_minmax);
|
||||||
DnaManager::newGen(&manager);
|
DnaManager::newGen(&manager);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -301,7 +339,38 @@ void Vapp::setUpTable()
|
|||||||
}
|
}
|
||||||
|
|
||||||
sql::reset(get_gen_stmt);
|
sql::reset(get_gen_stmt);
|
||||||
}
|
if(saveToFile)
|
||||||
|
{
|
||||||
|
int64_t id = ids[selected_id_index];
|
||||||
|
const char* buff = TextFormat("%ld.txt", id);
|
||||||
|
std::ofstream file(buff);
|
||||||
|
|
||||||
|
file << "| index | euclidean_distance | cosine_similarity | cosine_similarity_int | hamming_distance | levenshtein_distance | dot_minmax |\n";
|
||||||
|
file << "| --- | --- | --- | --- | --- | --- | --- |\n";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for (size_t i = 0; i < similTable.size(); i++)
|
||||||
|
{
|
||||||
|
file << "|" << i << "|";
|
||||||
|
for (size_t j = 0; j < similTable[i].size(); j++)
|
||||||
|
{
|
||||||
|
file << similTable[i][j] << "|";
|
||||||
|
}
|
||||||
|
file << "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sql::finalize(get_gen_stmt);
|
sql::finalize(get_gen_stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Vapp::drawToFile()
|
||||||
|
{
|
||||||
|
int64_t id = ids[selected_id_index];
|
||||||
|
char buff[50];
|
||||||
|
sprintf(buff, "%ld_%d.png", id, selected_gen);
|
||||||
|
Image image = LoadImageFromTexture(bigTexture.texture);
|
||||||
|
ExportImage(image, buff);
|
||||||
|
UnloadImage(image);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user