mirror of
				https://gitlab.com/MrFry/mrfrys-node-server
				synced 2025-04-01 20:24:18 +02:00 
			
		
		
		
	Merger comparing update
This commit is contained in:
		
							
								
								
									
										44
									
								
								merger.js
									
									
									
									
									
								
							
							
						
						
									
										44
									
								
								merger.js
									
									
									
									
									
								
							@@ -22,6 +22,10 @@
 | 
				
			|||||||
// join json datas, or raw datas
 | 
					// join json datas, or raw datas
 | 
				
			||||||
// or something else
 | 
					// or something else
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const minMatchAmmount = 55;
 | 
				
			||||||
 | 
					const minResultMatchPercent = 99;
 | 
				
			||||||
 | 
					const lengthDiffMultiplier = 10;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Question {
 | 
					class Question {
 | 
				
			||||||
	constructor(q, a, i) {
 | 
						constructor(q, a, i) {
 | 
				
			||||||
		this.Q = q;
 | 
							this.Q = q;
 | 
				
			||||||
@@ -46,19 +50,39 @@ class Question {
 | 
				
			|||||||
	IsComplete() {
 | 
						IsComplete() {
 | 
				
			||||||
		return this.HasQuestion() && this.HasAnswer();
 | 
							return this.HasQuestion() && this.HasAnswer();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	Compare(q2) {
 | 
						// TODO: TEST DIS
 | 
				
			||||||
		const qmatchpercent = Question.CompareString(this.Q, q2.Q);
 | 
						Compare(q2, i) {
 | 
				
			||||||
		const amatchpercent = Question.CompareString(this.A, q2.A);
 | 
							if (typeof q2 == 'string') {
 | 
				
			||||||
		if (this.I != undefined) {
 | 
								var qmatchpercent = Question.CompareString(this.Q, q2);
 | 
				
			||||||
			const imatchpercent = this.I == undefined ? Question.CompareString(this.I, q2.I) : 0;
 | 
					
 | 
				
			||||||
			return (qmatchpercent + amatchpercent + imatchpercent) / 3;
 | 
								if (i == undefined || i.length == 0)
 | 
				
			||||||
 | 
									return qmatchpercent;
 | 
				
			||||||
 | 
								else {
 | 
				
			||||||
 | 
									if (this.HasImage()) {
 | 
				
			||||||
 | 
										const imatchpercent = this.HasImage() ? Question.CompareString(this.I.join(" "), i.join(" ")) :
 | 
				
			||||||
 | 
											0;
 | 
				
			||||||
 | 
										return (qmatchpercent + imatchpercent) / 2;
 | 
				
			||||||
 | 
									} else {
 | 
				
			||||||
 | 
										qmatchpercent -= 30;
 | 
				
			||||||
 | 
										if (qmatchpercent < 0)
 | 
				
			||||||
 | 
											return 0;
 | 
				
			||||||
 | 
										else
 | 
				
			||||||
 | 
											return qmatchpercent;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			return (qmatchpercent + amatchpercent) / 2;
 | 
								const qmatchpercent = Question.CompareString(this.Q, q2.Q);
 | 
				
			||||||
 | 
								const amatchpercent = Question.CompareString(this.A, q2.A);
 | 
				
			||||||
 | 
								if (this.I != undefined) {
 | 
				
			||||||
 | 
									const imatchpercent = this.I == undefined ? Question.CompareString(this.I.join(" "), q2.I.join(
 | 
				
			||||||
 | 
										" ")) : 0;
 | 
				
			||||||
 | 
									return (qmatchpercent + amatchpercent + imatchpercent) / 3;
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									return (qmatchpercent + amatchpercent) / 2;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	static CompareString(s1, s2) {
 | 
						static CompareString(s1, s2) {
 | 
				
			||||||
		//if (s1 == undefined || s2 == undefined)
 | 
					 | 
				
			||||||
		//	return 0;
 | 
					 | 
				
			||||||
		s1 = SimplifyStringForComparison(s1).split(" ");
 | 
							s1 = SimplifyStringForComparison(s1).split(" ");
 | 
				
			||||||
		s2 = SimplifyStringForComparison(s2).split(" ");
 | 
							s2 = SimplifyStringForComparison(s2).split(" ");
 | 
				
			||||||
		var match = 0;
 | 
							var match = 0;
 | 
				
			||||||
@@ -67,7 +91,7 @@ class Question {
 | 
				
			|||||||
				match++;
 | 
									match++;
 | 
				
			||||||
		var percent = Math.round(((match / s1.length) * 100).toFixed(2)); // matched words percent
 | 
							var percent = Math.round(((match / s1.length) * 100).toFixed(2)); // matched words percent
 | 
				
			||||||
		var lengthDifference = Math.abs(s2.length - s1.length);
 | 
							var lengthDifference = Math.abs(s2.length - s1.length);
 | 
				
			||||||
		percent -= lengthDifference * 3;
 | 
							percent -= lengthDifference * lengthDiffMultiplier;
 | 
				
			||||||
		if (percent < 0)
 | 
							if (percent < 0)
 | 
				
			||||||
			percent = 0;
 | 
								percent = 0;
 | 
				
			||||||
		return percent;
 | 
							return percent;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user