Skip to content

Commit

Permalink
Merge pull request #531 from Bot-detector/kc-migration
Browse files Browse the repository at this point in the history
query report_sighting
  • Loading branch information
extreme4all authored Jul 29, 2024
2 parents 11fc55e + 449acd9 commit 4388258
Show file tree
Hide file tree
Showing 6 changed files with 516 additions and 38 deletions.
47 changes: 20 additions & 27 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,28 @@
version: '3'
services:
mysql:
container_name: database
build:
context: ../bot-detector-mysql
dockerfile: Dockerfile
image: bot-detector/bd-mysql:latest
context: ./mysql
image: mysql
environment:
- MYSQL_ROOT_PASSWORD=root_bot_buster
- MYSQL_USER=botssuck
- MYSQL_PASSWORD=botdetector
volumes:
- ../bot-detector-mysql/mount:/var/lib/mysql
- '../bot-detector-mysql/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d'
- ./mysql/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d
- ./mysql/conf.d:/etc/mysql/conf.d
# - ./mysql/mount:/var/lib/mysql # creates persistence
ports:
- "3306:3306"
- 3307:3306
networks:
- botdetector-network

kafka:
image: bitnami/kafka:latest
environment:
- ALLOW_PLAINTEXT_LISTENER=yes
- KAFKA_CFG_LISTENERS=PLAINTEXT://:9092,CONTROLLER://:9093,EXTERNAL://:9094
- KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT,EXTERNAL:PLAINTEXT
- KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://kafka:9092,EXTERNAL://localhost:9094
- KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE=true
ports:
- 9094:9094
networks:
- botdetector-network
healthcheck:
test: "mysqladmin ping -h localhost -u root -proot_bot_buster"
# during this period fails are not considered
start_period: 30s
# time between cmd
interval: 30s
# time given to the cmd
timeout: 5s

api:
build:
Expand All @@ -41,18 +35,17 @@ services:
command: uvicorn src.core.server:app --host 0.0.0.0 --reload --reload-include src/*
container_name: bd-dev-api
environment:
- sql_uri=mysql+asyncmy://root:root_bot_buster@mysql:3306/playerdata
- discord_sql_uri=mysql+asyncmy://root:root_bot_buster@mysql:3306/discord
- sql_uri=mysql+asyncmy://root:root_bot_buster@mysql/playerdata
- discord_sql_uri=mysql+asyncmy://root:root_bot_buster@mysql/discord
- token=verify_ban
volumes:
- ../Bot-Detector-Core-Files/src:/project/src:rw
- ./src:/project/src:rw
ports:
- 5000:5000
networks:
- botdetector-network
depends_on:
- mysql
- kafka

mysql:
condition: service_healthy
networks:
botdetector-network:
3 changes: 3 additions & 0 deletions mysql/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM mysql:8.0.32

EXPOSE 3306
1 change: 1 addition & 0 deletions mysql/docker-entrypoint-initdb.d/00_init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE DATABASE playerdata;
128 changes: 128 additions & 0 deletions mysql/docker-entrypoint-initdb.d/01_tables.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
USE playerdata;
-- Create a table for Players
CREATE TABLE Players (
id INT PRIMARY KEY AUTO_INCREMENT,
name TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP,
possible_ban BOOLEAN,
confirmed_ban BOOLEAN,
confirmed_player BOOLEAN,
label_id INTEGER,
label_jagex INTEGER,
ironman BOOLEAN,
hardcore_ironman BOOLEAN,
ultimate_ironman BOOLEAN,
normalized_name TEXT
);

CREATE TABLE `Labels` (
`id` int NOT NULL AUTO_INCREMENT,
`label` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `Unique_label` (`label`) USING BTREE
)
;

-- Create a table for Reports
CREATE TABLE Reports (
ID BIGINT PRIMARY KEY AUTO_INCREMENT,
created_at TIMESTAMP,
reportedID INT,
reportingID INT,
region_id INT,
x_coord INT,
y_coord INT,
z_coord INT,
timestamp TIMESTAMP,
manual_detect SMALLINT,
on_members_world INT,
on_pvp_world SMALLINT,
world_number INT,
equip_head_id INT,
equip_amulet_id INT,
equip_torso_id INT,
equip_legs_id INT,
equip_boots_id INT,
equip_cape_id INT,
equip_hands_id INT,
equip_weapon_id INT,
equip_shield_id INT,
equip_ge_value BIGINT,
CONSTRAINT `FK_Reported_Players_id` FOREIGN KEY (`reportedID`) REFERENCES `Players` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT `FK_Reporting_Players_id` FOREIGN KEY (`reportingID`) REFERENCES `Players` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
);
-- Create a table for Predictions
CREATE TABLE Predictions (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(12),
prediction VARCHAR(50),
created TIMESTAMP,
predicted_confidence DECIMAL(5, 2),
real_player DECIMAL(5, 2) DEFAULT 0,
pvm_melee_bot DECIMAL(5, 2) DEFAULT 0,
smithing_bot DECIMAL(5, 2) DEFAULT 0,
magic_bot DECIMAL(5, 2) DEFAULT 0,
fishing_bot DECIMAL(5, 2) DEFAULT 0,
mining_bot DECIMAL(5, 2) DEFAULT 0,
crafting_bot DECIMAL(5, 2) DEFAULT 0,
pvm_ranged_magic_bot DECIMAL(5, 2) DEFAULT 0,
pvm_ranged_bot DECIMAL(5, 2) DEFAULT 0,
hunter_bot DECIMAL(5, 2) DEFAULT 0,
fletching_bot DECIMAL(5, 2) DEFAULT 0,
clue_scroll_bot DECIMAL(5, 2) DEFAULT 0,
lms_bot DECIMAL(5, 2) DEFAULT 0,
agility_bot DECIMAL(5, 2) DEFAULT 0,
wintertodt_bot DECIMAL(5, 2) DEFAULT 0,
runecrafting_bot DECIMAL(5, 2) DEFAULT 0,
zalcano_bot DECIMAL(5, 2) DEFAULT 0,
woodcutting_bot DECIMAL(5, 2) DEFAULT 0,
thieving_bot DECIMAL(5, 2) DEFAULT 0,
soul_wars_bot DECIMAL(5, 2) DEFAULT 0,
cooking_bot DECIMAL(5, 2) DEFAULT 0,
vorkath_bot DECIMAL(5, 2) DEFAULT 0,
barrows_bot DECIMAL(5, 2) DEFAULT 0,
herblore_bot DECIMAL(5, 2) DEFAULT 0,
zulrah_bot DECIMAL(5, 2) DEFAULT 0,
gauntlet_bot DECIMAL(5, 2) DEFAULT 0,
nex_bot DECIMAL(5, 2) DEFAULT 0,
unknown_bot DECIMAL(5, 2) DEFAULT 0
);
-- Create a table for Feedback
CREATE TABLE PredictionsFeedback (
id INT PRIMARY KEY AUTO_INCREMENT,
ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
voter_id INT NOT NULL,
subject_id INT NOT NULL,
prediction VARCHAR(50) NOT NULL,
confidence FLOAT NOT NULL,
vote INT NOT NULL DEFAULT '0',
feedback_text TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci,
reviewed TINYINT NOT NULL DEFAULT '0',
reviewer_id INT DEFAULT NULL,
user_notified TINYINT NOT NULL DEFAULT '0',
proposed_label VARCHAR(50) DEFAULT NULL,
UNIQUE KEY Unique_Vote (
prediction,
subject_id,
voter_id
) USING BTREE,
CONSTRAINT `FK_Subject_ID` FOREIGN KEY (`subject_id`) REFERENCES `Players` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT `FK_Voter_ID` FOREIGN KEY (`voter_id`) REFERENCES `Players` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
);

CREATE TABLE report_sighting (
`report_sighting_id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`reporting_id` INT UNSIGNED NOT NULL,
`reported_id` INT UNSIGNED NOT NULL,
`manual_detect` TINYINT(1) DEFAULT 0,
PRIMARY key (`report_sighting_id`),
UNIQUE KEY unique_sighting (`reporting_id`, `reported_id`, `manual_detect`),
KEY idx_reported_id (`reported_id`)
);

CREATE TABLE report_migrated (
`reporting_id` INT UNSIGNED NOT NULL,
`migrated` TINYINT UNSIGNED,
PRIMARY KEY (`reporting_id`)
);
Loading

0 comments on commit 4388258

Please sign in to comment.