JS总时间计算

时间:2018-07-27 11:17:01

标签: javascript time

JSON文件:

foo <- function(df){
 a1 <- broom::tidy(t.test(age~gender, data=df))
 a2 <- broom::tidy(t.test(df$age))
 a3 <- broom::tidy(t.test(df$age[df$gender == 1]))
 a4 <- broom::tidy(t.test(df$age[df$gender == 2]))
 list(rbind(a2, a3, a4), a1)
}

foo(cohort)
[[1]]
  estimate statistic      p.value parameter conf.low conf.high            method alternative
1 27.58000 18.301678 1.543834e-33        99 24.58985  30.57015 One Sample t-test   two.sided
2 25.12121  9.545737 6.982763e-11        32 19.76068  30.48174 One Sample t-test   two.sided
3 28.79104 15.699854 5.700541e-24        66 25.12966  32.45243 One Sample t-test   two.sided

[[2]]
   estimate estimate1 estimate2 statistic   p.value parameter  conf.low conf.high                  method alternative
1 -3.669833  25.12121  28.79104 -1.144108 0.2568817  63.37702 -10.07895  2.739284 Welch Two Sample t-test   two.sided

我想要什么:
找出总投入与总产出之间的差异

我该怎么做?

1 个答案:

答案 0 :(得分:1)

您可以使用array.reduce并找到每个 "Exit" "Enter" 的总和,然后找出两者之间的差异,

演示

angular.module('MyModule', [])

.controller( 'MyController', function($scope){

    $scope.myjson = 
[   {
        "action1": "enter",
        "time": "13.00"
    },
    {
        "action2": "exit",
        "time": "13.20"
    },
    {
        "action1": "enter",
        "time": "13.50"
    },
    {
        "action2": "exit",
        "time": "15.00"
    },
    {
        "action1": "enter",
        "time": "16.00"
    },
    {
        "action2": "exit",
        "time": "20.00"
    }
];    
    
   $scope.sumByExit = function() {
    var total = 0;
    for (count = 0; count < $scope.myjson.length; count++) {
      if($scope.myjson[count].action1 === "exit")
      total += $scope.myjson[count].time;
    }
    return total
    }
    $scope.sumByEnter = function() {
    var total = 0;
    for (count = 0; count < $scope.myjson.length; count++) {
      if($scope.myjson[count].action1 === "enter")
      total += $scope.myjson[count].time;
    }
    return total
    }
   

    $scope.totalExit = $scope.sumByExit();   
    console.log($scope.totalExit);
    $scope.totalEnter = $scope.sumByEnter();
    $scope.totaldifference = parseInt($scope.totalExit) - parseInt($scope.totalEnter);
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app='MyModule' ng-controller='MyController'>
 
    <p>Difference = {{totaldifference}}</p>
</div>