Best Python code snippet using yandex-tank
MeasureComponent-test.jsx
Source:MeasureComponent-test.jsx
1/**2 * Copyright 2015, GeoSolutions Sas.3 * All rights reserved.4 *5 * This source code is licensed under the BSD-style license found in the6 * LICENSE file in the root directory of this source tree.7*/8import expect from 'expect';9import assign from 'object-assign';10import React from 'react';11import {DragDropContext as dragDropContext} from 'react-dnd';12import testBackend from 'react-dnd-test-backend';13import ReactDOM from 'react-dom';14import TestUtils from 'react-dom/test-utils';15import Message from '../../../I18N/Message';16import MeasureComponentComp from '../MeasureComponent';17const MeasureComponent = dragDropContext(testBackend)(MeasureComponentComp);18describe("test the MeasureComponent", () => {19 beforeEach((done) => {20 document.body.innerHTML = '<div id="container"></div>';21 setTimeout(done);22 });23 afterEach((done) => {24 ReactDOM.unmountComponentAtNode(document.getElementById("container"));25 document.body.innerHTML = '';26 setTimeout(done);27 });28 it('test component creation', () => {29 let measurement = {};30 const mc = ReactDOM.render(<MeasureComponent measurement={measurement}/>, document.getElementById("container"));31 expect(mc).toExist();32 });33 it('test creation of button UIs ', () => {34 let measurement = {};35 const mc = ReactDOM.render(<MeasureComponent useButtonGroup measurement={measurement}/>, document.getElementById("container"));36 expect(mc).toExist();37 const domNode = ReactDOM.findDOMNode(mc);38 expect(domNode).toExist();39 const domButtons = domNode.getElementsByTagName('button');40 expect(domButtons).toExist();41 expect(domButtons.length).toBe(4);42 });43 it('test creation of measurement result panel UI ', () => {44 let measurement = {};45 const mc = ReactDOM.render(<MeasureComponent measurement={measurement}/>, document.getElementById("container"));46 expect(mc).toExist();47 const domNode = ReactDOM.findDOMNode(mc);48 expect(domNode).toExist();49 const domResultPanel = document.getElementById('measure-result-panel');50 expect(domResultPanel).toExist();51 });52 it('test line activation', () => {53 let newMeasureState;54 let measurement = {55 geomType: null56 };57 const cmp = ReactDOM.render(58 <MeasureComponent59 measurement={measurement}60 geomType={'Polygon'}61 toggleMeasure={(data) => {62 newMeasureState = data;63 }}64 lineMeasureEnabled={false} />, document.getElementById("container")65 );66 expect(cmp).toExist();67 const cmpDom = ReactDOM.findDOMNode(cmp);68 expect(cmpDom).toExist();69 const buttons = cmpDom.getElementsByTagName('button');70 expect(buttons.length).toBe(4);71 const lineBtn = buttons.item(0);72 lineBtn.click();73 expect(newMeasureState).toExist();74 expect(newMeasureState.geomType).toBe('LineString');75 });76 it('test area activation', () => {77 let newMeasureState;78 let measurement = {79 geomType: null80 };81 const cmp = ReactDOM.render(82 <MeasureComponent83 measurement={measurement}84 toggleMeasure={(data) => {85 newMeasureState = data;86 }}87 areaMeasureEnabled={false} />, document.getElementById("container")88 );89 expect(cmp).toExist();90 const cmpDom = ReactDOM.findDOMNode(cmp);91 expect(cmpDom).toExist();92 const buttons = cmpDom.getElementsByTagName('button');93 expect(buttons.length).toBe(4);94 const areaBtn = buttons.item(1);95 areaBtn.click();96 expect(newMeasureState).toExist();97 expect(newMeasureState.geomType).toBe('Polygon');98 });99 it('test bearing activation', () => {100 let newMeasureState;101 let measurement = {102 geomType: null103 };104 const cmp = ReactDOM.render(105 <MeasureComponent106 measurement={measurement}107 toggleMeasure={(data) => {108 newMeasureState = data;109 }}110 bearingMeasureEnabled={false} />, document.getElementById("container")111 );112 expect(cmp).toExist();113 const cmpDom = ReactDOM.findDOMNode(cmp);114 expect(cmpDom).toExist();115 const buttons = cmpDom.getElementsByTagName('button');116 expect(buttons.length).toBe(4);117 const bearingBtn = buttons.item(2);118 bearingBtn.click();119 expect(newMeasureState).toExist();120 expect(newMeasureState.geomType).toBe('Bearing');121 });122 it('test measurements resetting', () => {123 let newMeasureState;124 let measurement = {125 geomType: 'Bearing'126 };127 const cmp = ReactDOM.render(128 <MeasureComponent129 measurement={measurement}130 toggleMeasure={(data) => {131 newMeasureState = data;132 }}133 withReset134 />, document.getElementById("container")135 );136 expect(cmp).toExist();137 const cmpDom = ReactDOM.findDOMNode(cmp);138 expect(cmpDom).toExist();139 const buttons = cmpDom.getElementsByTagName('button');140 expect(buttons.length).toBe(4);141 const resetBtn = buttons.item(3);142 // Dectivate143 resetBtn.click();144 expect(newMeasureState).toExist();145 expect(newMeasureState.geomType).toBe(null);146 });147 it('test bearing format', () => {148 let measurement = {149 lineMeasureEnabled: false,150 areaMeasureEnabled: false,151 bearingMeasureEnabled: true,152 geomType: 'LineString',153 len: 0,154 area: 0,155 bearing: 0156 };157 let cmp = ReactDOM.render(158 <MeasureComponent measurement={measurement} bearingMeasureEnabled bearingMeasureValueEnabled/>, document.getElementById("container")159 );160 expect(cmp).toExist();161 const bearingSpan = document.getElementById('measure-bearing-res');162 expect(bearingSpan).toExist();163 cmp = ReactDOM.render(164 <MeasureComponent measurement={{...measurement, bearing: 45}} bearingMeasureEnabled bearingMeasureValueEnabled/>, document.getElementById("container")165 );166 expect(bearingSpan.innerHTML).toBe("<h3><strong>N 45° 0' 0'' E</strong></h3>");167 cmp = ReactDOM.render(168 <MeasureComponent measurement={assign({}, measurement, {bearing: 135})} bearingMeasureEnabled bearingMeasureValueEnabled/>, document.getElementById("container")169 );170 expect(bearingSpan.innerHTML).toBe("<h3><strong>S 45° 0' 0'' E</strong></h3>");171 cmp = ReactDOM.render(172 <MeasureComponent measurement={assign({}, measurement, {bearing: 225})} bearingMeasureEnabled bearingMeasureValueEnabled/>, document.getElementById("container")173 );174 expect(bearingSpan.innerHTML).toBe("<h3><strong>S 45° 0' 0'' W</strong></h3>");175 cmp = ReactDOM.render(176 <MeasureComponent measurement={assign({}, measurement, {bearing: 315})} bearingMeasureEnabled bearingMeasureValueEnabled/>, document.getElementById("container")177 );178 expect(bearingSpan.innerHTML).toBe("<h3><strong>N 45° 0' 0'' W</strong></h3>");179 });180 it('test true bearing format', () => {181 let measurement = {182 lineMeasureEnabled: false,183 areaMeasureEnabled: false,184 bearingMeasureEnabled: true,185 trueBearing: { measureTrueBearing: true, fractionDigits: 0},186 geomType: 'LineString',187 len: 0,188 area: 0,189 bearing: 0190 };191 let cmp = ReactDOM.render(192 <MeasureComponent measurement={measurement} bearingMeasureEnabled bearingMeasureValueEnabled/>, document.getElementById("container")193 );194 expect(cmp).toExist();195 const bearingSpan = document.getElementById('measure-bearing-res');196 expect(bearingSpan).toExist();197 const bearingTitle = TestUtils.findRenderedDOMComponentWithClass(cmp, 'form-group');198 expect(bearingTitle.textContent).toContain('trueBearingLabel');199 cmp = ReactDOM.render(200 <MeasureComponent measurement={{...measurement, bearing: 45}} bearingMeasureEnabled bearingMeasureValueEnabled trueBearingLabel = {<Message msgId="True Bearing"/>}/>, document.getElementById("container")201 );202 expect(bearingSpan.innerHTML).toBe("<h3><strong>045°</strong></h3>");203 const bearingTitleText = TestUtils.findRenderedDOMComponentWithClass(cmp, 'form-group');204 expect(bearingTitleText.textContent).toContain('True Bearing');205 cmp = ReactDOM.render(206 <MeasureComponent measurement={{...measurement, bearing: 135.235648, trueBearing: {...measurement.trueBearing, fractionDigits: 4}}} bearingMeasureEnabled bearingMeasureValueEnabled/>, document.getElementById("container")207 );208 expect(bearingSpan.innerHTML).toBe("<h3><strong>135.2356°</strong></h3>");209 cmp = ReactDOM.render(210 <MeasureComponent measurement={{...measurement, bearing: 225.83202, trueBearing: {...measurement.trueBearing, fractionDigits: 2}}} bearingMeasureEnabled bearingMeasureValueEnabled/>, document.getElementById("container")211 );212 expect(bearingSpan.innerHTML).toBe("<h3><strong>225.83°</strong></h3>");213 cmp = ReactDOM.render(214 <MeasureComponent measurement={assign({}, measurement, {bearing: 315})} bearingMeasureEnabled bearingMeasureValueEnabled/>, document.getElementById("container")215 );216 expect(bearingSpan.innerHTML).toBe("<h3><strong>315°</strong></h3>");217 });218 it('test uom format area and lenght', () => {219 let measurement = {220 lineMeasureEnabled: false,221 areaMeasureEnabled: false,222 bearingMeasureEnabled: false,223 geomType: 'LineString',224 len: 0,225 area: 0,226 bearing: 0227 };228 let cmp = ReactDOM.render(229 <MeasureComponent230 uom={{231 length: {unit: 'km', label: 'km'},232 area: {unit: 'sqkm', label: 'km²'}233 }}234 measurement={measurement}235 lineMeasureEnabled236 lineMeasureValueEnabled237 />, document.getElementById("container")238 );239 expect(cmp).toExist();240 const lenSpan = document.getElementById('measure-len-res');241 expect(lenSpan).toExist();242 let testDiv = document.createElement("div");243 document.body.appendChild(testDiv);244 cmp = ReactDOM.render(245 <MeasureComponent246 lengthLabel="Length"247 lineMeasureEnabled248 lineMeasureValueEnabled249 uom={{250 length: {unit: 'km', label: 'km'},251 area: {unit: 'sqkm', label: 'km²'}252 }}253 measurement={assign({}, measurement, {len: 10000})}/>, document.getElementById("container")254 );255 expect(lenSpan.firstChild.firstChild.firstChild.innerHTML).toBe("10");256 cmp = ReactDOM.render(257 <MeasureComponent258 areaMeasureEnabled259 areaMeasureValueEnabled260 uom={{261 length: {unit: 'km', label: 'km'},262 area: {unit: 'sqkm', label: 'km²'}263 }} measurement={assign({}, measurement, {geomType: 'Polygon', area: 1000000})}/>, document.getElementById("container")264 );265 const areaSpan = document.getElementById('measure-area-res');266 expect(areaSpan).toExist();267 expect(areaSpan.firstChild.firstChild.firstChild.innerHTML).toBe("1");268 });269 it('test showing coordinate editor', () => {270 let measurement = {271 lineMeasureEnabled: true,272 areaMeasureEnabled: false,273 bearingMeasureEnabled: false,274 geomType: 'LineString',275 feature: {276 type: "Feature",277 geometry: {278 type: "LineString",279 coordinates: [[1, 2], [2, 5]]280 },281 properties: {}282 },283 len: 0,284 area: 0,285 bearing: 0286 };287 let cmp = ReactDOM.render(288 <MeasureComponent289 uom={{290 length: {unit: 'km', label: 'km'},291 area: {unit: 'sqkm', label: 'km²'}292 }}293 measurement={measurement}294 showCoordinateEditor295 format="decimal"296 isDraggable297 useSingleFeature298 lineMeasureEnabled299 />, document.getElementById("container")300 );301 expect(cmp).toExist();302 const coordEditorPanel = TestUtils.findRenderedDOMComponentWithClass(cmp, 'ms2-border-layout-body');303 expect(coordEditorPanel).toExist();304 const coordinateRows = TestUtils.scryRenderedDOMComponentsWithClass(cmp, 'coordinateRow');305 const submits = TestUtils.scryRenderedDOMComponentsWithClass(cmp, "glyphicon-ok");306 const isValid = TestUtils.scryRenderedDOMComponentsWithClass(cmp, "glyphicon-ok-sign");307 const isInValid = TestUtils.scryRenderedDOMComponentsWithClass(cmp, "glyphicon-exclamation-mark");308 expect(isValid).toExist();309 expect(coordinateRows.length).toBe(2);310 expect(isValid.length).toBe(1);311 expect(submits.length).toBe(2);312 expect(isInValid.length).toBe(0);313 });314 it('rendering a coordinate editor for Polygons with 4 empty rows', () => {315 let measurement = {316 lineMeasureEnabled: false,317 areaMeasureEnabled: true,318 bearingMeasureEnabled: false,319 geomType: 'Polygon',320 feature: {321 type: "Feature",322 geometry: {323 type: "Polygon",324 coordinates: [[["", ""], ["", ""], ["", ""], ["", ""]]]325 },326 properties: {}327 },328 len: 0,329 area: 0,330 bearing: 0331 };332 let cmp = ReactDOM.render(333 <MeasureComponent334 uom={{335 length: {unit: 'km', label: 'km'},336 area: {unit: 'sqkm', label: 'km²'}337 }}338 measurement={measurement}339 useSingleFeature340 showCoordinateEditor341 format="decimal"342 isDraggable343 areaMeasureEnabled344 />, document.getElementById("container")345 );346 expect(cmp).toExist();347 const coordEditorPanel = TestUtils.findRenderedDOMComponentWithClass(cmp, 'ms2-border-layout-body');348 const coordinateRows = TestUtils.scryRenderedDOMComponentsWithClass(cmp, 'coordinateRow');349 expect(coordEditorPanel).toExist();350 const submits = TestUtils.scryRenderedDOMComponentsWithClass(cmp, "glyphicon-ok");351 const isValid = TestUtils.scryRenderedDOMComponentsWithClass(cmp, "glyphicon-ok-sign");352 const isInValid = TestUtils.scryRenderedDOMComponentsWithClass(cmp, "glyphicon-exclamation-mark");353 expect(isValid).toExist();354 expect(coordinateRows.length).toBe(4);355 expect(isValid.length).toBe(0);356 expect(submits.length).toBe(4);357 expect(isInValid.length).toBe(1);358 });359 it('test showing measurement from annotation', () => {360 let measurement = {361 lineMeasureEnabled: true,362 areaMeasureEnabled: false,363 bearingMeasureEnabled: false,364 geomType: 'LineString',365 features: [{366 type: "Feature",367 geometry: {368 type: "LineString",369 coordinates: [[1, 2], [2, 5]]370 },371 properties: {}372 }],373 textLabels: [{position: [1, 1], text: "1,714 m"}],374 id: 1,375 geomTypeSelected: ['LineString'],376 exportToAnnotation: true,377 len: 0,378 area: 0,379 bearing: 0380 };381 const uom = {382 length: {unit: 'km', label: 'km'},383 area: {unit: 'sqkm', label: 'km²'}384 };385 const actions = {386 onAddAnnotation: () => {}387 };388 const spyOnAddAnnotation = expect.spyOn(actions, "onAddAnnotation");389 let cmp = ReactDOM.render(390 <MeasureComponent391 onAddAnnotation={actions.onAddAnnotation}392 uom={uom}393 measurement={measurement}394 format="decimal"395 isDraggable396 useSingleFeature397 lineMeasureEnabled398 showAddAsAnnotation399 />, document.getElementById("container")400 );401 expect(cmp).toExist();402 const toolbar = TestUtils.scryRenderedDOMComponentsWithClass(cmp, "btn-toolbar");403 const toolBarGroup = TestUtils.scryRenderedDOMComponentsWithClass(cmp, "btn-group");404 expect(toolbar).toExist();405 expect(toolBarGroup.length).toBe(3);406 const buttons = document.querySelectorAll('button');407 expect(buttons.length).toBe(7);408 expect(buttons[0].classList.contains('disabled')).toBe(false);409 expect(buttons[1].classList.contains('disabled')).toBe(false);410 expect(buttons[2].classList.contains('disabled')).toBe(false);411 expect(buttons[3].classList.contains('disabled')).toBe(false);412 expect(buttons[4].classList.contains('disabled')).toBe(false);413 expect(buttons[5].classList.contains('disabled')).toBe(true); // Add as layer button414 expect(buttons[6].classList.contains('disabled')).toBe(false);415 expect(buttons[6].childNodes[0].className).toContain('floppy-disk');416 // Save annotation417 TestUtils.Simulate.click(buttons[6]);418 expect(spyOnAddAnnotation).toHaveBeenCalled();419 expect(spyOnAddAnnotation.calls[0].arguments).toBeTruthy();420 expect(spyOnAddAnnotation.calls[0].arguments.length).toBe(5);421 expect(spyOnAddAnnotation.calls[0].arguments[0]).toEqual(measurement.features);422 expect(spyOnAddAnnotation.calls[0].arguments[1]).toEqual(measurement.textLabels);423 expect(spyOnAddAnnotation.calls[0].arguments[2]).toEqual(uom);424 expect(spyOnAddAnnotation.calls[0].arguments[3]).toBe(false);425 expect(spyOnAddAnnotation.calls[0].arguments[4].id).toBe(1);426 });427 it("test Measurement default", () =>{428 let measurement = {429 lineMeasureEnabled: true,430 features: [{431 type: "Feature",432 geometry: {433 type: "LineString",434 coordinates: [[1, 2], [2, 5]]435 },436 properties: {}437 }],438 textLabels: [{position: [1, 1], text: "1,714 m"}],439 id: 1,440 len: 0,441 area: 0,442 bearing: 0443 };444 let cmp = ReactDOM.render(445 <MeasureComponent446 measurement={measurement}447 format="decimal"448 isDraggable449 useSingleFeature450 lineMeasureEnabled451 showAddAsAnnotation452 />, document.getElementById("container")453 );454 expect(cmp).toExist();455 const toolbar = TestUtils.scryRenderedDOMComponentsWithClass(cmp, "btn-toolbar");456 const toolBarGroup = TestUtils.scryRenderedDOMComponentsWithClass(cmp, "btn-group");457 expect(toolbar).toExist();458 expect(toolBarGroup.length).toBe(3);459 const buttons = document.querySelectorAll('button');460 expect(buttons.length).toBe(7);461 // By default LineString is selected462 expect(buttons[0].className).toContain('active');463 // Restrict unselect of the geometry464 TestUtils.Simulate.click(buttons[0]);465 expect(buttons[0].className).toContain('active');466 });467 it("test Measurement with invalid features", () =>{468 let measurement = {469 lineMeasureEnabled: true,470 features: [{471 type: "Feature",472 geometry: {473 type: "LineString",474 coordinates: [[1, 2], [2, 5], ["", ""]]475 },476 properties: {477 disabled: true478 }479 }],480 textLabels: [{position: [1, 2], text: "1,714 m"},481 {position: [1, 1], text: "1,723 m"}],482 id: 1,483 len: 0,484 area: 0,485 bearing: 0486 };487 let cmp = ReactDOM.render(488 <MeasureComponent489 measurement={measurement}490 format="decimal"491 isDraggable492 useSingleFeature493 lineMeasureEnabled494 showAddAsAnnotation495 />, document.getElementById("container")496 );497 expect(cmp).toExist();498 const toolbar = TestUtils.scryRenderedDOMComponentsWithClass(cmp, "btn-toolbar");499 const toolBarGroup = TestUtils.scryRenderedDOMComponentsWithClass(cmp, "btn-group");500 expect(toolbar).toExist();501 expect(toolBarGroup.length).toBe(3);502 const geomTypeButtons = toolBarGroup[0].querySelectorAll('button');503 expect(geomTypeButtons.length).toBe(3);504 geomTypeButtons.forEach((btn, i)=> {505 if (i === 0) return expect(btn.className).toContain('active');506 return expect(btn.className).toContain('disabled');507 });508 const exportTools = toolBarGroup[2].querySelectorAll('button');509 expect(exportTools.length).toBe(3);510 exportTools.forEach((btn)=> expect(btn.className).toContain('disabled'));511 });...
cubeMeasures.js
Source:cubeMeasures.js
1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing, software13 * distributed under the License is distributed on an "AS IS" BASIS,14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.15 * See the License for the specific language governing permissions and16 * limitations under the License.17 */18'use strict';19KylinApp.controller('CubeMeasuresCtrl', function ($scope, $modal,MetaModel,cubesManager,CubeDescModel,SweetAlert,VdmUtil,TableModel,cubeConfig,modelsManager,kylinConfig) {20 $scope.num=0;21 $scope.convertedColumns=[];22 $scope.groupby=[];23 $scope.initUpdateMeasureStatus = function(){24 $scope.updateMeasureStatus = {25 isEdit:false,26 editIndex:-127 }28 };29 $scope.initUpdateMeasureStatus();30 var needLengthKeyList=cubeConfig.needSetLengthEncodingList;31 $scope.getEncodings =function (name){32 var columnType = modelsManager.getColumnTypeByColumnName(name);33 var encodings =$scope.store.supportedEncoding,filterEncoding=[];34 var matchList=VdmUtil.getObjValFromLikeKey($scope.store.encodingMaps,columnType);35 if($scope.isEdit) {36 if (name && $scope.newMeasure.function.configuration&&$scope.newMeasure.function.configuration['topn.encoding.' + name]) {37 var version = $scope.newMeasure.function.configuration['topn.encoding_version.' + name] || 1;38 filterEncoding = VdmUtil.getFilterObjectListByOrFilterVal(encodings, 'value', $scope.newMeasure.function.configuration['topn.encoding.' + name].replace(/:\d+/, "") + (version ? "[v" + version + "]" : "[v1]"), 'suggest', true);39 matchList.push($scope.newMeasure.function.configuration['topn.encoding.' + name].replace(/:\d+/, ""));40 filterEncoding=VdmUtil.getObjectList(filterEncoding,'baseValue',matchList);41 }else{42 filterEncoding=VdmUtil.getFilterObjectListByOrFilterVal(encodings,'suggest', true);43 filterEncoding=VdmUtil.getObjectList(filterEncoding,'baseValue',matchList);44 }45 }else{46 filterEncoding=VdmUtil.getFilterObjectListByOrFilterVal(encodings,'suggest', true);47 filterEncoding=VdmUtil.getObjectList(filterEncoding,'baseValue',matchList);48 }49 return filterEncoding;50 }51 $scope.addNewMeasure = function (measure, index) {52 if(measure&&index>=0){53 $scope.updateMeasureStatus.isEdit = true;54 $scope.updateMeasureStatus.editIndex = index;55 }56 $scope.nextParameters = [];57 $scope.measureParamValueColumn=$scope.getCommonMetricColumns();58 $scope.newMeasure = (!!measure)? jQuery.extend(true, {},measure):CubeDescModel.createMeasure();59 if(!!measure && measure.function.parameter.next_parameter){60 $scope.nextPara.value = measure.function.parameter.next_parameter.value;61 }62 if($scope.newMeasure.function.parameter.value){63 if($scope.metaModel.model.metrics&&$scope.metaModel.model.metrics.indexOf($scope.newMeasure.function.parameter.value)!=-1){64 $scope.newMeasure.showDim=false;65 }else{66 $scope.newMeasure.showDim=true;67 }68 }else{69 $scope.newMeasure.showDim=false;70 }71 $scope.measureParamValueUpdate();72 if($scope.newMeasure.function.expression=="TOP_N"){73 $scope.convertedColumns=[];74 if($scope.newMeasure.function.configuration==null){75 var GroupBy = {76 name:$scope.newMeasure.function.parameter.next_parameter.value,77 encoding:"dict[v1]",78 valueLength:0,79 }80 $scope.convertedColumns.push(GroupBy);81 }82 for(var configuration in $scope.newMeasure.function.configuration) {83 if(/topn\.encoding\./.test(configuration)){84 var _name=configuration.slice(14);85 var item=$scope.newMeasure.function.configuration[configuration];86 var _encoding = item;87 var _valueLength = 0 ;88 var version=$scope.newMeasure.function.configuration['topn.encoding_version.'+_name]||1;89 item=$scope.removeVersion(item);90 var baseKey=item.replace(/:\d+/,'');91 if(needLengthKeyList.indexOf(baseKey)!=-1){92 var result=/:(\d+)/.exec(item);93 _valueLength=result?result[1]:0;94 }95 _encoding=baseKey;96 $scope.GroupBy = {97 name:_name,98 encoding: _encoding + (version ? "[v" + version + "]" : "[v1]"),99 valueLength:_valueLength,100 encoding_version:version||1101 }102 $scope.convertedColumns.push($scope.GroupBy);103 }104 };105 }106 if ($scope.newMeasure.function.expression === 'COUNT_DISTINCT') {107 $scope.convertedColumns=[];108 if ($scope.newMeasure.function.parameter.next_parameter) {109 $scope.recursion($scope.newMeasure.function.parameter.next_parameter, $scope.convertedColumns)110 }111 }112 };113 $scope.updateNextParameter = function(){114 for(var i= 0;i<$scope.nextParameters.length-1;i++){115 $scope.nextParameters[i].next_parameter=$scope.nextParameters[i+1];116 }117 $scope.newMeasure.function.parameter.next_parameter = $scope.nextParameters[0];118 }119 $scope.editNextParameter = function(parameter){120 $scope.openParameterModal(parameter);121 }122 $scope.addNextParameter = function(){123 $scope.openParameterModal();124 }125 $scope.removeParameter = function(parameters,index){126 if(index>-1){127 parameters.splice(index,1);128 }129 $scope.updateNextParameter();130 }131 $scope.nextPara = {132 "type":"column",133 "value":"",134 "next_parameter":null135 }136 $scope.openParameterModal = function (parameter) {137 $modal.open({138 templateUrl: 'nextParameter.html',139 controller: NextParameterModalCtrl,140 resolve: {141 scope: function () {142 return $scope;143 },144 para:function(){145 return parameter;146 }147 }148 });149 };150 $scope.nextParameters =[];151 $scope.removeElement = function (arr, element) {152 var index = arr.indexOf(element);153 if (index > -1) {154 arr.splice(index, 1);155 }156 };157 $scope.clearNewMeasure = function () {158 $scope.newMeasure = null;159 $scope.initUpdateMeasureStatus();160 $scope.nextParameterInit();161 };162 $scope.saveNewMeasure = function () {163 if ($scope.newMeasure.function.expression === 'TOP_N' ) {164 if($scope.newMeasure.function.parameter.value == ""){165 SweetAlert.swal('', '[TOP_N] ORDER|SUM by Column is required', 'warning');166 return false;167 }168 if($scope.convertedColumns.length<1){169 SweetAlert.swal('', '[TOP_N] Group by Column is required', 'warning');170 return false;171 }172 var hasExisted = [];173 for (var column in $scope.convertedColumns){174 if(hasExisted.indexOf($scope.convertedColumns[column].name)==-1){175 hasExisted.push($scope.convertedColumns[column].name);176 }177 else{178 SweetAlert.swal('', 'The column named ['+$scope.convertedColumns[column].name+'] already exits.', 'warning');179 return false;180 }181 if ($scope.convertedColumns[column].encoding == 'int' && ($scope.convertedColumns[column].valueLength < 1 || $scope.convertedColumns[column].valueLength > 8)) {182 SweetAlert.swal('', 'int encoding column length should between 1 and 8.', 'warning');183 return false;184 }185 }186 $scope.nextPara.next_parameter={};187 $scope.newMeasure.function.configuration={};188 $scope.groupby($scope.nextPara);189 angular.forEach($scope.convertedColumns,function(item){190 var a='topn.encoding.'+item.name;191 var versionKey='topn.encoding_version.'+item.name;192 var version=$scope.getTypeVersion(item.encoding);193 var encoding="";194 if(needLengthKeyList.indexOf($scope.removeVersion(item.encoding))!=-1){195 encoding = $scope.removeVersion(item.encoding)+":"+item.valueLength;196 }else{197 encoding = $scope.removeVersion(item.encoding);198 item.valueLength=0;199 }200 $scope.newMeasure.function.configuration[a]= encoding;201 $scope.newMeasure.function.configuration[versionKey]=version;202 });203 }204 if ($scope.newMeasure.function.expression === 'COUNT_DISTINCT' && $scope.newMeasure.function.returntype!=='bitmap') {205 var hasExisted = [];206 for (var column in $scope.convertedColumns){207 if(hasExisted.indexOf($scope.convertedColumns[column].name)==-1){208 hasExisted.push($scope.convertedColumns[column].name);209 }210 else{211 SweetAlert.swal('', 'The column named ['+$scope.convertedColumns[column].name+'] already exits.', 'warning');212 return false;213 }214 }215 $scope.nextPara.next_parameter={};216 if ($scope.convertedColumns.length > 0) {217 $scope.groupby($scope.nextPara);218 } else {219 $scope.nextPara=null;220 $scope.newMeasure.function.parameter.next_parameter=null;221 }222 }223 if ($scope.isNameDuplicated($scope.cubeMetaFrame.measures, $scope.newMeasure) == true) {224 SweetAlert.swal('', 'The measure name: ' + $scope.newMeasure.name + ' is duplicated', 'warning');225 return false;226 }227 if($scope.nextPara && $scope.nextPara.value!=="" && ($scope.newMeasure.function.expression == 'EXTENDED_COLUMN' || $scope.newMeasure.function.expression == 'TOP_N'||$scope.newMeasure.function.expression == 'COUNT_DISTINCT')){228 $scope.newMeasure.function.parameter.next_parameter = jQuery.extend(true,{},$scope.nextPara);229 }230 if($scope.updateMeasureStatus.isEdit == true){231 $scope.cubeMetaFrame.measures[$scope.updateMeasureStatus.editIndex] = $scope.newMeasure;232 }233 else {234 $scope.cubeMetaFrame.measures.push($scope.newMeasure);235 }236 $scope.newMeasure = null;237 $scope.initUpdateMeasureStatus();238 $scope.nextParameterInit();239 return true;240 };241 $scope.isNameDuplicated = function (measures, newMeasure) {242 var names = [];243 for(var i = 0;i < measures.length; i++){244 names.push(measures[i].name);245 }246 var index = names.indexOf(newMeasure.name);247 return (index > -1 && index != $scope.updateMeasureStatus.editIndex);248 }249 $scope.nextParameterInit = function(){250 $scope.nextPara = {251 "type":"column",252 "value":"",253 "next_parameter": null254 }255 if($scope.newMeasure){256 $scope.newMeasure.function.parameter.next_parameter = null;257 }258 }259 $scope.addNewGroupByColumn = function () {260 $scope.nextGroupBy = {261 name:null,262 encoding:"dict[v1]",263 valueLength:0,264 }265 $scope.convertedColumns.push($scope.nextGroupBy);266 };267 $scope.removeColumn = function(arr,index){268 if (index > -1) {269 arr.splice(index, 1);270 }271 };272 $scope.refreshGroupBy=function (list,index,item) {273 var encoding;274 var name = item.name;275 if(item.encoding=="dict" || item.encoding=="date"|| item.encoding=="time"){276 item.valueLength=0;277 }278 };279 $scope.groupby= function (next_parameter){280 if($scope.num<$scope.convertedColumns.length-1){281 next_parameter.value=$scope.convertedColumns[$scope.num].name;282 next_parameter.type="column";283 next_parameter.next_parameter={};284 $scope.num++;285 $scope.groupby(next_parameter.next_parameter);286 }287 else{288 next_parameter.value=$scope.convertedColumns[$scope.num].name;289 next_parameter.type="column";290 next_parameter.next_parameter=null;291 $scope.num=0;292 return false;293 }294 }295 $scope.recursion = function (parameter, list) {296 list.push({name: parameter.value})297 if (parameter.next_parameter) {298 $scope.recursion(parameter.next_parameter, list)299 } else {300 return301 }302 }303 $scope.measureParamValueUpdate = function(){304 if($scope.newMeasure.function.expression !== 'EXTENDED_COLUMN' && $scope.newMeasure.showDim==true){305 $scope.measureParamValueColumn=$scope.getAllModelDimMeasureColumns();306 }307 if($scope.newMeasure.function.expression !== 'EXTENDED_COLUMN' && $scope.newMeasure.showDim==false){308 $scope.measureParamValueColumn=$scope.getCommonMetricColumns();309 }310 if($scope.newMeasure.function.expression == 'EXTENDED_COLUMN'){311 $scope.measureParamValueColumn=$scope.getExtendedHostColumn();312 }313 }314 //map right return type for param315 $scope.measureReturnTypeUpdate = function() {316 if ($scope.newMeasure.function.expression == 'TOP_N') {317 if ($scope.newMeasure.function.parameter.type == "" || !$scope.newMeasure.function.parameter.type) {318 $scope.newMeasure.function.parameter.type = 'column';319 }320 $scope.convertedColumns = [];321 $scope.newMeasure.function.returntype = "topn(100)";322 return;323 } else if ($scope.newMeasure.function.expression == 'COUNT_DISTINCT') {324 $scope.newMeasure.function.parameter.type= 'column';325 $scope.newMeasure.function.returntype = "hllc(10)";326 $scope.convertedColumns = [];327 } else if($scope.newMeasure.function.expression == 'EXTENDED_COLUMN'){328 $scope.newMeasure.function.parameter.type= 'column';329 $scope.newMeasure.function.returntype = "extendedcolumn(100)";330 return;331 }else if($scope.newMeasure.function.expression=='PERCENTILE'){332 $scope.newMeasure.function.parameter.type= 'column';333 }else{334 $scope.nextParameterInit();335 }336 if($scope.newMeasure.function.parameter.type=="constant"&&$scope.newMeasure.function.expression!=="COUNT_DISTINCT"){337 switch($scope.newMeasure.function.expression){338 case "SUM":339 case "COUNT":340 $scope.newMeasure.function.returntype = "bigint";341 break;342 default:343 $scope.newMeasure.function.returntype = "";344 break;345 }346 }347 if($scope.newMeasure.function.parameter.type=="column"&&$scope.newMeasure.function.expression!=="COUNT_DISTINCT"){348 $scope.newMeasure.function.returntype = $scope.getReturnType($scope.newMeasure.function.parameter.value, $scope.newMeasure.function.expression);349 }350 }351 // Open bulk add modal.352 $scope.openBulkAddModal = function () {353 $scope.initBulkAddMeasures();354 var modalInstance = $modal.open({355 templateUrl: 'bulkAddMeasures.html',356 controller: cubeBulkAddMeasureModalCtrl,357 backdrop: 'static',358 scope: $scope359 });360 };361 $scope.initBulkAddMeasures = function() {362 // init bulk add measure view model363 $scope.bulkMeasuresView = {364 SUM: [],365 MAX: [],366 MIN: [],367 RAW: [],368 PERCENTILE: []369 };370 angular.forEach($scope.getCommonMetricColumns(), function(paramValue) {371 var measures = _.filter($scope.cubeMetaFrame.measures, function(measure){ return measure.function.parameter.value == paramValue});372 for (var expression in $scope.bulkMeasuresView) {373 var bulkMeasure = {374 name: expression + '_' + paramValue.split('.')[1],375 parameter: paramValue,376 returntype: $scope.getReturnType(paramValue, expression),377 select: false,378 force: false379 };380 if (measures.length) {381 var measure = _.find(measures, function(measure){ return measure.function.expression == expression});382 if (!!measure) {383 bulkMeasure.name = measure.name;384 bulkMeasure.force = true;385 bulkMeasure.select = true;386 }387 }388 $scope.bulkMeasuresView[expression].push(bulkMeasure);389 }390 });391 // init expression selector392 $scope.bulkMeasureOptions = {393 expressionList: []394 };395 for (var expression in $scope.bulkMeasuresView) {396 var selectArr = _.filter($scope.bulkMeasuresView[expression], function(measure){ return measure.select && measure.force});397 var selectAll = $scope.getCommonMetricColumns().length == selectArr.length;398 var expressionSelect = {399 expression: expression,400 selectAll: selectAll,401 force: selectAll402 }403 $scope.bulkMeasureOptions.expressionList.push(expressionSelect);404 }405 $scope.bulkMeasureOptions.currentExpression = $scope.bulkMeasureOptions.expressionList[0];406 };407 $scope.getReturnType = function(parameter, expression) {408 if(parameter && (typeof parameter=="string")){409 var colType = $scope.getColumnType(VdmUtil.removeNameSpace(parameter), VdmUtil.getNameSpaceAliasName(parameter)); // $scope.getColumnType defined in cubeEdit.js410 }411 if(colType == '' || !colType) {412 return '';413 }414 switch(expression) {415 case 'SUM':416 if(colType === 'tinyint' || colType === 'smallint' || colType === 'int' || colType === 'bigint' || colType === 'integer') {417 return 'bigint';418 } else {419 if(colType.indexOf('decimal') != -1) {420 var returnRegex = new RegExp('(\\w+)(?:\\((\\w+?)(?:\\,(\\w+?))?\\))?');421 var returnValue = returnRegex.exec(colType);422 var precision = returnValue[2] || 0;423 var scale = returnValue[3] || 0;424 return 'decimal(' + precision + ',' + scale + ')';425 }else{426 return colType;427 }428 }429 break;430 case 'MIN':431 case 'MAX':432 return colType;433 break;434 case 'RAW':435 return 'raw';436 break;437 case 'COUNT':438 return 'bigint';439 break;440 case 'PERCENTILE':441 return 'percentile(100)';442 break;443 default:444 return '';445 break;446 }447 };448 if ($scope.state.mode == 'edit') {449 $scope.$on('$destroy', function () {450 // emit measures edit event in order to re-generate advanced dict.451 $scope.$emit('MeasuresEdited');452 });453 }454 $scope.isMeasureUnHidden = function(measure) {455 if (kylinConfig.getHiddenMeasures().indexOf(measure) == -1) {456 return true;457 } else {458 return false;459 }460 }461});462var NextParameterModalCtrl = function ($scope, scope,para,$modalInstance,cubeConfig, CubeService, MessageService, $location, SweetAlert,ProjectModel, loadingRequest,ModelService) {463 $scope.newmea={464 "measure":scope.newMeasure465 }466 $scope.cubeConfig = cubeConfig;467 $scope.cancel = function () {468 $modalInstance.dismiss('cancel');469 };470 $scope.getCommonMetricColumns = function(measure){471 return scope.getCommonMetricColumns(measure);472 }473 $scope.nextPara = {474 "type":"",475 "value":"",476 "next_parameter":null477 }478 var _index = scope.nextParameters.indexOf(para);479 if(para){480 $scope.nextPara = para;481 }482 $scope.ok = function(){483 if(_index!=-1){484 scope.nextParameters[_index] = $scope.nextPara;485 }486 else{487 scope.nextParameters.push($scope.nextPara);488 }489 scope.updateNextParameter();490 $modalInstance.dismiss('cancel');491 }492}493var cubeBulkAddMeasureModalCtrl = function($scope, $modalInstance, SweetAlert) {494 $scope.cancel = function () {495 $modalInstance.dismiss('cancel');496 };497 $scope.saveBulkMeasures = function () {498 $scope.bulkMeasures = [];499 // validation500 loopExp:501 for (var expression in $scope.bulkMeasuresView) {502 loopMeasureView:503 for (var measureView of $scope.bulkMeasuresView[expression]) {504 if (!measureView.force) {505 // validation506 var measureExisted = _.find($scope.cubeMetaFrame.measures, function(measure){ return measure.function.parameter.value == measureView.parameter && measure.function.expression == measureView.expression});507 if (!!measureExisted) {508 $scope.bulkMeasures = [];509 var errMsg = 'Duplicate measure for ' + measureView.name + ' and ' + measureExisted.name + '.';510 break loopExp;511 }512 if (measureView.select) {513 var measure = {514 name: measureView.name,515 function: {516 expression: expression,517 returntype: measureView.returntype,518 parameter: {519 type: 'column',520 value: measureView.parameter521 }522 }523 };524 $scope.bulkMeasures.push(measure);525 }526 }527 }528 }529 if (!!errMsg) {530 SweetAlert.swal('', errMsg, 'warning');531 } else {532 $scope.cubeMetaFrame.measures = $scope.cubeMetaFrame.measures.concat($scope.bulkMeasures);533 $modalInstance.close();534 }535 };536 $scope.selectAll = function() {537 angular.forEach($scope.bulkMeasuresView[$scope.bulkMeasureOptions.currentExpression.expression], function(measure) {538 if (!measure.force) {539 measure.select = $scope.bulkMeasureOptions.currentExpression.selectAll;540 }541 });542 };543 $scope.measureChange = function(measureSelect) {544 if ($scope.bulkMeasureOptions.currentExpression.selectAll) {545 if (!measureSelect) {546 $scope.bulkMeasureOptions.currentExpression.selectAll = false;547 }548 } else {549 for(var measureView of $scope.bulkMeasuresView[$scope.bulkMeasureOptions.currentExpression.expression]) {550 if (!measureView.select) {551 return;552 }553 }554 $scope.bulkMeasureOptions.currentExpression.selectAll = true;555 }556 }...
METRICS.SPEC
Source:METRICS.SPEC
1# VampirTrace metrics specification2#3# measurement definitions complement/extend native (and PAPI preset) definitions4# measured metrics derive from a single measured counter (in principle)5# all measure definitions are considered equivalent6# (though some may be platform-specific)7### generic (PAPI) measurement aliases8### level 1 cache accesses9measure L1_ACCESS = PAPI_L1_TCA10measure L1_I_ACCESS = PAPI_L1_ICA11measure L1_D_ACCESS = PAPI_L1_DCA12### level 1 cache reads13measure L1_READ = PAPI_L1_TCR14measure L1_I_READ = PAPI_L1_ICR # equivalent to PAPI_L1_ICA15measure L1_D_READ = PAPI_L1_DCR16### level 1 cache writes17measure L1_WRITE = PAPI_L1_TCW18measure L1_I_WRITE = PAPI_L1_ICW # never defined19measure L1_D_WRITE = PAPI_L1_DCW20### level 1 cache hits21measure L1_HIT = PAPI_L1_TCH22measure L1_I_HIT = PAPI_L1_ICH23measure L1_D_HIT = PAPI_L1_DCH24### level 1 cache misses25measure L1_MISS = PAPI_L1_TCM26measure L1_I_MISS = PAPI_L1_ICM27measure L1_D_MISS = PAPI_L1_DCM28measure L1_D_READ_MISS = PAPI_L1_LDM29measure L1_D_WRITE_MISS = PAPI_L1_STM30### alternate level 1 cache representation31measure L1_INST = PAPI_L1_ICA32measure L1_INST_HIT = PAPI_L1_ICH33measure L1_INST_MISS = PAPI_L1_ICM34measure L1_LOAD = PAPI_L1_DCR35measure L1_LOAD_HIT = PAPI_L1_LDH # non-standard36measure L1_LOAD_MISS = PAPI_L1_LDM37measure L1_STORE = PAPI_L1_DCW38measure L1_STORE_HIT = PAPI_L1_STH # non-standard39measure L1_STORE_MISS = PAPI_L1_STM40### level 2 cache accesses41measure L2_ACCESS = PAPI_L2_TCA42measure L2_I_ACCESS = PAPI_L2_ICA43measure L2_D_ACCESS = PAPI_L2_DCA44### level 2 cache reads45measure L2_READ = PAPI_L2_TCR46measure L2_I_READ = PAPI_L2_ICR # equivalent to PAPI_L2_ICA47measure L2_D_READ = PAPI_L2_DCR48### level 2 cache writes49measure L2_WRITE = PAPI_L2_TCW50measure L2_I_WRITE = PAPI_L2_ICW # never defined51measure L2_D_WRITE = PAPI_L2_DCW52### level 2 cache hits53measure L2_HIT = PAPI_L2_TCH54measure L2_I_HIT = PAPI_L2_ICH55measure L2_D_HIT = PAPI_L2_DCH56### level 2 cache misses57measure L2_MISS = PAPI_L2_TCM58measure L2_I_MISS = PAPI_L2_ICM59measure L2_D_MISS = PAPI_L2_DCM60measure L2_D_READ_MISS = PAPI_L2_LDM61measure L2_D_WRITE_MISS = PAPI_L2_STM62### alternate level 2 cache representation63measure L2_INST = PAPI_L2_ICA64measure L2_INST_HIT = PAPI_L2_ICH65measure L2_INST_MISS = PAPI_L2_ICM66measure L2_LOAD = PAPI_L2_DCR67measure L2_LOAD_HIT = PAPI_L2_LDH # non-standard68measure L2_LOAD_MISS = PAPI_L2_LDM69measure L2_STORE = PAPI_L2_DCW70measure L2_STORE_HIT = PAPI_L2_STH # non-standard71measure L2_STORE_MISS = PAPI_L2_STM72### level 3 cache accesses73measure L3_ACCESS = PAPI_L3_TCA74measure L3_I_ACCESS = PAPI_L3_ICA75measure L3_D_ACCESS = PAPI_L3_DCA76### level 3 cache reads77measure L3_READ = PAPI_L3_TCR78measure L3_I_READ = PAPI_L3_ICR # equivalent to PAPI_L3_ICA79measure L3_D_READ = PAPI_L3_DCR80### level 3 cache writes81measure L3_WRITE = PAPI_L3_TCW82measure L3_I_WRITE = PAPI_L3_ICW # never defined83measure L3_D_WRITE = PAPI_L3_DCW84### level 3 cache hits85measure L3_HIT = PAPI_L3_TCH86measure L3_I_HIT = PAPI_L3_ICH87measure L3_D_HIT = PAPI_L3_DCH88### level 3 cache misses89measure L3_MISS = PAPI_L3_TCM90measure L3_I_MISS = PAPI_L3_ICM91measure L3_D_MISS = PAPI_L3_DCM92measure L3_D_READ_MISS = PAPI_L3_LDM93measure L3_D_WRITE_MISS = PAPI_L3_STM94### alternate level 3 cache representation95measure L3_INST = PAPI_L3_ICA96measure L3_INST_HIT = PAPI_L3_ICH97measure L3_INST_MISS = PAPI_L3_ICM98measure L3_LOAD = PAPI_L3_DCR99measure L3_LOAD_HIT = PAPI_L3_LDH # non-standard100measure L3_LOAD_MISS = PAPI_L3_LDM101measure L3_STORE = PAPI_L3_DCW102measure L3_STORE_HIT = PAPI_L3_STH # non-standard103measure L3_STORE_MISS = PAPI_L3_STM104### TLB misses105measure TLB_MISS = PAPI_TLB_TL106measure TLB_I_MISS = PAPI_TLB_IM107measure TLB_D_MISS = PAPI_TLB_DM108### instructions109measure INSTRUCTION = PAPI_TOT_INS110measure INTEGER = PAPI_INT_INS111measure FLOATING_POINT = PAPI_FP_INS112measure FP_ADD = PAPI_FAD_INS113measure FP_MUL = PAPI_FML_INS114measure FP_FMA = PAPI_FMA_INS115measure FP_DIV = PAPI_FDV_INS116measure FP_INV = PAPI_FNV_INS117measure FP_SQRT = PAPI_FSQ_INS118measure VECTOR = PAPI_VEC_INS119measure SYNCH = PAPI_SYC_INS120measure LOAD_STORE = PAPI_LST_INS121measure LOAD = PAPI_LD_INS122measure STORE = PAPI_SR_INS123measure COND_STORE = PAPI_CSR_TOT124measure COND_STORE_SUCCESS = PAPI_CSR_SUC125measure COND_STORE_UNSUCCESS = PAPI_CSR_FAL126measure BRANCH = PAPI_BR_INS127measure UNCOND_BRANCH = PAPI_BR_UCN128measure COND_BRANCH = PAPI_BR_CN129measure COND_BRANCH_TAKEN = PAPI_BR_TKN130measure COND_BRANCH_NOTTAKEN = PAPI_BR_NTK131measure COND_BRANCH_PRED = PAPI_BR_PRC132measure COND_BRANCH_MISPRED = PAPI_BR_MSP133### cycles134measure CYCLES = PAPI_TOT_CYC135### idle units136measure INTEGER_UNIT_IDLE = PAPI_FXU_IDL137measure FLOAT_UNIT_IDLE = PAPI_FPU_IDL138measure BRANCH_UNIT_IDLE = PAPI_BRU_IDL139measure LOADSTORE_UNIT_IDLE = PAPI_LSU_IDL140### stalls141measure STALL_MEMORY_ACCESS = PAPI_MEM_SCY142measure STALL_MEMORY_READ = PAPI_MEM_RCY143measure STALL_MEMORY_WRITE = PAPI_MEM_WCY144measure STALL_INST_ISSUE = PAPI_STL_ICY145# platform-specific measurement aliases146# (complement or redefine generic measurement aliases)147# may need to key to particular platform if ambiguity148### POWER4-specific metrics149measure FP_LOAD = PM_LSU_LDF150measure FP_STORE = PM_FPU_STF151measure FP_MISC = PM_FPU_FMOV_FEST152### UltraSPARC-III/IV-specific metrics153measure STALL_L1_MISS = Re_DC_miss # /1154measure STALL_L2_MISS = Re_EC_miss # /1155measure STALL_IC_MISS = Dispatch0_IC_miss # /0156measure STALL_STOREQ = Rstall_storeQ # /0157measure STALL_IU_USE = Rstall_IU_use # /0158measure STALL_FP_USE = Rstall_FP_use # /1159measure STALL_PC_MISS = Re_PC_miss # /1160measure STALL_RAW_MISS = Re_RAW_miss # /1161measure STALL_FPU_BYPASS = Re_FPU_bypass # /1162measure STALL_MISPRED = Dispatch0_mispred # /1163measure STALL_BR_TARGET = Dispatch0_br_target # /0164measure STALL_2ND_BR = Dispatch0_2nd_br # /0165measure STALL_L1_MSOVHD = Re_DC_missovhd # /1166### groupings of metrics for collective measurement167### Opteron groupings (max 4 in group, unrestricted)168aggroup OPTERON_DC1 = DC_ACCESS DC_MISS DC_L2_REFILL_I DC_SYS_REFILL_I169aggroup OPTERON_DC2 = DC_L2_REFILL_M DC_L2_REFILL_O DC_L2_REFILL_E DC_L2_REFILL_S170aggroup OPTERON_DC3 = DC_SYS_REFILL_M DC_SYS_REFILL_O DC_SYS_REFILL_E DC_SYS_REFILL_S171aggroup OPTERON_IC = IC_FETCH IC_MISS IC_L2_REFILL IC_SYS_REFILL172aggroup OPTERON_TLB = DC_L1_DTLB_MISS_AND_L2_DTLB_MISS DC_L1_DTLB_MISS_AND_L2_DTLB_HIT IC_L1ITLB_MISS_AND_L2ITLB_MISS IC_L1ITLB_MISS_AND_L2ITLB_HIT173aggroup OPTERON_BR = FR_BR FR_BR_MIS FR_BR_TAKEN FR_BR_TAKEN_MIS174aggroup OPTERON_FP = FP_ADD_PIPE FP_MULT_PIPE FP_ST_PIPE FP_FAST_FLAG175aggroup OPTERON_FPU = FR_FPU_X87 FR_FPU_MMX_3D FR_FPU_SSE_SSE2_PACKED FR_FPU_SSE_SSE2_SCALAR176aggroup OPTERON_ST1 = IC_FETCH_STALL FR_DECODER_EMPTY FR_DISPATCH_STALLS FR_DISPATCH_STALLS_FULL_FPU177aggroup OPTERON_ST2 = FR_DISPATCH_STALLS_FULL_LS FR_DISPATCH_STALLS_FULL_REORDER FR_DISPATCH_STALLS_FULL_RESERVATION FR_DISPATCH_STALLS_BR178aggroup OPTERON_ST3 = FR_DISPATCH_STALLS_FAR FR_DISPATCH_STALLS_SER FR_DISPATCH_STALLS_SEG FR_DISPATCH_STALLS_QUIET179aggroup OPTERON_ETC = FR_X86_INS CPU_CLK_UNHALTED FR_HW_INTS FP_NONE_RET180aggroup OPTERON_HTM = HT_LL_MEM_XFR HT_LR_MEM_XFR HT_RL_MEM_XFR181aggroup OPTERON_HTI = HT_LL_IO_XFR HT_LR_IO_XFR HT_RL_IO_XFR182### POWER4-specific groupings (max 8 in group, restricted)183aggroup POWER4_DC = PM_DATA_FROM_L2 PM_DATA_FROM_L25_SHR PM_DATA_FROM_L25_MOD PM_DATA_FROM_L275_SHR PM_DATA_FROM_L275_MOD PM_DATA_FROM_L3 PM_DATA_FROM_L35 PM_DATA_FROM_MEM # 5184aggroup POWER4_IC = PM_INST_FROM_PREF PM_INST_FROM_L1 PM_INST_FROM_L2 PM_INST_FROM_L25_L275 PM_INST_FROM_L3 PM_INST_FROM_L35 PM_INST_FROM_MEM # 6185aggroup POWER4_L1 = PM_LD_REF_L1 PM_LD_MISS_L1 PM_ST_REF_L1 PM_ST_MISS_L1 # 56186aggroup POWER4_TLB = PM_ITLB_MISS PM_DTLB_MISS187aggroup POWER4_LX = PM_ITLB_MISS PM_DTLB_MISS PM_LD_REF_L1 PM_LD_MISS_L1 PM_ST_REF_L1 PM_ST_MISS_L1 # 56188aggroup POWER4_BR = PM_BR_ISSUED PM_BR_MPRED_CR PM_BR_MPRED_TA # 3,55,61189aggroup POWER4_BRT = PM_BR_ISSUED PM_BR_MPRED_CR PM_BR_MPRED_TA PM_BIQ_IDU_FULL_CYC PM_BRQ_FULL_CYC PM_L1_WRITE_CYC PM_INST_CMPL PM_CYC # 55190aggroup POWER4_LSF = PM_FPU_STF PM_LSU_LDF # 15,54,60191aggroup POWER4_STL = PM_CYC PM_FPU_FULL_CYC PM_FPU_STALL3 # 54192aggroup POWER4_LST = PM_INST_CMPL PM_FPU_STF PM_LSU_LDF PM_CYC PM_FPU_FULL_CYC PM_FPU_STALL3 # 54193aggroup POWER4_FP = PM_FPU_FIN PM_FPU_FMA PM_FPU_FDIV PM_FPU_FSQRT PM_FPU_FMOV_FEST # 53194aggroup POWER4_IFP = PM_FPU_FIN PM_FPU_FMA PM_FPU_FDIV PM_FPU_FSQRT PM_FPU_FMOV_FEST PM_FXU_FIN # 53195aggroup POWER4_II = PM_INST_DISP PM_INST_CMPL # 1,2,18,20196### MIPS-R1200 groupings (max 32 in group, unrestricted)197aggroup R12000_ALL = TLB_misses primary_data_cache_misses secondary_data_cache_misses primary_instruction_cache_misses secondary_instruction_cache_misses graduated_instructions mispredicted_branches graduated_loads graduated_stores graduated_floating-point_instructions decoded_instructions cycles prefetch_primary_data_cache_misses198aggroup R12000_ALL_PAPI = PAPI_L1_DCM PAPI_L1_ICM PAPI_L2_DCM PAPI_L2_ICM PAPI_TLB_TL PAPI_TOT_INS PAPI_FP_INS PAPI_LD_INS PAPI_SR_INS PAPI_TOT_IIS PAPI_BR_CN PAPI_BR_MSP PAPI_CSR_TOT PAPI_CSR_FAL PAPI_TOT_CYC PAPI_PRF_DM PAPI_CA_INV PAPI_CA_ITV199### UltraSPARC-III/IV groupings (max 2 in group, restricted)200aggroup US3_CPI = Cycle_cnt Instr_cnt # duplicates201# cycles/stalls groups202aggroup US3_SMP = Dispatch_rs_mispred Dispatch0_mispred # stall misprediction203aggroup US3_SUS = Rstall_IU_use Rstall_FP_use # stall IU/FP use204aggroup US3_SST = Rstall_storeQ Re_RAW_miss # stall store205aggroup US3_SCD = Cycle_cnt Re_DC_miss206aggroup US3_SCO = Dispatch0_br_target Re_DC_missovhd207aggroup US3_SCE = Dispatch0_2nd_br Re_EC_miss208aggroup US3_SCP = Dispatch0_IC_miss Re_PC_miss209aggroup US3_SCX = SI_ciq_flow Re_FPU_bypass # Re_FPU_bypass always zero?210# instruction and TLB groups211aggroup US3_FPU = FA_pipe_completion FM_pipe_completion212aggroup US3_BMS = IU_Stat_Br_miss_taken IU_Stat_Br_miss_untaken213aggroup US3_BCS = IU_Stat_Br_count_taken IU_Stat_Br_count_untaken214aggroup US3_ITL = Instr_cnt ITLB_miss215aggroup US3_DTL = Cycle_cnt DTLB_miss216# memory and cache groups217aggroup US3_ICH = IC_ref IC_miss218aggroup US3_DCR = DC_rd DC_rd_miss219aggroup US3_DCW = DC_wr DC_wr_miss220aggroup US3_ECI = EC_write_hit_RTO EC_ic_miss221aggroup US3_ECM = EC_rd_miss EC_misses 222# locality/SSM and other miscellaneous groups223aggroup US3_ECL = EC_miss_local EC_miss_remote # only SF15000/SF25000224aggroup US3_ECX = EC_wb_remote EC_miss_mtag_remote # only SF15000/SF25000225aggroup US3_ECW = EC_ref EC_wb226aggroup US3_ECS = EC_snoop_inv EC_snoop_cb227aggroup US3_PCR = PC_port0_rd PC_port1_rd228aggroup US3_ETC = SI_snoop PC_MS_misses229aggroup US3_WCM = SI_owned WC_miss230# memory controller groups231aggroup US3_SM1 = MC_stalls_0 MC_stalls_1232aggroup US3_SM2 = MC_stalls_2 MC_stalls_3233aggroup US3_MC0 = MC_reads_0 MC_writes_0234aggroup US3_MC1 = MC_reads_1 MC_writes_1235aggroup US3_MC2 = MC_reads_2 MC_writes_2236aggroup US3_MC3 = MC_reads_3 MC_writes_3237### Itanium2 groupings (max 4 in group, partially restricted)238aggroup ITANIUM2_TLB = ITLB_MISSES_FETCH_L1ITLB ITLB_MISSES_FETCH_L2ITLB L2DTLB_MISSES L1DTLB_TRANSFER239aggroup ITANIUM2_BR = BRANCH_EVENT BR_MISPRED_DETAIL_ALL_CORRECT_PRED BR_MISPRED_DETAIL_ALL_WRONG_PATH BR_MISPRED_DETAIL_ALL_WRONG_TARGET240aggroup ITANIUM2_STL = DISP_STALLED BACK_END_BUBBLE_ALL BE_EXE_BUBBLE_ALL BE_EXE_BUBBLE_FRALL241aggroup ITANIUM2_L1D = DATA_REFERENCES_SET1 L1D_READS_SET1 L1D_READ_MISSES_ALL L2_DATA_REFERENCES_L2_ALL242aggroup ITANIUM2_L2D = L2_DATA_REFERENCES_L2_DATA_READS L2_DATA_REFERENCES_L2_DATA_WRITES L3_READS_DATA_READ_ALL L3_WRITES_DATA_WRITE_ALL243aggroup ITANIUM2_L3D = L3_READS_DATA_READ_HIT L3_READS_DATA_READ_MISS L3_WRITES_DATA_WRITE_HIT L3_WRITES_DATA_WRITE_MISS244aggroup ITANIUM2_LXD = L2_MISSES L3_REFERENCES L3_READS_ALL_MISS L3_WRITES_ALL_MISS245aggroup ITANIUM2_LXX = L3_MISSES L3_WRITES_L2_WB_HIT L3_WRITES_L2_WB_MISS246aggroup ITANIUM2_ICD = L1I_READS L2_INST_DEMAND_READS L3_READS_DINST_FETCH_HIT L3_READS_DINST_FETCH_MISS # instruction cache (demand-load only)247aggroup ITANIUM2_ICP = L1I_PREFETCHES L2_INST_PREFETCHES L3_READS_INST_FETCH_HIT L3_READS_INST_FETCH_MISS # instruction cache (incl. prefetch)248aggroup ITANIUM2_IN1 = INST_DISPERSED IA32_INST_RETIRED IA64_INST_RETIRED LOADS_RETIRED249aggroup ITANIUM2_IN2 = FP_OPS_RETIRED LOADS_RETIRED CPU_CYCLES ISA_TRANSITIONS250aggroup ITANIUM2_ISA = IA32_INST_RETIRED IA64_INST_RETIRED IA32_ISA_TRANSITIONS STORES_RETIRED251aggroup ITANIUM2_FLP = CPU_CYCLES FP_OPS_RETIRED INST_DISPERSED LOADS_RETIRED252### compositions are derived by combining measurements and create hierarchies253### **** generic hierarchy ****254### cycles (including stalls)255compose CYCLES = BUSY + STALL + IDLE256compose STALL = DISPATCH + UNIT_USE + RECIRCULATE257### instructions258compose INSTRUCTION = BRANCH + INTEGER + FLOATING_POINT + MEMORY259compose BRANCH = BRANCH_PRED + BRANCH_MISP260compose FLOATING_POINT = FP_ADD + FP_MUL + FP_FMA + FP_DIV + FP_INV + FP_SQRT + FP_MISC261compose MEMORY = LOAD + STORE + SYNCH262### data accesses (to cache hierarchy & memory)263compose DATA_ACCESS = DATA_HIT_L1$ + DATA_HIT_L2$ + DATA_HIT_L3$ + DATA_HIT_MEM264compose DATA_HIT_L1$ = DATA_STORE_INTO_L1$ + DATA_LOAD_FROM_L1$265compose DATA_HIT_L2$ = DATA_STORE_INTO_L2$ + DATA_LOAD_FROM_L2$266compose DATA_HIT_L3$ = DATA_STORE_INTO_L3$ + DATA_LOAD_FROM_L3$267compose DATA_HIT_MEM = DATA_STORE_INTO_MEM + DATA_LOAD_FROM_MEM268### instruction accesses (to cache hierarchy & memory)269compose INST_ACCESS = INST_HIT_PREF + INST_HIT_L1$ + INST_HIT_L2$ + INST_HIT_L3$ + INST_HIT_MEM270### TLB accesses (instruction & data)271compose TLB_ACCESS = DATA_TLB_ACCESS + INST_TLB_ACCESS272compose DATA_TLB_ACCESS = DATA_TLB_HIT + DATA_TLB_MISS...
main.py
Source:main.py
1from Utils.SQL import sqlite_python as sql2from Utils.connection import connection_methods as connection_m3from Utils.data_processing import data_processing as dp4from Utils.date import date5from Utils.Console.console_manager import BeautifulPrint6import keyboard7# Establishing connection8ser = connection_m.connection_serial()9# Creating database10data_base = sql.DataBase('data_base')11data_base.create_table('materials', ['bar_code TEXT NOT NULL', 'name TEXT NOT NULL', 'measure REAL NOT NULL',12 'total_measure REAL NOT NULL', 'price REAL NOT NULL',13 'expiration_date TEXT NOT NULL', 'registration_date TEXT NOT NULL'])14data_base.create_table('materials_used', ['bar_code TEXT NOT NULL', 'name TEXT NOT NULL', 'measure REAL NOT NULL',15 'fraction_price REAL NOT NULL', 'expiration_date',16 'registration_date TEXT NOT NULL'])17# Methods18def consumed_material(table_to_send, _transfer_measure):19 """20 Consume the material21 :param table_to_send: table that will receive the material;22 :param _transfer_measure: Measure that will be transfer;23 """24 material_used_measure = 025 if _transfer_measure == 0:26 return None27 material_measure = dp.named_data(data_base, 'materials', bar_code).measure28 try:29 material_used_measure_t = dp.named_data(data_base, 'materials_used', bar_code).measure30 except AttributeError:31 pass32 else:33 material_used_measure = material_used_measure_t34 measurement_difference = material_measure - _transfer_measure35 price = dp.named_data(data_base, 'materials', bar_code).price36 total_measure = dp.named_data(data_base, 'materials', bar_code).total_measure37 formula = (price * _transfer_measure) / total_measure38 if material_measure == float(0):39 data_base.__delitem__('materials', 'bar_code', bar_code)40 return None41 if _transfer_measure > material_measure:42 print(f'Maximum transfer: {material_measure}')43 return None44 if _transfer_measure < float(0):45 if (_transfer_measure * -1) > material_used_measure:46 print(f'Maximum transfer: {material_used_measure}')47 return None48 data_base.update_value('materials', 'bar_code', bar_code, 'measure', measurement_difference)49 _materials_used = dp.named_data(data_base, 'materials_used', bar_code)50 fraction_price = formula51 if _materials_used is None:52 data_base.insert_data('materials_used', [bar_code, captured_inf.name, _transfer_measure, fraction_price,53 captured_inf.expiration_date, date.get_date()])54 else:55 sum_of_measure = dp.named_data(data_base, 'materials_used', bar_code).measure + _transfer_measure56 sum_of_fraction_price = dp.named_data(data_base, 'materials_used', bar_code).fraction_price + fraction_price57 data_base.update_value(dp.string_treatment(table_to_send), 'bar_code', bar_code, 'measure', sum_of_measure)58 data_base.update_value(dp.string_treatment(table_to_send), 'bar_code', bar_code, 'fraction_price',59 sum_of_fraction_price)60def register_material(table_name, _bar_code):61 """62 Register material;63 :param table_name: Name of table;64 :param _bar_code: Bar code to analyze.65 :return:66 """67 _material_name = dp.string_handling('Enter the material name')68 _material_measure = dp.float_treatment('Enter the material measure')69 _material_price = dp.float_treatment('Enter the material price')70 _material_expiration_date = dp.date_treatment('Enter the material expiration date')71 _total_measure = _material_measure72 if _material_name is None or _material_measure is None or _material_price is None or \73 _material_expiration_date is None:74 print('Registration canceled!')75 pass76 else:77 data_base.insert_data(dp.string_treatment(table_name), [_bar_code, _material_name, _material_measure,78 _total_measure, _material_price,79 _material_expiration_date, date.get_date()])80 print(f'Code |{bar_code}| registered!')81# Loop82if __name__ == '__main__':83 while True:84 bar_code = connection_m.read_serial_data(ser)85 if bar_code != '':86 named_material = dp.named_data(data_base, 'materials', bar_code)87 if named_material is None:88 register_material('materials', bar_code)89 else:90 captured_inf = dp.named_data(data_base, 'materials', bar_code)91 BeautifulPrint().print_table(captured_inf)92 transfer_measure = dp.float_treatment('Transfer measure')93 print('\n')94 if transfer_measure is not None:95 consumed_material('materials_used', transfer_measure)96 if keyboard.is_pressed('q'):...
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!!