Advertisement
Guest User

Untitled

a guest
Apr 15th, 2014
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. function getSellPrice($db, $omc){
  2. $realPrice = 0; //Init variable for real price.
  3. $totalSells = 0; //Total number of sells.
  4. $arr = array();
  5.  
  6. $query = $db->query("SELECT * FROM trans censored ;) WHERE category='sell' AND username='example'");
  7. $buysCount = $query->rowCount();
  8. if($buysCount == 0){ return "0.00"; }
  9. $rows = $query->fetchAll();
  10. foreach($rows as $row){
  11. $oldTime = $row['timestamp'];
  12. $newTime = time();
  13. //echo $newTime - $oldTime . "<br/>";
  14. if(($newTime - $oldTime) < 99999999){ //99999 is the seconds transactions are relevant
  15. $omcAmount = $row['amount'];
  16. $price = $row['pricePerOmc'];
  17. $nA = $buysCount*$price;
  18. $arr = array_merge(array($nA), $arr);
  19. }
  20. }
  21. return $this->standard_deviation($arr) / $buysCount;
  22. //return print_r($this->sd($arr));
  23. }
  24. function standard_deviation($x) {
  25. $summation = 0;
  26. $values = 0;
  27. $ex2 = 0;
  28. foreach ($x as $value) {
  29. if (is_numeric($value)) {
  30. $summation = $summation + $value;
  31. $values++;
  32. }
  33. }
  34. $mean = $summation/$values;
  35. foreach ($x as $value) {
  36. if (is_numeric($value)) {
  37. $ex2 = $ex2 + ($value*$value);
  38. }
  39. }
  40. $rawsd = ($ex2/$values) - ($mean * $mean);
  41. $sd = sqrt($rawsd);
  42. return $sd;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement