2013-03-25 80 views
0

我需要計算我公司在倉庫的平均每日增長量,但我懷疑,正確的方法是什麼? 對不起,使用谷歌翻譯。 =)如何計算我的倉庫每天的平均增長量?

空間用於存儲:

f_date  f_used 
12/03/2013 2708100 
13/03/2013 2708663 
14/03/2013 2712155 
15/03/2013 2715932 
16/03/2013 2717823 
17/03/2013 2719575 
18/03/2013 2723095 
19/03/2013 2726682 
20/03/2013 2730365 
21/03/2013 2733563 
22/03/2013 2737411 
23/03/2013 2644001 
24/03/2013 2645764 

我在PHP代碼:

for ($i = 1; $i < sizeof($array); $i++) { 
$resultado[] = $array[$i] - $array[$i-1]; 
} 
echo array_sum($resultado)/count($resultado); 

我的結果是: -5194.6666666667,是錯了?

+0

我覺得應該是'$ I = 0'在'一開始for'聲明。 – 2013-03-25 13:50:25

+0

@ EM-Creations當'$ i = 0' ..'$ i - 1 = -1'時超出範圍 – Kermit 2013-03-25 13:53:10

+0

@PolishPrince啊,是的,我看到他現在已經做到了。 – 2013-03-25 13:57:22

回答

0

該算法是正確的,併爲您提供日差的平均值

例子:

f_date  f_used difference 
12/03/2013 2708100 
13/03/2013 2708663 563 
14/03/2013 2712155 3492 
        ---- 
        4055
4055/2 (difference count) = 2027.5 

See the demo

+0

嗨,我的問題是負面差異 – user2207673 2013-03-25 14:35:47

+0

@ user2207673然後使用'$ resultado [] = abs($ array [$ i] - $ array [$ i-1]);'。在其解決方案中, – Kermit 2013-03-25 14:36:51

+0

顯示10gb的日常增長,這些信息會出錯,我認爲計算平均值僅需2天就是正確的。 – user2207673 2013-03-25 14:47:51