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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?PHP require('data.php'); ?>
  2. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  3. <html>
  4. <head>
  5. <title>Weight Tracking</title>
  6. <style type="text/css">
  7. table { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
  8. td, th { border: 1px solid black; padding: 5px; }
  9. div#stats { margin-left: 810px; margin-right: 5px; padding-top: 1px; }
  10. td { text-align: right; }
  11. th { font-weight: bold; color: #fff; background-color: #000; border: 1px solid #666; }
  12. tr.vbad td, td.bad { background-color: #f99; }
  13. tr.bad td { background-color: #fdd; }
  14. tr.ok td { background-color: #fff; }
  15. tr.good td { background-color: #dfd; }
  16. tr.vgood td, td.good { background-color: #9f9; }
  17. </style>
  18. </head>
  19. <body>
  20. <div id="graph" style="float: left;">
  21. <img src="newergraph.php" alt="Graph of weight">
  22. </div>
  23. <div id="stats">
  24. <table>
  25. <tr>
  26. <th rowspan="2">Wk</th><th rowspan="2">Mass</th><th rowspan="2">BMI</th>
  27. <th colspan="2">&Delta;Mass</th><th colspan="2">&Sigma;&Delta;Mass</th>
  28. </tr><tr>
  29. <th>kg</th><th>st</th><th>kg</th><th>st</th>
  30. </tr>
  31. <?PHP
  32. $last = 0;
  33. $first = 0;
  34. $number = 18;
  35. for ($i = count($data) - 1; $i > count($data) - $number; $i--) {
  36. if (isset($skips[$i])) { $number++; }
  37. }
  38. foreach ($data as $week => $weight) {
  39. $week++;
  40. if ($first == 0) {
  41. $first = $weight;
  42. }
  43. if ($last != 0) { $diffs[] = $weight - $last; }
  44. if ($week > count($data) - $number) {
  45. $diff = $weight - $last;
  46. if ($diff > 0.5) {
  47. $class = 'vbad';
  48. } else if ($diff > 0) {
  49. $class = 'bad';
  50. } else if ($diff == 0) {
  51. $class = 'ok';
  52. } else if ($diff > -1) {
  53. $class = 'good';
  54. } else {
  55. $class = 'vgood';
  56. }
  57. if (!isset($skips[$week - 1])) {
  58. echo '<tr class="', $class, '"><td>', $week, '</td><td>', sprintf('%01.1f', $weight), '</td><td>';
  59. echo sprintf('%01.1f', $weight / (HEIGHT * HEIGHT), 1), '</td><td>';
  60. if ($last == 0) {
  61. echo '-';
  62. } else {
  63. if ($weight - $last > 0) {
  64. echo '<span style="color: red;">';
  65. }
  66. echo sprintf('%01.1f', $weight - $last);
  67. }
  68. echo '</td><td>';
  69. if ($last == 0) {
  70. echo '-';
  71. } else {
  72. if ($weight - $last > 0) {
  73. echo '<span style="color: red;">';
  74. }
  75. echo sprintf('%01.1f', 0.157473044 * ($weight - $last));
  76. }
  77. echo '</td><td>', sprintf('%01.1f', $weight - $first), '</td>';
  78. echo '<td>', sprintf('%01.1f', 0.157473044 * ($weight - $first)), '</td></tr>';
  79. }
  80. }
  81. $last = $weight;
  82. }
  83. $a1 = array_sum($diffs) / count($diffs);
  84. $a2 = array_sum(array_slice($diffs, -4)) / 4;
  85. $a3 = array_pop($diffs);
  86. $bmi = $last / (HEIGHT * HEIGHT);
  87. $target = 5 * floor($bmi/5);
  88. $target2 = $target - 5;
  89. $targs = array($target, $target2);
  90. $tweeks = array();
  91. foreach ($targets as $targ) {
  92. list($tweek, $tbmi) = $targ;
  93. if ($bmi > $tbmi && $tweek > $week) {
  94. $tweeks[$tbmi] = $tweek;
  95. $targs[] = $tbmi;
  96. }
  97. }
  98. rsort($targs);
  99. $target = array_shift($targs);
  100. $target2 = array_shift($targs);
  101. $b35 = $target * HEIGHT * HEIGHT - $last;
  102. $b30 = ($target2) * HEIGHT * HEIGHT - $last;
  103. $target_s = $target . ' (' . round($target * HEIGHT * HEIGHT, 1) . ')';
  104. $target2_s = $target2 . ' (' . round($target2 * HEIGHT * HEIGHT, 1) . ')';
  105. ?>
  106. </table>
  107. <table>
  108. <tr><th rowspan="2">Timespan</th><th rowspan="2"><span style="border-top: 1px solid white;">&Delta;Mass</span></th><th colspan="2">ETA &rarr; BMI (KG)</th></tr>
  109. <tr><th><?PHP echo $target_s; ?></th><th><?PHP echo $target2_s; ?></th></tr>
  110. <tr><td>All time</td><td><?PHP printf('%01.1f', $a1); ?></td>
  111. <td class="<?PHP if (isset($tweeks[$target])) { echo ($a1 < 0 && ceil(abs($b35 / $a1)) < $tweeks[$target] - count($data)) ? 'good' : 'bad'; } ?>">
  112. <?PHP echo $a1 >= 0 ? 'Never' : date('d M y', strtotime('+'.ceil(abs($b35 / $a1)).'weeks')); ?></td>
  113. <td class="<?PHP if (isset($tweeks[$target2])) { echo ($a1 < 0 && ceil(abs($b30 / $a1)) < $tweeks[$target2] - count($data)) ? 'good' : 'bad'; } ?>">
  114. <?PHP echo $a1 >= 0 ? 'Never' : date('d M y', strtotime('+'.ceil(abs($b30 / $a1)).'weeks')); ?></td>
  115. </tr>
  116. <tr><td>Last month</td><td><?PHP printf('%01.1f', $a2); ?></td>
  117. <td class="<?PHP if (isset($tweeks[$target])) { echo ($a2 < 0 && ceil(abs($b35 / $a2)) < $tweeks[$target] - count($data)) ? 'good' : 'bad'; } ?>">
  118. <?PHP echo $a2 >= 0 ? 'Never' : date('d M y', strtotime('+'.ceil(abs($b35 / $a2)).'weeks')); ?></td>
  119. <td class="<?PHP if (isset($tweeks[$target2])) { echo ($a2 < 0 && ceil(abs($b30 / $a2)) < $tweeks[$target2] - count($data)) ? 'good' : 'bad'; } ?>">
  120. <?PHP echo $a2 >= 0 ? 'Never' : date('d M y', strtotime('+'.ceil(abs($b30 / $a2)).'weeks')); ?></td>
  121. </tr>
  122. <tr><td>Last week</td><td><?PHP printf('%01.1f', $a3); ?></td>
  123. <td class="<?PHP if (isset($tweeks[$target])) { echo ($a3 < 0 && ceil(abs($b35 / $a3)) < $tweeks[$target] - count($data)) ? 'good' : 'bad'; } ?>">
  124. <?PHP echo $a3 >= 0 ? 'Never' : date('d M y', strtotime('+'.ceil(abs($b35 / $a3)).'weeks')); ?></td>
  125. <td class="<?PHP if (isset($tweeks[$target2])) { echo ($a3 < 0 && ceil(abs($b30 / $a3)) < $tweeks[$target2] - count($data)) ? 'good' : 'bad'; } ?>">
  126. <?PHP echo $a3 >= 0 ? 'Never' : date('d M y', strtotime('+'.ceil(abs($b30 / $a3)).'weeks')); ?></td>
  127. </tr>
  128. <tr><th>Average</th><td><?PHP printf('%01.1f', ($a1 + $a2 + $a3)/3); ?></td>
  129. <td class="<?PHP if (isset($tweeks[$target])) { echo ($a1 + $a2 + $a3 < 0 && ceil(abs($b35 / (($a1 + $a2 + $a3)/3))) < $tweeks[$target] - count($data)) ? 'good' : 'bad'; } ?>">
  130. <?PHP echo $a1 + $a2 + $a3 >= 0 ? 'Never' : date('d M y', strtotime('+'.ceil(abs($b35 / (($a1 + $a2 + $a3)/3))).'weeks')); ?></td>
  131. <td class="<?PHP if (isset($tweeks[$target2])) { echo ($a1 + $a2 + $a3 < 0 && ceil(abs($b30 / (($a1 + $a2 + $a3)/3))) < $tweeks[$target2] - count($data)) ? 'good' : 'bad'; } ?>">
  132. <?PHP echo $a1 + $a2 + $a3 >= 0 ? 'Never' : date('d M y', strtotime('+'.ceil(abs($b30 / (($a1 + $a2 + $a3)/3))).'weeks')); ?></td>
  133. </tr>
  134. </table>
  135. </div>
  136. </body>
  137. </html>