Download code/validation/JavaScript/0060223_adjust.module.js from Variable-role/sajaniemi_variable_dataset_large: direct link, hf CLI and curl.
- Browser
- Download file 6.38 kB
-
https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/code/validation/JavaScript/0060223_adjust.module.js
- Command line
-
hf download hf://datasets/Variable-role/sajaniemi_variable_dataset_large/code/validation/JavaScript/0060223_adjust.module.js
-
curl -L -o 0060223_adjust.module.js https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/code/validation/JavaScript/0060223_adjust.module.js
6.38 kB
| angular.module("tbs.adjust", ["tbs.common"]).controller("AdjustController", | |
| function AdjustController($rootScope, $scope, $http, $uibModal, | |
| $filter, tbsWS, config, utils, auth) { | |
| $rootScope.title = "校秤"; | |
| $scope.item = null; | |
| $scope.method="method1"; | |
| $scope.stepNum = 0; | |
| $scope.valueIndex = 0; | |
| $scope.isGoing=false;// if user is adjusting, this value is true; | |
| $scope.isCurrentStep = function(stepName){ | |
| return (stepName === $scope.method+'_'+$scope.stepNum)&&$scope.isGoing; | |
| }; | |
| $scope.adjustMethods = { | |
| method1: { | |
| values: [] | |
| }, | |
| method2: { | |
| values: [] | |
| }, | |
| method3: { | |
| values: [] | |
| } | |
| }; | |
| $scope.$watch('isGoing',function(newValue,oldValue){ | |
| if(!$scope.adjustForm){ | |
| return; | |
| } | |
| if(newValue===true){ | |
| $scope.adjustForm.$setDirty(); | |
| }else{ | |
| $scope.adjustForm.$setPristine(); | |
| $scope.adjustForm.$setUntouched(); | |
| } | |
| }); | |
| $scope.preSelect = function (s){ | |
| if(s.scaleNum === $scope.item.scaleNum && $scope.isGoing){ | |
| return; | |
| } | |
| if($scope.isGoing){ | |
| utils.confirmDataLost($scope.adjustForm).then( | |
| function(){ | |
| $scope.selectItem(s); | |
| } | |
| ); | |
| }else{ | |
| $scope.selectItem(s); | |
| } | |
| }; | |
| $scope.selectItem = function (s) { | |
| $scope.isGoing = false; | |
| $scope.item = s; | |
| $scope.stepNum = 0; | |
| $scope.valueIndex = 0; | |
| //Init method1 value | |
| //$scope.adjustMethods.method1.values.length=10; | |
| function makeValue1_2() { | |
| var v = { | |
| target: s.adjustWeight, | |
| actul: undefined, | |
| lowLimit: s.adjustWeight - s.adjustTolerance, | |
| upLimit: s.adjustWeight + s.adjustTolerance | |
| }; | |
| return v | |
| }; | |
| function makeValue3(value, index) { | |
| if (index == 0 ) { | |
| return { | |
| target: 0, | |
| actul: undefined, | |
| lowLimit: 0, | |
| upLimit: 0 | |
| } | |
| } else { | |
| return { | |
| target: s["lineAdjustWeight" + index], | |
| actul: undefined, | |
| lowLimit: s["lineAdjustWeight" + index] - s["lineAdjustTole" + index], | |
| upLimit: s["lineAdjustWeight" + index] + s["lineAdjustTole" + index] | |
| } | |
| } | |
| }; | |
| $scope.adjustMethods.method1.values = new Array(5).fill().map(makeValue1_2); | |
| $scope.adjustMethods.method2.values = new Array(10).fill().map(makeValue1_2); | |
| //Init method2 value | |
| var a1 = new Array(4).fill().map(makeValue3); | |
| var a2 = new Array(4).fill().map(makeValue3); | |
| $scope.adjustMethods.method3.values =a1.concat(a2.reverse()); | |
| // $scope.adjustMethods.method4.values = new Array(4).fill().map(makeValue4); | |
| }; | |
| $scope.start = function () { | |
| console.log("HI"); | |
| $scope.isGoing = true; | |
| tbsWS.switch($scope.item.scaleNum); | |
| tbsWS.ZI().then(function () { | |
| tbsWS.SIR(); | |
| }); | |
| $scope.adjust($scope.method); | |
| // | |
| }; | |
| $scope.adjust = function (methodName) { | |
| var currentMethod = methodName; | |
| //var $scope.stepNum = 0; | |
| var justCompleteAstep = false; //标志是否刚刚完成一个校验值 | |
| if (methodName === 'method1' || methodName === 'method2') { | |
| tbsWS.setCallback(function (w) { | |
| var lowLimit = $scope.adjustMethods[currentMethod].values[$scope.stepNum].lowLimit; | |
| var upLimit = $scope.adjustMethods[currentMethod].values[$scope.stepNum].upLimit; | |
| var valueCount = $scope.adjustMethods[currentMethod].values.length; | |
| $scope.scaleWeighting = angular.copy(w); | |
| var weighting = $scope.scaleWeighting.weighting; | |
| if (weighting == 0 && w.status === 'S') { | |
| //If 0 S, means a new step start | |
| if (justCompleteAstep) { | |
| justCompleteAstep = false; | |
| $scope.stepNum++; | |
| console.log("S:" + $scope.stepNum); | |
| if ($scope.stepNum > (valueCount - 1)) { | |
| tbsWS.cancelCallback(); | |
| $scope.isGoing = false; | |
| var adjustLog = { | |
| "methodNum" : methodName, | |
| "scaleNum" : $scope.item.scaleNum | |
| }; | |
| $scope.selectItem($scope.item); | |
| $http.post(config.baseUrl + "adjustLog", adjustLog).then(function (response) { | |
| utils.showDialog({ | |
| title: "消息", | |
| message: "校秤信息保存成功!", | |
| type: "success" | |
| }); | |
| }); | |
| } | |
| } | |
| } else if ((lowLimit <= weighting) && (weighting <= upLimit) && w.status === 'S') { | |
| // valid | |
| $scope.adjustMethods[currentMethod].values[$scope.stepNum].actul = weighting; | |
| justCompleteAstep = true; | |
| console.log(currentMethod, $scope.stepNum, weighting); | |
| } | |
| $scope.$apply(); | |
| } | |
| ); | |
| } else { | |
| tbsWS.setCallback(function (w) { | |
| var lowLimit = $scope.adjustMethods[currentMethod].values[$scope.stepNum].lowLimit; | |
| var upLimit = $scope.adjustMethods[currentMethod].values[$scope.stepNum].upLimit; | |
| var valueCount = $scope.adjustMethods[currentMethod].values.length; | |
| $scope.scaleWeighting = angular.copy(w); | |
| var weighting = $scope.scaleWeighting.weighting; | |
| if ((lowLimit <= weighting) && (weighting <= upLimit) && w.status === 'S') { | |
| // valid | |
| $scope.adjustMethods[currentMethod].values[$scope.stepNum].actul = weighting; | |
| $scope.stepNum++; | |
| if ($scope.stepNum > (valueCount - 1)) { | |
| $scope.$apply(); | |
| tbsWS.cancelCallback(); | |
| var adjustLog = { | |
| "methodNum" : methodName, | |
| "scaleNum" : $scope.item.scaleNum | |
| }; | |
| $scope.isGoing = false; | |
| $scope.selectItem($scope.item); | |
| $http.post(config.baseUrl + "adjustLog", adjustLog).then(function (response) { | |
| utils.showDialog({ | |
| title: "消息", | |
| message: "校秤信息保存成功!", | |
| type: "success" | |
| }); | |
| }); | |
| } | |
| console.log(currentMethod, $scope.stepNum, weighting); | |
| } | |
| $scope.$apply(); | |
| } | |
| ); | |
| } | |
| }; | |
| $scope.cancel = function () { | |
| $scope.isGoing = false; | |
| $scope.selectItem($scope.item); | |
| tbsWS.cancelCallback(); | |
| }; | |
| $scope.init = function () { | |
| //$http.get(config.baseUrl + "scaleSetting").then(function (response) { | |
| tbsWS.getScales().then(function (response) { | |
| $rootScope.scales = response.data; | |
| $scope.scales = $rootScope.scales.filter(function (scale) { return scale && scale.isConnected; }); | |
| if ($scope.scales && $scope.scales.length > 0 && $scope.item == null) { | |
| $scope.selectItem($rootScope.scales[0]); | |
| } | |
| }); | |
| }; | |
| $scope.init(); | |
| }); |