Advertisement
viamvadens

Untitled

Dec 4th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.51 KB | None | 0 0
  1. <?php
  2. include(__DIR__ . "/../../init.php");
  3.  
  4.  
  5. $vm_id = array('084_KZ_KISLOV', '099_IK_SAIDZHONOV');
  6. $date_from = '2018-08-01';
  7.  
  8. $MASTER_BK = "pinnacle";
  9. $SLAVE_BK = "fonbet";
  10.  
  11.  
  12. echo __("[#] VM_IDS: %s\n", implode(", ", $vm_id));
  13.  
  14. echo __("[+] Loading bets from `forks_stakes` ... "); $t0 = microtime(true);
  15. $fs = DB()->fetchAll("
  16.  
  17. SELECT bet_result, fork_id, bk_name, event_name, bet_type, bet_name, cf, fork_income, game_score, added_at, UNIX_TIMESTAMP(added_at) as added_at_uts, margin1, margin2, limits_indicator, in_event_count
  18. FROM forks_stakes
  19. WHERE vm_id IN ('%s') AND DATE(added_at) >= '%s' AND bet_result IN (1,-1) AND 25 > margin1 > 0 AND 25 > margin2 > 0
  20. AND bet_type NOT IN ('WIN', 'HALF_WIN', 'TOTALS_CORNERS', 'HALF_TOTALS_CORNERS', 'HANDICAP_CORNERS', 'HALF_HANDICAP_CORNERS', 'WIN_CORNERS')
  21. #AND bet_result = -1
  22. GROUP BY event_name, bet_name
  23. ORDER BY added_at
  24. ", implode("','", $vm_id), $date_from);
  25. #$CFS1 = parseCfsRows($r1);
  26. echo __("%s row(s) [%.2fs]\n", number_format(count($fs)), microtime(true)-$t0);
  27. #print_r($fs); exit;
  28.  
  29. $fork_ids = array();
  30. foreach($fs as $r){
  31. $fork_ids[] = $r['fork_id'];
  32. }
  33.  
  34. #$fork_ids = array(11663533);
  35.  
  36.  
  37. echo __("[+] Loading data from `forks/forks_01` ... "); $t0 = microtime(true);
  38. $forks = DB()->fetchAll("
  39. SELECT
  40. id, bet_type, added_at, UNIX_TIMESTAMP(added_at) as added_at_uts,
  41. #income, IF(BK1_name='$SLAVE_BK', BK1_coef, BK2_coef) as slave_cf,
  42. IF(BK1_name='$MASTER_BK', BK1_game, BK2_game) as master_event_name,
  43. IF(BK1_name='$SLAVE_BK', BK1_game, BK2_game) as slave_event_name,
  44. IF(BK1_name='$MASTER_BK', BK1_league, BK2_league) as master_league_name,
  45. IF(BK1_name='$SLAVE_BK', BK1_league, BK2_league) as slave_league_name,
  46. IF(BK1_name='$MASTER_BK', BK1_is_initiator, BK2_is_initiator) as master_is_initiator,
  47. IF(BK1_name='$SLAVE_BK', BK1_is_initiator, BK2_is_initiator) as slave_is_initiator,
  48. IF(BK1_name='$MASTER_BK', BK1_forks_count, BK2_forks_count) as master_forks_count,
  49. IF(BK1_name='$SLAVE_BK', BK1_forks_count, BK2_forks_count) as slave_forks_count
  50. FROM (
  51. SELECT * FROM forks_01 WHERE id IN (%s)
  52. UNION
  53. SELECT * FROM forks WHERE id IN (%s)
  54. ) as t
  55. WHERE '%s' IN (BK1_name, BK2_name) and '%s' IN (BK1_name, BK2_name)
  56. ORDER BY added_at
  57.  
  58. ", implode(",", $fork_ids), implode(",", $fork_ids), $MASTER_BK, $SLAVE_BK);
  59. echo __("%s row(s) [%.2fs]\n", number_format(count($forks)), microtime(true)-$t0);
  60.  
  61. $_forks=array();
  62. foreach($forks as $r){
  63. $_forks[$r['id']] = $r;
  64. }
  65. #print_r($forks); exit;
  66.  
  67.  
  68. echo __("[+] Cleaning data from ... ");
  69. $_bets = array();
  70. foreach($fs as $_b){
  71. if(!isset($_forks[$_b['fork_id']]) or !($_f=$_forks[$_b['fork_id']])){
  72. continue;
  73. }
  74. if($_b['event_name'] != $_f['slave_event_name']){
  75. continue;
  76. }
  77. $_bets[] = $_b;
  78. }
  79. echo __("%s row(s)\n\n", number_format(count($_bets)));
  80. #print_r($_bets); exit;
  81.  
  82.  
  83. #shuffle($_bets);
  84.  
  85.  
  86. $out_keys = array();
  87. foreach($_bets as $_b){
  88. $_f=$_forks[$_b['fork_id']];
  89.  
  90. $_o = prepareStepOne($_b, $_f);
  91. if(count($out_keys) == 0){
  92. $out_keys = array_keys($_o);
  93. #echo implode(",", $out_keys) . "\n";
  94. }
  95. $_v = array();
  96. foreach($out_keys as $_k){
  97. $_v[] = $_o[$_k];
  98. }
  99. echo implode(",", $_v) . "\n";
  100. }
  101.  
  102. function prepareStepOne($_b, $_f){
  103.  
  104.  
  105. $BET_TYPES = array('HANDICAP', 'TOTALS', 'TEAM_TOTALS', 'TEAM_GOALS', 'HALF_TOTALS', 'HALF_HANDICAP', 'WIN', "HALF_WIN");
  106. $BET_TYPES2 = array('HANDICAP'=>1, 'TOTALS'=>2, 'TEAM_TOTALS'=>2, 'TEAM_GOALS'=>2, 'HALF_TOTALS'=>2, 'HALF_HANDICAP'=>1, 'WIN'=>3, "HALF_WIN"=>3);
  107. if(($_bet_type = array_search($_b['bet_type'], $BET_TYPES)) === false or !isset($BET_TYPES2[$_b['bet_type']]) or ($_bet_type2 = $BET_TYPES2[$_b['bet_type']]) === false){
  108. die(__("ERROR: prepareStepOne(): cant find bet_type '%s'", $_b['bet_type']));
  109. }
  110.  
  111.  
  112.  
  113. $_out = array(
  114. 'bet_result' => (intval($_b['bet_result']) == 1 ? 1.0 : 0.0),
  115. 'cf' => $_b['cf'],
  116. 'cf2' => __("%.6f", 1/floatval($_b['cf'])),
  117. 'cf3' => __("%.6f", 1/floatval($_b['cf']) - floatval($_b['margin2'])/2/100),
  118. 'fork_income' => $_b['fork_income'],
  119. 'overw_v3' => floatval($_b['fork_income'])+floatval($_b['margin2'])/2,
  120. 'bet_type' => $_bet_type,
  121. 'bet_type2' => $_bet_type2,
  122. 'bet_type3' => 0,
  123. 'time_wday' => intval(date('w', $_b['added_at_uts'])),
  124. 'time_hour' => intval(date('H', $_b['added_at_uts'])) + intval(date('i', $_b['added_at_uts']))/100,
  125. 'time_intraday' => __("%.6f", (intval(date('H', $_b['added_at_uts']))*60 + intval(date('i', $_b['added_at_uts'])))/(60*24)),
  126. 'margin1' => $_b['margin1'],
  127. 'margin2' => $_b['margin2'],
  128. 'limits_indicator' => $_b['limits_indicator'],
  129. 'in_event_count' => $_b['in_event_count'],
  130. 'added_at_diff' => intval($_b['added_at_uts'])-intval($_f['added_at_uts'])-15,
  131. 'master_is_initiator' => $_f['master_is_initiator'],
  132. 'slave_is_initiator' => $_f['slave_is_initiator'],
  133. 'master_forks_count' => $_f['master_is_initiator'],
  134. 'slave_forks_count' => $_f['slave_forks_count'],
  135. 'score_goals_total' => -1,
  136. 'score_goals_diff' => -1,
  137. 'score_match_min' => -1,
  138. 'score_match_period' => 1,
  139. #'added_at' => $_b['added_at']
  140. );
  141. if(preg_match("!^([0-9]+):([0-9]+)( |$)(\(([0-9]+):([0-9]+)\))?!", $_b['game_score'], $_sc)){
  142. #print_r($_sc); exit;
  143. $_out['score_goals_total'] = $_sc[1]+$_sc[2];
  144. $_out['score_goals_diff'] = abs($_sc[1]-$_sc[2]);
  145. if(isset($_sc[4]) and $_sc[4] != ''){
  146. #var_dump($_sc);
  147. $_out['score_match_period'] = 2;
  148. }
  149. }
  150. if(preg_match("! ([0-9]{1,2}):([0-5][0-9])$!", $_b['game_score'], $_sc)){
  151. #print_r($_sc); exit;
  152. $_out['score_match_min'] = $_sc[1]+1;
  153. }
  154. #$_out['game_score'] = $_b['game_score'];
  155.  
  156. $_BET_TYPES2 = array(
  157. '__GOALS__YES' => 2,
  158. '__GOALS__NO' => 1,
  159. 'HANDICAP__P[12]\(\-' => 2,
  160. 'HANDICAP__P[12]\(0' => 3,
  161. 'HANDICAP__P[12]\([0-9]' => 1,
  162. 'TOTALS__UNDER' => 1,
  163. 'TOTALS__OVER' => 2
  164. );
  165. foreach($_BET_TYPES2 as $_rg => $_v){
  166. if(preg_match("!$_rg!", $_b['bet_name'])){
  167. $_out['bet_type3'] = $_v;
  168. break;
  169. }
  170. }
  171. #$_out['___'] = $_b['bet_name'];
  172.  
  173. #print_r($_b); print_r($_f); print_r($_out); exit;
  174.  
  175. return $_out;
  176. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement