How to use test_history method in wpt

Best JavaScript code snippet using wpt

data.js

Source:data.js Github

copy

Full Screen

1'use strict';2angular.module('CloudApp.data_representation', ['ngRoute'])3.config(['$routeProvider', function($routeProvider) {4 $routeProvider.when('/charts', {5 templateUrl: 'views/data_representation/view.html',6 controller: 'ChartsCtrl'7 });8}])9.controller('ChartsCtrl', function($scope) {10 //List of all tests11 $scope.tests = [12 {13 id: 0,14 label: "Upload Small Data",15 selected: false16 },17 {18 id: 1,19 label: "Upload Large Data",20 selected: false21 },22 {23 id: 2,24 label: "Retrieve Small Data",25 selected: false26 },27 {28 id: 3,29 label: "Retrieve Large Data",30 selected: false31 },32 {33 id: 4,34 label: "Update Small Data",35 selected: false36 },37 {38 id: 5,39 label: "Update Large Data",40 selected: false41 }42 ];43 //List of all databases44 $scope.databases = [45 {46 name: "MongoDB",47 avatar: "/img/db/mongo.png",48 selected: false49 },50 {51 name: "DynamoDB",52 avatar: "/img/db/dynamodb.svg",53 selected: false54 },55 {56 name: "Firebase",57 avatar: "/img/db/firebase.png",58 selected: false59 },60 {61 name: "CouchDB",62 avatar: "/img/db/couchdb.png",63 selected: false64 }65 ];66 //List of databases to display on the graphs67 $scope.series = [$scope.databases[0].name, $scope.databases[1].name, $scope.databases[2].name, $scope.databases[3].name];68 //List of tests that are displayed on the graphs69 $scope.labels = [$scope.tests[0].label, $scope.tests[1].label, $scope.tests[2].label, $scope.tests[3].label, $scope.tests[4].label, $scope.tests[5].label];70 //2 dimensional array 0 initialized71 $scope.data = [72 [0, 0, 0, 0, 0, 0],73 [0, 0, 0, 0, 0, 0],74 [0, 0, 0, 0, 0, 0],75 [0, 0, 0, 0, 0, 0]76 ];77 //Graph options showing where to put the legend78 $scope.options = {legend: {display: true, position: "bottom"}};79 //2 dimensional array for data from mongodb tests80 $scope.mongoData = [81 [0, 0, 0, 0, 0, 0],82 [0, 0, 0, 0, 0, 0]83 ];84 //2 dimensional array for data from dynamodb tests85 $scope.dynamoData = [86 [0, 0, 0, 0, 0, 0],87 [0, 0, 0, 0, 0, 0]88 ];89 //2 dimensional array for data from firebase tests90 $scope.fireData = [91 [0, 0, 0, 0, 0, 0],92 [0, 0, 0, 0, 0, 0]93 ];94 //2 dimensional array for data from couchdb tests95 $scope.couchData = [96 [0, 0, 0, 0, 0, 0],97 [0, 0, 0, 0, 0, 0]98 ];99 /**100 * Get test data for all the tests from firebase101 */102 firebase.database().ref('test_history/post/mongodb/small').on('value', function(snapshot){103 //Calculate the average104 var average = 0, count = 0;105 snapshot.forEach(function(childSnapshot){106 average += childSnapshot.val().time_ms; count++;107 });108 //0 check to avoid divide by 0 error109 if (count > 0)110 average = average/count;111 $scope.data[0][0] = average.toFixed(2);112 $scope.$applyAsync();113 });114 firebase.database().ref('test_history/post/mongodb/large').on('value', function(snapshot){115 //Calculate the average116 var average = 0, count = 0;117 snapshot.forEach(function(childSnapshot){118 average += childSnapshot.val().time_ms; count++;119 });120 //0 check to avoid divide by 0 error121 if (count > 0)122 average = average/count;123 $scope.data[0][1] = average.toFixed(2);124 $scope.$applyAsync();125 });126 firebase.database().ref('test_history/get/mongodb/small').on('value', function(snapshot){127 //Calculate the average128 var average = 0, count = 0;129 snapshot.forEach(function(childSnapshot){130 average += childSnapshot.val().time_ms; count++;131 });132 //0 check to avoid divide by 0 error133 if (count > 0)134 average = average/count;135 $scope.data[0][2] = average.toFixed(2);136 $scope.$applyAsync();137 });138 firebase.database().ref('test_history/get/mongodb/large').on('value', function(snapshot){139 //Calculate the average140 var average = 0, count = 0;141 snapshot.forEach(function(childSnapshot){142 average += childSnapshot.val().time_ms; count++;143 });144 //0 check to avoid divide by 0 error145 if (count > 0)146 average = average/count;147 $scope.data[0][3] = average.toFixed(2);148 $scope.$applyAsync();149 });150 firebase.database().ref('test_history/update/mongodb/small').on('value', function(snapshot){151 //Calculate the average152 var average = 0, count = 0;153 snapshot.forEach(function(childSnapshot){154 average += childSnapshot.val().time_ms; count++;155 });156 //0 check to avoid divide by 0 error157 if (count > 0)158 average = average/count;159 $scope.data[0][4] = average.toFixed(2);160 $scope.$applyAsync();161 });162 firebase.database().ref('test_history/update/mongodb/large').on('value', function(snapshot){163 //Calculate the average164 var average = 0, count = 0;165 snapshot.forEach(function(childSnapshot){166 average += childSnapshot.val().time_ms; count++;167 });168 //0 check to avoid divide by 0 error169 if (count > 0)170 average = average/count;171 $scope.data[0][5] = average.toFixed(2);172 $scope.$applyAsync();173 });174 firebase.database().ref('test_history/post/dynamodb/small').on('value', function(snapshot){175 //Calculate the average176 var average = 0, count = 0;177 snapshot.forEach(function(childSnapshot){178 average += childSnapshot.val().time_ms; count++;179 });180 //0 check to avoid divide by 0 error181 if (count > 0)182 average = average/count;183 $scope.data[1][0] = average.toFixed(2);184 $scope.$applyAsync();185 });186 firebase.database().ref('test_history/post/dynamodb/large').on('value', function(snapshot){187 //Calculate the average188 var average = 0, count = 0;189 snapshot.forEach(function(childSnapshot){190 average += childSnapshot.val().time_ms; count++;191 });192 //0 check to avoid divide by 0 error193 if (count > 0)194 average = average/count;195 $scope.data[1][1] = average.toFixed(2);196 $scope.$applyAsync();197 });198 firebase.database().ref('test_history/get/dynamodb/small').on('value', function(snapshot){199 //Calculate the average200 var average = 0, count = 0;201 snapshot.forEach(function(childSnapshot){202 average += childSnapshot.val().time_ms; count++;203 });204 //0 check to avoid divide by 0 error205 if (count > 0)206 average = average/count;207 $scope.data[1][2] = average.toFixed(2);208 $scope.$applyAsync();209 });210 firebase.database().ref('test_history/get/dynamodb/large').on('value', function(snapshot){211 //Calculate the average212 var average = 0, count = 0;213 snapshot.forEach(function(childSnapshot){214 average += childSnapshot.val().time_ms; count++;215 });216 //0 check to avoid divide by 0 error217 if (count > 0)218 average = average/count;219 $scope.data[1][3] = average.toFixed(2);220 $scope.$applyAsync();221 });222 firebase.database().ref('test_history/update/dynamodb/small').on('value', function(snapshot){223 //Calculate the average224 var average = 0, count = 0;225 snapshot.forEach(function(childSnapshot){226 average += childSnapshot.val().time_ms; count++;227 });228 //0 check to avoid divide by 0 error229 if (count > 0)230 average = average/count;231 $scope.data[1][4] = average.toFixed(2);232 $scope.$applyAsync();233 });234 firebase.database().ref('test_history/update/dynamodb/large').on('value', function(snapshot){235 //Calculate the average236 var average = 0, count = 0;237 snapshot.forEach(function(childSnapshot){238 average += childSnapshot.val().time_ms; count++;239 });240 //0 check to avoid divide by 0 error241 if (count > 0)242 average = average/count;243 $scope.data[1][5] = average.toFixed(2);244 $scope.$applyAsync();245 });246 firebase.database().ref('test_history/post/firebase/small').on('value', function(snapshot){247 //Calculate the average248 var average = 0, count = 0;249 snapshot.forEach(function(childSnapshot){250 average += childSnapshot.val().time_ms; count++;251 });252 //0 check to avoid divide by 0 error253 if (count > 0)254 average = average/count;255 $scope.data[2][0] = average.toFixed(2);256 $scope.$applyAsync();257 });258 firebase.database().ref('test_history/post/firebase/large').on('value', function(snapshot){259 //Calculate the average260 var average = 0, count = 0;261 snapshot.forEach(function(childSnapshot){262 average += childSnapshot.val().time_ms; count++;263 });264 //0 check to avoid divide by 0 error265 if (count > 0)266 average = average/count;267 $scope.data[2][1] = average.toFixed(2);268 $scope.$applyAsync();269 });270 firebase.database().ref('test_history/get/firebase/small').on('value', function(snapshot){271 //Calculate the average272 var average = 0, count = 0;273 snapshot.forEach(function(childSnapshot){274 average += childSnapshot.val().time_ms; count++;275 });276 //0 check to avoid divide by 0 error277 if (count > 0)278 average = average/count;279 $scope.data[2][2] = average.toFixed(2);280 $scope.$applyAsync();281 });282 firebase.database().ref('test_history/get/firebase/large').on('value', function(snapshot){283 //Calculate the average284 var average = 0, count = 0;285 snapshot.forEach(function(childSnapshot){286 average += childSnapshot.val().time_ms; count++;287 });288 //0 check to avoid divide by 0 error289 if (count > 0)290 average = average/count;291 $scope.data[2][3] = average.toFixed(2);292 $scope.$applyAsync();293 });294 firebase.database().ref('test_history/update/firebase/small').on('value', function(snapshot){295 //Calculate the average296 var average = 0, count = 0;297 snapshot.forEach(function(childSnapshot){298 average += childSnapshot.val().time_ms; count++;299 });300 //0 check to avoid divide by 0 error301 if (count > 0)302 average = average/count;303 $scope.data[2][4] = average.toFixed(2);304 $scope.$applyAsync();305 });306 firebase.database().ref('test_history/update/firebase/large').on('value', function(snapshot){307 //Calculate the average308 var average = 0, count = 0;309 snapshot.forEach(function(childSnapshot){310 average += childSnapshot.val().time_ms; count++;311 });312 //0 check to avoid divide by 0 error313 if (count > 0)314 average = average/count;315 $scope.data[2][5] = average.toFixed(2);316 $scope.$applyAsync();317 });318 firebase.database().ref('test_history/post/couchdb/small').on('value', function(snapshot){319 //Calculate the average320 var average = 0, count = 0;321 snapshot.forEach(function(childSnapshot){322 average += childSnapshot.val().time_ms; count++;323 });324 //0 check to avoid divide by 0 error325 if (count > 0)326 average = average/count;327 $scope.data[3][0] = average.toFixed(2);328 $scope.$applyAsync();329 });330 firebase.database().ref('test_history/post/couchdb/large').on('value', function(snapshot){331 //Calculate the average332 var average = 0, count = 0;333 snapshot.forEach(function(childSnapshot){334 average += childSnapshot.val().time_ms; count++;335 });336 //0 check to avoid divide by 0 error337 if (count > 0)338 average = average/count;339 $scope.data[3][1] = average.toFixed(2);340 $scope.$applyAsync();341 });342 firebase.database().ref('test_history/get/couchdb/small').on('value', function(snapshot){343 //Calculate the average344 var average = 0, count = 0;345 snapshot.forEach(function(childSnapshot){346 average += childSnapshot.val().time_ms; count++;347 });348 //0 check to avoid divide by 0 error349 if (count > 0)350 average = average/count;351 $scope.data[3][2] = average.toFixed(2);352 $scope.$applyAsync();353 });354 firebase.database().ref('test_history/get/couchdb/large').on('value', function(snapshot){355 //Calculate the average356 var average = 0, count = 0;357 snapshot.forEach(function(childSnapshot){358 average += childSnapshot.val().time_ms; count++;359 });360 //0 check to avoid divide by 0 error361 if (count > 0)362 average = average/count;363 $scope.data[3][3] = average.toFixed(2);364 $scope.$applyAsync();365 });366 firebase.database().ref('test_history/update/couchdb/small').on('value', function(snapshot){367 //Calculate the average368 var average = 0, count = 0;369 snapshot.forEach(function(childSnapshot){370 average += childSnapshot.val().time_ms; count++;371 });372 //0 check to avoid divide by 0 error373 if (count > 0)374 average = average/count;375 $scope.data[3][4] = average.toFixed(2);376 $scope.$applyAsync();377 });378 firebase.database().ref('test_history/update/couchdb/large').on('value', function(snapshot){379 //Calculate the average380 var average = 0, count = 0;381 snapshot.forEach(function(childSnapshot){382 average += childSnapshot.val().time_ms; count++;383 });384 //0 check to avoid divide by 0 error385 if (count > 0)386 average = average/count;387 $scope.data[3][5] = average.toFixed(2);388 $scope.$applyAsync();389 });390 firebase.database().ref('test_history/post/mongodb/small').on('value', function(snapshot){391 var lowest = 9999;392 var highest = 0;393 //Get the highest and lowest times394 snapshot.forEach(function(childSnapshot){395 if (childSnapshot.val().time_ms > highest){396 highest = childSnapshot.val().time_ms;397 }398 if (childSnapshot.val().time_ms < lowest){399 lowest = childSnapshot.val().time_ms;400 }401 $scope.mongoData[0][0] = highest;402 $scope.mongoData[1][0] = lowest;403 });404 });405 firebase.database().ref('test_history/post/mongodb/large').on('value', function(snapshot){406 var lowest = 9999;407 var highest = 0;408 //Get the highest and lowest times409 snapshot.forEach(function(childSnapshot){410 if (childSnapshot.val().time_ms > highest){411 highest = childSnapshot.val().time_ms;412 }413 if (childSnapshot.val().time_ms < lowest){414 lowest = childSnapshot.val().time_ms;415 }416 $scope.mongoData[0][1] = highest;417 $scope.mongoData[1][1] = lowest;418 });419 });420 firebase.database().ref('test_history/get/mongodb/small').on('value', function(snapshot){421 var lowest = 9999;422 var highest = 0;423 //Get the highest and lowest times424 snapshot.forEach(function(childSnapshot){425 if (childSnapshot.val().time_ms > highest){426 highest = childSnapshot.val().time_ms;427 }428 if (childSnapshot.val().time_ms < lowest){429 lowest = childSnapshot.val().time_ms;430 }431 $scope.mongoData[0][2] = highest;432 $scope.mongoData[1][2] = lowest;433 });434 });435 firebase.database().ref('test_history/get/mongodb/large').on('value', function(snapshot){436 var lowest = 9999;437 var highest = 0;438 //Get the highest and lowest times439 snapshot.forEach(function(childSnapshot){440 if (childSnapshot.val().time_ms > highest){441 highest = childSnapshot.val().time_ms;442 }443 if (childSnapshot.val().time_ms < lowest){444 lowest = childSnapshot.val().time_ms;445 }446 $scope.mongoData[0][3] = highest;447 $scope.mongoData[1][3] = lowest;448 });449 });450 firebase.database().ref('test_history/update/mongodb/small').on('value', function(snapshot){451 var lowest = 9999;452 var highest = 0;453 //Get the highest and lowest times454 snapshot.forEach(function(childSnapshot){455 if (childSnapshot.val().time_ms > highest){456 highest = childSnapshot.val().time_ms;457 }458 if (childSnapshot.val().time_ms < lowest){459 lowest = childSnapshot.val().time_ms;460 }461 $scope.mongoData[0][4] = highest;462 $scope.mongoData[1][4] = lowest;463 });464 });465 firebase.database().ref('test_history/update/mongodb/large').on('value', function(snapshot){466 var lowest = 9999;467 var highest = 0;468 //Get the highest and lowest times469 snapshot.forEach(function(childSnapshot){470 if (childSnapshot.val().time_ms > highest){471 highest = childSnapshot.val().time_ms;472 }473 if (childSnapshot.val().time_ms < lowest){474 lowest = childSnapshot.val().time_ms;475 }476 $scope.mongoData[0][5] = highest;477 $scope.mongoData[1][5] = lowest;478 });479 });480 firebase.database().ref('test_history/post/dynamodb/small').on('value', function(snapshot){481 var lowest = 9999;482 var highest = 0;483 //Get the highest and lowest times484 snapshot.forEach(function(childSnapshot){485 if (childSnapshot.val().time_ms > highest){486 highest = childSnapshot.val().time_ms;487 }488 if (childSnapshot.val().time_ms < lowest){489 lowest = childSnapshot.val().time_ms;490 }491 $scope.dynamoData[0][0] = highest;492 $scope.dynamoData[1][0] = lowest;493 });494 });495 firebase.database().ref('test_history/post/dynamodb/large').on('value', function(snapshot){496 var lowest = 9999;497 var highest = 0;498 //Get the highest and lowest times499 snapshot.forEach(function(childSnapshot){500 if (childSnapshot.val().time_ms > highest){501 highest = childSnapshot.val().time_ms;502 }503 if (childSnapshot.val().time_ms < lowest){504 lowest = childSnapshot.val().time_ms;505 }506 $scope.dynamoData[0][1] = highest;507 $scope.dynamoData[1][1] = lowest;508 });509 });510 firebase.database().ref('test_history/get/dynamodb/small').on('value', function(snapshot){511 var lowest = 9999;512 var highest = 0;513 //Get the highest and lowest times514 snapshot.forEach(function(childSnapshot){515 if (childSnapshot.val().time_ms > highest){516 highest = childSnapshot.val().time_ms;517 }518 if (childSnapshot.val().time_ms < lowest){519 lowest = childSnapshot.val().time_ms;520 }521 $scope.dynamoData[0][2] = highest;522 $scope.dynamoData[1][2] = lowest;523 });524 });525 firebase.database().ref('test_history/get/dynamodb/large').on('value', function(snapshot){526 var lowest = 9999;527 var highest = 0;528 //Get the highest and lowest times529 snapshot.forEach(function(childSnapshot){530 if (childSnapshot.val().time_ms > highest){531 highest = childSnapshot.val().time_ms;532 }533 if (childSnapshot.val().time_ms < lowest){534 lowest = childSnapshot.val().time_ms;535 }536 $scope.dynamoData[0][3] = highest;537 $scope.dynamoData[1][3] = lowest;538 });539 });540 firebase.database().ref('test_history/update/dynamodb/small').on('value', function(snapshot){541 var lowest = 9999;542 var highest = 0;543 //Get the highest and lowest times544 snapshot.forEach(function(childSnapshot){545 if (childSnapshot.val().time_ms > highest){546 highest = childSnapshot.val().time_ms;547 }548 if (childSnapshot.val().time_ms < lowest){549 lowest = childSnapshot.val().time_ms;550 }551 $scope.dynamoData[0][4] = highest;552 $scope.dynamoData[1][4] = lowest;553 });554 });555 firebase.database().ref('test_history/update/dynamodb/large').on('value', function(snapshot){556 var lowest = 9999;557 var highest = 0;558 //Get the highest and lowest times559 snapshot.forEach(function(childSnapshot){560 if (childSnapshot.val().time_ms > highest){561 highest = childSnapshot.val().time_ms;562 }563 if (childSnapshot.val().time_ms < lowest){564 lowest = childSnapshot.val().time_ms;565 }566 $scope.dynamoData[0][5] = highest;567 $scope.dynamoData[1][5] = lowest;568 });569 });570 firebase.database().ref('test_history/post/firebase/small').on('value', function(snapshot){571 var lowest = 9999;572 var highest = 0;573 //Get the highest and lowest times574 snapshot.forEach(function(childSnapshot){575 if (childSnapshot.val().time_ms > highest){576 highest = childSnapshot.val().time_ms;577 }578 if (childSnapshot.val().time_ms < lowest){579 lowest = childSnapshot.val().time_ms;580 }581 $scope.fireData[0][0] = highest;582 $scope.fireData[1][0] = lowest;583 });584 });585 firebase.database().ref('test_history/post/firebase/large').on('value', function(snapshot){586 var lowest = 9999;587 var highest = 0;588 //Get the highest and lowest times589 snapshot.forEach(function(childSnapshot){590 if (childSnapshot.val().time_ms > highest){591 highest = childSnapshot.val().time_ms;592 }593 if (childSnapshot.val().time_ms < lowest){594 lowest = childSnapshot.val().time_ms;595 }596 $scope.fireData[0][1] = highest;597 $scope.fireData[1][1] = lowest;598 });599 });600 firebase.database().ref('test_history/get/firebase/small').on('value', function(snapshot){601 var lowest = 9999;602 var highest = 0;603 //Get the highest and lowest times604 snapshot.forEach(function(childSnapshot){605 if (childSnapshot.val().time_ms > highest){606 highest = childSnapshot.val().time_ms;607 }608 if (childSnapshot.val().time_ms < lowest){609 lowest = childSnapshot.val().time_ms;610 }611 $scope.fireData[0][2] = highest;612 $scope.fireData[1][2] = lowest;613 });614 });615 firebase.database().ref('test_history/get/firebase/large').on('value', function(snapshot){616 var lowest = 9999;617 var highest = 0;618 //Get the highest and lowest times619 snapshot.forEach(function(childSnapshot){620 if (childSnapshot.val().time_ms > highest){621 highest = childSnapshot.val().time_ms;622 }623 if (childSnapshot.val().time_ms < lowest){624 lowest = childSnapshot.val().time_ms;625 }626 $scope.fireData[0][3] = highest;627 $scope.fireData[1][3] = lowest;628 });629 });630 firebase.database().ref('test_history/update/firebase/small').on('value', function(snapshot){631 var lowest = 9999;632 var highest = 0;633 //Get the highest and lowest times634 snapshot.forEach(function(childSnapshot){635 if (childSnapshot.val().time_ms > highest){636 highest = childSnapshot.val().time_ms;637 }638 if (childSnapshot.val().time_ms < lowest){639 lowest = childSnapshot.val().time_ms;640 }641 $scope.fireData[0][4] = highest;642 $scope.fireData[1][4] = lowest;643 });644 });645 firebase.database().ref('test_history/update/firebase/large').on('value', function(snapshot){646 var lowest = 9999;647 var highest = 0;648 //Get the highest and lowest times649 snapshot.forEach(function(childSnapshot){650 if (childSnapshot.val().time_ms > highest){651 highest = childSnapshot.val().time_ms;652 }653 if (childSnapshot.val().time_ms < lowest){654 lowest = childSnapshot.val().time_ms;655 }656 $scope.fireData[0][5] = highest;657 $scope.fireData[1][5] = lowest;658 });659 });660 firebase.database().ref('test_history/post/couchdb/small').on('value', function(snapshot){661 var lowest = 9999;662 var highest = 0;663 //Get the highest and lowest times664 snapshot.forEach(function(childSnapshot){665 if (childSnapshot.val().time_ms > highest){666 highest = childSnapshot.val().time_ms;667 }668 if (childSnapshot.val().time_ms < lowest){669 lowest = childSnapshot.val().time_ms;670 }671 $scope.couchData[0][0] = highest;672 $scope.couchData[1][0] = lowest;673 });674 });675 firebase.database().ref('test_history/post/couchdb/large').on('value', function(snapshot){676 var lowest = 9999;677 var highest = 0;678 //Get the highest and lowest times679 snapshot.forEach(function(childSnapshot){680 if (childSnapshot.val().time_ms > highest){681 highest = childSnapshot.val().time_ms;682 }683 if (childSnapshot.val().time_ms < lowest){684 lowest = childSnapshot.val().time_ms;685 }686 $scope.couchData[0][1] = highest;687 $scope.couchData[1][1] = lowest;688 });689 });690 firebase.database().ref('test_history/get/couchdb/small').on('value', function(snapshot){691 var lowest = 9999;692 var highest = 0;693 //Get the highest and lowest times694 snapshot.forEach(function(childSnapshot){695 if (childSnapshot.val().time_ms > highest){696 highest = childSnapshot.val().time_ms;697 }698 if (childSnapshot.val().time_ms < lowest){699 lowest = childSnapshot.val().time_ms;700 }701 $scope.couchData[0][2] = highest;702 $scope.couchData[1][2] = lowest;703 });704 });705 firebase.database().ref('test_history/get/couchdb/large').on('value', function(snapshot){706 var lowest = 9999;707 var highest = 0;708 //Get the highest and lowest times709 snapshot.forEach(function(childSnapshot){710 if (childSnapshot.val().time_ms > highest){711 highest = childSnapshot.val().time_ms;712 }713 if (childSnapshot.val().time_ms < lowest){714 lowest = childSnapshot.val().time_ms;715 }716 $scope.couchData[0][3] = highest;717 $scope.couchData[1][3] = lowest;718 });719 });720 firebase.database().ref('test_history/update/couchdb/small').on('value', function(snapshot){721 var lowest = 9999;722 var highest = 0;723 //Get the highest and lowest times724 snapshot.forEach(function(childSnapshot){725 if (childSnapshot.val().time_ms > highest){726 highest = childSnapshot.val().time_ms;727 }728 if (childSnapshot.val().time_ms < lowest){729 lowest = childSnapshot.val().time_ms;730 }731 $scope.couchData[0][4] = highest;732 $scope.couchData[1][4] = lowest;733 });734 });735 firebase.database().ref('test_history/update/couchdb/large').on('value', function(snapshot){736 var lowest = 9999;737 var highest = 0;738 //Get the highest and lowest times739 snapshot.forEach(function(childSnapshot){740 if (childSnapshot.val().time_ms > highest){741 highest = childSnapshot.val().time_ms;742 }743 if (childSnapshot.val().time_ms < lowest){744 lowest = childSnapshot.val().time_ms;745 }746 $scope.couchData[0][5] = highest;747 $scope.couchData[1][5] = lowest;748 });749 });750 //For each test for each database get the latitude and longitude of where the test was performed and add them to heatmapData to display on the map751 $scope.heatmapData = [];752 firebase.database().ref('test_history/get/couchdb/small').on('value', function(snapshot){753 snapshot.forEach(function(childSnapshot){754 $scope.heatmapData.push({location: new google.maps.LatLng(childSnapshot.val().ip.latitude, childSnapshot.val().ip.longitude), weight: childSnapshot.val().time_ms});755 $scope.$applyAsync();756 });757 });758 firebase.database().ref('test_history/get/couchdb/large').on('value', function(snapshot){759 snapshot.forEach(function(childSnapshot){760 $scope.heatmapData.push({location: new google.maps.LatLng(childSnapshot.val().ip.latitude, childSnapshot.val().ip.longitude), weight: childSnapshot.val().time_ms});761 $scope.$applyAsync();762 });763 });764 firebase.database().ref('test_history/get/dynamodb/small').on('value', function(snapshot){765 snapshot.forEach(function(childSnapshot){766 $scope.heatmapData.push({location: new google.maps.LatLng(childSnapshot.val().ip.latitude, childSnapshot.val().ip.longitude), weight: childSnapshot.val().time_ms});767 $scope.$applyAsync();768 });769 });770 firebase.database().ref('test_history/get/dynamodb/large').on('value', function(snapshot){771 snapshot.forEach(function(childSnapshot){772 $scope.heatmapData.push({location: new google.maps.LatLng(childSnapshot.val().ip.latitude, childSnapshot.val().ip.longitude), weight: childSnapshot.val().time_ms});773 $scope.$applyAsync();774 });775 });776 firebase.database().ref('test_history/get/firebase/small').on('value', function(snapshot){777 snapshot.forEach(function(childSnapshot){778 $scope.heatmapData.push({location: new google.maps.LatLng(childSnapshot.val().ip.latitude, childSnapshot.val().ip.longitude), weight: childSnapshot.val().time_ms});779 $scope.$applyAsync();780 });781 });782 firebase.database().ref('test_history/get/firebase/large').on('value', function(snapshot){783 snapshot.forEach(function(childSnapshot){784 $scope.heatmapData.push({location: new google.maps.LatLng(childSnapshot.val().ip.latitude, childSnapshot.val().ip.longitude), weight: childSnapshot.val().time_ms});785 $scope.$applyAsync();786 });787 });788 firebase.database().ref('test_history/get/mongodb/small').on('value', function(snapshot){789 snapshot.forEach(function(childSnapshot){790 $scope.heatmapData.push({location: new google.maps.LatLng(childSnapshot.val().ip.latitude, childSnapshot.val().ip.longitude), weight: childSnapshot.val().time_ms});791 $scope.$applyAsync();792 });793 });794 firebase.database().ref('test_history/get/mongodb/large').on('value', function(snapshot){795 snapshot.forEach(function(childSnapshot){796 $scope.heatmapData.push({location: new google.maps.LatLng(childSnapshot.val().ip.latitude, childSnapshot.val().ip.longitude), weight: childSnapshot.val().time_ms});797 $scope.$applyAsync();798 });799 });800 firebase.database().ref('test_history/post/couchdb/small').on('value', function(snapshot){801 snapshot.forEach(function(childSnapshot){802 $scope.heatmapData.push({location: new google.maps.LatLng(childSnapshot.val().ip.latitude, childSnapshot.val().ip.longitude), weight: childSnapshot.val().time_ms});803 $scope.$applyAsync();804 });805 });806 firebase.database().ref('test_history/post/couchdb/large').on('value', function(snapshot){807 snapshot.forEach(function(childSnapshot){808 $scope.heatmapData.push({location: new google.maps.LatLng(childSnapshot.val().ip.latitude, childSnapshot.val().ip.longitude), weight: childSnapshot.val().time_ms});809 $scope.$applyAsync();810 });811 });812 firebase.database().ref('test_history/post/dynamodb/small').on('value', function(snapshot){813 snapshot.forEach(function(childSnapshot){814 $scope.heatmapData.push({location: new google.maps.LatLng(childSnapshot.val().ip.latitude, childSnapshot.val().ip.longitude), weight: childSnapshot.val().time_ms});815 $scope.$applyAsync();816 });817 });818 firebase.database().ref('test_history/post/dynamodb/large').on('value', function(snapshot){819 snapshot.forEach(function(childSnapshot){820 $scope.heatmapData.push({location: new google.maps.LatLng(childSnapshot.val().ip.latitude, childSnapshot.val().ip.longitude), weight: childSnapshot.val().time_ms});821 $scope.$applyAsync();822 });823 });824 firebase.database().ref('test_history/post/firebase/small').on('value', function(snapshot){825 snapshot.forEach(function(childSnapshot){826 $scope.heatmapData.push({location: new google.maps.LatLng(childSnapshot.val().ip.latitude, childSnapshot.val().ip.longitude), weight: childSnapshot.val().time_ms});827 $scope.$applyAsync();828 });829 });830 firebase.database().ref('test_history/post/firebase/large').on('value', function(snapshot){831 snapshot.forEach(function(childSnapshot){832 $scope.heatmapData.push({location: new google.maps.LatLng(childSnapshot.val().ip.latitude, childSnapshot.val().ip.longitude), weight: childSnapshot.val().time_ms});833 $scope.$applyAsync();834 });835 });836 firebase.database().ref('test_history/post/mongodb/small').on('value', function(snapshot){837 snapshot.forEach(function(childSnapshot){838 $scope.heatmapData.push({location: new google.maps.LatLng(childSnapshot.val().ip.latitude, childSnapshot.val().ip.longitude), weight: childSnapshot.val().time_ms});839 $scope.$applyAsync();840 });841 });842 firebase.database().ref('test_history/post/mongodb/large').on('value', function(snapshot){843 snapshot.forEach(function(childSnapshot){844 $scope.heatmapData.push({location: new google.maps.LatLng(childSnapshot.val().ip.latitude, childSnapshot.val().ip.longitude), weight: childSnapshot.val().time_ms});845 $scope.$applyAsync();846 });847 });848 firebase.database().ref('test_history/update/couchdb/small').on('value', function(snapshot){849 snapshot.forEach(function(childSnapshot){850 $scope.heatmapData.push({location: new google.maps.LatLng(childSnapshot.val().ip.latitude, childSnapshot.val().ip.longitude), weight: childSnapshot.val().time_ms});851 $scope.$applyAsync();852 });853 });854 firebase.database().ref('test_history/update/couchdb/large').on('value', function(snapshot){855 snapshot.forEach(function(childSnapshot){856 $scope.heatmapData.push({location: new google.maps.LatLng(childSnapshot.val().ip.latitude, childSnapshot.val().ip.longitude), weight: childSnapshot.val().time_ms});857 $scope.$applyAsync();858 });859 });860 firebase.database().ref('test_history/update/dynamodb/small').on('value', function(snapshot){861 snapshot.forEach(function(childSnapshot){862 $scope.heatmapData.push({location: new google.maps.LatLng(childSnapshot.val().ip.latitude, childSnapshot.val().ip.longitude), weight: childSnapshot.val().time_ms});863 $scope.$applyAsync();864 });865 });866 firebase.database().ref('test_history/update/dynamodb/large').on('value', function(snapshot){867 snapshot.forEach(function(childSnapshot){868 $scope.heatmapData.push({location: new google.maps.LatLng(childSnapshot.val().ip.latitude, childSnapshot.val().ip.longitude), weight: childSnapshot.val().time_ms});869 $scope.$applyAsync();870 });871 });872 firebase.database().ref('test_history/update/firebase/small').on('value', function(snapshot){873 snapshot.forEach(function(childSnapshot){874 $scope.heatmapData.push({location: new google.maps.LatLng(childSnapshot.val().ip.latitude, childSnapshot.val().ip.longitude), weight: childSnapshot.val().time_ms});875 $scope.$applyAsync();876 });877 });878 firebase.database().ref('test_history/update/firebase/large').on('value', function(snapshot){879 snapshot.forEach(function(childSnapshot){880 $scope.heatmapData.push({location: new google.maps.LatLng(childSnapshot.val().ip.latitude, childSnapshot.val().ip.longitude), weight: childSnapshot.val().time_ms});881 $scope.$applyAsync();882 });883 });884 firebase.database().ref('test_history/update/mongodb/small').on('value', function(snapshot){885 snapshot.forEach(function(childSnapshot){886 $scope.heatmapData.push({location: new google.maps.LatLng(childSnapshot.val().ip.latitude, childSnapshot.val().ip.longitude), weight: childSnapshot.val().time_ms});887 $scope.$applyAsync();888 });889 });890 firebase.database().ref('test_history/update/mongodb/large').on('value', function(snapshot){891 snapshot.forEach(function(childSnapshot){892 $scope.heatmapData.push({location: new google.maps.LatLng(childSnapshot.val().ip.latitude, childSnapshot.val().ip.longitude), weight: childSnapshot.val().time_ms});893 $scope.$applyAsync();894 });895 });...

Full Screen

Full Screen

ReportController.js

Source:ReportController.js Github

copy

Full Screen

1'use strict'2const Database = use('Database');3class ReportController {4 // Chấm điểm theo part5 countResutlOfPart(part) {6 if (!part) { return '' }7 let questionCount = 0;8 let questionRightCount = 0;9 for (let index = 0; index < part.questions.length; index++) {10 if (part.questions[index].content_type === 1 || part.questions[index].content_type === 2) {11 questionCount++;12 }13 if (part.questions[index].content_type === 3) {14 questionCount += part.questions[index].option_data.length;15 }16 questionRightCount += this.checkQuestionRight(part.questions[index])17 }18 return `'${questionRightCount}/${questionCount}`19 }20 checkQuestionRight(question) {21 let rightAnswer = 0;22 if (question.content_type === 1 || question.content_type === 2) {23 const questionRight = question.option_data.filter(qs => qs.right_answer === 'true' || qs.right_answer === true)24 if (questionRight.length === question.answers.length) {25 for (let index = 0; index < questionRight.length; index++) {26 const findIndex = question.answers.findIndex(ans => ans === questionRight[index].id)27 if (findIndex === -1 || questionRight[index].right_answer === false) {28 return rightAnswer29 }30 }31 rightAnswer = 132 }33 } else {34 for (let index = 0; index < question.option_data.length; index++) {35 const answer = question.answers[index] && question.answers[index] !== '' ? question.answers[index].trim().toLowerCase() : ''36 const option = question.option_data[index].content ? question.option_data[index].content.trim().toLowerCase() : ''37 const optionArray = option.split('|')38 for (let index2 = 0; index2 < optionArray.length; index2++) {39 const element = optionArray[index2];40 if (element !== '' && answer !== '' && element === answer) {41 rightAnswer += 142 break43 }44 }45 }46 }47 return rightAnswer48 }49 async TestResutl ({ request, response }) {50 let { start, end, email, phone } = request.all()51 let testList = Database.table('test_history')52 .leftJoin('contact', 'test_history.contact_id', 'contact.id')53 .join('exam', 'exam.id', 'test_history.exam_id')54 .join('contact_history', 'contact_history.id', 'test_history.contact_history')55 .select('contact.id as contact_id', 'contact.name', 'contact.phone', 'contact.subjectid', 'contact.classid', 'contact.email', 'test_history.created_at', 'test_history.time', 'test_history.confirm_phone', 'test_history.id as test_id', 'test_history.test_result', 'contact_history.utm_source', 'contact_history.utm_medium', 'contact_history.utm_campaign', 'contact_history.utm_term', 'contact_history.utm_content')56 .where('test_history.status', 1)57 .orderBy('test_history.created_at', 'desc')58 if (start) {59 testList.where('test_history.created_at', '>', start + ' 00:00:00')60 }61 if (end) {62 testList.where('test_history.created_at', '<', end + ' 23:59:59')63 }64 if (phone) {65 testList.where('contact.phone', phone)66 }67 if (email) {68 testList.where('contact.email', email)69 }70 // console.log(testList.clone().toSQL())71 testList = await testList72 // Check số lượng part tối đa73 let partLength = 0;74 for (let index = 0; index < testList.length; index++) {75 const testData = JSON.parse(testList[index].test_result)76 if (testData.part.length > partLength) {77 partLength = testData.part.length78 }79 }80 let data = []81 for (let index = 0; index < testList.length; index++) {82 let _testInfo = {83 stt: index + 1,84 name: testList[index].name,85 age: testList[index].age,86 phone: testList[index].phone,87 email: testList[index].email,88 time: testList[index].time,89 confirm_phone: testList[index].confirm_phone,90 // learned: testList[index].learned == 1 ? 'Đã học' : 'Chưa học',91 utm_source: testList[index].utm_source,92 utm_medium: testList[index].utm_medium,93 utm_campaign: testList[index].utm_campaign,94 utm_term: testList[index].utm_term,95 utm_content: testList[index].utm_content,96 created_at: testList[index].created_at97 }98 const testData = JSON.parse(testList[index].test_result)99 _testInfo['test_writing'] = ''100 // Loop for part101 for (let index2 = 0; index2 < partLength; index2++) {102 _testInfo['test_'+ (index2 + 1)] = ''103 if (testData.part[index2]) {104 if (testData.part[index2].part_type == 0) {105 _testInfo['test_'+ (index2 + 1)] = this.countResutlOfPart(testData.part[index2])106 }107 if (testData.part[index2].part_type == 1) {108 let writing = ''109 if (testData.part[index2].writing && testData.part[index2].writing != '') {110 writing = testData.part[index2].writing.replace(/<br>/g, '\n')111 writing = writing.replace(/(<([^>]+)>)/ig, '')112 }113 _testInfo['test_writing'] = writing114 }115 }116 }117 data.push(_testInfo)118 }119 return response.json({120 code: 1,121 data: data122 })123 }124 async teacherReport ({ request, response }) {125 let { page, date_start, date_end, classid, subjectid, teacherid, export_data } = request.all()126 if (!page) {page = 1}127 const limit = 200;128 let queryBuilder = Database.table('test_history')129 .leftJoin('exam', 'test_history.exam_id', 'exam.id')130 .leftJoin('users', 'test_history.updated_by', 'users.id')131 .where('test_history.mark_status', 1)132 .groupByRaw('test_history.updated_by, MONTH(test_history.created_at) ')133 .count('* as total')134 .orderByRaw('MONTH(test_history.created_at) ASC')135 .select(Database.raw('test_history.updated_by, MONTH(test_history.created_at) as month, users.name'))136 // .select(Database.raw('test_history.tick_status'))137 if (date_start) {138 queryBuilder.where('test_history.created_at', '>', date_start + ' 00:00:00')139 }140 if (date_end) {141 queryBuilder.where('test_history.created_at', '<', date_end + ' 23:59:59')142 }143 if (classid) {144 queryBuilder.where('exam.classid', classid)145 }146 if (subjectid) {147 queryBuilder.where('exam.subjectid', subjectid)148 }149 if (teacherid) {150 queryBuilder.where('test_history.updated_by', teacherid)151 }152 console.log(queryBuilder.clone().toSQL())153 let resultData154 if (export_data == 'true') {155 resultData = await queryBuilder156 for (let index = 0; index < resultData.length; index++) {157 // resultData[index].learned = resultData[index].learned == 1 ? 'Đã học' : 'Chưa học'158 // resultData[index].status = resultData[index].status == 1 ? 'Đã hoàn thành' : 'Chưa hoàn thành'159 resultData[index].created_at = this.dateToTimeString(resultData[index].created_at) + '<br>' + this.dateToDateString(resultData[index].created_at)160 }161 } else {162 // resultData = await queryBuilder.paginate(page, limit)163 resultData = await queryBuilder164 }165 return response.json({166 code: 1,167 data: resultData168 })169 }170 async productReport ({ request, response }) {171 let { page, date_start, date_end, classid, subjectid, export_data } = request.all()172 if (!page) {page = 1}173 const limit = 200;174 let queryBuilder = Database.table('test_history')175 .leftJoin('exam', 'test_history.exam_id', 'exam.id')176 // .groupByRaw('test_history.tick_status')177 .groupByRaw('test_history.tick_status, MONTH(test_history.created_at)')178 .count('* as total')179 .select(Database.raw('test_history.tick_status,MONTH(test_history.created_at) as month'))180 // .select(Database.raw('test_history.tick_status'))181 if (date_start) {182 queryBuilder.where('test_history.created_at', '>', date_start + ' 00:00:00')183 }184 if (date_end) {185 queryBuilder.where('test_history.created_at', '<', date_end + ' 23:59:59')186 }187 if (classid) {188 queryBuilder.where('exam.classid', classid)189 }190 if (subjectid) {191 queryBuilder.where('exam.subjectid', subjectid)192 }193 // console.log(queryBuilder.clone().toSQL())194 let resultData195 if (export_data == 'true') {196 resultData = await queryBuilder197 for (let index = 0; index < resultData.length; index++) {198 // resultData[index].learned = resultData[index].learned == 1 ? 'Đã học' : 'Chưa học'199 // resultData[index].status = resultData[index].status == 1 ? 'Đã hoàn thành' : 'Chưa hoàn thành'200 resultData[index].created_at = this.dateToTimeString(resultData[index].created_at) + '<br>' + this.dateToDateString(resultData[index].created_at)201 }202 } else {203 // resultData = await queryBuilder.paginate(page, limit)204 resultData = await queryBuilder205 }206 return response.json({207 code: 1,208 data: resultData209 })210 }211 async SyntheticReport ({ request, response }) {212 let { date_start, date_end, utm_source, utm_medium, utm_campaign, utm_term, utm_content, phone, email, learned, test_status, source , page, export_data } = request.all()213 if (!page) {page = 1}214 const limit = 200;215 let queryBuilder = Database.table('test_history')216 .leftJoin('contact_history', 'test_history.contact_history', 'contact_history.id')217 .leftJoin('contact', 'contact.id', 'contact_history.contact_id')218 .select('contact.name', 'contact.phone', 'contact.email', 'contact.learned', 'test_history.time', 'test_history.status', 'contact_history.source', 'contact_history.utm_source', 'contact_history.utm_medium', 'contact_history.utm_campaign', 'contact_history.utm_term', 'contact_history.utm_content', 'contact_history.created_at')219 if (date_start) {220 queryBuilder.where('test_history.created_at', '>', date_start + ' 00:00:00')221 }222 if (date_end) {223 queryBuilder.where('test_history.created_at', '<', date_end + ' 23:59:59')224 }225 if (utm_source) {226 queryBuilder.where('contact_history.utm_source', utm_source)227 }228 if (utm_medium) {229 queryBuilder.where('contact_history.utm_medium', utm_medium)230 }231 if (utm_campaign) {232 queryBuilder.where('contact_history.utm_campaign', utm_campaign)233 }234 if (utm_term) {235 queryBuilder.where('contact_history.utm_term', utm_term)236 }237 if (utm_content) {238 queryBuilder.where('contact_history.utm_content', utm_content)239 }240 if (phone) {241 queryBuilder.where('contact.phone', phone)242 }243 if (email) {244 queryBuilder.where('contact.email', email)245 }246 if (learned) {247 queryBuilder.where('contact.learned', learned)248 }249 if (test_status) {250 queryBuilder.where('test_history.status', test_status)251 }252 if (source) {253 queryBuilder.where('contact_history.source', source)254 }255 // console.log(queryBuilder.clone().toSQL())256 let resultData257 if (export_data == 'true') {258 resultData = await queryBuilder259 for (let index = 0; index < resultData.length; index++) {260 resultData[index].learned = resultData[index].learned == 1 ? 'Đã học' : 'Chưa học'261 resultData[index].status = resultData[index].status == 1 ? 'Đã hoàn thành' : 'Chưa hoàn thành'262 resultData[index].created_at = this.dateToTimeString(resultData[index].created_at) + '<br>' + this.dateToDateString(resultData[index].created_at)263 }264 } else {265 resultData = await queryBuilder.paginate(page, limit)266 }267 return response.json({268 code: 1,269 data: resultData270 })271 }272 dateToDateString(dateText) {273 const date = new Date(dateText)274 return `${date.getFullYear()}-${(`0${date.getMonth() + 1}`).slice(-2)}-${date.getDate() < 10 ? `0${date.getDate()}` : date.getDate()}`275 }276 dateToTimeString(dateText) {277 const date = new Date(dateText)278 return `${date.getHours() < 10 ? `0${date.getHours()}` : date.getHours()} : ${date.getMinutes() < 10 ? `0${date.getMinutes()}` : date.getMinutes()}`279 }280}...

Full Screen

Full Screen

views.py

Source:views.py Github

copy

Full Screen

1import requests, json2from django.http import HttpResponse, JsonResponse3from rest_framework.decorators import action4from rest_framework.permissions import BasePermission5from rest_framework import viewsets, status6from rest_framework import permissions7from rest_framework.response import Response8from rest_framework.views import APIView9from suggest_career.app.models import User, MBTI, TestHistory10from suggest_career.app.serializer import UserInfoSerializer, SignInSerializer, SignUpSerializer11class UserViewSet(viewsets.ModelViewSet):12 class UserPermissionClass(BasePermission):13 def has_permission(self, request, view):14 return True15 def has_object_permission(self, request, view, obj):16 return request.user == obj17 @action(methods=['POST'], detail=False)18 def signin(self, request, *args, **kwargs):19 s = SignInSerializer(data=request.data)20 s.is_valid(raise_exception=True)21 u = User.objects.get(username=request.data.get('username'))22 return Response(UserInfoSerializer(instance=u).data, status.HTTP_200_OK)23 @action(methods=['POST'], detail=False)24 def signup(self, request, *args, **kwargs):25 s = SignUpSerializer(data=request.data)26 s.is_valid(raise_exception=True)27 u = s.save()28 return Response(UserInfoSerializer(instance=u).data, status.HTTP_201_CREATED)29 queryset = User.objects.all()30 serializer_class = UserInfoSerializer31 permission_classes = [permissions.AllowAny]32# ___________________________________________________________________________33# ________________________흥미 검사____________________________________________34# ___________________________________________________________________________35class MiddleInterestTestViewSet(APIView):36 def get(self, request, user_pk, *args, **kwargs):37 apiKey = '403f9bbdb00069287e869a9b302b406b'38 URL = 'http://inspct.career.go.kr/openapi/test/questions?apikey=' + apiKey + '&q=4'39 res = requests.get(URL)40 return HttpResponse(res, content_type='application/json')41class MiddleInterestAnswerViewSet(APIView):42 def post(self, request, user_pk, *args, **kwargs):43 user = User.objects.get(id=user_pk)44 answer = request.data45 apikey = "403f9bbdb00069287e869a9b302b406b"46 answer_dict = {47 "apikey": apikey,48 "qestrnSeq": "4",49 "trgetSe": "100206",50 "name": user.username,51 "gender": "100323",52 "school": "중학교",53 "grade": "2",54 "email": "",55 "startDtm": 1550466291034,56 "answers": answer['answer']57 }58 url = 'http://inspct.career.go.kr/openapi/test/report?apikey=' + apikey + '&qestrnSeq=4'59 api_res_url = requests.post(url=url, json=answer_dict).json()['RESULT']['url']60 api_res_dict = {61 'url': api_res_url62 }63 api_res = json.dumps(api_res_dict, ensure_ascii=False)64 test_history = TestHistory()65 test_history.user = user66 test_history.result = api_res_url67 test_history.save()68 return HttpResponse(api_res, content_type='application/json')69# ___________________________________________________________________________70class HighInterestTestViewSet(APIView):71 def get(self, request, user_pk, *args, **kwargs):72 apiKey = '403f9bbdb00069287e869a9b302b406b'73 URL = 'http://inspct.career.go.kr/openapi/test/questions?apikey=' + apiKey + '&q=5'74 res = requests.get(URL)75 return HttpResponse(res, content_type='application/json')76class HighInterestAnswerViewSet(APIView):77 def post(self, request, user_pk, *args, **kwargs):78 user = User.objects.get(id=user_pk)79 answer = request.data80 apikey = "403f9bbdb00069287e869a9b302b406b"81 answer_dict = {82 "apikey": apikey,83 "qestrnSeq": "5",84 "trgetSe": "100207",85 "name": user.username,86 "gender": "100323",87 "school": "고등학교",88 "grade": "2",89 "email": "",90 "startDtm": 1550466291034,91 "answers": answer['answer']92 }93 url = 'http://inspct.career.go.kr/openapi/test/report?apikey=' + apikey + '&qestrnSeq=5'94 api_res_url = requests.post(url=url, json=answer_dict).json()['RESULT']['url']95 api_res_dict = {96 'url': api_res_url97 }98 api_res = json.dumps(api_res_dict, ensure_ascii=False)99 test_history = TestHistory()100 test_history.user = user101 test_history.result = api_res_url102 test_history.save()103 return HttpResponse(api_res, content_type='application/json')104# ___________________________________________________________________________105# ________________________적성 검사____________________________________________106# ___________________________________________________________________________107class MiddleAptitudeTestViewSet(APIView):108 def get(self, request, user_pk, *args, **kwargs):109 apiKey = '403f9bbdb00069287e869a9b302b406b'110 URL = 'http://inspct.career.go.kr/openapi/test/questions?apikey=' + apiKey + '&q=20'111 res = requests.get(URL)112 return HttpResponse(res, content_type='application/json')113class MiddleAptitudeAnswerViewSet(APIView):114 def post(self, request, user_pk, *args, **kwargs):115 user = User.objects.get(id=user_pk)116 answer = request.data117 apikey = "403f9bbdb00069287e869a9b302b406b"118 answer_dict = {119 "apikey": apikey,120 "qestrnSeq": "20",121 "trgetSe": "100206",122 "name": user.username,123 "gender": "100323",124 "school": "중학교",125 "grade": "2",126 "email": "",127 "startDtm": 1550466291034,128 "answers": answer['answer']129 }130 url = 'http://inspct.career.go.kr/openapi/test/report?apikey=' + apikey + '&qestrnSeq=20'131 api_res_url = requests.post(url=url, json=answer_dict).json()['RESULT']['url']132 api_res_dict = {133 'url': api_res_url134 }135 api_res = json.dumps(api_res_dict, ensure_ascii=False)136 test_history = TestHistory()137 test_history.user = user138 test_history.result = api_res_url139 test_history.save()140 return HttpResponse(api_res, content_type='application/json')141# ___________________________________________________________________________142class HighAptitudeTestViewSet(APIView):143 def get(self, request, user_pk, *args, **kwargs):144 apiKey = '403f9bbdb00069287e869a9b302b406b'145 URL = 'http://inspct.career.go.kr/openapi/test/questions?apikey=' + apiKey + '&q=21'146 res = requests.get(URL)147 return HttpResponse(res, content_type='application/json')148class HighAptitudeAnswerViewSet(APIView):149 def post(self, request, user_pk, *args, **kwargs):150 user = User.objects.get(id=user_pk)151 answer = request.data152 apikey = "403f9bbdb00069287e869a9b302b406b"153 answer_dict = {154 "apikey": apikey,155 "qestrnSeq": "21",156 "trgetSe": "100207",157 "name": user.username,158 "gender": "100323",159 "school": "고등학교",160 "grade": "2",161 "email": "",162 "startDtm": 1550466291034,163 "answers": answer['answer']164 }165 url = 'http://inspct.career.go.kr/openapi/test/report?apikey=' + apikey + '&qestrnSeq=21'166 api_res_url = requests.post(url=url, json=answer_dict).json()['RESULT']['url']167 api_res_dict = {168 'url': api_res_url169 }170 api_res = json.dumps(api_res_dict, ensure_ascii=False)171 test_history = TestHistory()172 test_history.user = user173 test_history.result = api_res_url174 test_history.save()175 return HttpResponse(api_res, content_type='application/json')176# ----------------------------------------------------------177# ----------------직업가치관 검사-------------------------------178# ----------------------------------------------------------179class ValueTestViewSet(APIView):180 def get(self, request, user_pk, *args, **kwargs):181 apiKey = '403f9bbdb00069287e869a9b302b406b'182 URL = 'http://inspct.career.go.kr/openapi/test/questions?apikey=' + apiKey + '&q=6'183 res = requests.get(URL)184 return HttpResponse(res, content_type='application/json')185class ValueAnswerViewSet(APIView):186 def post(self, request, user_pk, *args, **kwargs):187 user = User.objects.get(id=user_pk)188 answer = request.data189 apikey = "403f9bbdb00069287e869a9b302b406b"190 answer_dict = {191 "apikey": apikey,192 "qestrnSeq": "6",193 "trgetSe": "100206",194 "name": user.username,195 "gender": "100323",196 "school": "",197 "grade": "2",198 "email": "",199 "startDtm": 1550466291034,200 "answers": answer['answer']201 }202 url = 'http://inspct.career.go.kr/openapi/test/report?apikey=' + apikey + '&qestrnSeq=6'203 api_res_url = requests.post(url=url, json=answer_dict).json()['RESULT']['url']204 api_res_dict = {205 'url': api_res_url206 }207 api_res = json.dumps(api_res_dict, ensure_ascii=False)208 test_history = TestHistory()209 test_history.user = user210 test_history.result = api_res_url211 test_history.save()212 return HttpResponse(api_res, content_type='application/json')213# ----------------------------------------------------------214# ----------------이공계전공적합도-------------------------------215# ----------------------------------------------------------216class SEAptitudeTestViewSet(APIView):217 def get(self, request, user_pk, *args, **kwargs):218 apiKey = '403f9bbdb00069287e869a9b302b406b'219 URL = 'http://inspct.career.go.kr/openapi/test/questions?apikey=' + apiKey + '&q=9'220 res = requests.get(URL)221 return HttpResponse(res, content_type='application/json')222class SEAptitudeAnswerViewSet(APIView):223 def post(self, request, user_pk, *args, **kwargs):224 user = User.objects.get(id=user_pk)225 answer = request.data226 apikey = "403f9bbdb00069287e869a9b302b406b"227 answer_dict = {228 "apikey": apikey,229 "qestrnSeq": "9",230 "trgetSe": "100206",231 "name": user.username,232 "gender": "100323",233 "school": "",234 "grade": "2",235 "email": "",236 "startDtm": 1550466291034,237 "answers": answer['answer']238 }239 url = 'http://inspct.career.go.kr/openapi/test/report?apikey=' + apikey + '&qestrnSeq=9'240 api_res_url = requests.post(url=url, json=answer_dict).json()['RESULT']['url']241 api_res_dict = {242 'url': api_res_url243 }244 api_res = json.dumps(api_res_dict, ensure_ascii=False)245 test_history = TestHistory()246 test_history.user = user247 test_history.result = api_res_url248 test_history.save()249 return HttpResponse(api_res, content_type='application/json')250# ----------------------------------------------------------251# ----------------유저 히스토리--------------------------------252# ----------------------------------------------------------253class UserHistoryViewSet(APIView):254 def get(self, request, user_pk, *args, **kwargs):255 user = User.objects.get(id=user_pk)256 test_history_list = user.history_user.all()257 test_history_url_list = []258 for i in range(len(test_history_list)):259 test_history_url_list.append(test_history_list[i].result)260 dict = {261 'answer': test_history_url_list262 }263 resJson = json.dumps(dict, ensure_ascii=False)264 return HttpResponse(resJson, content_type='application/json')265# ----------------------------------------------------------266# ----------------MBTI--------------------------------------267# ----------------------------------------------------------268class MBTISaveViewSet(APIView):269 def post(self, request, user_pk, *args, **kwargs):270 user = User.objects.get(id=user_pk)271 mbti = request.data['mbti']272 user.mbti = mbti273 u = user.save()274 return JsonResponse({275 "detail": "MBTI saved"276 })277class MBTIViewSet(APIView):278 def get(self, request, user_pk, *args, **kwargs):279 user = User.objects.get(id=user_pk)280 mbti = MBTI.objects.get(type=user.mbti)281 res_dict = {282 "mbti": user.mbti,283 "job": mbti.list284 }285 resJson = json.dumps(res_dict, ensure_ascii=False)286 return HttpResponse(resJson, content_type='application/json')287class UnivAptitudeTestViewSet(APIView):288 def get(self, request, user_pk, *args, **kwargs):...

Full Screen

Full Screen

test_stop_criteria.py

Source:test_stop_criteria.py Github

copy

Full Screen

1"""Module for unit testing of bbo's test criteria.2"""3import unittest4import numpy as np5from bbo.stop_criteria import ImprovementCriterion, \6 CountMovementCriterion, DistanceMovementCriterion7class TestStopCriteria(unittest.TestCase):8 """Class to test the stop criteria included with BBO.9 """10 def test_best_improvement_not_enough_iterations(self):11 """Tests that when there are not enough iterations, the12 the improvement stop criterion with min automatically evaluates13 to True.14 """15 test_history = {"fitness": [1, 2, 3]}16 stop_process = ImprovementCriterion(17 stop_window=4, improvement_threshold=0.5, improvement_estimator=min)18 self.assertTrue(stop_process.stop_rule(test_history, 2))19 def test_best_improvement_improvement(self):20 """Tests that when there is some improvement,21 the improvement stop criterion with min evaluates to True.22 """23 test_history = {"fitness": [5, 6, 3, 4, 1, 2, 3]}24 stop_process = ImprovementCriterion(25 stop_window=4, improvement_threshold=0.2, improvement_estimator=min26 )27 self.assertTrue(stop_process.stop_rule(test_history, 2))28 def test_best_improvement_no_improvement(self):29 """Tests that when there is no improvement,30 the improvement stop criterion with min evaluates to False.31 """32 test_history = {"fitness": [4, 3, 1, 6, 3, 4, 1, 2, 3]}33 stop_process = ImprovementCriterion(34 stop_window=4, improvement_threshold=0.2, improvement_estimator=min35 )36 self.assertFalse(stop_process.stop_rule(test_history, 2))37 def test_average_improvement_improvement(self):38 """Tests that when there is some improvement,39 the improvement stop criterion evaluates to True when used40 with the average estimator.41 """42 test_history = {"fitness": [4, 3, 5, 6, 3, 4, 1, 2, 3]}43 stop_process = ImprovementCriterion(44 stop_window=4, improvement_threshold=0.2, improvement_estimator=np.mean45 )46 self.assertTrue(stop_process.stop_rule(test_history, 2))47 def test_average_improvement_no_improvement(self):48 """Tests that when there is no improvement,49 the improvement stop criterion evaluates to False when used50 with the average estimator.51 """52 test_history = {"fitness": [4, 3, 1, 1, 3, 4, 1, 4, 8]}53 stop_process = ImprovementCriterion(54 stop_window=4, improvement_threshold=0.2, improvement_estimator=np.mean55 )56 self.assertFalse(stop_process.stop_rule(test_history, 2))57 def test_count_movement_not_enough_iterations(self):58 """Tests that when there are not enough iterations, the59 best_improvement stop criterion automatically evaluates60 to False.61 """62 test_history = {"parameters": [np.array([1, 2]),63 np.array([2, 3]),64 np.array([1, 2]),65 np.array([2, 3]),66 np.array([1, 2])]67 }68 stop_process = CountMovementCriterion(69 nbr_parametrizations=2, stop_window=4)70 self.assertTrue(stop_process.stop_rule(test_history, 2))71 def test_count_movement_stop(self):72 """Tests that the optimization process stops if there is no73 unique newly tested parametrization.74 """75 test_history = {"parameters": np.array([np.array([2, 3]),76 np.array([1, 2]),77 np.array([1, 2]),78 np.array([2, 3]),79 np.array([1, 2]),80 np.array([1, 2]),81 np.array([1, 2]),82 np.array([2, 3]),83 np.array([1, 2]),84 ])85 }86 stop_process = CountMovementCriterion(87 nbr_parametrizations=2, stop_window=4)88 self.assertFalse(stop_process.stop_rule(test_history, 2))89 def test_count_movement_no_stop(self):90 """Tests that the optimization process stops if there is enough91 unique newly tested parametrization.92 """93 test_history = {"parameters": np.array([94 np.array([2, 3]),95 np.array([1, 2]),96 np.array([1, 2]),97 np.array([2, 3]),98 np.array([1, 2]),99 np.array([1, 2]),100 np.array([1, 2]),101 np.array([2, 3]),102 np.array([4, 5]),103 ])104 }105 stop_process = CountMovementCriterion(106 nbr_parametrizations=2, stop_window=4)107 self.assertTrue(stop_process.stop_rule(test_history, 2))108 def test_distance_movement_not_enough_iterations(self):109 """Tests that when there are not enough iterations, the110 best_improvement stop criterion automatically evaluates111 to False.112 """113 test_history = {"parameters": [114 np.array([2, 3]),115 np.array([1, 2]),116 np.array([1, 2]),117 np.array([2, 3]),118 np.array([1, 2])]119 }120 stop_process = DistanceMovementCriterion(121 stop_window=4, distance=2)122 self.assertTrue(stop_process.stop_rule(test_history, 2))123 def test_distance_movement_no_stop(self):124 """Tests that the optimization process stops if there is enough125 unique newly tested parametrization.126 """127 test_history = {"parameters": np.array([128 np.array([2, 3]),129 np.array([1, 2]),130 np.array([1, 2]),131 np.array([2, 3]),132 np.array([1, 2]),133 np.array([1, 2]),134 np.array([1, 2]),135 np.array([2, 3]),136 np.array([4, 5]),137 ])138 }139 stop_process = DistanceMovementCriterion(140 stop_window=4, distance=2)141 self.assertTrue(stop_process.stop_rule(test_history, 2))142 def test_distance_movement_stop(self):143 """Tests that the optimization process stops if there is enough144 unique newly tested parametrization.145 """146 test_history = {"parameters": np.array([147 np.array([2, 3]),148 np.array([1, 2]),149 np.array([1, 2]),150 np.array([2, 3]),151 np.array([1, 2]),152 np.array([1, 2]),153 np.array([1, 2]),154 np.array([2, 3]),155 np.array([1, 2]),156 ])157 }158 stop_process = DistanceMovementCriterion(159 stop_window=4, distance=1)160 self.assertFalse(stop_process.stop_rule(test_history, 2))161if __name__ == "__main__":...

Full Screen

Full Screen

History.js

Source:History.js Github

copy

Full Screen

1import React, { Component } from 'react';2import classes from './History.module.css';3import axios from '../../axios';4import ReactPaginate from 'react-paginate'5import Auxiliary from '../../hoc/Auxiliary/Auxiliary';6import Button from '../../components/UI/Button/Button'7import * as ButtonClasses from '../../components/UI/Button/ButtonClasses';8import * as strings from '../../strings';9import * as history_col from '../../store/dbDetails/history';10import TestHistory from '../../components/HistorySub/TestHistory/TestHistory';11//Equivalent to BurgerBuilder of the Udemy project12class History extends Component {13 state = {14 history: [],15 perPage: 5,16 offset: 017 }18 handlePageClick = (e) => {19 const selectedPage = e.selected;20 const offset = selectedPage * this.state.perPage;21 this.setState({offset: offset})22 }23 render() {24 console.log(this.state.history);25 let history = this.state.history.slice(this.state.offset, this.state.offset+this.state.perPage).map(test_history => {26 //console.log(test_history.random);27 return (28 <TestHistory id={test_history.history_id} random={test_history.random} index={test_history.index_start} name={test_history.name}29 meaning={test_history.meaning} mnemonic={test_history.mnemonic} sentence={test_history.sentence}30 meaning_sc={test_history.meaning_sc} mnemonic_sc={test_history.mnemonic_sc} sentence_sc={test_history.sentence_sc}31 total={test_history.total}>32 </TestHistory>33 )34 })35 return (36 <Auxiliary>37 <ReactPaginate38 previousLabel={"prev"}39 nextLabel={"next"}40 breakLabel={"..."}41 breakClassName={"break-me"}42 pageCount={this.state.history.length/this.state.perPage}43 marginPagesDisplayed={2}44 pageRangeDisplayed={this.state.perPage}45 onPageChange={this.handlePageClick}46 containerClassName={classes.pagination}47 subContainerClassName={[classes.pagination, 'pages'].join(' ')}48 activeClassName={"active"}/>49 {history}50 </Auxiliary>51 );52 }53 componentDidMount() {54 axios.get('/history/tests')55 .then(result => {56 console.log(result);57 this.setState({58 history: result.data.history59 })60 })61 }62}...

Full Screen

Full Screen

test_http_history.py

Source:test_http_history.py Github

copy

Full Screen

1import unittest2from unittest.mock import Mock, patch3from src.fuzzingtool.objects.http_history import HttpHistory4from src.fuzzingtool.utils.http_utils import UrlParse5from ..mock_utils.response_mock import ResponseMock6class TestHttpHistory(unittest.TestCase):7 def test_http_history(self):8 test_response = ResponseMock()9 test_history = HttpHistory(10 response=test_response,11 rtt=3.012 )13 self.assertIsInstance(test_history.parsed_url, UrlParse)14 self.assertEqual(test_history.body_size, 25)15 self.assertEqual(test_history.response_time, 2.0)16 self.assertEqual(test_history.request_time, 1.0)17 self.assertEqual(test_history.ip, '')18 self.assertEqual(test_history.request, test_response.request)19 self.assertEqual(test_history.response, test_response)20 def test_http_history_with_ip(self):21 expected_ip = '127.0.0.1'22 test_history = HttpHistory(ResponseMock(), 3.0, expected_ip)23 self.assertEqual(test_history.ip, expected_ip)24 @patch("src.fuzzingtool.objects.http_history.build_raw_response_header")25 def test_headers(self, mock_build_raw_response_header: Mock):26 test_headers = (27 "HTTP/1.1 200 OK\r\n"28 "Server: nginx/1.19.0\r\n"29 "Date: Fri, 17 Dec 2021 17:42:14 GMT\r\n"30 "Content-Type: text/html; charset=UTF-8\r\n"31 "Transfer-Encoding: chunked\r\n"32 "Connection: keep-alive\r\n"33 "X-Powered-By: PHP/5.6.40-38+ubuntu20.04.1+deb.sury.org+1\r\n"34 "\r\n"35 )36 mock_build_raw_response_header.return_value = test_headers37 test_response = ResponseMock()38 test_history = HttpHistory(39 response=test_response,40 rtt=3.041 )42 self.assertEqual(test_history.raw_headers, test_headers)...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.runTest(test_url, function(err, data) {4 if (err) return console.log(err);5 var testId = data.data.testId;6 console.log('Test ID: ' + testId);7 wpt.testHistory(testId, function(err, data) {8 if (err) return console.log(err);9 console.log(data);10 });11});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3var data = {4};5wpt.runTest(data.url, data, function(err, data) {6 if (err) return console.log(err);7 wpt.testHistory(data.data.testId, function(err, data) {8 if (err) return console.log(err);9 console.log(data);10 });11});

Full Screen

Using AI Code Generation

copy

Full Screen

1var WPT = require('webpagetest');2var wpt = new WPT('www.webpagetest.org');3var url = process.argv[2];4var key = process.argv[3];5var location = process.argv[4];6var browser = process.argv[5];7var runs = process.argv[6];8var connectivity = process.argv[7];9var testid;10wpt.runTest(url, {11}, function(err, data) {12 if (err) {13 console.log(err);14 } else {15 testid = data.data.testId;16 console.log('Test ID: ' + testid);17 wpt.getTestResults(testid, function(err, data) {18 if (err) {19 console.log(err);20 } else {21 console.log('Test Results: ' + data);22 }23 });24 }25});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var client = wpt('API_KEY');3client.testHistory('www.google.com', '2016-01-01', '2016-02-01', function(err, data) {4 if(err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10var wpt = require('webpagetest');11var client = wpt('API_KEY');12client.testStatus('160201_5F_1b1c7b9f4d4c7e6e1a1f7e6c0b8d7c6d', function(err, data) {13 if(err) {14 console.log(err);15 } else {16 console.log(data);17 }18});19var wpt = require('webpagetest');20var client = wpt('API_KEY');21client.testResult('160201_5F_1b1c7b9f4d4c7e6e1a1f7e6c0b8d7c6d', function(err, data) {22 if(err) {23 console.log(err);24 } else {25 console.log(data);26 }27});

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful