Compare commits
5 Commits
test_sqlit
...
060b9f9182
| Author | SHA1 | Date | |
|---|---|---|---|
| 060b9f9182 | |||
| 59fd47e684 | |||
| 593b813988 | |||
| 5f6305a2f2 | |||
| dddf8ca632 |
@@ -8,11 +8,7 @@ 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(
|
include_directories(external/include/)
|
||||||
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
|
||||||
@@ -22,7 +18,11 @@ link_libraries(
|
|||||||
m
|
m
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(shared STATIC
|
add_executable(app
|
||||||
|
app/src/main.cpp
|
||||||
|
app/src/App.cpp
|
||||||
|
app/src/DnaStore.cpp
|
||||||
|
app/src/sys.cpp
|
||||||
shared/src/canvas/BackGround.cpp
|
shared/src/canvas/BackGround.cpp
|
||||||
shared/src/canvas/BackGroundColors.cpp
|
shared/src/canvas/BackGroundColors.cpp
|
||||||
shared/src/canvas/Canvas.cpp
|
shared/src/canvas/Canvas.cpp
|
||||||
@@ -32,34 +32,36 @@ add_library(shared STATIC
|
|||||||
shared/src/values/mrand.cpp
|
shared/src/values/mrand.cpp
|
||||||
shared/src/values/Similarity.cpp
|
shared/src/values/Similarity.cpp
|
||||||
shared/src/TcpSocket.cpp
|
shared/src/TcpSocket.cpp
|
||||||
shared/src/sql.cpp
|
|
||||||
shared/src/values/DnaDB.cpp
|
|
||||||
)
|
)
|
||||||
|
# Add include directories
|
||||||
add_executable(app
|
target_include_directories(app PRIVATE app/inc shared/inc )
|
||||||
app/src/main.cpp
|
|
||||||
app/src/App.cpp
|
|
||||||
app/src/DnaStore.cpp
|
|
||||||
app/src/sys.cpp
|
|
||||||
)
|
|
||||||
target_include_directories(app PRIVATE app/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
|
||||||
)
|
)
|
||||||
target_include_directories(server PRIVATE server/inc)
|
# Add include directories
|
||||||
target_link_libraries(server PRIVATE shared)
|
target_include_directories(server PRIVATE server/inc shared/inc)
|
||||||
|
|
||||||
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
|
||||||
)
|
)
|
||||||
target_include_directories(view PRIVATE view/inc)
|
# Add include directories
|
||||||
target_link_libraries(view PRIVATE shared)
|
target_include_directories(view PRIVATE view/inc shared/inc)
|
||||||
|
|
||||||
add_executable(slike
|
|
||||||
random/slike.cpp
|
|
||||||
)
|
|
||||||
target_link_libraries(slike PRIVATE shared)
|
|
||||||
@@ -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
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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();
|
|
||||||
}
|
}
|
||||||
@@ -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))
|
||||||
|
|||||||
147
random/slike.cpp
147
random/slike.cpp
@@ -1,147 +0,0 @@
|
|||||||
#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,9 +32,8 @@ private:
|
|||||||
Vector2 start = {0};
|
Vector2 start = {0};
|
||||||
std::list<DrawArgs> drawCalls;
|
std::list<DrawArgs> drawCalls;
|
||||||
|
|
||||||
void calculateBranch();
|
void drawBranch();
|
||||||
|
|
||||||
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,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);
|
||||||
|
|||||||
@@ -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();
|
|
||||||
};
|
|
||||||
@@ -7,9 +7,9 @@
|
|||||||
|
|
||||||
enum Liked
|
enum Liked
|
||||||
{
|
{
|
||||||
tbd = 0,
|
tbd,
|
||||||
yes = 1,
|
yes,
|
||||||
no = 2,
|
no
|
||||||
};
|
};
|
||||||
|
|
||||||
struct UiUnit
|
struct UiUnit
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
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_minmax(Dna *d1, Dna *d2); // doent return betwen 0 to 1
|
// float dot_product(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);
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
#include "canvas/BackGround.hpp"
|
#include "canvas/BackGround.hpp"
|
||||||
#include "canvas/BackGroundColors.hpp"
|
#include "canvas/BackGroundColors.hpp"
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
#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
|
||||||
|
|
||||||
@@ -41,7 +40,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)
|
||||||
@@ -57,7 +56,7 @@ bool Tree::tick()
|
|||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
while (!drawCalls.empty())
|
while (!drawCalls.empty())
|
||||||
{
|
{
|
||||||
calculateBranch();
|
drawBranch();
|
||||||
drawCalls.pop_front();
|
drawCalls.pop_front();
|
||||||
i++;
|
i++;
|
||||||
if (i >= ITER_PER_FRAME)
|
if (i >= ITER_PER_FRAME)
|
||||||
@@ -69,7 +68,7 @@ bool Tree::tick()
|
|||||||
|
|
||||||
// Private
|
// Private
|
||||||
|
|
||||||
void Tree::calculateBranch()
|
void Tree::drawBranch()
|
||||||
{
|
{
|
||||||
DrawArgs arg = drawCalls.front();
|
DrawArgs arg = drawCalls.front();
|
||||||
if (arg.dep == MAX_DEPTH)
|
if (arg.dep == MAX_DEPTH)
|
||||||
@@ -87,14 +86,17 @@ void Tree::calculateBranch()
|
|||||||
|
|
||||||
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
|
||||||
@@ -198,51 +200,3 @@ 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,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);
|
||||||
|
|||||||
@@ -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()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
@@ -2,26 +2,10 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <numeric>
|
#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)
|
float euclidean_distance(Dna *d1, Dna *d2)
|
||||||
{
|
{
|
||||||
uint8_t *a = (uint8_t *)d1;
|
uint8_t *a = (uint8_t *)d1;
|
||||||
@@ -116,45 +100,8 @@ 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;
|
||||||
@@ -166,11 +113,6 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,7 +123,7 @@ namespace Similarity
|
|||||||
uint8_t *b = (uint8_t *)d2;
|
uint8_t *b = (uint8_t *)d2;
|
||||||
|
|
||||||
// Create a distance matrix
|
// Create a distance matrix
|
||||||
static std::vector<std::vector<uint32_t>> dp(len + 1, std::vector<uint32_t>(len + 1, 0));
|
std::vector<std::vector<uint32_t>> dp(len + 1, std::vector<uint32_t>(len + 1, 0));
|
||||||
|
|
||||||
// Initialize the first row and column
|
// Initialize the first row and column
|
||||||
for (size_t i = 0; i <= len; ++i)
|
for (size_t i = 0; i <= len; ++i)
|
||||||
|
|||||||
14
tmp.txt
14
tmp.txt
@@ -1,14 +0,0 @@
|
|||||||
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
|
|
||||||
@@ -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;
|
||||||
|
|||||||
@@ -105,12 +105,12 @@ void Vapp::update()
|
|||||||
simil[1] = Similarity::calc_similarity(manager.vector, Similarity::cosine_similarity);
|
simil[1] = Similarity::calc_similarity(manager.vector, Similarity::cosine_similarity);
|
||||||
simil[2] = Similarity::calc_similarity(manager.vector, Similarity::cosine_similarity_int);
|
simil[2] = Similarity::calc_similarity(manager.vector, Similarity::cosine_similarity_int);
|
||||||
simil[3] = Similarity::calc_similarity(manager.vector, Similarity::hamming_distance);
|
simil[3] = Similarity::calc_similarity(manager.vector, Similarity::hamming_distance);
|
||||||
simil[4] = Similarity::calc_similarity(manager.vector, Similarity::levenshtein_distance);
|
simil[4] = Similarity::calc_similarity(manager.vector, Similarity::hamming_distance_without_seeds);
|
||||||
simil[5] = Similarity::calc_similarity(manager.vector, Similarity::dot_minmax);
|
simil[5] = Similarity::calc_similarity(manager.vector, Similarity::levenshtein_distance);
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,8 +185,8 @@ void Vapp::draw()
|
|||||||
ImGui::LabelText("##sim2", "cosine_similarity: %f", simil[1]);
|
ImGui::LabelText("##sim2", "cosine_similarity: %f", simil[1]);
|
||||||
ImGui::LabelText("##sim3", "cosine_similarity_int: %f", simil[2]);
|
ImGui::LabelText("##sim3", "cosine_similarity_int: %f", simil[2]);
|
||||||
ImGui::LabelText("##sim4", "hamming_distance: %f", simil[3]);
|
ImGui::LabelText("##sim4", "hamming_distance: %f", simil[3]);
|
||||||
ImGui::LabelText("##sim5", "levenshtein_distance: %f", simil[4]);
|
ImGui::LabelText("##sim5", "hamming_distance_without_seeds: %f", simil[4]);
|
||||||
ImGui::LabelText("##sim6", "dot_minmax: %f", simil[5]);
|
ImGui::LabelText("##sim6", "levenshtein_distance: %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;
|
||||||
@@ -210,9 +206,9 @@ void Vapp::draw()
|
|||||||
ImGui::TableSetColumnIndex(4);
|
ImGui::TableSetColumnIndex(4);
|
||||||
ImGui::Text("hamming_distance");
|
ImGui::Text("hamming_distance");
|
||||||
ImGui::TableSetColumnIndex(5);
|
ImGui::TableSetColumnIndex(5);
|
||||||
ImGui::Text("levenshtein_distance");
|
ImGui::Text("hamming_distance_without_seeds");
|
||||||
ImGui::TableSetColumnIndex(6);
|
ImGui::TableSetColumnIndex(6);
|
||||||
ImGui::Text("dot_minmax");
|
ImGui::Text("levenshtein_distance");
|
||||||
|
|
||||||
for (int row = 0; row < similTable.size(); row++)
|
for (int row = 0; row < similTable.size(); row++)
|
||||||
{
|
{
|
||||||
@@ -329,8 +325,8 @@ void Vapp::setUpTable()
|
|||||||
similTable[s][1] = Similarity::calc_similarity(manager.vector, Similarity::cosine_similarity);
|
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][2] = Similarity::calc_similarity(manager.vector, Similarity::cosine_similarity_int);
|
||||||
similTable[s][3] = Similarity::calc_similarity(manager.vector, Similarity::hamming_distance);
|
similTable[s][3] = Similarity::calc_similarity(manager.vector, Similarity::hamming_distance);
|
||||||
similTable[s][4] = Similarity::calc_similarity(manager.vector, Similarity::levenshtein_distance);
|
similTable[s][4] = Similarity::calc_similarity(manager.vector, Similarity::hamming_distance_without_seeds);
|
||||||
similTable[s][5] = Similarity::calc_similarity(manager.vector, Similarity::dot_minmax);
|
similTable[s][5] = Similarity::calc_similarity(manager.vector, Similarity::levenshtein_distance);
|
||||||
DnaManager::newGen(&manager);
|
DnaManager::newGen(&manager);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -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 | hamming_distance_without_seeds | levenshtein_distance |\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);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user