📄 stat.java
字号:
package model;//Copyright (C) 2008 Harald Unander, Wang Wenjuan//// This file is part of WlanTV.//// WlanTV is free software: you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation, either version 3 of the License, or// (at your option) any later version.//// WlanTV is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.//// You should have received a copy of the GNU General Public License// along with WlanTV. If not, see <http://www.gnu.org/licenses/>.import java.util.ArrayList;public class Stat { double sdMean; private int min = 1000; private int max = -1000; private long sum; private ArrayList<Integer> list = new ArrayList<Integer>(); public void calc(int diff) {// System.out.println(diff+" "+min+" "+max+" "+list.size()); min = Math.min(min,diff); max = Math.max(max,diff); sum += diff; list.add(diff); } public double standardDeviation(Integer[] data) { long sdSum = 0; double totalVariance = 0; if (data.length==0 || data.length==1) return 0; for(int d: data) sdSum += d; sdMean = sdSum/data.length; for(int d: data) totalVariance += Math.pow(d-sdMean,2); double sd = Math.sqrt(totalVariance/(data.length-1));// return 1.96*sd/Math.sqrt((double)data.length); return sd; } public String get() { String s = ""; if (list.size() > 0) { double SD = standardDeviation(list.toArray(new Integer[list.size()])); s = Math.round(sum/list.size())+" "+ min+"/"+max+" "+ "SD:"+String.format("%.1f",SD);// "95%:"+Math.round(sdMean-2*SD)+"/"+Math.round(sdMean+2*SD); } return s; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -