main.js 13.5 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468

//로또 번호 생성
function dice(n, s, b) {
  var out = 0;
  for (i = 0; i < n; i++) {
    out += Math.ceil(s * Math.random());
  }
  return out + b;
}

//로또 번호를 생성하고 번호별로 style을 주며 당첨등을 총괄하기 위한 함수 
function count() {
  // console.log($('#inputnum').val());
  var numberSort = function(a, b) {
    return a[0] - b[0];
  };
  
  resets2();
  
  var win1 = 0;
  var win2 = 0;
  var win3 = 0;
  var win4 = 0;
  var win5 = 0;

  (function engine(i) {
    setTimeout(function() {
      var list_length = ($('#lottotable li').length + 1);
      var list = "";
      var val = [
        [0, 0], //[번호, 당첨여부]
        [0, 0],
        [0, 0],
        [0, 0],
        [0, 0],
        [0, 0]
      ];
      var match = 0; //몇개 숫자가 적중했나
      var match_b = 0; //보너스숫자가 적중했나

      for (j = 0; j < 6; j++) {
        // val[j][0] = dice(1, 45, 0);

        function roll(n) {
          if (j == 0) {
            val[j][0] = n;
          } else {
            for (l = 0; l < j; l++) {
              // console.log(n);
              if (n == val[l][0]) {
                roll(dice(1, 45, 0));
              } else {
                val[j][0] = n;
              }
            }
          }
        }
        roll(dice(1, 45, 0));
		
        // console.log("No." + (list_length) + ": " + val);
        for (m = 0; m < 6; m++) {
          if (val[j][0] == data[m]) {
            val[j][1] = 1;
            match++;
          }
        }
        // console.log("No." + (list_length) + ": " + val);
        if (val[j][0] == data[6]) {
          val[j][1] = 2;
          match_b = 1;
        }
	  }
      // console.log("before sort: "+val);
      val.sort(numberSort);
      // console.log("after sort: "+val);

	 
      for (j = 0; j < 6; j++) {
        function setColorClass() {
          if (val[j][0] <= 10) {
            num_class = "c1 ";
          } else if (val[j][0] <= 20) {
            num_class = "c2 ";
          } else if (val[j][0] <= 30) {
            num_class = "c3 ";
          } else if (val[j][0] <= 40) {
            num_class = "c4 ";
          } else {
            num_class = "c5 ";
          }
          if (val[j][1] == 1) {
            num_class += "match ";
          } else if (val[j][1] == 2) {
            num_class += "match_b ";
          }
        }

        var num_class;
        setColorClass();
        list += '<div class="output ' + num_class + '">' + val[j][0] + '</div>';
        // console.log(match);
      }
	  
	
	  
	  acum_list[val[0][0]-1]+=1;
	  acum_list[val[1][0]-1]+=1;
	  acum_list[val[2][0]-1]+=1;
	  acum_list[val[3][0]-1]+=1;
	  acum_list[val[4][0]-1]+=1;
	  acum_list[val[5][0]-1]+=1;
		
	  
	   
	  var win_class;
      if (match == 6) {
        win_class = 'win win1';
        win1++;
        console.log('win1');
      } else if (match == 5 && match_b == 1) {
        win_class = 'win win2';
        win2++;
        console.log('win2');
      } else if (match == 5) {
        win_class = 'win win3';
        win3++;
        console.log('win3');
      } else if (match == 4) {
        win_class = 'win win4';
        win4++;
        console.log('win4');
      } else if (match == 3) {
        win_class = 'win win5';
        win5++;
        console.log('win5');
      }
      $('#stats').html(
        '1등: ' + win1 + "<span class='translation'>(" + (win1 / list_length * 100).toFixed(2) + "%)</span>" +
        ' | 2등: ' + win2 + "<span class='translation'>(" + (win2 / list_length * 100).toFixed(2) + "%)</span>" +
        ' | 3등: ' + win3 + "<span class='translation'>(" + (win3 / list_length * 100).toFixed(2) + "%)</span>" +
        ' | 4등: ' + win4 + "<span class='translation'>(" + (win4 / list_length * 100).toFixed(2) + "%)</span>" +
        ' | 5등: ' + win5 + "<span class='translation'>(" + (win5 / list_length * 100).toFixed(2) + "%)</span>" +
        " | 총당첨율: " + ((win1 + win2 + win3 + win4 + win5) / list_length * 100).toFixed(2) + "%" +
		" | 손수익 : " + (((win1*2000000000)+(win2*50000000)+(win3*1000000)+(win4*50000)+(win5*5000))-(totalbuy*1000)).toFixed(0)+"원"+
        '<br><progress value="' + list_length + '" max="' + totalbuy + '"></progress>'
      );
      $('#lottotable').append('<li class="' + win_class + '">' + list + '</li>');
      // break;
      if (--i) engine(i);
    }, 0)
  })($('#inputnum').val());
  var totalmatch = (win1 + win2 + win3 + win4 + win5)
  var totalbuy = $('#inputnum').val();

}

//api로부터 당첨 data를 끌어오기 위한 함수
function loadlot(num) {
  $("#lottok").html('제 ' + (861-num+1) + '회차 당첨 결과(' + lotto_num[num-1][7] + ')'); // + '<br/>' +
  //a.nums + a.bnum;
  for (i = 0; i < 7; i++) {
    $('#output' + i).text(lotto_num[num-1][i]);
  }
  for (i = 0; i < 7; i++) {
    if (lotto_num[num-1][i] <= 10) {
      $('#output' + i).addClass("output c1");
    } else if (lotto_num[num-1][i] <= 20) {
      $('#output' + i).addClass("output c2");
    } else if (lotto_num[num-1][i] <= 30) {
      $('#output' + i).addClass("output c3");
    } else if (lotto_num[num-1][i] <= 40) {
      $('#output' + i).addClass("output c4");
    } else {
      $('#output' + i).addClass("output c5");
    }
  }
  
  
  data = lotto_num[num-1];
}

//생성한 번호별 누적횟수와 추천번호를 위한 함수
function accumulate_number() {
  resets2();
  
  var temp=  JSON.parse(JSON.stringify( acum_list )); 
  var out_temp=  JSON.parse(JSON.stringify( acum_list ));
 
  temp.sort(function(a,b){return a-b});
  
  var recom_number = new Array();
  
  $('#recom_table').append('<section id="recom_section" class="shadow"></scetion>');
  
  for(i=44;i>=0;i--) {
	  for(j=0;j<45;j++){
		  if(temp[i]==out_temp[j]){
			  if(j<9)
				  $('#recom_section').append('<div class="output c1">'+(j+1)+'</div>'+'<progress value="' + temp[i] + '" max="' + (temp[44]+20)+ '"></progress>'+' '+temp[i]);
			  else if(j<19)
				  $('#recom_section').append('<div class="output c2">'+(j+1)+'</div>'+'<progress value="' + temp[i] + '" max="' + (temp[44]+20)+ '"></progress>'+' '+temp[i]);
			  else if(j<29)
				  $('#recom_section').append('<div class="output c3">'+(j+1)+'</div>'+'<progress value="' + temp[i] + '" max="' + (temp[44]+20)+ '"></progress>'+' '+temp[i]);
			  else if(j<39)
				  $('#recom_section').append('<div class="output c4">'+(j+1)+'</div>'+'<progress value="' + temp[i] + '" max="' + (temp[44]+20)+ '"></progress>'+' '+temp[i]);
			  else
				  $('#recom_section').append('<div class="output c5">'+(j+1)+'</div>'+'<progress value="' + temp[i] + '" max="' + (temp[44]+20)+ '"></progress>'+' '+temp[i]);
			  out_temp[j]=null;
			  if(i>38){
				  recom_number[44-i]=j+1;
			  }
			  break;
		  }
	  }
  }

  recom_number.sort(function(a,b){return a-b});

  

  
  
  
  
  var list = "";

  var num_class= "c2 ";
  list += '<div class="output ' + num_class + '">' + "3" + '</div>';
 
  $('#accumulate_table').append('<section id="accumulate_section" class="shadow"></scetion>');
 
  $("#accumulate_section").append('추천 로또 번호(누적 상위 6개)'+'</font>'+'<br>'+'<br>');
  
   for (i = 0; i < 6; i++) {
    if (recom_number[i] <= 10) {
       $('#accumulate_section').append('<div class="output c1">'+recom_number[i]+'</div>');
    } else if (recom_number[i] <= 20) {
		$('#accumulate_section').append('<div class="output c2">'+recom_number[i]+'</div>');
    } else if (recom_number[i] <= 30) {
		$('#accumulate_section').append('<div class="output c3">'+recom_number[i]+'</div>');
    } else if (recom_number[i] <= 40) {
		$('#accumulate_section').append('<div class="output c4">'+recom_number[i]+'</div>');
    } else {
		$('#accumulate_section').append('<div class="output c5">'+recom_number[i]+'</div>');
    }
  }

  
}

//현재 보이는 화면을 초기화함과 동시에 누적번호 또한 초기화 하기 위한 함수
function resets() {
  resets2();
    for (i=0;i<45;i++){
	acum_list[i]=0;
  }
}

function resets2() {
  $('#lottotable').html(""); 
  $('#accumulate_table').html(""); 
  $('#recom_table').html(""); 
  $('#stats').html(""); 
  $('#patten_table').html(""); 
  $('#patten_recom_table').html(""); 
  $('#chart_div_1').html("");
  $('#chart_div_2').html("");
  $('#chart_div_3').html("");
  $('#chart_div_4').html("");
  
}


function patten() {
	  resets2()

	  var temp=  JSON.parse(JSON.stringify( nujuk )); 
	  var out_temp=  JSON.parse(JSON.stringify( nujuk ));
	 
	  temp.sort(function(a,b){return a-b});
	  

	  
	  $('#patten_table').append('<section id="patten_section" class="shadow"></scetion>');
	  for(i=44;i>=0;i--) {
		  for(j=0;j<45;j++){
			  if(temp[i]==out_temp[j]){
				  if(j<9)
					  $('#patten_section').append('<div class="output c1">'+(j+1)+'</div>'+'<progress value="' + temp[i] + '" max="' + (temp[44]+20)+ '"></progress>'+' '+temp[i]);
				  else if(j<19)
					  $('#patten_section').append('<div class="output c2">'+(j+1)+'</div>'+'<progress value="' + temp[i] + '" max="' + (temp[44]+20)+ '"></progress>'+' '+temp[i]);
				  else if(j<29)
					  $('#patten_section').append('<div class="output c3">'+(j+1)+'</div>'+'<progress value="' + temp[i] + '" max="' + (temp[44]+20)+ '"></progress>'+' '+temp[i]);
				  else if(j<39)
					  $('#patten_section').append('<div class="output c4">'+(j+1)+'</div>'+'<progress value="' + temp[i] + '" max="' + (temp[44]+20)+ '"></progress>'+' '+temp[i]);
				  else
					  $('#patten_section').append('<div class="output c5">'+(j+1)+'</div>'+'<progress value="' + temp[i] + '" max="' + (temp[44]+20)+ '"></progress>'+' '+temp[i]);
				  out_temp[j]=null;
				  break;
			  }
		  }
	  }



	
	


}

function graph_accum() { 
			resets2();
			
			var data = google.visualization.arrayToDataTable([
					['패턴요소', '수치'],
					['홀0:짝6',  9],
					['홀1:짝5',  58],
					['홀2:짝4',  192],
					['홀3:짝3',  299],
					['홀4:짝2',  223],
					['홀5:짝1',  65],
					['홀0:짝6',  15]
				]);
			var options = {
					title : '역대 홀수 짝수 비율',
					vAxis: {title: '출현횟수'},
					hAxis: {title: '1회~861회'}, 
					seriesType: 'bars',
					series: {5: {type: 'line'}},
					backgroundColor : 'ivory'
				};

			var data2 = google.visualization.arrayToDataTable([
					['패턴요소', '수치'],
					['저0:고6',  9],
					['저1:고5',  79],
					['저2:고4',  216],
					['저3:고3',  287],
					['저4:고2',  193],
					['저5:고1',  64],
					['저0:고6',  13]
				]);
			var options2 = {
					title : '역대 저&고 비율',
					vAxis: {title: '출현횟수'},
					hAxis: {title: '1회~861회'}, 
					seriesType: 'bars',
					series: {5: {type: 'line'}},
					backgroundColor : 'ivory'

				};
				
			var data3 = google.visualization.arrayToDataTable([
					['패턴요소', '수치'],
					['0개',  63],
					['1개',  234],
					['2개',  289],
					['3개',  212],
					['4개',  53],
					['5개',  8],
					['6개',  2]
				]);
			var options3 = {
					title : '역대 3의 배수 비율',
					vAxis: {title: '출현횟수'},
					hAxis: {title: '1회~861회'}, 
					seriesType: 'bars',
					series: {5: {type: 'line'}},
					backgroundColor : 'ivory'
				};				
			
			var data4 = google.visualization.arrayToDataTable([
					['패턴요소', '수치'],
					['0~100',  106],
					['101~120',  140],
					['121~140',  214],
					['141~160',  180],
					['161~180',  151],
					['181~260',  70]
				]);
			var options4 = {
					title : '역대 번호 총합 비율',
					vAxis: {title: '출현횟수'},
					hAxis: {title: '1회~861회'}, 
					seriesType: 'bars',
					series: {5: {type: 'line'}},
					backgroundColor : 'ivory'

				};				

				
	while(true){
		
		var val2=[0,0,0,0,0,0];
		
		for (j = 0; j < 6; j++) {

			function roll(n) {
			  if (j == 0) {
				val2[j] = n;
			  } else {
				for (l = 0; l < j; l++) {
				  // console.log(n);
				  if (n == val2[l]) {
					roll(dice(1, 45, 0));
				  } else {
					val2[j] = n;
				  }
				}
			  }
			}
			roll(dice(1, 45, 0));
		}
			
		val2.sort(function(a,b){return a-b});	
		
		var check_goju=0;
		var check_sum=0;
		var check_holjjak=0;
		var check_three_mul=0;
		for(i=0;i<6;i++){
			check_sum+=val2[i];
			if(val2[i]>22)
				check_goju+=1;
			if(val2[i]%2==0)
				check_holjjak+=1;
			if(val2[i]%3==0)
				check_three_mul+=1;
		}
		
		if((check_sum<=160 && check_sum>=121) && (check_goju==3 || check_goju==4) && ( check_holjjak ==2 || check_holjjak==3) && ( check_three_mul==1 || check_three_mul==2))
			break;
	}
		
		$('#patten_recom_table').append('<section id="patten_recom_section" class="shadow"></scetion>');
	 
		$("#patten_recom_section").append('추천 로또 번호(패턴 분석)'+'</font>'+'<br>'+'<br>');
	  
	   for (i = 0; i < 6; i++) {
		if (val2[i] <= 10) {
		   $('#patten_recom_section').append('<div class="output c1">'+val2[i]+'</div>');
		} else if (val2[i] <= 20) {
			$('#patten_recom_section').append('<div class="output c2">'+val2[i]+'</div>');
		} else if (val2[i] <= 30) {
			$('#patten_recom_section').append('<div class="output c3">'+val2[i]+'</div>');
		} else if (val2[i] <= 40) {
			$('#patten_recom_section').append('<div class="output c4">'+val2[i]+'</div>');
		} else {
			$('#patten_recom_section').append('<div class="output c5">'+val2[i]+'</div>');
		}
	  }
			
			
			
			var chart = new google.visualization.ComboChart(document.getElementById('chart_div_1'));
			chart.draw(data, options);
			var chart = new google.visualization.ComboChart(document.getElementById('chart_div_2'));
			chart.draw(data2, options2);
			var chart = new google.visualization.ComboChart(document.getElementById('chart_div_3'));
			chart.draw(data3, options3);
			var chart = new google.visualization.ComboChart(document.getElementById('chart_div_4'));
			chart.draw(data4, options4);


}