Unsupported PHP script for displaying weight data over time
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?PHP
  2. require('user-data.php');
  3. /* user-data.php contains user-supplied data.
  4. *
  5. * It should define a HEIGHT constant in metres, e.g.:
  6. *
  7. * define('HEIGHT', 1.765);
  8. *
  9. * Weigh-ins are collected in a $data array, with one entry in kilograms per
  10. * week, e.g.:
  11. *
  12. * $data = array(100.0, 99.0, 98.0);
  13. *
  14. * If a weight is recorded as -1, the week will be skipped and an average of
  15. * the nearest actual readings will be used. You can skip multiple weeks in
  16. * a row.
  17. *
  18. * Targets (shown as crosses on the graph) can be defined in an array called
  19. * $targets. Each entry in the array must be an array with two elements -
  20. * the week number and the target BMI (not weight!). e.g.:
  21. *
  22. * $targets = array(array(52, 70.0));
  23. */
  24. $skips = array();
  25. // Replace -1 entries
  26. for ($i = 0; $i < count($data); $i++) {
  27. if ($data[$i] == -1) {
  28. $skips[$i] = true;
  29. $j = 1;
  30. while (isset($data[$i + $j]) && $data[$i + $j] == -1) { $j++; }
  31. $k = -1;
  32. while (isset($data[$i + $k]) && $data[$i + $k] == -1) { $k--; }
  33. if (isset($data[$i + $j])) {
  34. $data[$i] = round($data[$i + $k] + ($data[$i + $j] - $data[$i + $k]) / ($j - $k), 1);
  35. } else {
  36. $data[$i] = $data[$i - 1];
  37. }
  38. }
  39. }
  40. ?>