Best JavaScript code snippet using best
ux_day_breakdown.js
Source:ux_day_breakdown.js
1$(function () {2 ux_day_breakdown();3 var timer = setInterval( ux_day_breakdown, 10000);4 });5function ux_day_breakdown() {6 var now = new Date();7 var hours = now.getHours();8 var minutes = now.getMinutes();9 var seconds = now.getSeconds();10 var counter = Math.floor((hours*60 + minutes)/15) % 2;11 baseDay_query = '/api/labs/ux/energy/hours.json?base_time=' + baseTime;12 comparingDay_query = '/api/labs/ux/energy/hours.json?base_time=' + lastWeekDayTime; // ì§ë 주 ê°ì ìì¼ë¡ ì¤ì 13 console.log(baseDay_query);14 console.log(comparingDay_query);15 var comparingDay_queryReturn = [];16 var today_queryReturn = [];17 var comparingDay_loading = false;18 var today_loading = false;19 var xAxis_categories = [];20 var comparingDay_plotData = [];21 var today_plotData = [];22 var comparingSum = 0;23 var todaySum = 0;24 var currentState;25 var stateColors = ['#a50a0a','#f7cb00','#3e721f'];26 var comparing_breakdownColors = ['#b3d5c8', '#f5e0b3', '#e8c2c1', '#d3bdd1']; //com, light, hvac, etc27 var today_breakdownColors = ['#7db19f', '#eecf8d', '#f3a3a1', '#a889a5'];28 var today_total = [];29 var today_hvac = [];30 var today_com = [];31 var today_light = [];32 var today_etc = [];33 var comparingDay_hvac = [];34 var comparingDay_com = [];35 var comparingDay_light = [];36 var comparingDay_etc = [];37 // console.log("baseDay_query", baseDay_query);38 // console.log("comparingDay_query", comparingDay_query);39 invokeOpenAPI(comparingDay_query, comparingDayCB);40 invokeOpenAPI(baseDay_query, todayCB);41 function todayCB(today_){42 today_queryReturn = today_;43 today_loading = true;44 for(var index = 0; index < today_queryReturn.length; index++){45 total = today_queryReturn[index].sum;46 hvac = accumulator(today_queryReturn[index], 'hvac');47 com = accumulator(today_queryReturn[index], 'computer');48 light = accumulator(today_queryReturn[index], 'light');49 etc = total - (hvac + com + light);50 today_total.push(Number(total.toFixed(1)));51 today_hvac.push(Number(hvac.toFixed(3)));//íì¬ hvacê°ì´ ë®ì fixed(1)íë©´ 모ë 0ì¼ë¡ ëì weekê³¼ ì«ì ë¶ì¼ì¹, ì¶í hvacì¬ì©ë ëìì§ë©´ ë¤ì ìì 52 today_com.push(Number(com.toFixed(1)));53 today_light.push(Number(light.toFixed(1)));54 today_etc.push(Number(etc.toFixed(1)));55 today_plotData.push(Number(today_queryReturn[index].sum.toFixed(1)));56 }57 if (comparingDay_loading) {58 drawChart();59 }60 }61 function comparingDayCB (comparingDay_) {62 comparingDay_queryReturn = comparingDay_;63 comparingDay_loading = true;64 for(var index = 0; index < comparingDay_queryReturn.length; index++){65 comparingDay_plotData.push(Number(comparingDay_queryReturn[index].sum.toFixed(1)));66 xAxis_categories.push(new Date(comparingDay_queryReturn[index].dateTo).getHours() + 'ì');67 hvac = accumulator(comparingDay_queryReturn[index], 'hvac');68 com = accumulator(comparingDay_queryReturn[index], 'computer');69 light = accumulator(comparingDay_queryReturn[index], 'light');70 etc = total - (hvac + com + light);71 comparingDay_hvac.push(Number(hvac.toFixed(3))); //íì¬ hvacê°ì´ ë®ì fixed(1)íë©´ 모ë 0ì¼ë¡ ëì weekê³¼ ì«ì ë¶ì¼ì¹, ì¶í hvacì¬ì©ë ëìì§ë©´ ë¤ì ìì 72 comparingDay_com.push(Number(com.toFixed(1)));73 comparingDay_light.push(Number(light.toFixed(1)));74 comparingDay_etc.push(Number(etc.toFixed(1)));75 }76 if (today_loading) {77 drawChart();78 }79 }80 // function hourlyMean(data){81 // var result = new Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);82 // denominator = data.length/24;83 // // console.log(denominator);84 // // var tmp = 0;85 // for(var index=0; index < data.length; index++){86 // // if(index%24==1) {87 // // console.log(data[index]);88 // // tmp = tmp + data[index];89 // // }90 // result[index % 24] = result[index % 24] + data[index];91 // }92 // // console.log(tmp, result);93 //94 // for(var index=0; index < result.length; index++){95 // result[index] = Number((result[index] / denominator).toFixed(1));96 // }97 // // console.log(result);98 // return(result);99 // }100 function drawChart() {101 console.log(comparingDay_queryReturn);102 console.log(today_queryReturn);103 // weekDay_hourlyMean = hourlyMean(lastMonthWeekDay_data);104 // weekEnd_hourlyMean = hourlyMean(lastMonthWeekEnd_data);105 // console.log("weekDay_hourlyMean", weekDay_hourlyMean);106 // console.log("weekEnd_hourlyMean", weekEnd_hourlyMean);107 comparingSum = limitedArraySum(comparingDay_plotData, today_queryReturn.length);108 todaySum = limitedArraySum(today_plotData, today_queryReturn.length);109 var savingRate_Day = todaySum / comparingSum;110 if(savingRate_Day > 1.20) {111 currentState = 0;112 } else if ( savingRate_Day > 1.00) {113 currentState = 1;114 } else {115 currentState = 2;116 }117 if(weekDay_Indicator){118 // var vsData = weekDay_hourlyMean;119 } else {120 // var vsData = weekEnd_hourlyMean;121 }122 var legend_x = 50;123 var legend_y = 47;124 console.log('currentState: ', currentState);125 console.log('colorcode: ', stateColors[currentState-1]);126 console.log('*************counter:',counter);127 if (Math.floor(seconds/10%3) == 1) {128 // counter=1;129 $('#ux_day_breakdown').highcharts({130 chart: {131 backgroundColor: "#f9f3e8"132 },133 title: {134 // text: 'ì´ì ì ì¤ë (' + comparingDay_queryReturn[0].location + 'í¸ - ì¬ì©ë ì ì²´)'135 // text: '[ ì´ì ì ì¤ë ]'136 text: null137 },138 credits: {139 enabled: false140 },141 legend: {142 layout: 'vertical',143 align: 'left',144 verticalAlign: 'top',145 // x: legend_x+(today_queryReturn.length - 1)*24,146 x:777,147 y: 305,148 floating: true,149 borderWidth: 1,150 //backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF',151 backgroundColor: 'rgba(255, 255, 255, .8)',152 borderColor: '#FFFFFF'153 },154 exporting: {155 enabled: false156 },157 xAxis: {158 categories: xAxis_categories159 // plotBands: [{ // visualize so far160 // from: -0.5,161 // to: today_queryReturn.length - 1,162 // color: 'rgba(68, 170, 213, .1)'163 // }]164 },165 yAxis: {166 maxPadding: 0.1,167 title: {168 text: 'ì ë ¥ ì¬ì©ë (kW/h)'169 }170 },171 plotOptions: {172 line: {173 dataLabels: {174 enabled: true175 },176 enableMouseTracking: false177 },178 area: { /* or spline, area, series, areaspline etc.*/179 marker: {180 enabled: false181 }182 }183 },184 series: [{185 //name: 'ì´ì : ' + (comparingDay_queryReturn.getMonth() + 1) + 'ì ' + comparingDay_queryReturn.getDate() + 'ì¼(' + dayLabel[comparingDay_queryReturn.getDay()] + ')',186 name: 'ì¼ì£¼ ì ëëë°© ì¬ì© í¨í´',187 data: comparingDay_hvac,188 // data: vsData,189 color: comparing_breakdownColors[2],190 lineWidth: 1,191 // linkedTo: ':previous',192 zIndex: 0193 },{194 //name: 'ì´ì : ' + (comparingDay_queryReturn.getMonth() + 1) + 'ì ' + comparingDay_queryReturn.getDate() + 'ì¼(' + dayLabel[comparingDay_queryReturn.getDay()] + ')',195 name: 'ì¼ì£¼ ì ì´ ìê°: ' + limitedArraySum(comparingDay_hvac, today_queryReturn.length).toFixed(1) + ' kW/h',196 data: comparingDay_hvac.slice(0,today_plotData.length),197 type: 'area',198 lineWidth: 0,199 color: comparing_breakdownColors[2],//'#848174',200 fillOpacity: 1,201 zIndex: 0202 },{203 name: 'ì¤ë ì´ ìê°: ' + limitedArraySum(today_hvac, today_queryReturn.length).toFixed(1) + ' kW/h',204 data: today_hvac,205 // data: vsData,206 // color: stateColors[currentState],207 color: today_breakdownColors[2],208 type: 'area',209 lineWidth: 0,210 fillOpacity: 0.5,211 // linkedTo: ':previous',212 zIndex: 0213 }, {214 data: today_hvac.slice(0,today_plotData.length),215 // data: vsData,216 // color: stateColors[currentState],217 color: today_breakdownColors[2],218 lineWidth: 1,219 linkedTo: ':previous',220 zIndex: 0221 }]222 });223 }else if (Math.floor(seconds/10%3) == 2) { //counter==1224 // counter++;225 $('#ux_day_breakdown').highcharts({226 chart: {227 backgroundColor: "#f9f3e8"228 },229 title: {230 // text: 'ì´ì ì ì¤ë (' + comparingDay_queryReturn[0].location + 'í¸ - ì¬ì©ë ì ì²´)'231 // text: '[ ì´ì ì ì¤ë ]'232 text: null233 },234 credits: {235 enabled: false236 },237 legend: {238 layout: 'vertical',239 align: 'left',240 verticalAlign: 'top',241 // x: legend_x+(today_queryReturn.length - 1)*24,242 x:777,243 y: 305,244 floating: true,245 borderWidth: 1,246 //backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF',247 backgroundColor: 'rgba(255, 255, 255, .8)',248 borderColor: '#FFFFFF'249 },250 exporting: {251 enabled: false252 },253 xAxis: {254 categories: xAxis_categories255 // plotBands: [{ // visualize so far256 // from: -0.5,257 // to: today_queryReturn.length - 1,258 // color: 'rgba(68, 170, 213, .1)'259 // }]260 },261 yAxis: {262 maxPadding: 0.1,263 title: {264 text: 'ì ë ¥ ì¬ì©ë (kW/h)'265 }266 },267 plotOptions: {268 line: {269 dataLabels: {270 enabled: true271 },272 enableMouseTracking: false273 },274 area: { /* or spline, area, series, areaspline etc.*/275 marker: {276 enabled: false277 }278 }279 },280 series: [{281 //name: 'ì´ì : ' + (comparingDay_queryReturn.getMonth() + 1) + 'ì ' + comparingDay_queryReturn.getDate() + 'ì¼(' + dayLabel[comparingDay_queryReturn.getDay()] + ')',282 name: 'ì¼ì£¼ ì ì»´í¨í° ì¬ì© í¨í´',283 data: comparingDay_com,284 // data: vsData,285 color: comparing_breakdownColors[0],286 lineWidth: 1,287 // linkedTo: ':previous',288 zIndex: 0289 },{290 //name: 'ì´ì : ' + (comparingDay_queryReturn.getMonth() + 1) + 'ì ' + comparingDay_queryReturn.getDate() + 'ì¼(' + dayLabel[comparingDay_queryReturn.getDay()] + ')',291 name: 'ì¼ì£¼ ì ì´ ìê°: ' + limitedArraySum(comparingDay_com, today_queryReturn.length).toFixed(1) + ' kW/h',292 data: comparingDay_com.slice(0,today_plotData.length),293 type: 'area',294 lineWidth: 0,295 color: comparing_breakdownColors[0],//'#848174',296 fillOpacity: 0.7,297 zIndex: 0298 },{299 name: 'ì¤ë ì´ ìê°: ' + limitedArraySum(today_com, today_queryReturn.length).toFixed(1) + ' kW/h',300 data: today_com,301 // data: vsData,302 // color: stateColors[currentState],303 type: 'area',304 color: today_breakdownColors[0],305 fillOpacity: 0.7,306 zIndex: 0307 }, {308 data: today_com.slice(0,today_plotData.length),309 // data: vsData,310 // color: stateColors[currentState],311 color: today_breakdownColors[0],312 lineWidth: 1,313 linkedTo: ':previous',314 zIndex: 0315 }]316 });317 } else {//counter==0318 // counter++;319 $('#ux_day_breakdown').highcharts({320 chart: {321 backgroundColor: "#f9f3e8"322 },323 title: {324 // text: 'ì´ì ì ì¤ë (' + comparingDay_queryReturn[0].location + 'í¸ - ì¬ì©ë ì ì²´)'325 // text: '[ ì´ì ì ì¤ë ]'326 text: null327 },328 credits: {329 enabled: false330 },331 legend: {332 layout: 'vertical',333 align: 'left',334 verticalAlign: 'top',335 // x: legend_x+(today_queryReturn.length - 1)*24,336 x:770,337 y: 305,338 floating: true,339 borderWidth: 1,340 //backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF',341 backgroundColor: 'rgba(255, 255, 255, .8)',342 borderColor: '#FFFFFF'343 },344 exporting: {345 enabled: false346 },347 xAxis: {348 categories: xAxis_categories349 // plotBands: [{ // visualize so far350 // from: -0.5,351 // to: today_queryReturn.length - 1,352 // color: 'rgba(68, 170, 213, .1)'353 // }]354 },355 yAxis: {356 maxPadding: 0.1,357 title: {358 text: 'ì ë ¥ ì¬ì©ë (kW/h)'359 }360 },361 plotOptions: {362 line: {363 dataLabels: {364 enabled: true365 },366 enableMouseTracking: false367 },368 area: { /* or spline, area, series, areaspline etc.*/369 marker: {370 enabled: false371 }372 }373 },374 series: [{375 //name: 'ì´ì : ' + (comparingDay_queryReturn.getMonth() + 1) + 'ì ' + comparingDay_queryReturn.getDate() + 'ì¼(' + dayLabel[comparingDay_queryReturn.getDay()] + ')',376 name: 'ì¼ì£¼ ì ì ë± ì¬ì© í¨í´',377 data: comparingDay_light,378 // data: vsData,379 color: comparing_breakdownColors[1],380 lineWidth: 1,381 // linkedTo: ':previous',382 zIndex: 0383 },{384 //name: 'ì´ì : ' + (comparingDay_queryReturn.getMonth() + 1) + 'ì ' + comparingDay_queryReturn.getDate() + 'ì¼(' + dayLabel[comparingDay_queryReturn.getDay()] + ')',385 name: 'ì¼ì£¼ ì ì´ ìê°: ' + limitedArraySum(comparingDay_light, today_queryReturn.length).toFixed(1) + ' kW/h',386 data: comparingDay_light.slice(0,today_plotData.length),387 type: 'area',388 lineWidth: 0,389 color: comparing_breakdownColors[1],//'#848174',390 fillOpacity: 1,391 zIndex: 0392 },{393 name: 'ì¤ë ì´ ìê°: ' + limitedArraySum(today_light, today_queryReturn.length).toFixed(1) + ' kW/h',394 data: today_light,395 // data: vsData,396 // color: stateColors[currentState],397 type: 'area',398 color: today_breakdownColors[1],399 fillOpacity: 0.7,400 // linkedTo: ':previous',401 zIndex: 0402 }, {403 data: today_light.slice(0,today_plotData.length),404 // data: vsData,405 // color: stateColors[currentState],406 color: today_breakdownColors[1],407 lineWidth: 1,408 linkedTo: ':previous',409 zIndex: 0410 }]411 });412 }413 // else {414 // counter=1;415 // $('#ux_day_breakdown').highcharts({416 // chart: {417 // backgroundColor: "#f9f3e8"418 // },419 // title: {420 // // text: 'ì´ì ì ì¤ë (' + comparingDay_queryReturn[0].location + 'í¸ - ì¬ì©ë ì ì²´)'421 // // text: '[ ì´ì ì ì¤ë ]'422 // text: null423 // },424 // credits: {425 // enabled: false426 // },427 // legend: {428 // layout: 'vertical',429 // align: 'left',430 // verticalAlign: 'top',431 // // x: legend_x+(today_queryReturn.length - 1)*24,432 // x:745,433 // y: 286,434 // floating: true,435 // borderWidth: 1,436 // //backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF',437 // backgroundColor: 'rgba(255, 255, 255, .8)',438 // borderColor: '#FFFFFF'439 // },440 // exporting: {441 // enabled: false442 // },443 //444 // xAxis: {445 // categories: xAxis_categories446 // // plotBands: [{ // visualize so far447 // // from: -0.5,448 // // to: today_queryReturn.length - 1,449 // // color: 'rgba(68, 170, 213, .1)'450 // // }]451 // },452 // yAxis: {453 // maxPadding: 0.1,454 // title: {455 // text: 'ì ë ¥ ì¬ì©ë (kW/h)'456 // }457 // },458 // plotOptions: {459 // line: {460 // dataLabels: {461 // enabled: true462 // },463 // enableMouseTracking: false464 // },465 // area: { /* or spline, area, series, areaspline etc.*/466 // marker: {467 // enabled: false468 // }469 // }470 // },471 //472 // series: [{473 // //name: 'ì´ì : ' + (comparingDay_queryReturn.getMonth() + 1) + 'ì ' + comparingDay_queryReturn.getDate() + 'ì¼(' + dayLabel[comparingDay_queryReturn.getDay()] + ')',474 // name: 'ì¼ì£¼ ì 기í ì¬ì© í¨í´',475 // data: comparingDay_etc,476 // // data: vsData,477 // color: comparing_breakdownColors[3],478 // lineWidth: 1,479 // // linkedTo: ':previous',480 // zIndex: 0481 // },{482 // //name: 'ì´ì : ' + (comparingDay_queryReturn.getMonth() + 1) + 'ì ' + comparingDay_queryReturn.getDate() + 'ì¼(' + dayLabel[comparingDay_queryReturn.getDay()] + ')',483 // name: 'ì¼ì£¼ ì ì´ ìê°: ' + limitedArraySum(comparingDay_etc, today_queryReturn.length).toFixed(1) + ' kW/h',484 // data: comparingDay_etc.slice(0,today_plotData.length),485 // type: 'area',486 // lineWidth: 0,487 // color: comparing_breakdownColors[3],//'#848174',488 // fillOpacity: 0.7,489 // zIndex: 0490 // },{491 // name: 'ì¤ë ì´ ìê°: ' + limitedArraySum(today_etc, today_queryReturn.length).toFixed(1) + ' kW/h',492 // data: today_etc,493 // // data: vsData,494 // // color: stateColors[currentState],495 // type: 'area',496 // color: today_breakdownColors[3],497 // fillOpacity: 0.7,498 // // linkedTo: ':previous',499 // zIndex: 0500 // }, {501 // data: today_etc.slice(0,today_plotData.length),502 // // data: vsData,503 // // color: stateColors[currentState],504 // color: today_breakdownColors[3],505 // lineWidth: 1,506 // linkedTo: ':previous',507 // zIndex: 0508 // }]509 // });510 // }511 var day = baseDay.getDay();512 $('#arrow').empty();513 if(day==0){514 $('#arrow').prepend('<img id="faces" src="./images/arrow_depth_sun.png" />');515 }else if (day==1) {516 $('#arrow').prepend('<img id="faces" src="./images/arrow_depth_mon.png" />');517 }else if (day==2) {518 $('#arrow').prepend('<img id="faces" src="./images/arrow_depth_tue.png" />');519 }else if (day==3) {520 $('#arrow').prepend('<img id="faces" src="./images/arrow_depth_wed.png" />');521 }else if (day==4) {522 $('#arrow').prepend('<img id="faces" src="./images/arrow_depth_thu.png" />');523 }else if (day==5) {524 $('#arrow').prepend('<img id="faces" src="./images/arrow_depth_fri.png" />');525 }else {526 $('#arrow').prepend('<img id="faces" src="./images/arrow_depth_sat.png" />');527 }528 // var breakdown_info_percent = 0;529 // var breakdown_info_title;530 // $('#breakdown_info').empty();531 // if(Math.floor(seconds/10%3) == 1){532 // console.log('#######info:',Math.floor(seconds/10%3));533 // breakdown_info_percent = (limitedArraySum(today_hvac, today_queryReturn.length)/limitedArraySum(comparingDay_hvac, today_queryReturn.length)).toFixed(1);534 // breakdown_info_title=$("<div>").attr("id","breakdown_info_title").css({"font-size": "19px", "display" : "inline"}).text('ëëë°©<br />ì´ì ì´ìê° ëë¹<br>'+breakdown_info_percent+'% ì¬ì©ì¤');535 // $('#breakdown_info').append('<img id="faces" src="./images/hvac.png" />').append(breakdown_info_title);536 // }else if (Math.floor(seconds/10%3)==2) {537 // console.log('#######info:',Math.floor(seconds/10%3));538 // breakdown_info_percent = limitedArraySum(today_com, today_queryReturn.length)/limitedArraySum(comparingDay_com, today_queryReturn.length);539 // breakdown_info_percent.toFixed(1);540 // breakdown_info_title=$("<div>").attr("id","breakdown_info_title").css({"font-size": "19px", "display" : "inline"}).text('ì»´í¨í°<br />ì´ì ì´ìê° ëë¹<br>'+breakdown_info_percent+'% ì¬ì©ì¤');541 // $('#breakdown_info').append('<img id="faces" src="./images/computer.png" />').append(breakdown_info_title);542 // }else {543 // console.log('#######info:',Math.floor(seconds/10%3));544 // breakdown_info_percent = limitedArraySum(today_light, today_queryReturn.length)/limitedArraySum(comparingDay_light, today_queryReturn.length);545 // breakdown_info_percent.toFixed(1);546 // breakdown_info_title=$("<div>").attr("id","breakdown_info_title").css({"font-size": "19px", "display" : "inline"}).text('ì ë±<br /> ì´ì ì´ìê° ëë¹'+breakdown_info_percent+'% ì¬ì©ì¤');547 // $('#breakdown_info').append('<img id="faces" src="./images/light.png" />').append(breakdown_info_title);548 // }549 }//drawChart()...
compare.ts
Source:compare.ts
1import express from "express";2import * as fs from "fs";3import * as path from "path";4import useAsync from "common/server-only/middlewares/useAsync";5import ProjectService from "domain/services/ProjectService";6import HistoryId from "common/all/types/HistoryId";7import DetectionResult from "common/all/types/DetectionResult";8import EDetectionResult, {9 convertE,10 MappingResult11} from "common/all/types/EDetectionResult";12import FileId from "common/all/types/FileId";13import ClonePairId from "common/all/types/ClonePairId";14import Fragment from "common/all/types/Fragment";15import ClonePair from "common/all/types/ClonePair";16import { Registry } from "types/registry";17import {18 createEntityId,19 InternalHistoryEntityId20} from "common/server-only/value-objects/EntityId";21import ProjectRepository from "infrastructure/repositories/ProjectRepository";22const router = express.Router({ mergeParams: true });23const cv = (f1: Fragment, f2: Fragment): boolean => {24 return (25 (Math.min(f1.end, f2.end) - Math.max(f1.begin, f2.begin) + 1) /26 (f2.end - f2.begin + 1) >27 0.628 );29};30const cmatch = (cp1: ClonePair, cp2: ClonePair): boolean => {31 return cv(cp1.f1, cp2.f1) && cv(cp1.f2, cp2.f2);32};33const cfmatch = (cp1: ClonePair, cp2: ClonePair): boolean =>34 cmatch(cp1, cp2) && cmatch(cp2, cp1);35const map = (36 base: EDetectionResult,37 comparing: EDetectionResult38): MappingResult => {39 let fileCtr = 0;40 const allFiles: MappingResult["allFiles"] = {};41 const comparingToAllF: MappingResult["comparingToAllF"] = {};42 const baseToComparing: MappingResult["baseToComparing"] = {};43 const comparingToBase: MappingResult["comparingToBase"] = {};44 const allGrids: MappingResult["allGrids"] = {};45 console.log("Object");46 console.log(JSON.stringify(Object));47 Object.entries(base.files).forEach(([id, f]) => {48 allFiles[fileCtr] = { path: f, base: Number(id) as FileId };49 allGrids[fileCtr] = {};50 fileCtr += 1;51 });52 Object.entries(comparing.files).forEach(([id, f]) => {53 const file = Object.entries(allFiles).find(([, ff]) => ff.path === f);54 console.log("file");55 console.log(file);56 if (file) {57 comparingToAllF[Number(id)] = file[1].base;58 allFiles[Number(file[0])] = {59 ...file[1],60 comparing: Number(id) as FileId61 };62 } else {63 allFiles[fileCtr] = { path: f, comparing: Number(id) as FileId };64 allGrids[fileCtr] = {};65 comparingToAllF[Number(id)] = fileCtr as FileId;66 fileCtr += 1;67 }68 });69 Object.entries(allFiles).forEach(([y, yf]) => {70 Object.entries(allFiles).forEach(([x, xf]) => {71 const xx = Number(x);72 const yy = Number(y);73 if (xx <= yy) {74 let baseCP: ClonePairId[] = [];75 let comparingCP: ClonePairId[] = [];76 if (yf.base!=null && xf.base!=null) {77 78 const f1 = Math.min(yf.base, xf.base);79 const f2 = Math.max(yf.base, xf.base);80 baseCP = Object.entries(base.clonePairs)81 .filter(82 ([, cp]) => cp.f1.file === f1 && cp.f2.file === f283 )84 .map(([id]) => Number(id) as ClonePairId);85 }86 if (yf.comparing!=null && xf.comparing!=null) {87 const f1 = Math.min(yf.comparing, xf.comparing);88 const f2 = Math.max(yf.comparing, xf.comparing);89 comparingCP = Object.entries(comparing.clonePairs)90 .filter(91 ([, cp]) => cp.f1.file === f1 && cp.f2.file === f292 )93 .map(([id]) => Number(id) as ClonePairId);94 }95 if (baseCP.length > 0 || comparingCP.length > 0) {96 allGrids[yy][xx] = {97 base: baseCP,98 comparing: comparingCP99 };100 }101 }102 });103 });104 Object.values(allGrids).forEach((row) => {105 Object.values(row).forEach((grid) => {106 grid.base.forEach((bcp) => {107 grid.comparing.forEach((ccp) => {108 const bbcp = base.clonePairs[bcp];109 const cccp = comparing.clonePairs[ccp];110 if (cfmatch(bbcp, cccp)) {111 if (bcp in baseToComparing) {112 const v = baseToComparing[bcp];113 v.push(ccp);114 baseToComparing[bcp] = v;115 } else {116 baseToComparing[bcp] = [ccp];117 }118 if (ccp in comparingToBase) {119 const v = comparingToBase[ccp];120 v.push(bcp);121 comparingToBase[ccp] = v;122 } else {123 comparingToBase[ccp] = [bcp];124 }125 }126 });127 });128 });129 });130 return {131 base,132 comparing,133 comparingToAllF,134 baseToComparing,135 comparingToBase,136 allFiles,137 allGrids138 };139};140const defineRoute = (registry: Registry): express.Router => {141 // for checking directory path and revision142 router.get<143 { userEntityId: string; projectName: string },144 MappingResult,145 unknown,146 {147 base?: string;148 comparing?: string;149 }150 >(151 "/",152 useAsync(async (req, res) => {153 const { userEntityId, projectName } = req.params;154 const { base, comparing } = req.query;155 if (typeof base !== "string" || typeof comparing !== "string") {156 res.sendStatus(403);157 return;158 }159 const [baseHistoryId, baseResultId] = base.split("-");160 const [comparingHistoryId, comparingResultId] = comparing.split(161 "-"162 );163 const project = await ProjectService.findProjectByName(164 createEntityId(userEntityId),165 projectName166 );167 const [baseR, comparingR] = (168 await Promise.all([169 ProjectRepository.readResult(170 project.ownerId,171 project.internalProjectEntityId,172 createEntityId(173 baseHistoryId174 ) as InternalHistoryEntityId,175 baseResultId176 ),177 ProjectRepository.readResult(178 project.ownerId,179 project.internalProjectEntityId,180 createEntityId(181 comparingHistoryId182 ) as InternalHistoryEntityId,183 comparingResultId184 )185 ])186 ).map((r) => convertE(r));187 res.send(map(baseR, comparingR));188 })189 );190 return router;191};...
SortTestHelpers.js
Source:SortTestHelpers.js
1exports.arrToSort = [24, 99, 37, 18, 44, 29, 11, 2, 80];2exports.arrToSort2 = [99, 90, 80, 70, 60, 50, 40, 30, 20, 10];3exports.arrToSort3 = [1, 2, 3, 4, 5, 6, 7, 8, 9];4exports.barOffset = [142.3, 332.0, 142.3, -47.4, 94.8, -47.4, -237.1, -332.0, -47.4];5exports.barOffset2 = [384, 298, 213, 128, 42, -42, -128, -213, -298, -384];6exports.barOffset3 = [0, 0, 0, 0, 0, 0, 0, 0, 0];7exports.comparisons = [['Comparing', '24', '99'], ['Comparing', '24', '37'], ['Comparing', '24', '18'], ['Comparing', '18', '44'],8 ['Comparing', '18', '29'], ['Comparing', '18', '11'], ['Comparing', '11', '02'], ['Comparing', '02', '80'], ['Swapping', '02', '24'],9 ['Comparing', '99', '37'], ['Comparing', '37', '18'], ['Comparing', '18', '29'], ['Comparing', '18', '11'],10 ['Comparing', '11', '24'], ['Comparing', '11', '80'], ['Swapping', '11', '99'], ['Comparing', '37', '18'],11 ['Comparing', '18', '44'], ['Comparing', '18', '29'], ['Comparing', '18', '99'], ['Comparing', '18', '24'],12 ['Comparing', '18', '80'], ['Swapping', '18', '37'], ['Comparing', '37', '44'], ['Comparing', '37', '29'],13 ['Comparing', '29', '99'], ['Comparing', '29', '24'], ['Comparing', '24', '80'], ['Swapping', '24', '37'],14 ['Comparing', '44', '29'], ['Comparing', '29', '99'], ['Comparing', '29', '37'], ['Comparing', '29', '80'],15 ['Swapping', '29', '44'], ['Comparing', '44', '99'], ['Comparing', '44', '37'], ['Comparing', '37', '80'],16 ['Swapping', '37', '44'], ['Comparing', '99', '44'], ['Comparing', '44', '80'], ['Swapping', '44', '99'], ['Comparing', '99', '80'],17 ['Swapping', '80', '99']];18exports.comparisons2 = [['Comparing', 99, 90], ['Comparing', 90, 80], ['Comparing', 80, 70], ['Comparing', 70, 60],19 ['Comparing', 60, 50], ['Comparing', 50, 40], ['Comparing', 40, 30], ['Comparing', 30, 20], ['Comparing', 20, 10],20 ['Swapping', 10, 99], ['Comparing', 90, 80], ['Comparing', 80, 70], ['Comparing', 70, 60],21 ['Comparing', 60, 50], ['Comparing', 50, 40], ['Comparing', 40, 30], ['Comparing', 30, 20],22 ['Comparing', 20, 99], ['Swapping', 20, 90], ['Comparing', 80, 70], ['Comparing', 70, 60],23 ['Comparing', 60, 50], ['Comparing', 50, 40], ['Comparing', 40, 30], ['Comparing', 30, 90],24 ['Comparing', 30, 99], ['Swapping', 30, 80], ['Comparing', 70, 60], ['Comparing', 60, 50],25 ['Comparing', 50, 40], ['Comparing', 40, 80], ['Comparing', 40, 90], ['Comparing', 40, 99],26 ['Swapping', 40, 70], ['Comparing', 60, 50], ['Comparing', 50, 70], ['Comparing', 50, 80],27 ['Comparing', 50, 90], ['Comparing', 50, 99], ['Swapping', 50, 60], ['Comparing', 60, 70],28 ['Comparing', 60, 80], ['Comparing', 60, 90], ['Comparing', 60, 99], ['Comparing', 70, 80],29 ['Comparing', 70, 90], ['Comparing', 70, 99], ['Comparing', 80, 90], ['Comparing', 80, 99],30 ['Comparing', 90, 99]];31exports.comparisons3 = [['Comparing', '01', '02'], ['Comparing', '01', '03'], ['Comparing', '01', '04'], ['Comparing', '01', '05'],32 ['Comparing', '01', '06'], ['Comparing', '01', '07'], ['Comparing', '01', '08'], ['Comparing', '01', '09'], ['Comparing', '02', '03'],33 ['Comparing', '02', '04'], ['Comparing', '02', '05'], ['Comparing', '02', '06'], ['Comparing', '02', '07'],34 ['Comparing', '02', '08'], ['Comparing', '02', '09'], ['Comparing', '03', '04'], ['Comparing', '03', '05'],35 ['Comparing', '03', '06'], ['Comparing', '03', '07'], ['Comparing', '03', '08'], ['Comparing', '03', '09'],36 ['Comparing', '04', '05'], ['Comparing', '04', '06'], ['Comparing', '04', '07'], ['Comparing', '04', '08'],37 ['Comparing', '04', '09'], ['Comparing', '05', '06'], ['Comparing', '05', '07'], ['Comparing', '05', '08'],38 ['Comparing', '05', '09'], ['Comparing', '06', '07'], ['Comparing', '06', '08'], ['Comparing', '06', '09'],39 ['Comparing', '07', '08'], ['Comparing', '07', '09'], ['Comparing', '08', '09']];40let sorts = ['Selection Sort', //041 'Bubble Sort', //142 'Insertion Sort', //243 'Merge Sort', //344 'Quick Sort', //445 'Heap Sort', //546 'Bucket Sort', //647 'Shell Sort', //748 'Radix Sort']; //849export function clickAllSortsExceptN(n){50 for(let i=0; i<sorts.length; i++){51 if(i!==n){52 cy.get('button').contains(sorts[i]).click({force: true});53 }54 }55}56function checkBarOffsets(arrToSort, barOffset)57{58 if (barOffset == "none")59 {60 for (let i = 0; i < arrToSort.length; i++)61 {62 cy.react('Bar', {props: {barHeight: arrToSort[i]}})63 .should('have.attr', 'style')64 .should('not.contain', 'translateX')65 }66 }67 else68 {69 for (let i = 0; i < arrToSort.length; i++)70 {71 cy.react('Bar', {props: {barHeight: arrToSort[i]}})72 .should('have.attr', 'style')73 .should('contain', 'translateX('+barOffset[i])74 }75 }76}77export function testSort(arrToSort, barOffset, sortNum)78{79 clickAllSortsExceptN(sortNum);80 cy.get('input[id="input-numbers-to-sort"]').clear().type(arrToSort.join());81 cy.get('button').contains(new RegExp("^Play$")).click({force: true});82 cy.get('textarea[class="algorithm-log"]', {timeout: 1500000}).should("have.text", "SORTED");83 checkBarOffsets(arrToSort, barOffset);...
Using AI Code Generation
1var BestMatch = require('best-match');2var bm = new BestMatch(['foo', 'bar', 'baz']);3var BestMatch = require('best-match');4var bm = new BestMatch(['foo', 'bar', 'baz']);5var BestMatch = require('best-match');6var bm = new BestMatch(['foo', 'bar', 'baz']);7var BestMatch = require('best-match');8var bm = new BestMatch(['foo', 'bar', 'baz']);9var BestMatch = require('best-match');10var bm = new BestMatch(['foo', 'bar', 'baz']);11var BestMatch = require('best-match');12var bm = new BestMatch(['foo', 'bar', 'baz']);13var BestMatch = require('best-match');14var bm = new BestMatch(['foo', 'bar', 'baz
Using AI Code Generation
1var BestMatch = require('best-match');2var bestMatch = new BestMatch();3bestMatch.add('foo', 'foo');4bestMatch.add('bar', 'bar');5bestMatch.add('baz', 'baz');6var BestMatch = require('best-match');7var bestMatch = new BestMatch();8bestMatch.add('foo', 'foo');9bestMatch.add('bar', 'bar');10bestMatch.add('baz', 'baz');11var BestMatch = require('best-match');12var bestMatch = new BestMatch();13bestMatch.add('foo', 'foo');14bestMatch.add('bar', 'bar');15bestMatch.add('baz', 'baz');16var BestMatch = require('best-match');17var bestMatch = new BestMatch();18bestMatch.add('foo', 'foo');19bestMatch.add('bar', 'bar');20bestMatch.add('baz', 'baz');
Using AI Code Generation
1var BestMatch = require('bestmatch');2var bestMatch = new BestMatch();3bestMatch.add('foo', 'foo');4bestMatch.add('bar', 'bar');5bestMatch.add('baz', 'baz');6bestMatch.add('foobar', 'foobar');7bestMatch.add('barbaz', 'barbaz');8bestMatch.add('foobaz', 'foobaz');9bestMatch.add('barfoo', 'barfoo');10bestMatch.add('bazfoo', 'bazfoo');11bestMatch.add('bazbar', 'bazbar');12bestMatch.add('foobarbaz', 'foobarbaz');13bestMatch.add('foobazbar', 'foobazbar');14bestMatch.add('barfoobaz', 'barfoobaz');15bestMatch.add('bazbarfoo', 'bazbarfoo');16bestMatch.add('bazfoobar', 'bazfoobar');17bestMatch.add('barbazfoo', 'barbazfoo');18bestMatch.add('foobazbar', 'foobazbar');19bestMatch.add('bazbarfoo', 'bazbarfoo');20bestMatch.add('bazfoobar', 'bazfoobar');21bestMatch.add('barbazfoo', 'barbazfoo');22bestMatch.add('foobazbar', 'foobazbar');23bestMatch.add('bazbarfoo', 'bazbarfoo');24bestMatch.add('bazfoobar', 'bazfoobar');25bestMatch.add('barbazfoo', 'barbazfoo');26bestMatch.add('foobazbar', 'foobazbar');27bestMatch.add('bazbarfoo', 'bazbarfoo');28bestMatch.add('bazfoobar', 'bazfoobar');29bestMatch.add('barbazfoo', 'barbazfoo');30bestMatch.add('foobazbar', 'foobazbar');31bestMatch.add('bazbarfoo', 'bazbarfoo');32bestMatch.add('bazfoobar', 'bazfoobar');33bestMatch.add('barbazfoo', 'barbazfoo');34bestMatch.add('foobazbar', 'foobazbar');35bestMatch.add('bazbarfoo', 'bazbarfoo');36bestMatch.add('bazfoobar', 'bazfoobar');37bestMatch.add('barbazfoo', 'barbazfoo');38bestMatch.add('foobazbar', 'foobazbar');39bestMatch.add('bazbarfoo', 'bazbarfoo');40bestMatch.add('bazfoobar', 'bazfoobar');41bestMatch.add('barbazfoo', 'bar
Using AI Code Generation
1var BestMatch = require('best-match');2var bm = new BestMatch();3bm.add('test');4bm.add('test2');5bm.add('test3');6bm.add('test4');7bm.add('test5');8bm.remove('test4');9bm.removeAll();
Using AI Code Generation
1var BestMatch = require('./BestMatch.js');2var bestMatch = new BestMatch();3var data = {4};5var result = bestMatch.compare(data, 'app');6BestMatch.prototype.compare = function(data, target) {7 var self = this;8 var result = {};9 var bestMatch = self.getBestMatch(data, target);10 result[bestMatch] = data[bestMatch];11 return result;12}13BestMatch.prototype.getBestMatch = function(data, target) {14 var self = this;15 var keys = Object.keys(data);16 var bestMatch = keys[0];17 var bestMatchDistance = self.getDistance(target, bestMatch);18 for (var i = 1; i < keys.length; i++) {19 var currentKey = keys[i];20 var currentDistance = self.getDistance(target, currentKey);21 if (currentDistance < bestMatchDistance) {22 bestMatchDistance = currentDistance;23 bestMatch = currentKey;24 }25 }26 return bestMatch;27}28BestMatch.prototype.getDistance = function(a, b) {29 var self = this;30 var distance = 0;31 if (a.length > b.length) {32 var c = a;33 a = b;34 b = c;35 }36 for (var i = 0; i < a.length; i++) {37 if (a[i] != b[i]) {38 distance += (a.length - i);39 }40 }41 distance += (b.length - a.length);42 return distance;43}44module.exports = BestMatch;45BestMatch.prototype.compare = function(data, target) {46 var self = this;47 var result = {};48 var bestMatch = self.getBestMatch(data, target);49 result[bestMatch] = data[bestMatch];50 return result;51}52BestMatch.prototype.getBestMatch = function(data, target) {53 var self = this;54 var keys = Object.keys(data);55 var bestMatch = keys[0];56 var bestMatchDistance = self.getDistance(target, bestMatch);57 for (var i = 1; i < keys.length; i++) {
Using AI Code Generation
1var BestMatch = require('./bestMatch.js');2var user1 = {3};4var user2 = {5};6var user3 = {7};8var user4 = {9};10var user5 = {11};12var user6 = {13};14var users = [user1, user2, user3, user4, user5, user6];15var bestMatch = new BestMatch(user1, users);16bestMatch.compare();17function BestMatch(user, users) {18 this.user = user;19 this.users = users;20}21BestMatch.prototype.compare = function() {22 var userInterests = this.user.interests;23 var bestMatches = [];24 var bestMatch = {25 };26 var match = 0;27 for (var i = 0; i < this.users.length; i++) {28 var user = this.users[i];29 var interests = user.interests;30 for (var j = 0; j < userInterests.length; j++) {31 var interest = userInterests[j];32 if (interests.indexOf(interest) > -1) {33 match++;34 }35 }36 if (match > bestMatch.match) {37 bestMatch.name = user.name;38 bestMatch.match = match;39 }40 if (match === bestMatch.match) {41 bestMatches.push(user.name);42 }43 match = 0;44 }45 console.log(bestMatches);46}47module.exports = BestMatch;
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!