<commit_before>"use strict";

/**************************
 * Import important stuff *
 **************************/

const fs = require("fs");
const _ = require("lodash");

/****************************
 * The DiscordUserMap class *
 ****************************/

/**
 * Handles the mapping between UserID and Username in Discord and saves it to a file when it changes
 */
class DiscordUserMap {
	/**
	 * Creates a new mapping betweein user IDs and usernames
	 *
	 * @param {String} filename	Name of the file read the map from and store it to
	 */
	constructor(filename) {
		/**
		 * The filename this map is associated with
		 *
		 * @private
	 	 */
		this._filename = filename;

		try {
			// Check if the file exists. This throws if it doesn't
			fs.accessSync(this.filename, fs.constants.F_OK);
		} catch (e) {
			// Nope, it doesn't. Create it
			fs.writeFileSync(this.filename, JSON.stringify({}));
		}

		// Read the file
		let data = fs.readFileSync(this.filename);

		// Parse it as JSON
		try {
			data = JSON.parse(data);
		} catch(e) {
			// Invalid JSON. Log it, and start with an empty object
			console.log(`Invalid JSON in ${this.filename}:\n\n${data}\n\nStarting with empty usermap`);
			data = {};
		}

		/**
		 * The mapping between IDs and names
		 *
		 * @private
		 */
		this._idToName = data;

		/**
		 * The mapping between names and IDs
		 *
		 * @private
		 */
		this._nameToId = {};
		for (let id in data) {<commit_msg>Changed 'log' to 'warn' for the message when the discord user map contains invalid json<commit_after>"use strict";

/**************************
 * Import important stuff *
 **************************/

const fs = require("fs");
const _ = require("lodash");

/****************************
 * The DiscordUserMap class *
 ****************************/

/**
 * Handles the mapping between UserID and Username in Discord and saves it to a file when it changes
 */
class DiscordUserMap {
	/**
	 * Creates a new mapping betweein user IDs and usernames
	 *
	 * @param {String} filename	Name of the file read the map from and store it to
	 */
	constructor(filename) {
		/**
		 * The filename this map is associated with
		 *
		 * @private
	 	 */
		this._filename = filename;

		try {
			// Check if the file exists. This throws if it doesn't
			fs.accessSync(this.filename, fs.constants.F_OK);
		} catch (e) {
			// Nope, it doesn't. Create it
			fs.writeFileSync(this.filename, JSON.stringify({}));
		}

		// Read the file
		let data = fs.readFileSync(this.filename);

		// Parse it as JSON
		try {
			data = JSON.parse(data);
		} catch(e) {
			// Invalid JSON. Log it, and start with an empty object
			console.warn(`Invalid JSON in ${this.filename}:\n\n${data}\n\nStarting with empty usermap`);
			data = {};
		}

		/**
		 * The mapping between IDs and names
		 *
		 * @private
		 */
		this._idToName = data;

		/**
		 * The mapping between names and IDs
		 *
		 * @private
		 */
		this._nameToId = {};
		for (let id in data) {
{'fraction_non_alphanumeric': 0.18806875631951467, 'fraction_numerical': 0.0, 'mean_word_length': 2.9838926174496643, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '460677', 'n_tokens_mistral': 1026, 'n_tokens_neox': 886, 'n_words': 302}