Commit 9bafd1f9 authored by Stuart McCulloch Anderson's avatar Stuart McCulloch Anderson

Merge branch 'develop' into 'master'

Develop

Closes #190 and #191

See merge request !35
parents ddf0d740 6f5ecc55
Pipeline #105 passed with stages
in 2 minutes and 3 seconds
......@@ -137,8 +137,8 @@
array('remote_api'), array(
'level' => 'info',
'extra' => array(
'api_req' => $_GET['get'],
'user' => $_GET['user'],
'api_req' => $job['trigger'],
'user' => $job['user'],
'cooldown' => $cooldown,
'php_version' => phpversion(),
'core_version' => $fitbitApp->getSetting("version", "0.0.0.1", true)
......@@ -173,6 +173,8 @@
nxr(2, "Can not process " . $fitbitApp->supportedApi($job['trigger']) . " since " . $job['user'] . " is no longer a user.");
$fitbitApp->delCronJob($job['user'], $job['trigger']);
}
nxr(0, "Cron " . $fitbitApp->supportedApi($job['trigger']) . " completed for " . $job['user']);
} else {
nxr(0, "Timeout reached skipping " . $fitbitApp->supportedApi($job['trigger']) . " for " . $job['user']);
$repopulate_queue = false;
......
......@@ -8,7 +8,12 @@
header('Access-Control-Allow-Origin: https://wp.dev.psi.nxfifteen.me.uk');
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');
if (array_key_exists("debug", $_GET) and $_GET['debug'] == "true") {
header('Content-type: text/plain');
} else {
header('Content-type: application/json');
}
if (array_key_exists("user", $_GET) && array_key_exists("data", $_GET)) {
$start = microtime(true);
......
......@@ -311,8 +311,7 @@
return new DateTime ($this->getAppClass()->getDatabase()->get($this->getAppClass()->getSetting("db_prefix",
null, false) . "runlog", "lastrun", array(
"user" => $this->getUserID(),
"ORDER" => array("lastrun" => "ASC"),
"LIMIT" => 1
"ORDER" => array("lastrun" => "ASC")
)));
}
} else {
......@@ -330,8 +329,7 @@
"user" => $this->getUserID(),
"activity" => $scope
),
"ORDER" => array("lastrun" => "ASC"),
"LIMIT" => 1
"ORDER" => array("lastrun" => "ASC")
)));
return $returnTime;
......@@ -341,6 +339,41 @@
return new DateTime ("1970-01-01");
}
/**
* Calculates the great-circle distance between two points, with
* the Haversine formula.
*
* @param $lat1
* @param $lon1
* @param $lat2
* @param $lon2
* @param $unit
*
* @return float Distance between points in [m] (same as earthRadius)
* @internal param float $latitudeFrom Latitude of start point in [deg decimal]
* @internal param float $longitudeFrom Longitude of start point in [deg decimal]
* @internal param float $latitudeTo Latitude of target point in [deg decimal]
* @internal param float $longitudeTo Longitude of target point in [deg decimal]
* @internal param float $earthRadius Mean earth radius in [m]
*/
private function haversineGreatCircleDistance($lat1, $lon1, $lat2, $lon2, $unit)
{
$theta = $lon1 - $lon2;
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
$miles = $dist * 60 * 1.1515;
$unit = strtoupper($unit);
if ($unit == "K") {
return ($miles * 1.609344);
} else if ($unit == "N") {
return ($miles * 0.8684);
} else {
return $miles;
}
}
/**
* @param int $limit
* @param string $tableName
......@@ -794,41 +827,6 @@
return $returnArray;
}
/**
* Calculates the great-circle distance between two points, with
* the Haversine formula.
*
* @param $lat1
* @param $lon1
* @param $lat2
* @param $lon2
* @param $unit
*
* @return float Distance between points in [m] (same as earthRadius)
* @internal param float $latitudeFrom Latitude of start point in [deg decimal]
* @internal param float $longitudeFrom Longitude of start point in [deg decimal]
* @internal param float $latitudeTo Latitude of target point in [deg decimal]
* @internal param float $longitudeTo Longitude of target point in [deg decimal]
* @internal param float $earthRadius Mean earth radius in [m]
*/
private function haversineGreatCircleDistance($lat1, $lon1, $lat2, $lon2, $unit)
{
$theta = $lon1 - $lon2;
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
$miles = $dist * 60 * 1.1515;
$unit = strtoupper($unit);
if ($unit == "K") {
return ($miles * 1.609344);
} else if ($unit == "N") {
return ($miles * 0.8684);
} else {
return $miles;
}
}
/**
* @param null $tcxFileName
* @param null $tcxTrackName
......@@ -3031,8 +3029,7 @@
"length"
),
array(
"AND" => array("fuid" => $this->getUserID(), "goal" => "steps", "end_date[!]" => !null),
"LIMIT" => 1,
"AND" => array("fuid" => $this->getUserID(), "goal" => "steps", "end_date[!]" => null),
"ORDER" => array("length" => "DESC")
));
......@@ -3065,8 +3062,7 @@
"length"
),
array(
"AND" => array("fuid" => $this->getUserID(), "goal" => "steps", "end_date[!]" => !null),
"LIMIT" => 1,
"AND" => array("fuid" => $this->getUserID(), "goal" => "steps", "end_date[!]" => null),
"ORDER" => array("start_date" => "DESC")
));
......@@ -3923,8 +3919,7 @@
null, false) . "nomie_events",
'datestamp', array(
"AND" => array("fuid" => $this->getUserID(), "id" => $tracker['id']),
"ORDER" => array("datestamp" => "ASC"),
"LIMIT" => 1
"ORDER" => array("datestamp" => "ASC")
));
if (empty($dbEventFirst)) {
......@@ -3936,8 +3931,7 @@
null, false) . "nomie_events",
'datestamp', array(
"AND" => array("fuid" => $this->getUserID(), "id" => $tracker['id']),
"ORDER" => array("datestamp" => "DESC"),
"LIMIT" => 1
"ORDER" => array("datestamp" => "DESC")
));
if (empty($dbEventLast)) {
......
......@@ -355,8 +355,7 @@
return new DateTime ($this->getDatabase()->get($this->getApiSetting("db_prefix", null,
false) . "runlog", "lastrun", array(
"user" => $this->getActiveUser(),
"ORDER" => array("lastrun" => "ASC"),
"LIMIT" => 1
"ORDER" => array("lastrun" => "ASC")
)));
}
} else {
......@@ -373,8 +372,7 @@
"user" => $this->getActiveUser(),
"activity" => $scope
),
"ORDER" => array("lastrun" => "ASC"),
"LIMIT" => 1
"ORDER" => array("lastrun" => "ASC")
)));
return $returnTime;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment