<commit_before>package io.github.thatsmusic99.headsplus.sql;

import io.github.thatsmusic99.configurationmaster.api.ConfigSection;
import io.github.thatsmusic99.headsplus.HeadsPlus;
import io.github.thatsmusic99.headsplus.config.ConfigMobs;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;

public class StatisticsSQLManager extends SQLManager {

    private static StatisticsSQLManager instance;

    public StatisticsSQLManager() {
        instance = this;
        createTable();
        transferOldData();
    }

    public static StatisticsSQLManager get() {
        return instance;
    }

    @Override
    public void createTable() {
        try (Connection connection = implementConnection()) {
            PreparedStatement statement = connection.prepareStatement(
                    "CREATE TABLE IF NOT EXISTS headsplus_stats " +
                            "(user_id INT NOT NULL," +
                            "collection_type VARCHAR(32) NOT NULL," +
                            "head VARCHAR(256) NOT NULL," +
                            "metadata VARCHAR(256) NOT NULL," +
                            "count INT NOT NULL)"
            );

            statement.executeUpdate();
        } catch (SQLException exception) {
            exception.printStackTrace();
        }
    }

    @Override
    public void transferOldData() {
        File storageFolder = new File(HeadsPlus.get().getDataFolder(), "storage");
        if (!storageFolder.exists()) return;
        File playerInfo = new File(storageFolder, "playerinfo.json");
        if (!playerInfo.exists()) return;
        try (FileReader reader = new FileReader(playerInfo)) {
            JSONObject core = (JSONObject) new JSONParser().parse(reader);
            for (Object uuidObj : core.keySet()) {
                if (uuidObj.equals("server-total")) continue;
                JSONObject playerObj = (JSONObject) core.get(uuidObj);
                UUID uuid = UUID.fromString((String) uuidObj);

                JSONObject huntingObj = (JSONObject) playerObj.get("hunting");
                if (huntingObj != null) {
                    for (Object mobObj : huntingObj.keySet()) {
                        if (mobObj.equals("total")) continue;
                        HeadsPlus.debug((String) mobObj);
                        ConfigSection defaultSection = ConfigMobs.get().getConfigSection(mobObj + ".default");
                        String head = "";
                        if (defaultSection != null && defaultSection.getKeys(false).size() != 0) {
                            head = defaultSection.getKeys(false).get(0);
                        }
                        int total = Integer.parseInt(String.valueOf(huntingObj.get(mobObj)));
                        addToTotalSync(uuid, CollectionType.HUNTING, head, "mob=" + mobObj, total);
                    }
                }

                JSONObject craftingObj = (JSONObject) playerObj.get("crafting");
                if (craftingObj != null) {
                    for (Object mobObj : craftingObj.keySet()) {
                        if (mobObj.equals("total")) continue;
                        ConfigSection defaultSection = ConfigMobs.get().getConfigSection(mobObj + ".default");
                        String head = "";
                        if (defaultSection != null && defaultSection.getKeys(false).size() != 0) {
                            head = defaultSection.getKeys(false).get(0);
                        }
                        int total = Integer.parseInt(String.valueOf(huntingObj.get(mobObj)));
                        addToTotalSync(uuid, CollectionType.CRAFTING, head, "mob=" + mobObj, total);
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ParseException ignored) {
        }
        playerInfo.renameTo(new File(storageFolder, "playerinfo-backup.json"));
    }

    public CompletableFuture<Integer> getStat(UUID uuid, CollectionType type) {
        return CompletableFuture.supplyAsync(() -> getStatSync(uuid, type), HeadsPlus.async);
    }

    public CompletableFuture<Integer> getStat(UUID uuid, CollectionType type, String head) {
        return CompletableFuture.supplyAsync(() -> getStatSync(uuid, type, head), HeadsPlus.async);
    }

    public CompletableFuture<Integer> getStatMeta(UUID uuid, CollectionType type, String metadata) {
        return CompletableFuture.supplyAsync(() -> getStatMetaSync(uuid, type, metadata), HeadsPlus.async);
    }

    public CompletableFuture<Integer> getStat(UUID uuid, CollectionType type, String head, String metadata) {
        return CompletableFuture.supplyAsync(() -> getStatSync(uuid, type, head, metadata), HeadsPlus.async);
    }<commit_msg>correct typo in transferOldData method<commit_after>package io.github.thatsmusic99.headsplus.sql;

import io.github.thatsmusic99.configurationmaster.api.ConfigSection;
import io.github.thatsmusic99.headsplus.HeadsPlus;
import io.github.thatsmusic99.headsplus.config.ConfigMobs;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;

public class StatisticsSQLManager extends SQLManager {

    private static StatisticsSQLManager instance;

    public StatisticsSQLManager() {
        instance = this;
        createTable();
        transferOldData();
    }

    public static StatisticsSQLManager get() {
        return instance;
    }

    @Override
    public void createTable() {
        try (Connection connection = implementConnection()) {
            PreparedStatement statement = connection.prepareStatement(
                    "CREATE TABLE IF NOT EXISTS headsplus_stats " +
                            "(user_id INT NOT NULL," +
                            "collection_type VARCHAR(32) NOT NULL," +
                            "head VARCHAR(256) NOT NULL," +
                            "metadata VARCHAR(256) NOT NULL," +
                            "count INT NOT NULL)"
            );

            statement.executeUpdate();
        } catch (SQLException exception) {
            exception.printStackTrace();
        }
    }

    @Override
    public void transferOldData() {
        File storageFolder = new File(HeadsPlus.get().getDataFolder(), "storage");
        if (!storageFolder.exists()) return;
        File playerInfo = new File(storageFolder, "playerinfo.json");
        if (!playerInfo.exists()) return;
        try (FileReader reader = new FileReader(playerInfo)) {
            JSONObject core = (JSONObject) new JSONParser().parse(reader);
            for (Object uuidObj : core.keySet()) {
                if (uuidObj.equals("server-total")) continue;
                JSONObject playerObj = (JSONObject) core.get(uuidObj);
                UUID uuid = UUID.fromString((String) uuidObj);

                JSONObject huntingObj = (JSONObject) playerObj.get("hunting");
                if (huntingObj != null) {
                    for (Object mobObj : huntingObj.keySet()) {
                        if (mobObj.equals("total")) continue;
                        HeadsPlus.debug((String) mobObj);
                        ConfigSection defaultSection = ConfigMobs.get().getConfigSection(mobObj + ".default");
                        String head = "";
                        if (defaultSection != null && defaultSection.getKeys(false).size() != 0) {
                            head = defaultSection.getKeys(false).get(0);
                        }
                        int total = Integer.parseInt(String.valueOf(huntingObj.get(mobObj)));
                        addToTotalSync(uuid, CollectionType.HUNTING, head, "mob=" + mobObj, total);
                    }
                }

                JSONObject craftingObj = (JSONObject) playerObj.get("crafting");
                if (craftingObj != null) {
                    for (Object mobObj : craftingObj.keySet()) {
                        if (mobObj.equals("total")) continue;
                        ConfigSection defaultSection = ConfigMobs.get().getConfigSection(mobObj + ".default");
                        String head = "";
                        if (defaultSection != null && defaultSection.getKeys(false).size() != 0) {
                            head = defaultSection.getKeys(false).get(0);
                        }
                        int total = Integer.parseInt(String.valueOf(craftingObj.get(mobObj)));
                        addToTotalSync(uuid, CollectionType.CRAFTING, head, "mob=" + mobObj, total);
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ParseException ignored) {
        }
        playerInfo.renameTo(new File(storageFolder, "playerinfo-backup.json"));
    }

    public CompletableFuture<Integer> getStat(UUID uuid, CollectionType type) {
        return CompletableFuture.supplyAsync(() -> getStatSync(uuid, type), HeadsPlus.async);
    }

    public CompletableFuture<Integer> getStat(UUID uuid, CollectionType type, String head) {
        return CompletableFuture.supplyAsync(() -> getStatSync(uuid, type, head), HeadsPlus.async);
    }

    public CompletableFuture<Integer> getStatMeta(UUID uuid, CollectionType type, String metadata) {
        return CompletableFuture.supplyAsync(() -> getStatMetaSync(uuid, type, metadata), HeadsPlus.async);
    }

    public CompletableFuture<Integer> getStat(UUID uuid, CollectionType type, String head, String metadata) {
        return CompletableFuture.supplyAsync(() -> getStatSync(uuid, type, head, metadata), HeadsPlus.async);
    }
{'fraction_non_alphanumeric': 0.1050184072854098, 'fraction_numerical': 0.003875217981011432, 'mean_word_length': 2.1636530799877414, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1697079', 'n_tokens_mistral': 2662, 'n_tokens_neox': 2566, 'n_words': 572}