mirror of
				https://gitlab.com/MrFry/mrfrys-node-server
				synced 2025-04-01 20:24:18 +02:00 
			
		
		
		
	Merger print fixing
This commit is contained in:
		
							
								
								
									
										61
									
								
								merger.js
									
									
									
									
									
								
							
							
						
						
									
										61
									
								
								merger.js
									
									
									
									
									
								
							@@ -136,12 +136,14 @@ var actions = require('./actions.js');
 | 
			
		||||
Main();
 | 
			
		||||
 | 
			
		||||
function Main() {
 | 
			
		||||
	console.clear();
 | 
			
		||||
	const params = GetParams();
 | 
			
		||||
	console.log(params);
 | 
			
		||||
	var dbs = [];
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	for (var i = 0; i < params.length; i++) {
 | 
			
		||||
		PrintLN();
 | 
			
		||||
		console.log(params[i] + ": ");
 | 
			
		||||
		try {
 | 
			
		||||
			dbs.push(ParseJSONData(utils.ReadFile(params[i])));
 | 
			
		||||
@@ -151,10 +153,15 @@ function Main() {
 | 
			
		||||
			console.log("Trying with old format...");
 | 
			
		||||
			dbs.push(ReadData(utils.ReadFile(params[i])).result);
 | 
			
		||||
		}
 | 
			
		||||
		console.log("---------------------------------");
 | 
			
		||||
	}
 | 
			
		||||
	PrintLN();
 | 
			
		||||
 | 
			
		||||
	dbs.forEach((item) => {
 | 
			
		||||
		PrintDB(item);
 | 
			
		||||
	});
 | 
			
		||||
 | 
			
		||||
	console.log("Parsed data count: " + dbs.length);
 | 
			
		||||
	console.log("---------------------------------");
 | 
			
		||||
	PrintLN();
 | 
			
		||||
 | 
			
		||||
	console.log("Merging databases...");
 | 
			
		||||
	var db = MergeDatabases(dbs);
 | 
			
		||||
@@ -162,14 +169,58 @@ function Main() {
 | 
			
		||||
	console.log("Removing duplicates...");
 | 
			
		||||
	var r = RemoveDuplicates(db);
 | 
			
		||||
 | 
			
		||||
	for (var i = 0; i < r.length; i++) {
 | 
			
		||||
		console.log(i + ": " + r.Subjects[i].Name + ": " + r.Subjects[i].length + " db");
 | 
			
		||||
	}
 | 
			
		||||
	console.log("RESULT:");
 | 
			
		||||
	PrintDB(r);
 | 
			
		||||
 | 
			
		||||
	utils.WriteFile(JSON.stringify(r), "newData");
 | 
			
		||||
	console.log("File written!");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function PrintLN() {
 | 
			
		||||
	console.log("------------------------------------------------------");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function PrintDB(r) {
 | 
			
		||||
	console.log("Data subject count: " + r.length);
 | 
			
		||||
	var maxLength = 0;
 | 
			
		||||
	for (var i = 0; i < r.length; i++) {
 | 
			
		||||
		if (maxLength < r.Subjects[i].Name.length)
 | 
			
		||||
			maxLength = r.Subjects[i].Name.length;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	console.log("MAXL" + maxLength);
 | 
			
		||||
 | 
			
		||||
	for (var i = 0; i < r.length; i++) {
 | 
			
		||||
		let line = i;
 | 
			
		||||
		if (line < 10)
 | 
			
		||||
			line += ' ';
 | 
			
		||||
 | 
			
		||||
		line += ": ";
 | 
			
		||||
		var currLength = line.length + maxLength + 4;
 | 
			
		||||
		line += r.Subjects[i].Name;
 | 
			
		||||
 | 
			
		||||
		while (line.length < currLength) {
 | 
			
		||||
			if (i % 4 == 0)
 | 
			
		||||
				line += ".";
 | 
			
		||||
			else
 | 
			
		||||
				line += " ";
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (r.Subjects[i].length < 10)
 | 
			
		||||
			line += " ";
 | 
			
		||||
		if (r.Subjects[i].length < 100)
 | 
			
		||||
			line += " ";
 | 
			
		||||
 | 
			
		||||
		line += r.Subjects[i].length;
 | 
			
		||||
			
 | 
			
		||||
		line += " db";
 | 
			
		||||
		
 | 
			
		||||
		console.log(line);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	PrintLN();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function GetParams() {
 | 
			
		||||
	return process.argv.splice(2);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user