Esempio n. 1
1
 /**
  * @param string $modelId Id of model
  * @param integer $targetId Current value of primary key
  */
 public static function updateRating($modelId, $targetId)
 {
     $likes = static::find()->where(['model_id' => $modelId, 'target_id' => $targetId, 'value' => self::VOTE_LIKE])->count();
     $dislikes = static::find()->where(['model_id' => $modelId, 'target_id' => $targetId, 'value' => self::VOTE_DISLIKE])->count();
     if ($likes + $dislikes !== 0) {
         // Рейтинг = Нижняя граница доверительного интервала Вильсона (Wilson) для параметра Бернулли
         // http://habrahabr.ru/company/darudar/blog/143188/
         $rating = (($likes + 1.9208) / ($likes + $dislikes) - 1.96 * SQRT($likes * $dislikes / ($likes + $dislikes) + 0.9604) / ($likes + $dislikes)) / (1 + 3.8416 / ($likes + $dislikes));
     } else {
         $rating = 0;
     }
     $rating = round($rating * 10, 2);
     $aggregateModel = AggregateRating::findOne(['model_id' => $modelId, 'target_id' => $targetId]);
     if (null === $aggregateModel) {
         $aggregateModel = new AggregateRating();
         $aggregateModel->model_id = $modelId;
         $aggregateModel->target_id = $targetId;
     }
     $aggregateModel->likes = $likes;
     $aggregateModel->dislikes = $dislikes;
     $aggregateModel->rating = $rating;
     $aggregateModel->save();
 }
Esempio n. 2
0
function procDistanceTime2($coor, $thiscoor, $ref, $mode)
{
    $xdistance = ABS($thiscoor['x'] - $coor['x']);
    if ($xdistance > WORLD_MAX) {
        $xdistance = 2 * WORLD_MAX + 1 - $xdistance;
    }
    $ydistance = ABS($thiscoor['y'] - $coor['y']);
    if ($ydistance > WORLD_MAX) {
        $ydistance = 2 * WORLD_MAX + 1 - $ydistance;
    }
    $distance = SQRT(POW($xdistance, 2) + POW($ydistance, 2));
    if (!$mode) {
        if ($ref == 1) {
            $speed = 16;
        } else {
            if ($ref == 2) {
                $speed = 12;
            } else {
                if ($ref == 3) {
                    $speed = 24;
                } else {
                    if ($ref == 300) {
                        $speed = 5;
                    } else {
                        $speed = 1;
                    }
                }
            }
        }
    } else {
        $speed = $ref;
    }
    return round($distance / $speed * 3600 / INCREASE_SPEED);
}
Esempio n. 3
0
 public function get_list($lat, $long, $page, $pagesize, $activity_type)
 {
     $where = array("status" => 0, "invite_time" => array("gt", time()));
     if ($activity_type !== false) {
         $sql = "SELECT i.*, u.* FROM " . C("DB_PREFIX") . "user as u INNER JOIN " . C("DB_PREFIX") . "invitation as i ON i.uid=u.uid WHERE i.status=0 AND i.activity_type=" . $activity_type . " AND i.invite_time>" . time() . " ORDER BY i.pigcms_id DESC, u.sex DESC";
         $where["activity_type"] = intval($activity_type);
     } else {
         $sql = "SELECT i.*, u.* FROM " . C("DB_PREFIX") . "user as u INNER JOIN " . C("DB_PREFIX") . "invitation as i ON i.uid=u.uid WHERE i.status=0 AND i.invite_time>" . time() . " ORDER BY i.pigcms_id DESC, u.sex DESC";
     }
     $start = ($page - 1) * $pagesize;
     $count = $this->where($where)->count();
     $sql .= " limit {$start}, {$pagesize}";
     $mode = new Model();
     $res = $mode->query($sql);
     $today = strtotime(date("Y-m-d")) + 86400;
     $tomorrow = $today + 86400;
     $lastday = $tomorrow + 86400;
     foreach ($res as &$v) {
         $v["_time"] = date("Y-m-d H:i", $v["invite_time"]);
         $v["juli"] = ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN(($lat * PI() / 180 - $v["lat"] * PI() / 180) / 2), 2) + COS($lat * PI() / 180) * COS($v["lat"] * PI() / 180) * POW(SIN(($long * PI() / 180 - $v["long"] * PI() / 180) / 2), 2))) * 1000);
         $v["juli"] = 1000 < $v["juli"] ? number_format($v["juli"] / 1000, 1) . "km" : ($v["juli"] < 100 ? "<100m" : $v["juli"] . "m");
         $v["invite_time"] = $v["invite_time"] < $today ? "今天 " . date("H:i", $v["invite_time"]) : ($v["invite_time"] < $tomorrow ? "明天  " . date("H:i", $v["invite_time"]) : ($v["invite_time"] < $lastday ? "后天  " . date("H:i", $v["invite_time"]) : date("m-d H:i", $v["invite_time"])));
         $v["birthday"] && ($v["age"] = date("Y") - date("Y", strtotime($v["birthday"])));
         $v["age"] = 100 < $v["age"] || $v["age"] < 0 ? "保密" : $v["age"] . "岁";
     }
     return array("data" => $res, "total" => $count);
 }
Esempio n. 4
0
 public function procDistanceTime($coor, $thiscoor, $ref, $mode)
 {
     global $bid28, $bid14, $building;
     $xdistance = ABS($thiscoor['x'] - $coor['x']);
     if ($xdistance > WORLD_MAX) {
         $xdistance = 2 * WORLD_MAX + 1 - $xdistance;
     }
     $ydistance = ABS($thiscoor['y'] - $coor['y']);
     if ($ydistance > WORLD_MAX) {
         $ydistance = 2 * WORLD_MAX + 1 - $ydistance;
     }
     $distance = SQRT(POW($xdistance, 2) + POW($ydistance, 2));
     if (!$mode) {
         if ($ref == 1) {
             $speed = 16;
         } else {
             if ($ref == 2) {
                 $speed = 12;
             } else {
                 if ($ref == 3) {
                     $speed = 24;
                 } else {
                     if ($ref == 300) {
                         $speed = 5;
                     } else {
                         $speed = 1;
                     }
                 }
             }
         }
     } else {
         $speed = $ref;
         if ($building->getTypeLevel(14) != 0 && $distance >= TS_THRESHOLD) {
             $speed = $speed * ($bid14[$building->gettypeLevel(14)]['attri'] / 100);
         }
     }
     if ($speed != 0) {
         return round($distance / $speed * 3600 / INCREASE_SPEED);
     } else {
         return round($distance * 3600 / INCREASE_SPEED);
     }
 }
Esempio n. 5
0
function gen_score($sid)
{
  global $ore_price;
  global $organics_price;
  global $goods_price;
  global $energy_price;
  global $upgrade_cost;
  global $upgrade_factor;
  global $dev_genesis_price;
  global $dev_beacon_price;
  global $dev_emerwarp_price;
  global $dev_warpedit_price;
  global $dev_minedeflector_price;
  global $dev_escapepod_price;
  global $dev_fuelscoop_price;
  global $dev_lssd_price;
  global $fighter_price;
  global $torpedo_price;
  global $armour_price;
  global $colonist_price;
  global $base_ore;
  global $base_goods;
  global $base_organics;
  global $base_credits;
  global $db, $dbtables;

  $calc_hull = "ROUND(pow($upgrade_factor,hull))";
  $calc_engines = "ROUND(pow($upgrade_factor,engines))";
  $calc_power = "ROUND(pow($upgrade_factor,power))";
  $calc_computer = "ROUND(pow($upgrade_factor,computer))";
  $calc_sensors = "ROUND(pow($upgrade_factor,sensors))";
  $calc_beams = "ROUND(pow($upgrade_factor,beams))";
  $calc_torp_launchers = "ROUND(pow($upgrade_factor,torp_launchers))";
  $calc_shields = "ROUND(pow($upgrade_factor,shields))";
  $calc_armour = "ROUND(pow($upgrade_factor,armour))";
  $calc_cloak = "ROUND(pow($upgrade_factor,cloak))";
  $calc_levels = "($calc_hull+$calc_engines+$calc_power+$calc_computer+$calc_sensors+$calc_beams+$calc_torp_launchers+$calc_shields+$calc_armour+$calc_cloak)*$upgrade_cost";

  $calc_torps = "torps*$torpedo_price";
  $calc_armour_pts = "armour_pts*$armour_price";
  $calc_ship_ore = "ship_ore*$ore_price";
  $calc_ship_organics = "ship_organics*$organics_price";
  $calc_ship_goods = "ship_goods*$goods_price";
  $calc_ship_energy = "ship_energy*$energy_price";
  $calc_ship_colonists = "ship_colonists*$colonist_price";
  $calc_ship_fighters = "ship_fighters*$fighter_price";
  $calc_equip = "$calc_torps+$calc_armour_pts+$calc_ship_ore+$calc_ship_organics+$calc_ship_goods+$calc_ship_energy+$calc_ship_colonists+$calc_ship_fighters";

  $calc_dev_warpedit = "dev_warpedit*$dev_warpedit_price";
  $calc_dev_genesis = "dev_genesis*$dev_genesis_price";
  $calc_dev_beacon = "dev_beacon*$dev_beacon_price";
  $calc_dev_emerwarp = "dev_emerwarp*$dev_emerwarp_price";
  $calc_dev_escapepod = "IF(dev_escapepod='Y', $dev_escapepod_price, 0)";
  $calc_dev_fuelscoop = "IF(dev_fuelscoop='Y', $dev_fuelscoop_price, 0)";
  $calc_dev_lssd = "IF(dev_lssd='Y', $dev_lssd_price, 0)";
  $calc_dev_minedeflector = "dev_minedeflector*$dev_minedeflector_price";
  $calc_dev = "$calc_dev_warpedit+$calc_dev_genesis+$calc_dev_beacon+$calc_dev_emerwarp+$calc_dev_escapepod+$calc_dev_fuelscoop+$calc_dev_minedeflector+$calc_dev_lssd";
  $calc_planet_goods = "SUM($dbtables[planets].organics)+SUM($dbtables[planets].ore)+SUM($dbtables[planets].goods)+SUM($dbtables[planets].energy)";
   //$calc_planet_goods = "SUM($dbtables[planets].organics)*$organics_price+SUM($dbtables[planets].ore)*$ore_price+SUM($dbtables[planets].goods)*$goods_price+SUM($dbtables[planets].energy)*$energy_price";
  $calc_planet_colonists = "SUM($dbtables[planets].colonists)*$colonist_price";
$calc_planet_defence = "SUM($dbtables[planets].fighters)*$fighter_price+SUM(IF($dbtables[planets].base='Y', $base_credits+$base_ore*$ore_price+$base_organics*$organics_price+$base_goods*$goods_price, 0))+SUM($dbtables[planets].torps)*$torpedo_price";
  $calc_planet_credits = "SUM($dbtables[planets].credits)";
  $res = $db->Execute("SELECT $dbtables[players].credits+$calc_planet_goods+$calc_planet_colonists+$calc_planet_defence+$calc_planet_credits AS score FROM $dbtables[players] LEFT JOIN $dbtables[planets] ON $dbtables[planets].owner=player_id WHERE player_id=$sid");
  $row = $res->fields;
  $score = $row[score];
  // New ship code - neatly calcs for every ship owned! Furangee tech is half price
  $res = $db->Execute("SELECT SUM($calc_levels+$calc_equip+$calc_dev) AS score FROM $dbtables[ships] WHERE player_id=$sid AND ship_destroyed='N' AND fur_tech='Y'");
  $row = $res->fields;
  $score += ($row[score]);
  $res = $db->Execute("SELECT SUM($calc_levels+$calc_equip+$calc_dev) AS score FROM $dbtables[ships] WHERE player_id=$sid AND ship_destroyed='N' AND fur_tech='N'");
  $row = $res->fields;
  $score += $row[score];  
  
  $res = $db->Execute("SELECT balance, loan FROM $dbtables[ibank_accounts] where player_id = $sid");
  if($res)
  {
     $row = $res->fields;
     $score += ($row[balance] - $row[loan]);
  }
  if ($score < 1000) {
	$score = 1000;
  }
  $score = ROUND(SQRT($score));
  $db->Execute("UPDATE $dbtables[players] SET score=$score WHERE player_id=$sid");

  return $score;
}
Esempio n. 6
0
 public function getArea()
 {
     // Calculate and return the area:
     return SQRT($this->_perimeter / 2 * ($this->_perimeter / 2 - $this->_sides[0]) * ($this->_perimeter / 2 - $this->_sides[1]) * ($this->_perimeter / 2 - $this->_sides[2]));
 }
Esempio n. 7
0
function invtcdf($p, $ndf, $dec = 4)
{
    $half_pi = M_PI / 2;
    $eps = 1.0E-12;
    $origp = $p;
    if ($p > 0.5) {
        $p = 1 - $p;
    }
    $p = $p * 2;
    if ($ndf < 1 || $p > 1 || $p <= 0) {
        echo "error in params";
        return false;
    }
    if (abs($ndf - 2) < $eps) {
        //special case ndf=2
        $fn_val = round(SQRT(2 / ($p * (2 - $p)) - 2), $dec);
        if ($origp < 0.5) {
            return -1 * $fn_val;
        } else {
            return $fn_val;
        }
    } else {
        if (abs($ndf - 4) < $eps) {
            //special case ndf=4
            $v = 4 / sqrt($p * (2 - $p)) * cos(1 / 3 * acos(sqrt($p * (2 - $p))));
            $fn_val = round(sqrt($v - 4), $dec);
            if ($origp < 0.5) {
                return -1 * $fn_val;
            } else {
                return $fn_val;
            }
        } else {
            if ($ndf < 1 + $eps) {
                //special case ndf=1
                $prob = $p * $half_pi;
                $fn_val = round(cos($prob) / sin($prob), $dec);
                if ($origp < 0.5) {
                    return -1 * $fn_val;
                } else {
                    return $fn_val;
                }
            } else {
                $a = 1 / ($ndf - 0.5);
                $b = 48 / pow($a, 2);
                $c = ((20700 * $a / $b - 98) * $a - 16) * $a + 96.36;
                $d = ((94.5 / ($b + $c) - 3) / $b + 1) * sqrt($a * $half_pi) * $ndf;
                $x = $d * $p;
                $y = pow($x, 2 / $ndf);
                if ($y > 0.05 + $a) {
                    $x = invnormalcdf($origp, $dec + 10);
                    $y = pow($x, 2);
                    if ($ndf < 5) {
                        $c = $c + 0.3 * ($ndf - 4.5) * ($x + 0.6);
                    }
                    $c = (((0.05 * $d * $x - 5) * $x - 7) * $x - 2) * $x + $b + $c;
                    $y = (((((0.4 * $y + 6.3) * $y + 36) * $y + 94.5) / $c - $y - 3) / $b + 1) * $x;
                    $y = $a * pow($y, 2);
                    if ($y > 0.002) {
                        $y = exp($y) - 1;
                    } else {
                        $y = 0.5 * pow($y, 2) + $y;
                    }
                } else {
                    $y = ((1 / ((($ndf + 6) / ($ndf * $y) - 0.089 * $d - 0.822) * ($ndf + 2) * 3) + 0.5 / ($ndf + 4)) * $y - 1) * ($ndf + 1) / ($ndf + 2) + 1 / $y;
                }
            }
        }
    }
    if ($dec > 3) {
        $fn_val = invtrefine(sqrt($ndf * $y), 1 - $p / 2, $ndf, $dec);
        //echo "orig: ".sqrt($ndf*$y).", refined: $fn_val <br/>";
    } else {
        $fn_val = round(sqrt($ndf * $y), $dec);
    }
    if ($origp < 0.5) {
        return -1 * $fn_val;
    } else {
        return $fn_val;
    }
}
Esempio n. 8
0
 /**
  * @param $entity
  * @param $targetId
  */
 public static function updateRating($entity, $targetId)
 {
     $positive = static::find()->where(['entity' => $entity, 'target_id' => $targetId, 'value' => self::VOTE_POSITIVE])->count();
     $negative = static::find()->where(['entity' => $entity, 'target_id' => $targetId, 'value' => self::VOTE_NEGATIVE])->count();
     if ($positive + $negative !== 0) {
         $rating = (($positive + 1.9208) / ($positive + $negative) - 1.96 * SQRT($positive * $negative / ($positive + $negative) + 0.9604) / ($positive + $negative)) / (1 + 3.8416 / ($positive + $negative));
     } else {
         $rating = 0;
     }
     $rating = round($rating * 10, 2);
     $aggregateModel = VoteAggregate::findOne(['entity' => $entity, 'target_id' => $targetId]);
     if ($aggregateModel == null) {
         $aggregateModel = new VoteAggregate();
         $aggregateModel->entity = $entity;
         $aggregateModel->target_id = $targetId;
     }
     $aggregateModel->positive = $positive;
     $aggregateModel->negative = $negative;
     $aggregateModel->rating = $rating;
     $aggregateModel->save();
 }
Esempio n. 9
0
function ogdbRadius($zip, $km, $sort = 'asc')
{
    $fileData = explode("\n", ogdbGetData());
    foreach ($fileData as $fileRow) {
        $fileRow = explode("\t", $fileRow);
        //var_dump($fileRow);
        $dataStructure = ogdbDataStructure($fileRow);
        //var_dump($dataStructure);
        if (isset($fileRow[$dataStructure['zip_pos']]) && isset($fileRow[$dataStructure['lon_pos']]) && isset($fileRow[$dataStructure['lat_pos']])) {
            if (substr_count($fileRow[$dataStructure['zip_pos']], $zip) == 1) {
                $origin_lon = $fileRow[$dataStructure['lon_pos']];
                $origin_lat = $fileRow[$dataStructure['lat_pos']];
                $id = $fileRow[0];
            }
        }
        unset($dataStructure, $fileRow);
    }
    $lambda = $origin_lon * pi() / 180;
    $phi = $origin_lat * pi() / 180;
    // Umwandlung der Kurgelkoordinaten ins kartesische Koordinatensystem
    $geoKoordX = OGDB_EARTH_RADIUS * cos($phi) * cos($lambda);
    $geoKoordY = OGDB_EARTH_RADIUS * cos($phi) * sin($lambda);
    $geoKoordZ = OGDB_EARTH_RADIUS * sin($phi);
    $data = array();
    if (isset($origin_lon) && isset($origin_lat) && isset($id)) {
        foreach ($fileData as $fileRow) {
            $fileRow = explode("\t", $fileRow);
            $dataStructure = ogdbDataStructure($fileRow);
            if (isset($fileRow[$dataStructure['zip_pos']]) && isset($fileRow[$dataStructure['lon_pos']]) && isset($fileRow[$dataStructure['lat_pos']])) {
                $distance = 2 * OGDB_EARTH_RADIUS * asin(SQRT(pow($geoKoordX - OGDB_EARTH_RADIUS * cos($fileRow[$dataStructure['lat_pos']] * pi() / 180) * cos($fileRow[$dataStructure['lon_pos']] * pi() / 180), 2) + pow($geoKoordY - OGDB_EARTH_RADIUS * cos($fileRow[$dataStructure['lat_pos']] * pi() / 180) * sin($fileRow[$dataStructure['lon_pos']] * pi() / 180), 2) + pow($geoKoordZ - OGDB_EARTH_RADIUS * sin($fileRow[$dataStructure['lat_pos']] * pi() / 180), 2)) / (2 * OGDB_EARTH_RADIUS));
                // var_dump($distance);
                // die;
                //var_dump($fileRow[3] . '<b> '. round($distance, 2) .'</b>');
                //die;
                if ($distance < $km and $fileRow[3] != '') {
                    $data[($distance + 0.01) * 1000] = array('loc_id' => $fileRow[0], 'name' => $fileRow[3], 'zip' => $fileRow[$dataStructure['zip_pos']], 'distance' => $distance, 'adresse' => $fileRow[16], 'lat_pos' => $fileRow[4], 'lon_pos' => $fileRow[5], 'url' => $fileRow[12]);
                }
                //var_dump($data);
                unset($distance);
            }
            unset($dataStructure, $fileRow);
        }
    }
    switch ($sort) {
        case 'asc':
            ksort($data);
            break;
        case 'desc':
            krsort($data);
            break;
    }
    return $data;
}
Esempio n. 10
0
 public function generate_score($user_id)
 {
     $sql_manager = new manage_table();
     global $db_prefix;
     global $db;
     global $upgrade_factor;
     global $upgrade_cost;
     global $torpedo_price;
     global $armor_price;
     global $fighter_price;
     global $ore_price;
     global $organics_price;
     global $goods_price;
     global $energy_price;
     global $colonist_price;
     global $dev_genesis_price;
     global $dev_beacon_price;
     global $dev_emerwarp_price;
     global $dev_warpedit_price;
     global $dev_minedeflector_price;
     global $dev_escapepod_price;
     global $dev_fuelscoop_price;
     global $dev_lssd_price;
     global $base_ore;
     global $base_goods;
     global $base_organics;
     global $base_credits;
     $calc_hull = "ROUND(pow({$upgrade_factor},hull))";
     $calc_engines = "ROUND(pow({$upgrade_factor},engines))";
     $calc_power = "ROUND(pow({$upgrade_factor},power))";
     $calc_computer = "ROUND(pow({$upgrade_factor},computer))";
     $calc_sensors = "ROUND(pow({$upgrade_factor},sensors))";
     $calc_beams = "ROUND(pow({$upgrade_factor},beams))";
     $calc_torp_launchers = "ROUND(pow({$upgrade_factor},torp_launchers))";
     $calc_shields = "ROUND(pow({$upgrade_factor},shields))";
     $calc_armor = "ROUND(pow({$upgrade_factor},armor))";
     $calc_cloak = "ROUND(pow({$upgrade_factor},cloak))";
     $calc_levels = "({$calc_hull} + {$calc_engines} + {$calc_power} + {$calc_computer} + {$calc_sensors} + {$calc_beams} + {$calc_torp_launchers} + {$calc_shields} + {$calc_armor} + {$calc_cloak}) * {$upgrade_cost}";
     $calc_torps = "" . $db_prefix . "ships.torps * {$torpedo_price}";
     $calc_armor_pts = "armor_pts * {$armor_price}";
     $calc_ship_ore = "ship_ore * {$ore_price}";
     $calc_ship_organics = "ship_organics * {$organics_price}";
     $calc_ship_goods = "ship_goods * {$goods_price}";
     $calc_ship_energy = "ship_energy * {$energy_price}";
     $calc_ship_colonists = "ship_colonists * {$colonist_price}";
     $calc_ship_fighters = "ship_fighters * {$fighter_price}";
     $calc_equip = "{$calc_torps} + {$calc_armor_pts} + {$calc_ship_ore} + {$calc_ship_organics} + {$calc_ship_goods} + {$calc_ship_energy} + {$calc_ship_colonists} + {$calc_ship_fighters}";
     $calc_dev_warpedit = "dev_warpedit * {$dev_warpedit_price}";
     $calc_dev_genesis = "dev_genesis * {$dev_genesis_price}";
     $calc_dev_beacon = "dev_beacon * {$dev_beacon_price}";
     $calc_dev_emerwarp = "dev_emerwarp * {$dev_emerwarp_price}";
     $calc_dev_escapepod = "if (dev_escapepod='Y', {$dev_escapepod_price}, 0)";
     $calc_dev_fuelscoop = "if (dev_fuelscoop='Y', {$dev_fuelscoop_price}, 0)";
     $calc_dev_lssd = "if (dev_lssd='Y', {$dev_lssd_price}, 0)";
     $calc_dev_minedeflector = "dev_minedeflector * {$dev_minedeflector_price}";
     $calc_dev = "{$calc_dev_warpedit} + {$calc_dev_genesis} + {$calc_dev_beacon} + {$calc_dev_emerwarp} + {$calc_dev_escapepod} + {$calc_dev_fuelscoop} + {$calc_dev_minedeflector} + {$calc_dev_lssd}";
     $calc_planet_goods = "SUM(" . $db_prefix . "planets.organics) * {$organics_price} + SUM(" . $db_prefix . "planets.ore) * {$ore_price} + SUM(" . $db_prefix . "planets.goods) * {$goods_price} + SUM(" . $db_prefix . "planets.energy) * {$energy_price}";
     $calc_planet_colonists = "SUM(" . $db_prefix . "planets.colonists) * {$colonist_price}";
     $calc_planet_defence = "SUM(" . $db_prefix . "planets.fighters) * {$fighter_price} + if (" . $db_prefix . "planets.base='Y', {$base_credits} + SUM(" . $db_prefix . "planets.torps) * {$torpedo_price}, 0)";
     $calc_planet_credits = "SUM(" . $db_prefix . "planets.credits)";
     $result_planet = $this->connect->query("SELECT if(COUNT(*)>0, " . $calc_planet_goods . " + " . $calc_planet_colonists . " + " . $calc_planet_defence . " + " . $calc_planet_credits . ", 0) as planet_score FROM " . $db_prefix . "planets WHERE owner=" . $user_id . "");
     $result_planet = $result_planet->fetch();
     $planet_score = $result_planet['planet_score'];
     $result_player = $this->connect->query("SELECT if(COUNT(*)>0, " . $calc_levels . " + " . $calc_equip . " + " . $calc_dev . " + " . $db_prefix . "ships.credits, 0) AS ship_score FROM " . $db_prefix . "ships LEFT JOIN " . $db_prefix . "planets ON " . $db_prefix . "planets.owner=ship_id WHERE ship_id=" . $user_id . " AND ship_destroyed='N'");
     $result_player = $result_player->fetch();
     $ship_score = $result_player['ship_score'];
     $result_bank = $this->connect->query("SELECT (balance - loan) as bank_score FROM " . $db_prefix . "ibank_accounts WHERE ship_id=" . $user_id . "");
     $result_bank = $result_bank->fetch();
     $bank_score = $result_bank['bank_score'];
     $score = $ship_score + $planet_score + $bank_score;
     if ($score < 0) {
         $score = 0;
     }
     $score = (int) ROUND(SQRT($score));
     $updated_stats = array('score' => $score);
     $sql_manager->updatePlayer($user_id, "ships", $updated_stats);
     return $score;
 }
Esempio n. 11
0
function gen_score($sid)
{
    global $db;
    global $upgrade_factor;
    global $upgrade_cost;
    global $torpedo_price;
    global $armor_price;
    global $fighter_price;
    global $ore_price;
    global $organics_price;
    global $goods_price;
    global $energy_price;
    global $colonist_price;
    global $dev_genesis_price;
    global $dev_beacon_price;
    global $dev_emerwarp_price;
    global $dev_warpedit_price;
    global $dev_minedeflector_price;
    global $dev_escapepod_price;
    global $dev_fuelscoop_price;
    global $dev_lssd_price;
    global $base_ore;
    global $base_goods;
    global $base_organics;
    global $base_credits;
    $calc_hull = "ROUND(pow({$upgrade_factor},hull))";
    $calc_engines = "ROUND(pow({$upgrade_factor},engines))";
    $calc_power = "ROUND(pow({$upgrade_factor},power))";
    $calc_computer = "ROUND(pow({$upgrade_factor},computer))";
    $calc_sensors = "ROUND(pow({$upgrade_factor},sensors))";
    $calc_beams = "ROUND(pow({$upgrade_factor},beams))";
    $calc_torp_launchers = "ROUND(pow({$upgrade_factor},torp_launchers))";
    $calc_shields = "ROUND(pow({$upgrade_factor},shields))";
    $calc_armor = "ROUND(pow({$upgrade_factor},armor))";
    $calc_cloak = "ROUND(pow({$upgrade_factor},cloak))";
    $calc_levels = "({$calc_hull} + {$calc_engines} + {$calc_power} + {$calc_computer} + {$calc_sensors} + {$calc_beams} + {$calc_torp_launchers} + {$calc_shields} + {$calc_armor} + {$calc_cloak}) * {$upgrade_cost}";
    $calc_torps = "{$db->prefix}ships.torps * {$torpedo_price}";
    $calc_armor_pts = "armor_pts * {$armor_price}";
    $calc_ship_ore = "ship_ore * {$ore_price}";
    $calc_ship_organics = "ship_organics * {$organics_price}";
    $calc_ship_goods = "ship_goods * {$goods_price}";
    $calc_ship_energy = "ship_energy * {$energy_price}";
    $calc_ship_colonists = "ship_colonists * {$colonist_price}";
    $calc_ship_fighters = "ship_fighters * {$fighter_price}";
    $calc_equip = "{$calc_torps} + {$calc_armor_pts} + {$calc_ship_ore} + {$calc_ship_organics} + {$calc_ship_goods} + {$calc_ship_energy} + {$calc_ship_colonists} + {$calc_ship_fighters}";
    $calc_dev_warpedit = "dev_warpedit * {$dev_warpedit_price}";
    $calc_dev_genesis = "dev_genesis * {$dev_genesis_price}";
    $calc_dev_beacon = "dev_beacon * {$dev_beacon_price}";
    $calc_dev_emerwarp = "dev_emerwarp * {$dev_emerwarp_price}";
    $calc_dev_escapepod = "if (dev_escapepod='Y', {$dev_escapepod_price}, 0)";
    $calc_dev_fuelscoop = "if (dev_fuelscoop='Y', {$dev_fuelscoop_price}, 0)";
    $calc_dev_lssd = "if (dev_lssd='Y', {$dev_lssd_price}, 0)";
    $calc_dev_minedeflector = "dev_minedeflector * {$dev_minedeflector_price}";
    $calc_dev = "{$calc_dev_warpedit} + {$calc_dev_genesis} + {$calc_dev_beacon} + {$calc_dev_emerwarp} + {$calc_dev_escapepod} + {$calc_dev_fuelscoop} + {$calc_dev_minedeflector} + {$calc_dev_lssd}";
    $calc_planet_goods = "SUM({$db->prefix}planets.organics) * {$organics_price} + SUM({$db->prefix}planets.ore) * {$ore_price} + SUM({$db->prefix}planets.goods) * {$goods_price} + SUM({$db->prefix}planets.energy) * {$energy_price}";
    $calc_planet_colonists = "SUM({$db->prefix}planets.colonists) * {$colonist_price}";
    $calc_planet_defence = "SUM({$db->prefix}planets.fighters) * {$fighter_price} + if ({$db->prefix}planets.base='Y', {$base_credits} + SUM({$db->prefix}planets.torps) * {$torpedo_price}, 0)";
    $calc_planet_credits = "SUM({$db->prefix}planets.credits)";
    $res = $db->Execute("SELECT if(COUNT(*)>0, {$calc_planet_goods} + {$calc_planet_colonists} + {$calc_planet_defence} + {$calc_planet_credits}, 0) as planet_score FROM {$db->prefix}planets WHERE owner=?", array($sid));
    db_op_result($db, $res, __LINE__, __FILE__);
    $planet_score = $res->fields['planet_score'];
    $res = $db->Execute("SELECT if(COUNT(*)>0, {$calc_levels} + {$calc_equip} + {$calc_dev} + {$db->prefix}ships.credits, 0) AS ship_score FROM {$db->prefix}ships LEFT JOIN {$db->prefix}planets ON {$db->prefix}planets.owner=ship_id WHERE ship_id=? AND ship_destroyed='N'", array($sid));
    db_op_result($db, $res, __LINE__, __FILE__);
    $ship_score = $res->fields['ship_score'];
    $res = $db->Execute("SELECT (balance - loan) as bank_score FROM {$db->prefix}ibank_accounts WHERE ship_id = ?;", array($sid));
    db_op_result($db, $res, __LINE__, __FILE__);
    $bank_score = $res->fields['bank_score'];
    $score = $ship_score + $planet_score + $bank_score;
    if ($score < 0) {
        $score = 0;
    }
    $score = (int) ROUND(SQRT($score));
    $resa = $db->Execute("UPDATE {$db->prefix}ships SET score=? WHERE ship_id=?", array($score, $sid));
    db_op_result($db, $resa, __LINE__, __FILE__);
    return $score;
}
Esempio n. 12
0
 private function procDistanceTime($coor, $thiscoor, $ref, $mode)
 {
     global $bid14, $database, $generator;
     $resarray = $database->getResourceLevel($generator->getBaseID($coor['x'], $coor['y']));
     $xdistance = ABS($thiscoor['x'] - $coor['x']);
     if ($xdistance > WORLD_MAX) {
         $xdistance = 2 * WORLD_MAX + 1 - $xdistance;
     }
     $ydistance = ABS($thiscoor['y'] - $coor['y']);
     if ($ydistance > WORLD_MAX) {
         $ydistance = 2 * WORLD_MAX + 1 - $ydistance;
     }
     $distance = SQRT(POW($xdistance, 2) + POW($ydistance, 2));
     if (!$mode) {
         if ($ref == 1) {
             $speed = 16;
         } else {
             if ($ref == 2) {
                 $speed = 12;
             } else {
                 if ($ref == 3) {
                     $speed = 24;
                 } else {
                     if ($ref == 300) {
                         $speed = 5;
                     } else {
                         $speed = 1;
                     }
                 }
             }
         }
     } else {
         $speed = $ref;
         for ($i = 19; $i <= 40; $i++) {
             if ($resarray['f' . $i . 't'] == 14) {
                 $ts_level = $resarray['f' . $i];
                 $ts_attri = $bid14[$ts_level]['attri'];
             }
         }
         if ($ts_attri > 0) {
             $speed = $distance <= TS_THRESHOLD ? $speed : $speed * ((TS_THRESHOLD + ($distance - TS_THRESHOLD) * $ts_attri / 100) / $distance);
         }
     }
     return round($distance / $speed * 3600 / INCREASE_SPEED);
 }
Esempio n. 13
0
 public function getArea()
 {
     $p = $this->perimeter / 2;
     return SQRT($p * ($p - $this->sides[0]) * ($p - $this->sides[1]) * ($p - $this->sides[2]));
 }
Esempio n. 14
0
function ogdbRadius($zip, $km, $sort = 'asc')
{
    ini_set('precision', 49);
    // http://de2.php.net/manual/de/function.pi.php
    $fileData = explode("\n", ogdbGetData());
    foreach ($fileData as $fileRow) {
        $fileRow = explode("\t", $fileRow);
        $dataStructure = ogdbDataStructure($fileRow);
        if (isset($fileRow[$dataStructure['zip_pos']]) && isset($fileRow[$dataStructure['lon_pos']]) && isset($fileRow[$dataStructure['lat_pos']])) {
            if (substr_count($fileRow[$dataStructure['zip_pos']], $zip) == 1) {
                $origin_lon = $fileRow[$dataStructure['lon_pos']];
                $origin_lat = $fileRow[$dataStructure['lat_pos']];
                $id = $fileRow[0];
            }
        }
        unset($dataStructure, $fileRow);
    }
    $lambda = $origin_lon * pi() / 180;
    $phi = $origin_lat * pi() / 180;
    // Umwandlung der Kurgelkoordinaten ins kartesische Koordinatensystem
    $geoKoordX = OGDB_EARTH_RADIUS * cos($phi) * cos($lambda);
    $geoKoordY = OGDB_EARTH_RADIUS * cos($phi) * sin($lambda);
    $geoKoordZ = OGDB_EARTH_RADIUS * sin($phi);
    $data = array();
    if (isset($origin_lon) && isset($origin_lat) && isset($id)) {
        foreach ($fileData as $fileRow) {
            $fileRow = explode("\t", $fileRow);
            $dataStructure = ogdbDataStructure($fileRow);
            if (isset($fileRow[$dataStructure['zip_pos']]) && isset($fileRow[$dataStructure['lon_pos']]) && isset($fileRow[$dataStructure['lat_pos']])) {
                $distance = 2 * OGDB_EARTH_RADIUS * asin(SQRT(pow($geoKoordX - OGDB_EARTH_RADIUS * cos($fileRow[$dataStructure['lat_pos']] * pi() / 180) * cos($fileRow[$dataStructure['lon_pos']] * pi() / 180), 2) + pow($geoKoordY - OGDB_EARTH_RADIUS * cos($fileRow[$dataStructure['lat_pos']] * pi() / 180) * sin($fileRow[$dataStructure['lon_pos']] * pi() / 180), 2) + pow($geoKoordZ - OGDB_EARTH_RADIUS * sin($fileRow[$dataStructure['lat_pos']] * pi() / 180), 2)) / (2 * OGDB_EARTH_RADIUS));
                if ($distance < $km && $id != $fileRow[0]) {
                    $data[$distance] = array('loc_id' => $fileRow[0], 'name' => $fileRow[3], 'zip' => $fileRow[$dataStructure['zip_pos']], 'distance' => $distance);
                }
                unset($distance);
            }
            unset($dataStructure, $fileRow);
        }
    }
    switch ($sort) {
        case 'asc':
            ksort($data);
            break;
        case 'desc':
            krsort($data);
            break;
    }
    return $data;
}
 public function wap_get_store_list_by_catid($cat_id, $area_id, $order, $lat, $long, $cat_url)
 {
     $stores = D('Store_category')->field('store_id')->where("cat_id='{$cat_id}'")->select();
     foreach ($stores as $s) {
         $store_ids[] = $s['store_id'];
     }
     $store_ids && ($where['store_id'] = array('in', $store_ids));
     if ($cat_url == 'dianying' && empty($store_ids)) {
         return false;
     }
     // 		$where['have_meal'] = 1;
     $where['status'] = 1;
     $area_id && ($where['area_id'] = $area_id);
     $count = D('Merchant_store')->where($where)->count();
     //排序
     switch ($order) {
         case 'distance':
             $order = "ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN(({$lat} * PI() / 180- `lat` * PI()/180)/2),2)+COS({$lat} *PI()/180)*COS(`lat`*PI()/180)*POW(SIN(({$long} *PI()/180- `long`*PI()/180)/2),2)))*1000) ASC";
             //'`g`.`price` ASC,`g`.`group_id` DESC';
             break;
             // 			case 'priceDesc':
             // 				$order = '`g`.`price` DESC,`g`.`group_id` DESC';
             // 				break;
             // 			case 'solds':
             // 				$order = '`g`.`sale_count` DESC,`g`.`group_id` DESC';
             // 				break;
             // 			case 'rating':
             // 				$order = '`g`.`score_mean` DESC,`g`.`group_id` DESC';
             // 				break;
             // 			case 'start':
             // 				$order = '`g`.`last_time` DESC,`g`.`group_id` DESC';
             // 				break;
         // 			case 'priceDesc':
         // 				$order = '`g`.`price` DESC,`g`.`group_id` DESC';
         // 				break;
         // 			case 'solds':
         // 				$order = '`g`.`sale_count` DESC,`g`.`group_id` DESC';
         // 				break;
         // 			case 'rating':
         // 				$order = '`g`.`score_mean` DESC,`g`.`group_id` DESC';
         // 				break;
         // 			case 'start':
         // 				$order = '`g`.`last_time` DESC,`g`.`group_id` DESC';
         // 				break;
         default:
             $order = '`store_id` DESC';
     }
     import('@.ORG.wap_group_page');
     $p = new Page($count, C('config.group_page_row'), C('config.group_page_val'));
     $list = D('Merchant_store')->field(true)->where($where)->order($order)->limit($p->firstRow . ',' . $p->listRows)->select();
     // 		echo D('Merchant_store')->_sql();
     $return['pagebar'] = $p->show();
     if ($list) {
         $store_image_class = new store_image();
         foreach ($list as &$v) {
             $images = $store_image_class->get_allImage_by_path($v['pic_info']);
             $v['image'] = $images ? array_shift($images) : '';
             $v['juli'] = ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN(($lat * PI() / 180 - $v['lat'] * PI() / 180) / 2), 2) + COS($lat * PI() / 180) * COS($v['lat'] * PI() / 180) * POW(SIN(($long * PI() / 180 - $v['long'] * PI() / 180) / 2), 2))) * 1000);
             $v['juli'] = $v['juli'] > 1000 ? number_format($v['juli'] / 1000, 1) . 'km' : ($v['juli'] < 100 ? '<100m' : $v['juli'] . 'm');
         }
     }
     $return['store_list'] = $list;
     return $return;
 }
Esempio n. 16
0
 public function mysign()
 {
     $invitation_signs = D("Invitation_sign")->field("invid")->where(array("uid" => $this->user_session["uid"]))->order("invid DESC")->select();
     $invids = $pre = "";
     foreach ($invitation_signs as $is) {
         $invids .= $pre . $is["invid"];
         $pre = ",";
     }
     $today = strtotime(date("Y-m-d")) + 86400;
     $tomorrow = $today + 86400;
     $lastday = $tomorrow + 86400;
     if ($invids) {
         $sql = "SELECT i.*, u.* FROM " . C("DB_PREFIX") . "user as u INNER JOIN " . C("DB_PREFIX") . "invitation as i ON i.uid=u.uid WHERE i.pigcms_id IN ({$invids}) ORDER BY i.pigcms_id DESC, u.sex DESC";
         $mode = new Model();
         $res = $mode->query($sql);
         foreach ($res as &$v) {
             $v["_time"] = date("Y-m-d H:i", $v["invite_time"]);
             $v["juli"] = ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN(($this->_lat * PI() / 180 - $v["lat"] * PI() / 180) / 2), 2) + COS($this->_lat * PI() / 180) * COS($v["lat"] * PI() / 180) * POW(SIN(($this->_long * PI() / 180 - $v["long"] * PI() / 180) / 2), 2))) * 1000);
             $v["juli"] = 1000 < $v["juli"] ? number_format($v["juli"] / 1000, 1) . "km" : ($v["juli"] < 100 ? "<100m" : $v["juli"] . "m");
             $v["invite_time"] = $v["invite_time"] < $today ? "今天 " . date("H:i", $v["invite_time"]) : ($v["invite_time"] < $tomorrow ? "明天  " . date("H:i", $v["invite_time"]) : ($v["invite_time"] < $lastday ? "后天  " . date("H:i", $v["invite_time"]) : date("m-d H:i", $v["invite_time"])));
             $v["birthday"] && ($v["age"] = date("Y") - date("Y", strtotime($v["birthday"])));
         }
         $this->assign("date_list", $res);
     }
     $this->display();
 }
Esempio n. 17
0
 function ogdbRadius($plz, $km, $sort = 'asc')
 {
     // $fileData = explode("\n",ogdbGetData());
     $res = $this->filialeRepository->getOpengeoDb($plz);
     foreach ($res as $fileRow) {
         //$fileRow = explode(";",$fileRow);
         //$dataStructure = ogdbDataStructure($fileRow);
         //var_dump($dataStructure);
         if (isset($fileRow['plz']) && isset($fileRow['lon']) && isset($fileRow['lat'])) {
             if (substr_count($fileRow['plz'], $plz) == 1) {
                 $origin_lon = $fileRow['lon'];
                 $origin_lat = $fileRow['lat'];
                 $id = $fileRow['loc_id'];
             }
         }
         unset($fileRow);
     }
     $lambda = $origin_lon * pi() / 180;
     $phi = $origin_lat * pi() / 180;
     // Umwandlung der Kurgelkoordinaten ins kartesische Koordinatensystem
     $geoKoordX = OGDB_EARTH_RADIUS * cos($phi) * cos($lambda);
     $geoKoordY = OGDB_EARTH_RADIUS * cos($phi) * sin($lambda);
     $geoKoordZ = OGDB_EARTH_RADIUS * sin($phi);
     $data = array();
     if (isset($origin_lon) && isset($origin_lat) && isset($id)) {
         foreach ($res as $fileRow) {
             //$fileRow = explode("\t",$fileRow);
             //$dataStructure = ogdbDataStructure($fileRow);
             if (isset($fileRow['plz']) && isset($fileRow['lon']) && isset($fileRow['lat'])) {
                 $distance = 2 * OGDB_EARTH_RADIUS * asin(SQRT(pow($geoKoordX - OGDB_EARTH_RADIUS * cos($fileRow['lat'] * pi() / 180) * cos($fileRow['lon'] * pi() / 180), 2) + pow($geoKoordY - OGDB_EARTH_RADIUS * cos($fileRow['lat'] * pi() / 180) * sin($fileRow['lon'] * pi() / 180), 2) + pow($geoKoordZ - OGDB_EARTH_RADIUS * sin($fileRow['lat'] * pi() / 180), 2)) / (2 * OGDB_EARTH_RADIUS));
                 //var_dump($fileRow[3] . '<b> '. round($distance, 2) .'</b>');
                 if ($distance < $km and $fileRow['name'] != '') {
                     // die;
                     $data[($distance + 0.01) * 1000] = array('loc_id' => $fileRow['loc_id'], 'name' => $fileRow['name'], 'zip' => $fileRow['plz'], 'distance' => $distance, 'adresse' => $fileRow['adresse'], 'lat_pos' => $fileRow['lat'], 'lon_pos' => $fileRow['lon'], 'url' => $fileRow['typ']);
                 }
                 //var_dump($data);
                 unset($distance);
             }
             unset($fileRow);
         }
     }
     switch ($sort) {
         case 'asc':
             ksort($data);
             break;
         case 'desc':
             krsort($data);
             break;
     }
     \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($data, date('d-m-Y  H:i'));
     return $data;
 }
Esempio n. 18
0
 public function procDistanceTime($coor, $thiscoor, $ref, $mode)
 {
     global $bid14, $database, $generator;
     $resarray = $database->getResourceLevel($generator->getBaseID($coor['x'], $coor['y']));
     $xdistance = ABS($thiscoor['x'] - $coor['x']);
     if ($xdistance > WORLD_MAX) {
         $xdistance = 2 * WORLD_MAX + 1 - $xdistance;
     }
     $ydistance = ABS($thiscoor['y'] - $coor['y']);
     if ($ydistance > WORLD_MAX) {
         $ydistance = 2 * WORLD_MAX + 1 - $ydistance;
     }
     $distance = SQRT(POW($xdistance, 2) + POW($ydistance, 2));
     if (!$mode) {
         if ($ref == 1) {
             $speed = 16;
         } else {
             if ($ref == 2) {
                 $speed = 12;
             } else {
                 if ($ref == 3) {
                     $speed = 24;
                 } else {
                     if ($ref == 300) {
                         $speed = 5;
                     } else {
                         $speed = 1;
                     }
                 }
             }
         }
     } else {
         $speed = $ref;
         if ($this->getsort_typeLevel(14, $resarray) != 0 && $distance >= TS_THRESHOLD) {
             $speed = $speed * ($bid14[$this->getsort_typeLevel(14, $resarray)]['attri'] / 100);
         }
     }
     if ($speed != 0) {
         return round($distance / $speed * 3600 / INCREASE_SPEED);
     } else {
         return round($distance * 3600 / INCREASE_SPEED);
     }
 }
Esempio n. 19
0
 public function procDistanceTime($coor, $thiscoor, $ref, $vid)
 {
     global $bid28, $bid14;
     $xdistance = ABS($thiscoor['x'] - $coor['x']);
     if ($xdistance > WORLD_MAX) {
         $xdistance = 2 * WORLD_MAX + 1 - $xdistance;
     }
     $ydistance = ABS($thiscoor['y'] - $coor['y']);
     if ($ydistance > WORLD_MAX) {
         $ydistance = 2 * WORLD_MAX + 1 - $ydistance;
     }
     $distance = SQRT(POW($xdistance, 2) + POW($ydistance, 2));
     $speed = $ref;
     if ($this->getTypeLevel(14, $vid) != 0 && $distance >= TS_THRESHOLD) {
         $speed = $speed * ($bid14[$this->getTypeLevel(14, $vid)]['attri'] / 100);
     }
     if ($speed != 0) {
         return round($distance / $speed * 3600 / INCREASE_SPEED);
     } else {
         return round($distance * 3600 / INCREASE_SPEED);
     }
 }
Esempio n. 20
0
 /**
  * ZTEST
  *
  * Returns the Weibull distribution. Use this distribution in reliability
  * analysis, such as calculating a device's mean time to failure.
  *
  * @param	float		$value
  * @param	float		$alpha		Alpha Parameter
  * @param	float		$beta		Beta Parameter
  * @param	boolean		$cumulative
  * @return	float
  *
  */
 public static function ZTEST($dataSet, $m0, $sigma = null)
 {
     $dataSet = PHPExcel_Calculation_Functions::flattenArrayIndexed($dataSet);
     $m0 = PHPExcel_Calculation_Functions::flattenSingleValue($m0);
     $sigma = PHPExcel_Calculation_Functions::flattenSingleValue($sigma);
     if (is_null($sigma)) {
         $sigma = self::STDEV($dataSet);
     }
     $n = count($dataSet);
     return 1 - self::NORMSDIST((self::AVERAGE($dataSet) - $m0) / ($sigma / SQRT($n)));
 }
Esempio n. 21
0
 static function gps_distance($lon1, $lat1, $lon2, $lat2)
 {
     return 2 * ATAN2(SQRT(SIN(($lat1 - $lat2) * PI() / 180 / 2) * SIN(($lat1 - $lat2) * PI() / 180 / 2) + COS($lat2 * PI() / 180) * COS($lat1 * PI() / 180) * SIN(($lon1 - $lon2) * PI() / 180 / 2) * SIN(($lon1 - $lon2) * PI() / 180 / 2)), SQRT(1 - SIN(($lat1 - $lat2) * PI() / 180 / 2) * SIN(($lat1 - $lat2) * PI() / 180 / 2) + COS($lat2 * PI() / 180) * COS($lat1 * PI() / 180) * SIN(($lon1 - $lon2) * PI() / 180 / 2) * SIN(($lon1 - $lon2) * PI() / 180 / 2))) * 6378140;
 }