How to use firstArg method in stryker-parent

Best JavaScript code snippet using stryker-parent

StatisticsModel.ts

Source:StatisticsModel.ts Github

copy

Full Screen

1import { IStatisticsDataService } from '../../data/statistics/IStatisticsDataService';2import { Statistics } from '../../data/statistics/Statistics';3import { States } from '../../common/States';4import { IObjectGroupsViewModel } from '../object_groups/IObjectGroupsViewModel';5import { IObjectsViewModel } from '../../models/objects/IObjectsViewModel';6import { IEventRulesViewModel } from '../../models/event_rules/IEventRulesViewModel';7import { IZonesViewModel } from '../../models/zones/IZonesViewModel';8import { ObjectGroup } from '../../data';9import { StatisticsParams } from '../../common/panels/statistics_filter/StatisticsParams';10import { IOrganizationService } from '../../services';11export class StatisticsModel {12 private _state: string;13 private selectIndex: number;14 private transaction: pip.services.Transaction;15 private groupIds: string[];16 private groups: ObjectGroup[];17 private prevRequest: any = null;18 public lastRequestDate: Date = null;19 public lastRequestType: string = null;20 private allStatistics: Statistics[];21 private DateTypes: any = {22 daily: 4,23 shift: 4,24 range: 4,25 weekly: 3,26 monthly: 3,27 yearly: 228 };29 private minuteNumber: any = {30 daily: 60,31 weekly: 1440,32 monthly: 1440,33 yearly: 4320034 };35 private _statistics: any | any[];36 constructor(37 private $log: ng.ILogService,38 private $location: ng.ILocationService,39 private $timeout: ng.ITimeoutService,40 private pipTransaction: pip.services.ITransactionService,41 private pipTranslate: pip.services.ITranslateService,42 private iqsOrganization: IOrganizationService,43 private iqsObjectGroupsViewModel: IObjectGroupsViewModel,44 private iqsObjectsViewModel: IObjectsViewModel,45 private iqsEventRulesViewModel: IEventRulesViewModel,46 private iqsZonesViewModel: IZonesViewModel,47 private iqsStatisticsData: IStatisticsDataService48 ) {49 "ngInject";50 this.transaction = pipTransaction.create('Statistics');51 }52 public get state() {53 return this._state;54 }55 public get selectedIndex() {56 return this.selectedIndex;57 }58 public set selectedIndex(index) {59 this.selectedIndex = index;60 }61 public getStatistics(firstArg: string, secondArg: string, thirdArg: string, forthArg: string, from_time: Date | string, to_time: Date | string, type: string, each: boolean = false, successCallback?) {62 if (this.isSameRequest(firstArg, secondArg, thirdArg, forthArg, from_time, to_time, type, each)) return;63 this._state = States.Progress;64 this.lastRequestDate = moment(from_time).toDate();65 this.lastRequestType = type;66 if (firstArg === 'states') {67 this.statesForSpecificDevice(from_time, to_time, type, secondArg, successCallback);68 return;69 }70 if (firstArg === 'incidents' && forthArg === 'all') {71 this.allEvents(from_time, to_time, type, firstArg, secondArg, thirdArg, true, each, successCallback);72 return;73 }74 if (firstArg === 'params' && secondArg === 'all' && thirdArg === 'all' && forthArg === 'all') {75 this.allParams(from_time, to_time, type, secondArg, thirdArg, firstArg, successCallback);76 return;77 }78 if (firstArg === 'events' && secondArg === 'all' && thirdArg === 'all' && forthArg === 'all') {79 this.allEvents(from_time, to_time, type, firstArg, 'all', thirdArg, false, each, successCallback);80 return;81 }82 // ----------------------------83 // for list84 // список объектов группы для зоны85 if (firstArg === 'presence' && secondArg !== 'all' && thirdArg !== 'all' && each) {86 this.specificZoneForAllObjectsOfGroup(from_time, to_time, type, secondArg, thirdArg, forthArg, firstArg, successCallback);87 return;88 }89 // список объектов и групп для зоні90 if (firstArg === 'presence' && secondArg === 'all' && thirdArg !== 'all' && each) {91 this.allObjects(from_time, to_time, type, firstArg, secondArg, thirdArg, successCallback);92 return;93 }94 if (firstArg === 'presence' && secondArg !== 'all' && thirdArg === 'all' && each) {95 this.allZones(from_time, to_time, type, firstArg, secondArg, thirdArg, each, successCallback);96 return;97 }98 // for chart 99 if (firstArg === 'presence' && secondArg === 'all' && thirdArg === 'all' && !each) {100 this.allZones(from_time, to_time, type, firstArg, secondArg, thirdArg, each, successCallback);101 return;102 }103 if (firstArg === 'presence' && secondArg !== 'all' && !each) {104 this.specificForSpecificObjectOrGroup(from_time, to_time, type, secondArg, thirdArg, forthArg, firstArg, successCallback);105 return;106 }107 if (firstArg === 'presence' && thirdArg !== 'all' && !each) {108 this.specificForSpecificObjectOrGroup(from_time, to_time, type, secondArg, thirdArg, forthArg, firstArg, successCallback);109 return;110 }111 // ----------------------------112 //113 if (StatisticsParams.all.indexOf(firstArg) != -1 && secondArg === 'all' && thirdArg === 'all' && each) {114 this.allObjects(from_time, to_time, type, firstArg, secondArg, 'all', successCallback);115 return;116 }117 if (StatisticsParams.all.indexOf(firstArg) != -1 && secondArg === 'all' && thirdArg === 'all' && !each) {118 this.allZones(from_time, to_time, type, firstArg, secondArg, thirdArg, each, successCallback);119 return;120 }121 //122 if (StatisticsParams.all.indexOf(firstArg) != -1 && secondArg === 'all' && thirdArg != 'all' && each) {123 this.allObjects(from_time, to_time, type, firstArg, secondArg, thirdArg, successCallback);124 return;125 }126 if (StatisticsParams.all.indexOf(firstArg) != -1 && secondArg === 'all' && thirdArg != 'all' && !each) {127 this.specificForSpecificZone(from_time, to_time, type, secondArg, thirdArg, forthArg, firstArg, successCallback);128 return;129 }130 //131 if (StatisticsParams.all.indexOf(firstArg) != -1 && secondArg !== 'all' && thirdArg === 'all' && !each) {132 // this.allZones(from_time, to_time, type, firstArg, secondArg, thirdArg, each, successCallback);133 this.specificForSpecificZone(from_time, to_time, type, secondArg, thirdArg, forthArg, firstArg, successCallback);134 return;135 }136 //137 if (StatisticsParams.all.indexOf(firstArg) != -1 && secondArg !== 'all' && thirdArg != 'all' && !each) {138 this.specificForSpecificZone(from_time, to_time, type, secondArg, thirdArg, forthArg, firstArg, successCallback);139 return;140 }141 //142 if (StatisticsParams.all.indexOf(firstArg) != -1 && secondArg !== 'all' && each) {143 this.specificZoneForAllObjectsOfGroup(from_time, to_time, type, secondArg, thirdArg, forthArg, firstArg, successCallback);144 }145 //146 if (secondArg === 'all' && thirdArg === 'all' && forthArg !== 'all') {147 this.specificForAll(from_time, to_time, type, secondArg, thirdArg, forthArg, firstArg, successCallback);148 return;149 }150 if (firstArg === 'params' && (secondArg !== 'all' || thirdArg !== 'all') && forthArg === 'all') {151 this.allParams(from_time, to_time, type, secondArg, thirdArg, firstArg, successCallback);152 return;153 }154 if (firstArg === 'events' && (secondArg !== 'all' || thirdArg !== 'all') && forthArg === 'all') {155 this.allEvents(from_time, to_time, type, firstArg, secondArg, thirdArg, false, each, successCallback);156 return;157 }158 if ((secondArg !== 'all' || thirdArg !== 'all') && forthArg !== 'all' && !each) {159 this.specificForAll(from_time, to_time, type, secondArg, thirdArg, forthArg, firstArg, successCallback);160 return;161 }162 if (firstArg === 'params' && (secondArg !== 'all' || thirdArg !== 'all') && forthArg !== 'all' && each) {163 this.specificParamForAllObjectsOfGroup(from_time, to_time, type, secondArg, thirdArg, forthArg, firstArg, successCallback);164 return;165 }166 if ((firstArg === 'events' || firstArg === 'incidents') && (secondArg !== 'all' || thirdArg !== 'all') && forthArg !== 'all' && each) {167 this.specificEventForAllObjectsOfGroup(from_time, to_time, type, secondArg, thirdArg, forthArg, 'events', successCallback);168 return;169 }170 }171 private isActualRequest(firstArg: string, secondArg: string, thirdArg: string, forthArg: string, from_time: Date | string, to_time: Date | string, type: string, each: boolean = false) {172 let isEqual = _.isEqual(this.prevRequest, {173 firstArg: firstArg,174 secondArg: secondArg,175 thirdArg: thirdArg,176 forthArg: forthArg,177 from_time: from_time,178 to_time: to_time,179 type: type,180 each: each181 });182 return isEqual;183 }184 private isSameRequest(firstArg: string, secondArg: string, thirdArg: string, forthArg: string, from_time: Date | string, to_time: Date | string, type: string, each: boolean = false) {185 let isEqual = _.isEqual(this.prevRequest, {186 firstArg: firstArg,187 secondArg: secondArg,188 thirdArg: thirdArg,189 forthArg: forthArg,190 from_time: from_time,191 to_time: to_time,192 type: type,193 each: each194 });195 if (isEqual) {196 return this.state == 'progress';197 } else {198 this.prevRequest = {199 firstArg: firstArg,200 secondArg: secondArg,201 thirdArg: thirdArg,202 forthArg: forthArg,203 from_time: from_time,204 to_time: to_time,205 type: type,206 each: each207 };208 return false;209 }210 }211 public prepareParamsStatisticsData(data, secondArg, thirdArg, forthArg, from_time, to_time, type, dateType, callback) {212 switch (type) {213 case 'offline': {214 let allMinutes = this.minuteNumber[dateType];215 _.each(data.values, (statValue) => {216 statValue.value = allMinutes - statValue.value;217 });218 if (callback) callback();219 break;220 }221 case 'speed': {222 this.iqsStatisticsData.readStatistics(this.prepareRequest('params', secondArg, thirdArg, 'online', from_time, to_time, dateType), (onlineData: Statistics[]) => {223 _.each(data.values, (statValue) => {224 statValue.value = this.getSameDateValue(statValue, onlineData.values);225 });226 if (callback) callback();227 })228 break;229 }230 default: {231 if (callback) callback();232 }233 }234 }235 public specificForAll(from_time: Date | string, to_time: Date | string, type: string, secondArg, thirdArg, forthArg: string, firstArg: string = 'params', successCallback) {236 this._statistics = {};237 this.iqsStatisticsData.readStatistics(this.prepareRequest(firstArg == 'incidents' ? 'events' : firstArg, secondArg, thirdArg, forthArg, from_time, to_time, type), (data: Statistics[]) => {238 if (this.isActualRequest(firstArg, secondArg, thirdArg, forthArg, from_time, to_time, type, false)) {239 this._statistics = data;240 if (firstArg === 'params') {241 this.prepareParamsStatisticsData(this._statistics, secondArg, thirdArg, forthArg, from_time, to_time, forthArg, type, () => {242 this.specificDataCallback(firstArg, forthArg, type, from_time, to_time);243 if (successCallback) successCallback(this._statistics);244 })245 } else {246 this.specificDataCallback(firstArg, forthArg, type, from_time, to_time);247 if (successCallback) successCallback(this._statistics);248 }249 }250 });251 }252 private statesForSpecificDevice(from_time: Date | string, to_time: Date | string, type: string, secondArg: string, successCallback) {253 this._statistics = {};254 let fisrtArgs = ['state_updates', 'state_errors'];255 let colors = {256 state_updates: '#42A5F5',257 state_errors: '#EF5350'258 };259 async.each(fisrtArgs, (arg, callback) => {260 this.iqsStatisticsData.readStatistics(this.prepareRequest(arg, secondArg, null, null, from_time, to_time, type), (data: Statistics[]) => {261 if (this.isActualRequest('states', secondArg, null, null, from_time, to_time, type, false)) {262 this._statistics[arg] = data;263 this.prepareSeries(this._statistics[arg], type, from_time, to_time);264 }265 callback();266 })267 }, (error) => {268 if (!error) {269 if (this.isActualRequest('states', secondArg, null, null, from_time, to_time, type, false)) {270 this._statistics.series = [];271 for (let prop in this._statistics) {272 if (prop === 'series') continue;273 this._statistics.series.push({274 key: this.pipTranslate.translate('STATISTICS_' + prop.toUpperCase()),275 values: this._statistics[prop].filledValues,276 color: colors[prop]277 });278 }279 if (successCallback) successCallback(this._statistics);280 this._state = States.Data;281 }282 }283 });284 }285 private specificDataCallback(firstArg, forthArg, type, from_time, to_time) {286 this.prepareSeries(this._statistics, type, from_time, to_time);287 this._statistics.series = [{288 key: this.getSeriaName(forthArg, firstArg),289 values: this._statistics.filledValues290 }];291 this._state = States.Data;292 }293 private getSeriaName(name, type) {294 switch (type) {295 case 'params':296 return this.pipTranslate.translate('FILTER_PARAMS_' + name.toUpperCase());297 default:298 return '';299 }300 }301 public specificForSpecificObjectOrGroup(from_time: Date | string, to_time: Date | string, type: string, id: string, thirdArg: string, forthArg: string, firstArg: string = 'params', successCallback) {302 this._statistics = {};303 this.iqsStatisticsData.readStatistics(this.prepareRequest(firstArg == 'incidents' ? 'events' : firstArg, id, thirdArg, forthArg === 'offline' ? 'online' : forthArg, from_time, to_time, type),304 (data: Statistics[]) => {305 if (this.isActualRequest(firstArg, id, thirdArg, forthArg, from_time, to_time, type, false)) {306 this._statistics = data;307 if (firstArg === 'params') {308 this.prepareParamsStatisticsData(this._statistics, id, thirdArg, forthArg, from_time, to_time, forthArg, type, () => {309 this.specificDataCallback(firstArg, forthArg, type, from_time, to_time);310 if (successCallback) successCallback(this._statistics);311 })312 } else {313 this.specificDataCallback(firstArg, forthArg, type, from_time, to_time);314 if (successCallback) successCallback(this._statistics);315 }316 }317 });318 }319 public specificForSpecificZone(from_time: Date | string, to_time: Date | string, type: string, secondArg: string, id: string, forthArg: string, firstArg: string = 'params', successCallback) {320 this._statistics = {};321 let fArg = StatisticsParams.all.indexOf(firstArg) != -1 ? 'params' : firstArg == 'incidents' ? 'events' : firstArg;322 this.iqsStatisticsData.readStatistics(this.prepareRequest(fArg, secondArg, id, forthArg === 'offline' ? 'online' : forthArg, from_time, to_time, type),323 (data: Statistics[]) => {324 if (this.isActualRequest(firstArg, secondArg, id, forthArg, from_time, to_time, type, false)) {325 this._statistics = data;326 if (firstArg === 'params' || fArg === 'params') {327 this.prepareParamsStatisticsData(this._statistics, secondArg, id, forthArg, from_time, to_time, forthArg, type, () => {328 this.specificDataCallback(firstArg, forthArg, type, from_time, to_time);329 if (successCallback) successCallback(this._statistics);330 })331 } else {332 this.specificDataCallback(firstArg, forthArg, type, from_time, to_time);333 if (successCallback) successCallback(this._statistics);334 }335 }336 });337 }338 public specificParamForAllObjectsOfGroup(from_time: Date | string, to_time: Date | string, type: string, id: string, thirdArg: string, forthArg: string, firstArg: string = 'params', successCallback) {339 let group = this.iqsObjectGroupsViewModel.getGroupById(id);340 if (!group) {341 this._state = States.Empty;342 return;343 }344 this._statistics = {};345 async.each(group.object_ids, (object_id, callback) => {346 this.iqsStatisticsData.readStatistics(this.prepareRequest(firstArg === 'incidents' ? 'events' : firstArg, object_id, thirdArg, forthArg === 'offline' ? 'online' : forthArg, from_time, to_time, type),347 (data: Statistics[]) => {348 if (this.isActualRequest(firstArg, id, thirdArg, forthArg, from_time, to_time, type, true)) {349 this._statistics[object_id] = data;350 if (forthArg === 'speed') {351 this.iqsStatisticsData.readStatistics(this.prepareRequest(firstArg, object_id, thirdArg, 'online', from_time, to_time, type), (onlineData) => {352 this._statistics[object_id].value = this.getSum(data.values, true, onlineData.values);353 callback();354 });355 } else {356 if (forthArg === 'offline') {357 let diff = (moment(to_time).valueOf() - moment(from_time).valueOf()) / 1000;358 this._statistics[object_id].value = diff - this.getSum(data.values, false, null);359 } else {360 this._statistics[object_id].value = this.getSum(data.values, false, null);361 }362 callback();363 }364 } else {365 callback();366 }367 });368 }, (error) => {369 if (!error) {370 if (this.isActualRequest(firstArg, id, thirdArg, forthArg, from_time, to_time, type, true)) {371 this._state = States.Data;372 this._statistics.series = [];373 for (let prop in this._statistics) {374 let object = this.iqsObjectsViewModel.getObjectById(prop);375 if (object) {376 this._statistics.series.push({377 key: object.name,378 value: this._statistics[prop].value,379 display: this.prepareDisplayValue(this._statistics[prop], thirdArg)380 });381 }382 }383 if (successCallback) successCallback(this._statistics);384 }385 }386 });387 }388 public specificEventForAllObjectsOfGroup(from_time: Date | string, to_time: Date | string, type: string, id: string, thirdArg: string, forthArg: string, firstArg: string = 'params', successCallback) {389 let group = this.iqsObjectGroupsViewModel.getGroupById(id);390 if (!group) {391 this._state = States.Empty;392 return;393 }394 this._statistics = {};395 async.each(group.object_ids, (object_id, callback) => {396 this.iqsStatisticsData.readStatistics(this.prepareRequest(firstArg, object_id, thirdArg, forthArg, from_time, to_time, type),397 (data: Statistics[]) => {398 if (this.isActualRequest(firstArg, id, thirdArg, forthArg, from_time, to_time, type, true)) {399 this._statistics[object_id] = data;400 if (forthArg === 'speed') {401 this.iqsStatisticsData.readStatistics(this.prepareRequest(firstArg, object_id, thirdArg, 'online', from_time, to_time, type), (onlineData) => {402 this._statistics[object_id].value = this.getSum(data.values, true, onlineData.values);403 callback();404 });405 } else {406 this._statistics[object_id].value = this.getSum(data.values, false, null);407 callback();408 }409 } else {410 callback();411 }412 });413 }, (error) => {414 if (!error) {415 if (this.isActualRequest(firstArg, id, thirdArg, forthArg, from_time, to_time, type, true)) {416 this._state = States.Data;417 this._statistics.series = [];418 for (let prop in this._statistics) {419 let object = this.iqsObjectsViewModel.getObjectById(prop);420 if (object) {421 this._statistics.series.push({422 key: object.name,423 value: this._statistics[prop].value424 });425 }426 }427 if (successCallback) successCallback(this._statistics);428 }429 }430 });431 }432 public specificZoneForAllObjectsOfGroup(from_time: Date | string, to_time: Date | string, type: string, id: string, thirdArg: string, forthArg: string, firstArg: string = 'params', successCallback) {433 let group = this.iqsObjectGroupsViewModel.getGroupById(id);434 if (!group) {435 this._state = States.Empty;436 return;437 }438 this._statistics = {};439 let displayFormat = StatisticsParams.all.indexOf(firstArg) != -1 && firstArg != 'presence' ? firstArg : 'online';440 let fArg = StatisticsParams.all.indexOf(firstArg) != -1 ? 'params' : firstArg == 'incidents' ? 'events' : firstArg;441 async.each(group.object_ids, (object_id, callback) => {442 this.iqsStatisticsData.readStatistics(this.prepareRequest(fArg, object_id, thirdArg, forthArg, from_time, to_time, type),443 (data: Statistics[]) => {444 if (this.isActualRequest(firstArg, id, thirdArg, forthArg, from_time, to_time, type, true)) {445 this._statistics[object_id] = data;446 if (forthArg === 'speed') {447 this.iqsStatisticsData.readStatistics(this.prepareRequest(firstArg, object_id, thirdArg, 'online', from_time, to_time, type), (onlineData) => {448 this._statistics[object_id].value = this.getSum(data.values, true, onlineData.values);449 callback();450 });451 } else {452 this._statistics[object_id].value = this.getSum(data.values, false, null);453 callback();454 }455 } else {456 callback();457 }458 });459 }, (error) => {460 if (!error) {461 if (this.isActualRequest(firstArg, id, thirdArg, forthArg, from_time, to_time, type, true)) {462 this._state = States.Data;463 this._statistics.series = [];464 for (let prop in this._statistics) {465 let object = this.iqsObjectsViewModel.getObjectById(prop);466 if (object) {467 this._statistics.series.push({468 key: object.name,469 value: this._statistics[prop].value,470 // display: this.prepareDisplayValue(this._statistics[prop], 'online')471 display: this.prepareDisplayValue(this._statistics[prop], displayFormat)472 });473 }474 }475 if (successCallback) successCallback(this._statistics);476 }477 }478 });479 }480 private prepareSeries(data, type: string, from_time: Date | string, to_time: Date | string) {481 switch (type) {482 case 'yearly': {483 data.filledValues = new Array(13);484 _.each(data.values, (statValue) => {485 data.filledValues.splice(statValue.month, 1, statValue);486 });487 _.each(data.filledValues, (statValue, index: number) => {488 statValue = statValue || {};489 statValue.x = statValue.month ? statValue.month : index;490 statValue.value = statValue.value || 0;491 if (index !== 0) data.filledValues.splice(index, 1, statValue);492 });493 data.filledValues.splice(0, 1);494 break;495 }496 case 'daily': {497 data.filledValues = new Array(24);498 _.each(data.values, (statValue) => {499 data.filledValues.splice(statValue.hour, 1, statValue);500 });501 _.each(data.filledValues, (statValue, index) => {502 statValue = statValue || {};503 statValue.x = statValue.hour || index;504 statValue.value = statValue.value || 0;505 data.filledValues.splice(index, 1, statValue);506 });507 break;508 }509 case 'monthly': {510 data.filledValues = new Array(moment(from_time).daysInMonth() + 1);511 _.each(data.values, (statValue) => {512 data.filledValues.splice(statValue.day, 1, statValue);513 });514 _.each(data.filledValues, (statValue, index: number) => {515 statValue = statValue === undefined ? {} : statValue;516 statValue.x = statValue.day || index;517 statValue.value = statValue.value || 0;518 if (index !== 0) data.filledValues.splice(index, 1, statValue);519 });520 data.filledValues.splice(0, 1);521 break;522 }523 case 'weekly': {524 data.filledValues = new Array(7);525 _.each(data.values, (statValue) => {526 let date = new Date(statValue.year, statValue.month - 1, statValue.day);527 let diff = Math.round((date.getTime() - moment(from_time).valueOf()) / (1000 * 60 * 60 * 24));528 statValue.x = diff;529 data.filledValues.splice(diff, 1, statValue);530 });531 _.each(data.filledValues, (statValue, index) => {532 statValue = statValue || {};533 statValue.x = statValue.x || index;534 statValue.value = statValue.value || 0;535 data.filledValues.splice(index, 1, statValue);536 });537 break;538 }539 default: { // shift and range540 let count = (moment(to_time).valueOf() - moment(from_time).valueOf()) / (1000 * 60 * 60);541 let multiplier = 4;542 let curDate = moment(from_time).toDate();543 data.filledValues = new Array(Math.round(count) + 1);544 _.each(data.filledValues, (statValue, index) => {545 let value = _.find(data.values, (v: any) => {546 return v.day == curDate.getDate() && v.hour == curDate.getHours();547 });548 let xHour = value ? value.hour : curDate.getHours();549 let l = String(xHour).length == 1;550 statValue = value || {};551 statValue.x = curDate.getTime();552 statValue.value = value ? value.value : 0;553 data.filledValues.splice(index, 1, statValue);554 curDate.setHours(curDate.getHours() + 1);555 });556 }557 }558 }559 private prepareValue(value, type) {560 if (value === 0) return 0;561 switch (type) {562 case 'online': {563 return value / 1000;564 }565 case 'offline': {566 return value / 1000;567 }568 case 'distance': {569 return value / 1000;570 }571 case 'freezed': {572 return value / 3600;573 }574 case 'immobile': {575 return value / 3600;576 }577 case 'speed': {578 return typeof value === 'number' ? value : new Number(value);579 }580 default: {581 return typeof value === 'number' ? value : new Number(value);582 }583 }584 }585 public allParams(from_time: Date | string, to_time: Date | string, type: string, id: string, thirdArg: string, firstArg: string = 'params', successCallback) {586 let fortArgs = _.without(StatisticsParams.all, 'online');587 this._statistics = {};588 this.iqsStatisticsData.readStatistics(this.prepareRequest(firstArg, id, thirdArg, 'online', from_time, to_time, type), (data: Statistics[]) => {589 this._statistics['online'] = data;590 this._statistics['online'].value = this.getSum(data.values, false, null);591 this.prepareDisplayValue(this._statistics['online'], 'online');592 async.each(fortArgs, (arg, callback) => {593 this.iqsStatisticsData.readStatistics(this.prepareRequest(firstArg, id, thirdArg, arg, from_time, to_time, type), (data: Statistics[]) => {594 if (this.isActualRequest(firstArg, id, thirdArg, 'all', from_time, to_time, type, false)) {595 this._statistics[arg] = data;596 this._statistics[arg].value = arg === 'speed' ? this.getSum(data.values, true, this._statistics['online'].values) : this.getSum(data.values, false, null);597 if (arg === 'offline') {598 let diff = (moment(to_time).valueOf() - moment(from_time).valueOf()) / 1000;599 this._statistics[arg].value = diff - this._statistics['online'].value;600 }601 this.prepareDisplayValue(this._statistics[arg], arg);602 }603 callback();604 });605 }, (error) => {606 if (!error) {607 this._state = States.Data;608 if (successCallback) successCallback(this._statistics);609 }610 });611 });612 }613 public allEvents(from_time: Date | string, to_time: Date | string, type: string, firstArg: string = 'events', id: string = 'all', thirdArg: string, isIncidents: boolean = false, each: boolean = false, successCallback) {614 let forthArgs = this.iqsEventRulesViewModel.getCollection();615 if (isIncidents) forthArgs = _.filter(forthArgs, (event) => { return event.incident; });616 this._statistics = { series: [] };617 async.each(forthArgs, (arg, callback) => {618 this.iqsStatisticsData.readStatistics(this.prepareRequest('events', id, thirdArg, arg.id, from_time, to_time, type), (data: Statistics[]) => {619 if (this.isActualRequest(firstArg, id, thirdArg, 'all', from_time, to_time, type, each)) {620 this._statistics[arg.id] = data;621 this._statistics[arg.id].value = this.getSum(data.values, false, null);622 this._statistics.series.push({623 key: arg.name,624 value: this._statistics[arg.id].value625 });626 }627 callback();628 });629 }, (error) => {630 if (!error) {631 this._state = States.Data;632 if (successCallback) successCallback(this._statistics);633 }634 });635 }636 public allZones(from_time: Date | string, to_time: Date | string, type: string, firstArg: string = 'params', id: string = 'all', thirdArg: string, each: boolean, successCallback) {637 let thirdArgs = this.iqsZonesViewModel.zones;638 this._statistics = { series: [] };639 async.each(thirdArgs, (arg, callback) => {640 let tArg = firstArg == 'presence' || StatisticsParams.all.indexOf(firstArg) != -1 ? arg.id : thirdArg;641 let fArg = firstArg == 'presence' || StatisticsParams.all.indexOf(firstArg) != -1 ? null : arg.id;642 let displayFormat = StatisticsParams.all.indexOf(firstArg) != -1 && firstArg != 'presence' ? firstArg : 'online';643 let fActualArg = StatisticsParams.all.indexOf(firstArg) != -1 ? firstArg : 'all';644 this.iqsStatisticsData.readStatistics(this.prepareRequest(firstArg, id, tArg, fArg, from_time, to_time, type),645 (data: Statistics[]) => {646 if (this.isActualRequest(firstArg, id, 'all', fActualArg, from_time, to_time, type, each)) {647 this._statistics[arg.id] = data;648 if (firstArg === 'speed') {649 this.iqsStatisticsData.readStatistics(this.prepareRequest(firstArg, id, tArg, 'online', from_time, to_time, type), (onlineData) => {650 this._statistics[arg.id].value = this.getSum(data.values, true, onlineData.values);651 this._statistics.series.push({652 key: arg.name,653 value: this._statistics[arg.id].value,654 display: this.prepareDisplayValue(this._statistics[arg.id], displayFormat)655 });656 callback();657 });658 } else {659 this._statistics[arg.id].value = this.getSum(data.values, false, null);660 this._statistics.series.push({661 key: arg.name,662 value: this._statistics[arg.id].value,663 display: this.prepareDisplayValue(this._statistics[arg.id], displayFormat)664 });665 callback();666 }667 } else {668 callback();669 }670 });671 }, (error) => {672 if (!error) {673 this._state = States.Data;674 if (successCallback) successCallback(this._statistics);675 }676 });677 }678 public allObjects(from_time: Date | string, to_time: Date | string, type: string, firstArg: string = 'params', secondArg: string, id: string = 'all', successCallback) {679 let thirdArgs = [];680 _.each(this.iqsObjectGroupsViewModel.getCollection(), (item) => {681 thirdArgs.push(item);682 });683 _.each(this.iqsObjectsViewModel.allObjects, (item) => {684 thirdArgs.push(item);685 });686 this._statistics = { series: [] };687 async.each(thirdArgs, (arg, callback) => {688 let fArg = StatisticsParams.all.indexOf(firstArg) != -1 || firstArg == 'presence' ? arg.id : secondArg;689 let tArg = StatisticsParams.all.indexOf(firstArg) != -1 ? null : arg.id;690 let displayFormat = StatisticsParams.all.indexOf(firstArg) != -1 && firstArg != 'presence' ? firstArg : 'online';691 let evArg = firstArg != 'presence' ? firstArg : 'all';692 this.iqsStatisticsData.readStatistics(this.prepareRequest(firstArg, fArg, id, tArg, from_time, to_time, type),693 (data: Statistics[]) => {694 if (this.isActualRequest(firstArg, 'all', id, evArg, from_time, to_time, type, true)) {695 this._statistics[arg.id] = data;696 if (firstArg === 'speed') {697 this.iqsStatisticsData.readStatistics(this.prepareRequest(firstArg, fArg, id, 'online', from_time, to_time, type), (onlineData) => {698 this._statistics[arg.id].value = this.getSum(data.values, true, onlineData.values);699 this._statistics.series.push({700 key: arg.name,701 value: this._statistics[arg.id].value,702 display: this.prepareDisplayValue(this._statistics[arg.id], displayFormat)703 });704 callback();705 });706 } else {707 this._statistics[arg.id].value = this.getSum(data.values, false, null);708 this._statistics.series.push({709 key: arg.name,710 value: this._statistics[arg.id].value,711 display: this.prepareDisplayValue(this._statistics[arg.id], displayFormat)712 });713 callback();714 }715 } else {716 callback();717 }718 });719 }, (error) => {720 if (!error) {721 this._state = States.Data;722 if (successCallback) successCallback(this._statistics);723 }724 });725 }726 private prepareRequest(firstArg: string, secondArg: string, thirdArg: string, forthArg: string, from_time: Date | string, to_time: Date | string, type: string) {727 let name = null;728 if (firstArg == 'presence') name = firstArg + '.' + secondArg + (thirdArg === null ? '' : ('.' + thirdArg))729 else if (StatisticsParams.all.indexOf(firstArg) != -1) {730 name = 'params' + '.' + secondArg + (thirdArg === null ? '' : ('.' + thirdArg)) + (forthArg === null ? ('.' + firstArg) : ('.' + forthArg));731 } else name = firstArg + '.' + secondArg + (thirdArg === null ? '' : ('.' + thirdArg)) + (forthArg === null ? '' : ('.' + forthArg));732 let from = typeof from_time === 'string' ? from_time : from_time.toISOString();733 let to = typeof to_time === 'string' ? to_time : to_time.toISOString();734 let t = this.DateTypes[type];735 let er = new Error();736 return { name: name, from_time: from, to_time: to, type: t };737 }738 private getSameDateValue(value, values) {739 let index = _.findIndex(values, (val: any) => {740 return value.year === val.year && value.month === val.month && value.day === val.day && value.hour === val.hour;741 });742 return index > -1 ? (values[index].value > 0 ? value.value / values[index].value : 0) : 0;743 }744 private getSum(values, average = false, dividerValues) {745 let sum = 0;746 let result = null;747 let count: number = 0;748 _.each(values, (v) => {749 let value = v.value;750 if (dividerValues && _.isArray(dividerValues)) {751 value = this.getSameDateValue(v, dividerValues);752 }753 sum += value;754 if (value) count += 1;755 });756 result = average && count > 0 ? sum / count : sum;757 return result;758 }759 public get statistics() {760 return this._statistics;761 }762 private prepareDisplayValue(data, name) {763 switch (name) {764 case 'speed': {765 data.display = data.value ? this.prepareValue(data.value, name).toFixed(0) : 0;766 break;767 }768 case 'distance': {769 data.display = data.value ? this.prepareValue(data.value, name).toFixed(2) : 0;770 break;771 }772 default: {773 if (!data.value) {774 data.display = {775 hours: 0,776 minutes: 0,777 seconds: 0778 };779 } else {780 let h: number = Math.floor(data.value / 3600);781 data.display = {782 hours: h,783 minutes: ((data.value / 60) % 60).toFixed(0),784 seconds: ((data.value) % 60).toFixed(0)785 };786 }787 }788 }789 return data.display;790 }791 public formatDisplayData(value, name) {792 let display = this.prepareDisplayValue({ value: value }, name);793 switch (name) {794 case 'speed': {795 return display + ' ' + this.pipTranslate.translate('KM_IN_H');796 }797 case 'distance': {798 return display + ' ' + this.pipTranslate.translate('KM');799 }800 default: {801 let h: number = Math.floor(value / 3600);802 let m: number = value - h * 3600 > 0 ? Math.floor((value - h * 3600) / 60) : 0;803 let s: number = value - h * 3600 - m * 60 > 1 ? Math.floor((value - h * 3600 - m * 60)) : 0;804 return (h > 0 ? (("0" + h).substr(-2, 2) + ':') : '00:')805 + (m > 0 ? ("0" + m).substr(-2, 2) : '00');806 }807 }808 }809 private changeDateTypeForAllParamsRequest(type) {810 switch (type) {811 case 'daily': {812 return 'weekly';813 }814 case 'monthly': {815 return 'yearly';816 }817 default: {818 return type;819 }820 }821 }...

Full Screen

Full Screen

REPLHandler.js

Source:REPLHandler.js Github

copy

Full Screen

1'use strict';2const print = require('./print')3const { errorMessage, fatalErrorMessage } = require('../utils/messages');4const { fileReader } = require('../utils/fileReader')5const { lex, testParser, failed, reset, help, env } = require('./commands')6const { process } = require('../../vm')7const isLexCommand = firstArg => firstArg === '.lex';8const isTestParserCommand = firstArg => firstArg === '.ast';9const isLoadCommand = firstArg => firstArg === '.load';10const isFailedCommand = firstArg => firstArg === '.failed';11const isResetCommand = firstArg => firstArg === '.reset';12const isHelpCommand = firstArg => firstArg === '.help';13const isExitCommand = firstArg => firstArg === '.';14const isEnvCommand = firstArg => firstArg === '.env';15const getArgs = (input) => {16 const formatedArgs = input.replace(/\s+/g, ' ').trim()17 return formatedArgs.split(' ');18}19const getFirstArg = (input) => input.shift();20const validateSpecialCall = (input) => input && input[0] === '.';21const printError = ({ input, error, fileInfo }) => input ? errorMessage({ input, error, fileInfo }) : null;22const executeLine = fileName => (data, line) => {23 if (!data) return24 const result = REPLHandler(data, { fileName, line });25 if (result === 'break') process.exit(0);26}27/**28 * @param {Object} options 29 * @param {String} options.firstArg 30 * @param {Array<String>} options.args31 * @param {String} options.input32 * @param {[Object]} options.fileInfo33 * @returns 34 */35const evalSpecialCall = ({ firstArg, args, input, fileInfo }) => {36 if (isExitCommand(firstArg)) {37 return 'break';38 } else if (isLexCommand(firstArg)) {39 lex({ args, fileInfo })40 return;41 } else if (isEnvCommand(firstArg)) {42 env()43 return;44 } else if (isTestParserCommand(firstArg)) {45 testParser({ args, fileInfo })46 return;47 } else if (isFailedCommand(firstArg)) {48 failed({ input, fileInfo })49 return;50 } else if (isResetCommand(firstArg)) {51 reset({ input, fileInfo })52 return;53 } else if (isHelpCommand(firstArg)) {54 help();55 return;56 } else if (isLoadCommand(firstArg)) {57 const fileName = args[0];58 const fileContent = fileReader(fileName);59 if (fileContent) {60 fileContent.lines.forEach(executeLine(fileName));61 } else {62 const error = `Error loading file: ${args.join(' ')}`63 printError({ input, error })64 }65 return;66 } else {67 printError({ input, fileInfo })68 return;69 }70}71/**72 * Root Handler for the REPL73 * @param {[Object]} fileInfo74 * @param {[Object]} fileInfo.fileName75 * @param {[Object]} fileInfo.line76 * @param {String} input77 */78const REPLHandler = (input, fileInfo) => {79 try {80 const args = getArgs(input);81 if (validateSpecialCall(input)) {82 const firstArg = getFirstArg(args);83 return evalSpecialCall({ firstArg, args, input, fileInfo })84 } else {85 const response = process(args)86 print(input, response, fileInfo)87 return;88 }89 } catch (error) {90 return fatalErrorMessage({error: error.message, fileInfo, input})91 }92};93module.exports = {94 REPLHandler...

Full Screen

Full Screen

vector.js

Source:vector.js Github

copy

Full Screen

1var Vector = function (components) {2 this.components = components3 result4 5 };6 Vector.prototype.add = function(arr) {7 let result = []8 let firstArg = this.components9 let secondArg = arr.components10 if (secondArg.length != firstArg.length) throw 'error'11 else {12 for (let i=0; i<firstArg.length; i++) {13 result.push(firstArg[i]+secondArg[i])14 }15 }16 this.result = result17 return this18 }19 Vector.prototype.subtract = function(arr) {20 let result = []21 let firstArg = this.components22 let secondArg = arr.components23 if (secondArg.length != firstArg.length) throw 'error'24 else {25 for (let i=0; i<firstArg.length; i++) {26 result.push(firstArg[i]-secondArg[i])27 }28 }29 this.result = result30 return this31 }32 Vector.prototype.dot = function(arr) {33 let result = 034 let firstArg = this.components35 let secondArg = arr.components36 if (secondArg.length != firstArg.length) throw 'error'37 else {38 for (let i=0; i<firstArg.length; i++) {39 result += firstArg[i]*secondArg[i]40 }41 }42 return result43 }44 Vector.prototype.equals = function(arg) {45 let flag = true46 let result = this.result47 arg2 = arg.components48 if (arg2.length != result.length) return false49 for (let i=0; i<result.length; i++) {50 if (arg2[i] != result[i]) flag = false51 }52 return flag53 }54 Vector.prototype.norm = function() {55 let result = 056 let firstArg = this.components57 for (let i=0; i<firstArg.length; i++) {58 result += firstArg[i]**259 }60 return result61 }62var a = new Vector([1, 2]);63var b = new Vector([3, 4]);64var c = new Vector([5, 6, 7, 8]);65console.log(a.add(b).equals(new Vector([4,6])))66// a.add(b); // should return a new Vector([4, 6, 8])67// a.subtract(b); // should return a new Vector([-2, -2, -2])68// a.dot(b); // should return 1*3 + 2*4 + 3*5 = 2669// a.norm(); // should return sqrt(1^2 + 2^2 + 3^2) = sqrt(14)...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const firstArg = require('stryker-parent').firstArg;2const secondArg = require('stryker-parent').secondArg;3const thirdArg = require('stryker-parent').thirdArg;4const fourthArg = require('stryker-parent').fourthArg;5const childFirstArg = require('stryker-child').firstArg;6const childSecondArg = require('stryker-child').secondArg;7const childThirdArg = require('stryker-child').thirdArg;8const childFourthArg = require('stryker-child').fourthArg;9const childFirstArg = require('stryker-child').firstArg;10const childSecondArg = require('stryker-child').secondArg;11const childThirdArg = require('stryker-child').thirdArg;12const childFourthArg = require('stryker-child').fourthArg;13const childFirstArg = require('stryker-child').firstArg;14const childSecondArg = require('stryker-child').secondArg;15const childThirdArg = require('stryker-child').thirdArg;16const childFourthArg = require('stryker-child').fourthArg;17const childFirstArg = require('stryker-child').firstArg;18const childSecondArg = require('stryker-child').secondArg;19const childThirdArg = require('stryker-child').thirdArg;20const childFourthArg = require('stryker-child').fourthArg;21const childFirstArg = require('stryker-child').firstArg;22const childSecondArg = require('stryker-child').secondArg;23const childThirdArg = require('stryker-child').thirdArg;24const childFourthArg = require('stryker-child').fourthArg;25const childFirstArg = require('stryker-child').firstArg;26const childSecondArg = require('stryker-child').secondArg;27const childThirdArg = require('stryker-child').thirdArg;28const childFourthArg = require('stryker-child').fourthArg;29const childFirstArg = require('stryker-child').firstArg

Full Screen

Using AI Code Generation

copy

Full Screen

1const firstArg = require('stryker-parent').firstArg;2firstArg('foo', 'bar');3const secondArg = require('stryker-parent').secondArg;4secondArg('foo', 'bar');5const strykerParent = require('stryker-parent');6strykerParent.firstArg('foo', 'bar');7strykerParent.secondArg('foo', 'bar');8import { firstArg, secondArg } from 'stryker-parent';9firstArg('foo', 'bar');10secondArg('foo', 'bar');11import * as strykerParent from 'stryker-parent';12strykerParent.firstArg('foo', 'bar');13strykerParent.secondArg('foo', 'bar');14import strykerParent from 'stryker-parent';15strykerParent.firstArg('foo', 'bar');16strykerParent.secondArg('foo', 'bar');17import { firstArg, secondArg } from 'stryker-parent';18firstArg('foo', 'bar');19secondArg('foo', 'bar');20import * as strykerParent from 'stryker-parent';21strykerParent.firstArg('foo', 'bar');22strykerParent.secondArg('foo', 'bar');23import strykerParent from 'stryker-parent';24strykerParent.firstArg('foo', 'bar');25strykerParent.secondArg('foo', 'bar');26const firstArg = require('stryker-parent').firstArg;27firstArg('foo', 'bar');28const secondArg = require('stryker-parent').secondArg;29secondArg('foo', 'bar');30const strykerParent = require('stryker-parent');31strykerParent.firstArg('foo', 'bar');32strykerParent.secondArg('foo', 'bar');33const strykerParent = require('stryker-parent');34strykerParent.firstArg('foo', 'bar');35strykerParent.secondArg('foo', 'bar');36import { firstArg, secondArg } from 'stryker-parent';37firstArg('foo', 'bar');38secondArg('foo', 'bar');39import * as strykerParent from 'stryker-parent';40strykerParent.firstArg('foo', 'bar');41strykerParent.secondArg('foo', 'bar');42import strykerParent from 'stryker-parent';

Full Screen

Using AI Code Generation

copy

Full Screen

1var firstArg = require('stryker-parent').firstArg;2var assert = require('assert');3describe('firstArg', function() {4 it('should return the first argument', function() {5 assert.equal(firstArg(1, 2, 3), 1);6 });7});

Full Screen

Using AI Code Generation

copy

Full Screen

1const firstArg = require('stryker-parent').firstArg;2const strykerParent = require('stryker-parent');3const strykerParent = require('stryker-parent');4const strykerParent = require('stryker-parent');5const strykerParent = require('stryker-parent');6const strykerParent = require('stryker-parent');7const strykerParent = require('stryker-parent');8const strykerParent = require('stryker-parent');9const strykerParent = require('stryker-parent');10const strykerParent = require('stryker-parent');11console.log(strykerParent.firstArg('foo', 'bar

Full Screen

Using AI Code Generation

copy

Full Screen

1const firstArg = require('stryker-parent').firstArg;2module.exports = function (a, b) {3 return firstArg(a, b);4}5const firstArg = require('stryker-parent').firstArg;6module.exports = function (a, b) {7 return firstArg(a, b);8}9const firstArg = require('stryker-parent').firstArg;10module.exports = function (a, b) {11 return firstArg(a, b);12}13const firstArg = require('stryker-parent').firstArg;14module.exports = function (a, b) {15 return firstArg(a, b);16}17const firstArg = require('stryker-parent').firstArg;18module.exports = function (a, b) {19 return firstArg(a, b);20}21const firstArg = require('stryker-parent').firstArg;22module.exports = function (a, b) {23 return firstArg(a, b);24}25const firstArg = require('stryker-parent').firstArg;26module.exports = function (a, b) {27 return firstArg(a, b);28}29const firstArg = require('stryker-parent').firstArg;30module.exports = function (a, b) {31 return firstArg(a, b);32}33const firstArg = require('stryker-parent').firstArg;34module.exports = function (a, b) {35 return firstArg(a, b);36}37const firstArg = require('stryker-parent').firstArg;38module.exports = function (a, b) {39 return firstArg(a, b);40}

Full Screen

Using AI Code Generation

copy

Full Screen

1var strykerParent = require('stryker-parent');2strykerParent.firstArg('foo', 'bar');3var strykerFoo = require('stryker-foo');4strykerFoo.firstArg('foo', 'bar');5var strykerParent = require('stryker-parent');6strykerParent.firstArg('foo', 'bar');7var strykerFoo = require('stryker-foo');8strykerFoo.firstArg('foo', 'bar');9var strykerParent = require('stryker-parent');10strykerParent.firstArg('foo', 'bar');11var strykerFoo = require('stryker-foo');12strykerFoo.firstArg('foo', 'bar');

Full Screen

Using AI Code Generation

copy

Full Screen

1var stryker = require('stryker-parent');2console.log(stryker.firstArg('hello', 'world'));3var stryker = require('stryker-parent');4console.log(stryker.firstArg('hello', 'world'));5var stryker = require('stryker-parent');6console.log(stryker.firstArg('hello', 'world'));7var stryker = require('stryker-parent');8console.log(stryker.firstArg('hello', 'world'));9var stryker = require('stryker-parent');10console.log(stryker.firstArg('hello', 'world'));11var stryker = require('stryker-parent');12console.log(stryker.firstArg('hello', 'world'));13var stryker = require('stryker-parent');14console.log(stryker.firstArg('hello', 'world'));15var stryker = require('stryker-parent');16console.log(stryker.firstArg('hello', 'world'));17var stryker = require('stryker-parent');18console.log(stryker.firstArg('hello', 'world'));19var stryker = require('stryker-parent');20console.log(stryker.firstArg('hello', 'world'));21var stryker = require('stryker-parent');22console.log(stryker.firstArg('

Full Screen

Using AI Code Generation

copy

Full Screen

1var parent = require('stryker-parent');2var firstArg = parent.firstArg;3console.log(firstArg('a', 'b', 'c'));4var firstArg = function () {5 return arguments[0];6};7module.exports = {8};

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 stryker-parent 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