<?php
define('MAX_AGE',45);
define('MIN_AGE',18);
define('CHANGE_RATE',0.05);
define('DEF_RATE',0.8);
$sex_rate = DEF_RATE;
$c_matrix = array(
'18' => array('1'=>2,'2'=>2,'3'=>1,'4'=>1,'5'=>2,'6'=>2,'7'=>1,'8'=>2,'9'=>1,'10'=>2,'11'=>1,'12'=>1),
'19' => array('1'=>1,'2'=>2,'3'=>1,'4'=>1,'5'=>2,'6'=>2,'7'=>1,'8'=>2,'9'=>1,'10'=>2,'11'=>1,'12'=>2),
'20' => array('1'=>2,'2'=>1,'3'=>2,'4'=>1,'5'=>1,'6'=>1,'7'=>1,'8'=>2,'9'=>1,'10'=>2,'11'=>1,'12'=>1),
'44' => array('1'=>2,'2'=>1,'3'=>2,'4'=>1,'5'=>1,'6'=>1,'7'=>1,'8'=>2,'9'=>1,'10'=>2,'11'=>1,'12'=>1),
'45' => array('1'=>2,'2'=>1,'3'=>2,'4'=>1,'5'=>1,'6'=>1,'7'=>1,'8'=>2,'9'=>1,'10'=>2,'11'=>1,'12'=>1)
);//TODO
//get borthday
$old_birth_year = 2000;//TODO
//get xx_day
$old_xx_year = 2017;//TODO
$old_xx_month = 12;//TODO
$cnt_year = $old_xx_year - $old_birth_year + 1;
/*
if($cnt_year > MAX_AGE || $cnt_year < MIN_AGE) {
//TODO error
exit(0);
} */
if(!array_key_exists($cnt_year,$c_matrix)){
echo 'cant calculate.';
exit(0);
}
$c_sex = $c_matrix[$cnt_year][$old_xx_month];
//pre_s
$c_pre_sex = null;
if($old_xx_month>=2) {
$c_pre_sex = $c_matrix[$cnt_year][$old_xx_month - 1];
}else {
if($cnt_year>MIN_AGE) {
$c_pre_sex = $c_matrix[$cnt_year-1][12];
}
}
//next_s
$c_next_sex = null;
if($old_xx_month<12) {
$c_next_sex = $c_matrix[$cnt_year][$old_xx_month + 1];
}else{
if($cnt_year<MAX_AGE) {
$c_next_sex = $c_matrix[$cnt_year+1][1];
}
}
//add or minus
if(!empty($c_pre_sex)) {
if($c_sex == $c_pre_sex) {
$sex_rate += 1 * CHANGE_RATE;
}else {
$sex_rate += -1 * CHANGE_RATE;
}
}
if(!empty($c_next_sex)) {
if($c_sex == $c_next_sex) {
$sex_rate += 1 * CHANGE_RATE;
}else {
$sex_rate += -1 * CHANGE_RATE;
}
}
$prt_str =<<<EOD
<div>test</div>
EOD;
echo $prt_str;
echo $c_pre_sex . '-' . $c_sex . '-' . $c_next_sex . '<br>';
echo $c_sex . '--rate--' . $sex_rate;