You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

70 lines
2.2 KiB

#pragma once
#include "sqlite3.h"
#include <string>
#include <cstdio>
#include <vector>
#include <tuple>
#include <optional>
class songdb {
std::string filepath;
sqlite3 *db;
public:
struct runtime_vals { };
runtime_vals runtime_data;
protected:
enum error_codes {
NOT_FOUND,
ALREADY_ADDED
};
static int callback(void *valmap, int argc, char **argv, char **azColName);
bool setup_tables();
int check_error(int rc);
public:
struct track_entry {
int64_t id;
std::string name;
std::string artist;
std::optional<std::string> spotify_id;
};
struct vote {
int song;
int list;
int64_t user;
double value;
};
struct base_weight_vector {
std::vector<int64_t> person_order;
std::vector<int64_t> song_order;
std::vector<std::vector<double>> weights;
};
void create_new_list(int64_t group_id);
int64_t get_song_list_id(int64_t group_id);
std::optional<track_entry> get_song(int64_t id);
std::optional<track_entry> get_song(std::string name, std::string artist);
std::optional<track_entry> get_song(std::string name, std::string artist, std::optional<std::string> spotify_id);
std::optional<track_entry> insert_song(std::string name, std::string artist, std::optional<std::string> spotify_id);
bool insert_vote(int64_t user, int64_t group, int value, int64_t songid);
std::vector<vote> get_votes_list(int64_t song_list);
base_weight_vector get_base_weights (int64_t song_list);
double dot_product(const std::vector<double> &a, const std::vector<double> &b);
double weight_badness_inner_product(const std::vector<double> &current_badness, const std::vector<double> &song_goodness);
std::vector<double> update_badness(std::vector<double> old_badness, std::vector<double> song_goodness);
base_weight_vector get_top_songs(base_weight_vector input, std::vector<double> starting_badness, int num);
std::string get_top_5_songs(int64_t telegram_group);
std::vector<track_entry> generate_track_list(int64_t song_list);
songdb(std::string filepath);
~songdb();
};