Best JavaScript code snippet using best
localMessage.js
Source:localMessage.js
1/**2 * This file provides the mock "data" received3 * by your visualization code when you develop4 * locally.5 *6 */7export const message = {8 tables: {9 DEFAULT: [10 {11 dateDimensionID: ['20180615'],12 valueMetricID: [21.5],13 minRangeMetricID: [27],14 maxRangeMetricID: [14],15 unitMetricID: ['mm/mol'],16 nameValueID: ['BPM'],17 },18 {19 dateDimensionID: ['20180815'],20 valueMetricID: [19.3],21 minRangeMetricID: [27],22 maxRangeMetricID: [14],23 unitMetricID: ['mm/mol'],24 nameValueID: ['BPM'],25 },26 {27 dateDimensionID: ['20181015'],28 valueMetricID: [23.5],29 minRangeMetricID: [27],30 maxRangeMetricID: [14],31 unitMetricID: ['mm/mol'],32 nameValueID: ['BPM'],33 },34 {35 dateDimensionID: ['20181215'],36 valueMetricID: [24],37 minRangeMetricID: [27],38 maxRangeMetricID: [14],39 unitMetricID: ['mm/mol'],40 nameValueID: ['BPM'],41 },42 {43 dateDimensionID: ['20190102'],44 valueMetricID: [21.5],45 minRangeMetricID: [27],46 maxRangeMetricID: [14],47 unitMetricID: ['mm/mol'],48 nameValueID: ['BPM'],49 },50 {51 dateDimensionID: ['20180615'],52 valueMetricID: [1.5],53 minRangeMetricID: [7],54 maxRangeMetricID: [4],55 unitMetricID: ['mm'],56 nameValueID: ['HCP'],57 },58 {59 dateDimensionID: ['20180815'],60 valueMetricID: [1.3],61 minRangeMetricID: [7],62 maxRangeMetricID: [4],63 unitMetricID: ['mm'],64 nameValueID: ['HCP'],65 },66 {67 dateDimensionID: ['20181015'],68 valueMetricID: [3.5],69 minRangeMetricID: [7],70 maxRangeMetricID: [4],71 unitMetricID: ['mm'],72 nameValueID: ['HCP'],73 },74 {75 dateDimensionID: ['20181215'],76 valueMetricID: [2],77 minRangeMetricID: [2],78 maxRangeMetricID: [1],79 unitMetricID: ['mm'],80 nameValueID: ['HCP'],81 },82 {83 dateDimensionID: ['20190102'],84 valueMetricID: [1.5],85 minRangeMetricID: [4],86 maxRangeMetricID: [2],87 unitMetricID: ['mm'],88 nameValueID: ['HCP'],89 },90 {91 dateDimensionID: ['20180615'],92 valueMetricID: [10.5],93 minRangeMetricID: [4],94 maxRangeMetricID: [2],95 unitMetricID: ['mm1'],96 nameValueID: ['HCP1'],97 },98 {99 dateDimensionID: ['20180815'],100 valueMetricID: [10.3],101 minRangeMetricID: [4],102 maxRangeMetricID: [2],103 unitMetricID: ['mm1'],104 nameValueID: ['HCP1'],105 },106 {107 dateDimensionID: ['20181015'],108 valueMetricID: [30.5],109 minRangeMetricID: [4],110 maxRangeMetricID: [2],111 unitMetricID: ['mm1'],112 nameValueID: ['HCP1'],113 },114 {115 dateDimensionID: ['20181215'],116 valueMetricID: [20],117 minRangeMetricID: [4],118 maxRangeMetricID: [2],119 unitMetricID: ['mm1'],120 nameValueID: ['HCP1'],121 },122 {123 dateDimensionID: ['20190102'],124 valueMetricID: [10.5],125 minRangeMetricID: [4],126 maxRangeMetricID: [2],127 unitMetricID: ['mm1'],128 nameValueID: ['HCP1'],129 },130 {131 dateDimensionID: ['20180615'],132 valueMetricID: [10.5],133 minRangeMetricID: [4],134 maxRangeMetricID: [2],135 unitMetricID: ['%'],136 nameValueID: ['Another'],137 },138 {139 dateDimensionID: ['20180815'],140 valueMetricID: [10.3],141 minRangeMetricID: [4],142 maxRangeMetricID: [2],143 unitMetricID: ['%'],144 nameValueID: ['Another'],145 },146 {147 dateDimensionID: ['20181015'],148 valueMetricID: [30.5],149 minRangeMetricID: [4],150 maxRangeMetricID: [2],151 unitMetricID: ['%'],152 nameValueID: ['Another'],153 },154 {155 dateDimensionID: ['20181215'],156 valueMetricID: [20],157 minRangeMetricID: [4],158 maxRangeMetricID: [2],159 unitMetricID: ['%'],160 nameValueID: ['Another'],161 },162 {163 dateDimensionID: ['20190102'],164 valueMetricID: [10.5],165 minRangeMetricID: [4],166 maxRangeMetricID: [2],167 unitMetricID: ['%'],168 nameValueID: ['Another'],169 },170 ],171 },172 fields: {173 dateDimensionID: [174 {175 id: 'qt_nzqx6a0xvb',176 name: 'Date',177 type: 'TEXT',178 concept: 'DIMENSION',179 },180 ],181 valueMetricID: [182 {183 id: 'qt_8isx6a0xvb',184 name: 'Value',185 type: 'NUMBER',186 concept: 'METRIC',187 },188 ],189 maxRangeMetricID: [190 {191 id: 'qt_8isx6a0xvb',192 name: 'Maximum',193 type: 'NUMBER',194 concept: 'METRIC',195 },196 ],197 minRangeMetricID: [198 {199 id: 'qt_f74x6a0xvb',200 name: 'Minimum',201 type: 'NUMBER',202 concept: 'METRIC',203 },204 ],205 unitMetricID: [206 {207 id: 'qt_f76x6a0xvb',208 name: 'Unit',209 type: 'TEXT',210 concept: 'DIMENSION',211 },212 ],213 nameValueID: [214 {215 id: 'qt_f76x8a0xvb',216 name: 'Name Value',217 type: 'TEXT',218 concept: 'DIMENSION',219 },220 ],221 },222 style: {223 themeColor: {224 value: {225 color: '#6ed597'226 }227 }228 },...
metric.ts
Source:metric.ts
1import * as CaseGrowth from 'common/metrics/case_growth';2import * as TestRates from 'common/metrics/positive_rate';3import * as Hospitalizations from 'common/metrics/hospitalizations';4import * as ContactTracing from 'common/metrics/contact_tracing';5import * as FutureProjections from 'common/metrics/future_projection';6import { Projection } from 'common/models/Projection';7import { Level, LevelInfo } from 'common/level';8import { assert } from './utils';9export enum Metric {10 CASE_GROWTH_RATE,11 POSITIVE_TESTS,12 HOSPITAL_USAGE,13 CONTACT_TRACING,14 FUTURE_PROJECTIONS,15}16// Not sure if there's a better way to enumerate all enum values? :-(17export const ALL_METRICS = Object.values(Metric).filter(18 v => typeof v === 'number',19) as Metric[];20// Future Projections has a graph but not a value.21export const ALL_VALUE_METRICS = ALL_METRICS.filter(22 m => m !== Metric.FUTURE_PROJECTIONS,23);24const METRIC_TO_NAME = {25 [Metric.CASE_GROWTH_RATE]: CaseGrowth.METRIC_NAME,26 [Metric.POSITIVE_TESTS]: TestRates.METRIC_NAME,27 [Metric.HOSPITAL_USAGE]: Hospitalizations.METRIC_NAME,28 [Metric.CONTACT_TRACING]: ContactTracing.METRIC_NAME,29 [Metric.FUTURE_PROJECTIONS]: FutureProjections.METRIC_NAME,30};31export function getMetricName(metric: Metric) {32 return METRIC_TO_NAME[metric];33}34const ALL_METRICS_LEVEL_INFO_MAP = {35 [Metric.CASE_GROWTH_RATE]: CaseGrowth.CASE_GROWTH_RATE_LEVEL_INFO_MAP,36 [Metric.POSITIVE_TESTS]: TestRates.POSITIVE_TESTS_LEVEL_INFO_MAP,37 [Metric.HOSPITAL_USAGE]: Hospitalizations.HOSPITAL_USAGE_LEVEL_INFO_MAP,38 [Metric.CONTACT_TRACING]: ContactTracing.CONTACT_TRACING_LEVEL_INFO_MAP,39 [Metric.FUTURE_PROJECTIONS]: null, // Future Projections doesn't have levels.40};41export function getLevelInfo(metric: Metric, value: number | null): LevelInfo {42 assert(43 metric !== Metric.FUTURE_PROJECTIONS,44 `Future Projections don't have levels`,45 );46 const level = getLevel(metric, value);47 return ALL_METRICS_LEVEL_INFO_MAP[metric][level];48}49export function getLevel(metric: Metric, value: number | null): Level {50 assert(51 metric !== Metric.FUTURE_PROJECTIONS,52 `Future Projections don't have levels`,53 );54 const levelInfoMap = ALL_METRICS_LEVEL_INFO_MAP[metric];55 // TODO(michael): Is there a typesafe way to enumerate enum values? :-/56 if (value === null) return Level.UNKNOWN;57 for (const level of [58 Level.LOW,59 Level.MEDIUM,60 Level.MEDIUM_HIGH,61 Level.HIGH,62 ]) {63 if (value <= levelInfoMap[level].upperLimit) {64 return level;65 }66 }67 return Level.UNKNOWN;68}69const METRIC_TO_DISCLAIMER: { [metricName: number]: string } = {70 [Metric.CASE_GROWTH_RATE]: CaseGrowth.CASE_GROWTH_DISCLAIMER,71 [Metric.POSITIVE_TESTS]: TestRates.POSITIVE_RATE_DISCLAIMER,72 [Metric.HOSPITAL_USAGE]: Hospitalizations.HOSPITALIZATIONS_DISCLAIMER,73 [Metric.CONTACT_TRACING]: ContactTracing.CONTACT_TRACING_DISCLAIMER,74};75export function getMetricDisclaimer(metric: Metric) {76 return METRIC_TO_DISCLAIMER[metric];77}78export function getMetricStatusText(metric: Metric, projection: Projection) {79 const METRIC_TO_STATUS_TEXT: { [metricName: number]: string } = {80 [Metric.CASE_GROWTH_RATE]: CaseGrowth.caseGrowthStatusText(projection),81 [Metric.POSITIVE_TESTS]: TestRates.positiveTestsStatusText(projection),82 [Metric.HOSPITAL_USAGE]: Hospitalizations.hospitalOccupancyStatusText(83 projection,84 ),85 [Metric.CONTACT_TRACING]: ContactTracing.contactTracingStatusText(86 projection,87 ),88 };89 return METRIC_TO_STATUS_TEXT[metric];...
metric-selector-item.js
Source:metric-selector-item.js
1import React from 'react';2import classNames from 'classnames';3import { connect } from 'react-redux';4import { hoverMetric, pinMetric, unpinMetric } from '../actions/app-actions';5import { selectedMetricTypeSelector } from '../selectors/node-metric';6import { trackAnalyticsEvent } from '../utils/tracking-utils';7class MetricSelectorItem extends React.Component {8 constructor(props, context) {9 super(props, context);10 this.onMouseOver = this.onMouseOver.bind(this);11 this.onMouseClick = this.onMouseClick.bind(this);12 }13 trackEvent(eventName) {14 trackAnalyticsEvent(eventName, {15 layout: this.props.topologyViewMode,16 metricType: this.props.metric.get('label'),17 parentTopologyId: this.props.currentTopology.get('parentId'),18 topologyId: this.props.currentTopology.get('id'),19 });20 }21 onMouseOver() {22 const metricType = this.props.metric.get('label');23 this.props.hoverMetric(metricType);24 }25 onMouseClick() {26 const metricType = this.props.metric.get('label');27 const { pinnedMetricType } = this.props;28 if (metricType !== pinnedMetricType) {29 this.trackEvent('scope.metric.selector.pin.click');30 this.props.pinMetric(metricType);31 } else {32 this.trackEvent('scope.metric.selector.unpin.click');33 this.props.unpinMetric();34 }35 }36 render() {37 const { metric, selectedMetricType, pinnedMetricType } = this.props;38 const type = metric.get('label');39 const isPinned = (type === pinnedMetricType);40 const isSelected = (type === selectedMetricType);41 const className = classNames('metric-selector-action', {42 'metric-selector-action-selected': isSelected43 });44 return (45 <div46 key={type}47 className={className}48 onMouseOver={this.onMouseOver}49 onClick={this.onMouseClick}>50 {type}51 {isPinned && <i className="fa fa-thumbtack" />}52 </div>53 );54 }55}56function mapStateToProps(state) {57 return {58 currentTopology: state.get('currentTopology'),59 pinnedMetricType: state.get('pinnedMetricType'),60 selectedMetricType: selectedMetricTypeSelector(state),61 topologyViewMode: state.get('topologyViewMode'),62 };63}64export default connect(65 mapStateToProps,66 { hoverMetric, pinMetric, unpinMetric }...
Using AI Code Generation
1var x = [1,2,3,4,5,6,7,8,9,10];2var y = [1,2,3,4,5,6,7,8,9,10];3var m = 0;4var b = 0;5var r = 0;6var r2 = 0;7var n = 10;8var i = 0;9var a = 0;10var b = 0;11var c = 0;12var d = 0;13var e = 0;14var f = 0;15var g = 0;16var h = 0;17var j = 0;18var k = 0;19var l = 0;20var m = 0;21var n = 0;22var o = 0;23var p = 0;24var q = 0;25var r = 0;26var s = 0;27var t = 0;28var u = 0;29var v = 0;30var w = 0;31var x = 0;32var y = 0;33var z = 0;34var a2 = 0;35var b2 = 0;36var c2 = 0;37var d2 = 0;38var e2 = 0;39var f2 = 0;40var g2 = 0;41var h2 = 0;42var j2 = 0;43var k2 = 0;44var l2 = 0;45var m2 = 0;46var n2 = 0;47var o2 = 0;48var p2 = 0;49var q2 = 0;50var r2 = 0;51var s2 = 0;52var t2 = 0;53var u2 = 0;54var v2 = 0;55var w2 = 0;56var x2 = 0;57var y2 = 0;58var z2 = 0;59var a3 = 0;60var b3 = 0;61var c3 = 0;62var d3 = 0;63var e3 = 0;64var f3 = 0;65var g3 = 0;66var h3 = 0;67var j3 = 0;68var k3 = 0;69var l3 = 0;70var m3 = 0;
Using AI Code Generation
1var BestFitLine = require('./BestFitLine');2var x = [1, 2, 3, 4, 5];3var y = [1, 2, 3, 4, 5];4var bfl = new BestFitLine(x, y);5var m = bfl.metric();6console.log(m);7function BestFitLine(x, y) {8 this.x = x;9 this.y = y;10}11BestFitLine.prototype.metric = function() {12 var sumX = 0;13 for (var i = 0; i < this.x.length; i++) {14 sumX += this.x[i];15 }16 var sumY = 0;17 for (var i = 0; i < this.y.length; i++) {18 sumY += this.y[i];19 }20 var sumXY = 0;21 for (var i = 0; i < this.x.length; i++) {22 sumXY += this.x[i] * this.y[i];23 }24 var sumX2 = 0;25 for (var i = 0; i < this.x.length; i++) {26 sumX2 += this.x[i] * this.x[i];27 }28 var sumY2 = 0;29 for (var i = 0; i < this.y.length; i++) {30 sumY2 += this.y[i] * this.y[i];31 }32 var n = this.x.length;33 var m = (n * sumXY - sumX * sumY) / (n * sumX2 - sumX * sumX);34 var b = (sumY - m * sumX) / n;35 var r = (n * sumXY - sumX * sumY) / Math.sqrt((n * sumX2 - sumX * sumX) * (n * sumY2 - sumY * sumY));36 return { m: m, b: b, r: r };37}38module.exports = BestFitLine;39var BestFitLine = require('./BestFitLine');40var bfl = new BestFitLine(x, y);
Using AI Code Generation
1var BestFitLine = require('./BestFitLine.js');2var bfl = new BestFitLine();3bfl.addPoint(1, 1);4bfl.addPoint(2, 2);5bfl.addPoint(3, 3);6bfl.addPoint(4, 4);7console.log(bfl.getBestFitLine());8bfl.clearPoints();9bfl.addPoint(1, 1);10bfl.addPoint(2, 2);11bfl.addPoint(3, 3);12bfl.addPoint(4, 4);13bfl.addPoint(5, 5);14bfl.addPoint(6, 6);15bfl.addPoint(7, 7);16bfl.addPoint(8, 8);17console.log(bfl.getBestFitLine());18bfl.clearPoints();19bfl.addPoint(1, 1);20bfl.addPoint(2, 2);21bfl.addPoint(3, 3);22bfl.addPoint(4, 4);23bfl.addPoint(5, 5);24bfl.addPoint(6, 6);25bfl.addPoint(7, 7);26bfl.addPoint(8, 8);27bfl.addPoint(9, 9);28bfl.addPoint(10, 10);29console.log(bfl.getBestFitLine());30bfl.clearPoints();31bfl.addPoint(1, 1);32bfl.addPoint(2, 2);33bfl.addPoint(3, 3);34bfl.addPoint(4, 4);35bfl.addPoint(5, 5);36bfl.addPoint(6, 6);37bfl.addPoint(7, 7);38bfl.addPoint(8, 8);39bfl.addPoint(9, 9);40bfl.addPoint(10, 10);41bfl.addPoint(11, 11);42bfl.addPoint(12, 12);43bfl.addPoint(13, 13);44bfl.addPoint(14, 14);45bfl.addPoint(15, 15);46bfl.addPoint(16, 16);47bfl.addPoint(17, 17);48bfl.addPoint(18, 18);49bfl.addPoint(19, 19);50bfl.addPoint(20, 20);51console.log(bfl.getBestFitLine());
Using AI Code Generation
1var bfl = require('./BestFitLine');2var x = [1,2,3,4,5];3var y = [2,3,4,5,6];4var line = bfl.metric(x,y);5console.log('Metric Best Fit Line: y = ' + line.a.toFixed(3) + 'x + ' + line.b.toFixed(3));6var bfl = require('./BestFitLine');7var x = [1,2,3,4,5];8var y = [2,3,4,5,6];9var line = bfl.metric(x,y);10console.log('Metric Best Fit Line: y = ' + line.a.toFixed(3) + 'x + ' + line.b.toFixed(3));11var bfl = require('./BestFitLine');12var x = [1,2,3,4,5];13var y = [2,3,4,5,6];14var line = bfl.metric(x,y);15console.log('Metric Best Fit Line: y = ' + line.a.toFixed(3) + 'x + ' + line.b.toFixed(3));16var bfl = require('./BestFitLine');17var x = [1,2,3,4,5];18var y = [2,3,4,5,6];19var line = bfl.metric(x,y);20console.log('Metric Best Fit Line: y = ' + line.a.toFixed(3) + 'x + ' + line.b.toFixed(3));21var bfl = require('./BestFitLine');22var x = [1,2,3,4,5];23var y = [2,3,4,5,6];24var line = bfl.metric(x,y);25console.log('Metric Best Fit Line: y = ' + line.a.toFixed(3) + 'x + ' + line.b.toFixed(3));26var bfl = require('./BestFitLine');
Using AI Code Generation
1var BestFitLine = require('./BestFitLine');2var bfl = new BestFitLine();3bfl.setData([[1,1],[2,2],[3,3]]);4var BestFitLine = require('./BestFitLine');5var bfl = new BestFitLine();6bfl.setData([[1,1],[2,2],[3,3]]);7var BestFitLine = require('./BestFitLine');8var bfl = new BestFitLine();9bfl.setData([[1,1],[2,2],[3,3]]);10var BestFitLine = require('./BestFitLine');11var bfl = new BestFitLine();12bfl.setData([[1,1],[2,2],[3,3]]);13var BestFitLine = require('./BestFitLine');14var bfl = new BestFitLine();15bfl.setData([[1,1],[2,2],[3,3]]);
Using AI Code Generation
1var data = new Array();2var data2 = new Array();3var data3 = new Array();4var data4 = new Array();5var data5 = new Array();6var data6 = new Array();7var data7 = new Array();8var data8 = new Array();9var data9 = new Array();10var data10 = new Array();11var data11 = new Array();12var data12 = new Array();13var data13 = new Array();14var data14 = new Array();15var data15 = new Array();16var data16 = new Array();17var data17 = new Array();18var data18 = new Array();19var data19 = new Array();20var data20 = new Array();21var data21 = new Array();22var data22 = new Array();23var data23 = new Array();24var data24 = new Array();25var data25 = new Array();26var data26 = new Array();27var data27 = new Array();28var data28 = new Array();29var data29 = new Array();30var data30 = new Array();31var data31 = new Array();32var data32 = new Array();33var data33 = new Array();34var data34 = new Array();35var data35 = new Array();36var data36 = new Array();37var data37 = new Array();38var data38 = new Array();39var data39 = new Array();40var data40 = new Array();41var data41 = new Array();42var data42 = new Array();43var data43 = new Array();44var data44 = new Array();45var data45 = new Array();46var data46 = new Array();47var data47 = new Array();48var data48 = new Array();49var data49 = new Array();50var data50 = new Array();51var data51 = new Array();52var data52 = new Array();53var data53 = new Array();54var data54 = new Array();55var data55 = new Array();56var data56 = new Array();57var data57 = new Array();58var data58 = new Array();59var data59 = new Array();60var data60 = new Array();61var data61 = new Array();62var data62 = new Array();63var data63 = new Array();64var data64 = new Array();65var data65 = new Array();66var data66 = new Array();67var data67 = new Array();68var data68 = new Array();
Using AI Code Generation
1var x = [1,2,3,4,5];2var y = [2,4,6,8,10];3var bf = new BestFit();4var line = bf.metric(x,y);5console.log("y = " + line.a + " + " + line.b + "x");6var x1 = 6;7var y1 = line.a + line.b * x1;8console.log("y for x = " + x1 + " is " + y1);9var y2 = 12;10var x2 = (y2 - line.a) / line.b;11console.log("x for y = " + y2 + " is " + x2);12console.log("correlation coefficient = " + bf.r);13console.log("coefficient of determination = " + bf.r2);14console.log("standard error of the estimate = " + bf.s);15console.log("sum of squared residuals = " + bf.ssr);16console.log("sum of squared total = " + bf.sst);17console.log("sum of squared error = " + bf.sse);18console.log("sum of squared regression = " + bf.ssr);19console.log("mean squared error = " + bf.mse);20console.log("mean squared regression = " + bf.msr);21console.log("mean squared error = " + bf.mse);22console.log("F statistic = " + bf.f);23console.log("p value = " + bf.p);24console.log("t statistic = " + bf.t);
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!