Compare commits

..

10 Commits

Author SHA1 Message Date
98bc42be7d Add slike to random 2026-02-03 15:25:15 +01:00
208f849b47 add header 2026-01-29 13:43:51 +01:00
771cabed8f old_data 2026-01-05 22:20:51 +01:00
96f4f51e69 ch 2025-12-04 13:31:30 +01:00
525936c6e7 f 2025-10-24 16:54:16 +02:00
060b9f9182 s 2025-10-22 19:07:59 +02:00
59fd47e684 Add print image 2025-10-22 18:47:05 +02:00
593b813988 Add similaritys 2025-10-22 17:56:26 +02:00
5f6305a2f2 s 2025-10-09 15:53:58 +02:00
dddf8ca632 t 2025-10-08 19:41:46 +02:00
14 changed files with 93 additions and 218 deletions

View File

@@ -33,7 +33,6 @@ add_library(shared STATIC
shared/src/values/Similarity.cpp shared/src/values/Similarity.cpp
shared/src/TcpSocket.cpp shared/src/TcpSocket.cpp
shared/src/sql.cpp shared/src/sql.cpp
shared/src/values/DnaDB.cpp
) )
add_executable(app add_executable(app
@@ -48,6 +47,7 @@ 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
) )
target_include_directories(server PRIVATE server/inc) target_include_directories(server PRIVATE server/inc)
target_link_libraries(server PRIVATE shared) target_link_libraries(server PRIVATE shared)
@@ -59,6 +59,7 @@ add_executable(view
target_include_directories(view PRIVATE view/inc) target_include_directories(view PRIVATE view/inc)
target_link_libraries(view PRIVATE shared) target_link_libraries(view PRIVATE shared)
add_executable(slike add_executable(slike
random/slike.cpp random/slike.cpp
) )

View File

@@ -1,7 +1,6 @@
#include <array> #include <array>
#include "canvas/Canvas.hpp" #include "canvas/Canvas.hpp"
#include "DnaStore.hpp" #include "DnaStore.hpp"
class App class App
{ {

View File

@@ -2,8 +2,6 @@
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);

View File

@@ -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,5 +239,4 @@ void App::deinit()
UnloadRenderTexture(canvasTexure[i]); UnloadRenderTexture(canvasTexure[i]);
} }
canvas.deinit(); canvas.deinit();
DnaStore::deinit();
} }

View File

@@ -9,7 +9,6 @@
#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>
@@ -18,30 +17,19 @@
#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 "localhost" #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(); {
if(!ids.empty()){ sys::loadDataFromFile(ID_FILE_NAME, &data->id, sizeof(int64_t));
data->id = ids[0]; }
}else{ else
{
data->id = time(nullptr); data->id = time(nullptr);
dnaDB.insertUser(data->id, 0); sys::saveDataToFile(ID_FILE_NAME, &data->id, sizeof(int64_t));
} }
if (sys::fileExists(DATA_FILE_NAME)) if (sys::fileExists(DATA_FILE_NAME))

View File

@@ -3,116 +3,109 @@
#include <cmath> #include <cmath>
#include <vector> #include <vector>
Vector2 newPoint(Vector2 start, float len, float angleD){ float len = 300;
float angleR = (angleD * PI) / 180; // radian float angleD = 100;
return {start.x + len * cos(angleR), start.y - len * sin(angleR)}; float angleR = (angleD * PI) / 180; // radian
} Vector2 start = {250, 400};
Vector2 end = {250, start.y - len};
void drawBranch(Vector2 startV, Vector2 endV, Color startC, Color endC, int startR, int endR){ Vector2 end_kot = {};
float fstep = 0.05; float radius = 20;
for (float i = 0; i < 1.05; i += fstep) float radiusS = 80;
{ float radiusE = 60;
Vector2 point = Vector2Lerp(startV, endV, i); Color colorS = RED;
Color color = ColorLerp(startC, endC, i); Color colorE = GREEN;
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)(); typedef void (*slika)();
Vector2 tstart = {10, 10};
int tsize = 30;
int idx = 0; int idx = 0;
std::vector<slika> v_slik = { std::vector<slika> v_slik = {
[]() []()
{ {
DrawText("Zacetna tocka", tstart.x, tstart.y, tsize, BLACK);
DrawCircleV(start, radius, BLACK); DrawCircleV(start, radius, BLACK);
}, },
[]() []()
{ {
Vector2 end = {start.x, start.y - len}; DrawText("Dolzina", tstart.x, tstart.y, tsize, BLACK);
DrawCircleV(start, radius, BLACK); DrawCircleV(start, radius, BLACK);
DrawLineEx(start, end, 10, BLACK); DrawLineEx(start, end, 10, BLACK);
}, },
[]() []()
{ {
Vector2 end = newPoint(start, len, angleD); DrawText("Kot in Koncna tocka", tstart.x, tstart.y, tsize, BLACK);
DrawCircleV(start, radius, BLACK); DrawCircleV(start, radius, BLACK);
DrawLineEx(start, end, 10, BLACK); DrawLineEx(start, end_kot, 10, BLACK);
DrawCircleV(end, radius, BLACK); DrawCircleV(end_kot, radius, BLACK);
DrawCircleSectorLines(start, len / 3, 360 - angleD, 360, 30, BLACK); DrawCircleSectorLines(start, len / 3, 360 - angleD, 360, 30, BLACK);
}, },
[]() []()
{ {
Vector2 end = newPoint(start, len, angleD); DrawText("Zacetna debelina", tstart.x, tstart.y, tsize, BLACK);
DrawCircleV(start, radius, BLACK); DrawCircleV(start, radius, BLACK);
DrawLineEx(start, end, 10, BLACK); DrawLineEx(start, end_kot, 10, BLACK);
DrawCircleV(end, radius, BLACK); DrawCircleV(end_kot, radius, BLACK);
DrawCircleLinesV(start, radiusS, BLACK); DrawCircleLinesV(start, radiusS, BLACK);
DrawCircleLinesV(end, radiusE, BLACK); },
[]()
{
DrawText("Koncna debelina", tstart.x, tstart.y, tsize, BLACK);
DrawCircleV(start, radius, BLACK);
DrawLineEx(start, end_kot, 10, BLACK);
DrawCircleV(end_kot, radius, BLACK);
DrawCircleLinesV(start, radiusS, BLACK);
DrawCircleLinesV(end_kot, radiusE, BLACK);
}, },
[]() []()
{ {
Vector2 end = newPoint(start, len, angleD); DrawText("Zacetna barva", tstart.x, tstart.y, tsize, BLACK);
DrawLineEx(start, end, 10, BLACK); DrawLineEx(start, end_kot, 10, BLACK);
DrawCircleV(end_kot, radius, BLACK);
DrawCircleV(start, radiusS, colorS); DrawCircleV(start, radiusS, colorS);
DrawCircleV(end, radiusE, colorE); DrawCircleLinesV(end_kot, radiusE, BLACK);
}, },
[]() []()
{ {
Vector2 end = newPoint(start, len, angleD); DrawText("Koncna barva", tstart.x, tstart.y, tsize, BLACK);
drawBranch(start, end, colorS, colorE, radiusS, radiusE); DrawLineEx(start, end_kot, 10, BLACK);
DrawCircleV(start, radiusS, colorS);
DrawCircleV(end_kot, radiusE, colorE);
}, },
[]() []()
{ {
Vector2 p = newPoint(start, len, angleD); DrawText("Veja", tstart.x, tstart.y, tsize, BLACK);
drawBranch(start, p, colorS, colorE, radiusS, radiusE); float fstep = 0.05;
Vector2 p1 = newPoint(p, len, 135); for (float i = 0; i < 1.05; i += fstep)
Vector2 p2 = newPoint(p, len, 90); {
Vector2 p3 = newPoint(p, len, 45); Vector2 point = Vector2Lerp(start, end_kot, i);
DrawLineEx(p, p1, 10, BLACK); Color color = ColorLerp(colorS, colorE, i);
DrawLineEx(p, p2, 10, BLACK); int size = Lerp(radiusS, radiusE, i);
DrawLineEx(p, p3, 10, BLACK); DrawCircleV(point, size, color);
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[]) int main(int argc, char *argv[])
{ {
int screenWidth = 500;
int screenHeight = 500;
float ny = len * sin(angleR);
float nx = len * cos(angleR);
end_kot.x = start.x + nx;
end_kot.y = start.y - ny;
InitWindow(screenWidth, screenHeight, "Slike"); InitWindow(screenWidth, screenHeight, "Slike");
SetTargetFPS(60); SetTargetFPS(60);

View File

@@ -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,7 +44,6 @@ 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);

View File

@@ -1,20 +0,0 @@
#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();
};

View File

@@ -7,9 +7,9 @@
enum Liked enum Liked
{ {
tbd = 0, tbd,
yes = 1, yes,
no = 2, no
}; };
struct UiUnit struct UiUnit

View File

@@ -78,10 +78,6 @@ 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);

View File

@@ -1,69 +0,0 @@
#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()
{
}

View File

@@ -136,11 +136,7 @@ namespace Similarity
} }
else if (f == &Similarity::hamming_distance) else if (f == &Similarity::hamming_distance)
{ {
return "hamming_distance"; return "hamming";
}
else if (f == &Similarity::hamming_distance_without_seeds)
{
return "hamming_distance_without_seeds";
} }
else if (f == &Similarity::levenshtein_distance) else if (f == &Similarity::levenshtein_distance)
{ {
@@ -148,7 +144,7 @@ namespace Similarity
} }
else else
{ {
return "unknown nameofFunc"; return "unknown";
} }
} }
@@ -171,6 +167,7 @@ namespace Similarity
const auto int_ms = std::chrono::duration_cast<std::chrono::microseconds>(stop - start); const auto int_ms = std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
TraceLog(LOG_INFO, "%s, %d", nameofFunc(f), int_ms);
return average_similarity * 100.0f; return average_similarity * 100.0f;
} }

View File

@@ -28,7 +28,6 @@ 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;

View File

@@ -110,7 +110,7 @@ void Vapp::update()
stageOfDrawing = DrawingStage::save; stageOfDrawing = DrawingStage::save;
break; break;
case DrawingStage::save: case DrawingStage::save:
if(saveToFile) drawToFile(); drawToFile();
stageOfDrawing = DrawingStage::done; stageOfDrawing = DrawingStage::done;
break; break;
case DrawingStage::done: case DrawingStage::done:
@@ -140,10 +140,6 @@ void Vapp::draw()
{ {
setUpTable(); setUpTable();
} }
if(ImGui::MenuItem("Save to File", nullptr, saveToFile, true))
{
saveToFile = !saveToFile;
}
ImGui::EndMainMenuBar(); ImGui::EndMainMenuBar();
} }
@@ -339,28 +335,27 @@ void Vapp::setUpTable()
} }
sql::reset(get_gen_stmt); sql::reset(get_gen_stmt);
if(saveToFile)
int64_t id = ids[selected_id_index];
char buff[50];
sprintf(buff, "%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++)
{ {
int64_t id = ids[selected_id_index]; file << "|" << i << "|";
const char* buff = TextFormat("%ld.txt", id); for (size_t j = 0; j < similTable[i].size(); j++)
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 << "|"; file << similTable[i][j] << "|";
for (size_t j = 0; j < similTable[i].size(); j++)
{
file << similTable[i][j] << "|";
}
file << "\n";
} }
file << "\n";
} }
} }
sql::finalize(get_gen_stmt); sql::finalize(get_gen_stmt);
} }