Advertisement
Guest User

Untitled

a guest
Jan 13th, 2015
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.12 KB | None | 0 0
  1. $url = 'http://www.flashflashrevolution.com/api/api.php?key=hehu&action=ranks&username=' . $urlusername;
  2.  
  3. #echo $url . "<p>";
  4. #echo "\n";
  5. #echo $username;
  6. #echo "\n";
  7.  
  8. $json = file_get_contents($url) or die('not a user! or i can\'t connec to the internets.');
  9.  
  10. # var_dump(json_decode($json, true));
  11.  
  12. $array = json_decode($json, true);
  13.  
  14. $username = mysql_real_escape_string($array['user']['name']);
  15. $siteid = $array['user']['id'];
  16.  
  17. $numberofsongs = max(array_keys($array['songs']));
  18.  
  19. $time2 = time() + microtime();
  20.  
  21. for ($i = 0; $i < $numberofsongs; $i++) {
  22.  
  23. # echo $array['user']['songs'][$i]['scores']['good'];
  24.  
  25. if (isset($array['songs'][$i])) {
  26.  
  27. $played[$i] = $array['songs'][$i]['scores']['played'];
  28.  
  29. $notecount = $array['songs'][$i]['scores']['perfect'] + $array['songs'][$i]['scores']['good'] + $array['songs'][$i]['scores']['average'] + $array['songs'][$i]['scores']['miss'];
  30. $notesinsong = $array['songs'][$i]['info']['notes'];
  31.  
  32. if ($notecount == $notesinsong) {
  33.  
  34. $goodcount[$i] = $array['songs'][$i]['scores']['good'] + ($array['songs'][$i]['scores']['average'] * 1.8) + ($array['songs'][$i]['scores']['miss'] * 2.4) + ($array['songs'][$i]['scores']['boo'] * 0.2);
  35.  
  36. }
  37.  
  38.  
  39. if ($goodcount[$i] > 20) {
  40. unset($goodcount[$i]);
  41. }
  42.  
  43. $d = $array['songs'][$i]['info']['difficulty'];
  44. $songs[$d][$i] = $array['songs'][$i];
  45. $ngc[$d][$i] = $goodcount[$i];
  46.  
  47. if (isset($goodcount[$i])) {
  48. $songweight[$i] = (20 - $goodcount[$i]) * $d;
  49. }
  50.  
  51. #if(!empty($songweight[$i])) {
  52.  
  53. #echo $i . " - " . $songweight[$i] . "<br>";
  54.  
  55. if ($notecount == $notesinsong) {
  56. $played_weights[$d][$i] = $songweight[$i];
  57. }
  58.  
  59. $weights[$d][$i] = $songweight[$i];
  60.  
  61. #}
  62.  
  63. /*
  64. echo "Song ID: " . $i . " - ";
  65. echo "Good Count: " . $goodcount[$i] . " - ";
  66. echo "Difficulty: " . $d . " - ";
  67. echo "Weight: " . $songweight[$i];
  68. echo "Played: " . $played[$i];
  69. echo "<br>";
  70. */
  71.  
  72.  
  73. }
  74. }
  75.  
  76. $time3 = time() + microtime();
  77.  
  78. $maximum_d = max(array_keys($weights)) - 900;
  79.  
  80. #echo $maximum_d;
  81.  
  82. for ($d = 1; $d <= $maximum_d; $d++) {
  83.  
  84. if (isset($weights[$d])) {
  85.  
  86. $n_w1d[$d] = count($weights[$d]);
  87. $n_w2d[$d] = count($played_weights[$d]);
  88.  
  89. if ($n_w2d[$d] > 0) {
  90.  
  91. $sums[$d] = array_sum($weights[$d]);
  92. $ngcsum[$d] = array_sum($ngc[$d]);
  93.  
  94. $w[$d] = $sums[$d];
  95. $w1[$d] = $sums[$d] / $n_w1d[$d];
  96. $w2[$d] = $sums[$d] / $n_w2d[$d];
  97. $w3[$d] = $sums[$d] / $n_w2d[$d] + $ngcsum[$d];
  98.  
  99. /*
  100. echo "difficulty: " . $d . "<br>";
  101. echo "songs played: " . $n_w2d[$d] . "/" . $n_w1d[$d] . " songs <br>";
  102. echo "NGC: " . $ngcsum[$d] . "<br>";
  103. echo "weight: " . $w[$d] . "<br>";
  104. echo "weight1: " . $w1[$d] . "<br>";
  105. echo "weight2: " . $w2[$d] . "<br>";
  106. echo "weight3: " . $w3[$d] . "<p>";
  107. */
  108.  
  109. $dw[$d] = $w[$d] * $d;
  110. $dw1[$d] = $w1[$d] * $d;
  111. $dw2[$d] = $w2[$d] * $d;
  112. $dw3[$d] = $w3[$d] * $d;
  113.  
  114. }
  115.  
  116. /*
  117. echo "Sum of weights in difficulty: " . $d;
  118. echo " - ";
  119. echo $weights[$d]['sum'];
  120. echo "<br>";
  121. */
  122.  
  123. }
  124.  
  125. }
  126.  
  127. $time4 = time() + microtime();
  128.  
  129. $peak = max($w);
  130. $peak1 = max($w1);
  131. $peak2 = max($w2);
  132. $peak3 = max($w3);
  133.  
  134. $peak_d = array_keys($w, $peak);
  135. $peak1_d = array_keys($w1, $peak1);
  136. $peak2_d = array_keys($w2, $peak2);
  137. $peak3_d = array_keys($w3, $peak3);
  138.  
  139. /*
  140. var_dump($peak);
  141. var_dump($peak1);
  142. var_dump($peak2);
  143. var_dump($peak3);
  144. var_dump($peak_d);
  145. var_dump($peak1_d);
  146. var_dump($peak2_d);
  147. var_dump($peak3_d);
  148.  
  149. var_dump($w);
  150. var_dump($w1);
  151. var_dump($w2);
  152. var_dump($w3);
  153. */
  154.  
  155. for ($d = $peak_d[0]; $d <= $maximum_d; $d++) {
  156. $iw[$d] = $w[$d];
  157. $idw[$d] = $dw[$d];
  158. }
  159.  
  160. $time4a = time() + microtime();
  161.  
  162. for ($d = $peak1_d[0]; $d <= $maximum_d; $d++) {
  163. $iw1[$d] = $w1[$d];
  164. $idw1[$d] = $dw1[$d];
  165. }
  166.  
  167. $time4b = time() + microtime();
  168.  
  169. for ($d = $peak2_d[0]; $d <= $maximum_d; $d++) {
  170. $iw2[$d] = $w2[$d];
  171. $idw2[$d] = $dw2[$d];
  172. }
  173.  
  174. $time4c = time() + microtime();
  175.  
  176. for ($d = $peak3_d[0]; $d <= $maximum_d; $d++) {
  177. $iw3[$d] = $w3[$d];
  178. $idw3[$d] = $dw3[$d];
  179. }
  180.  
  181. $time4d = time() + microtime();
  182.  
  183. /*
  184. var_dump($iw);
  185. var_dump($idw);
  186. var_dump($iw1);
  187. var_dump($idw1);
  188. var_dump($iw2);
  189. var_dump($idw2);
  190. var_dump($iw3);
  191. var_dump($idw3);
  192. */
  193.  
  194. $z_sum1 = array_sum($iw);
  195. $z_sum2 = array_sum($idw);
  196. $z1_sum1 = array_sum($iw1);
  197. $z1_sum2 = array_sum($idw1);
  198. $z2_sum1 = array_sum($iw2);
  199. $z2_sum2 = array_sum($idw2);
  200. $z3_sum1 = array_sum($iw3);
  201. $z3_sum2 = array_sum($idw3);
  202.  
  203. $z = $z_sum2 / $z_sum1;
  204. $z1 = $z1_sum2 / $z1_sum1;
  205. $z2 = $z2_sum2 / $z2_sum1;
  206. $z3 = $z3_sum2 / $z3_sum1;
  207.  
  208. $zA = ($z1 + $z2 + $z3) / 3;
  209.  
  210. echo '<p>';
  211.  
  212. $time5 = time() + microtime();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement