/** * Save laps data into database. */ public function algorithm($data, $parent_id) { $db = \utils\DB\Database::getInstance(); $conn = $db->getConnection(); $ids = array(); foreach ($data as $lap) { $lap = $lap->getVars(); if ($stmt = $conn->prepare("INSERT INTO `gps_db`.`activityLap_t` (`StartTime`, `TotalTimeSeconds`, `DistanceMeters`, `MaximumSpeed`, `Calories`, `AverageHeartRateBpm`, `MaximumHeartRateBpm`, `Intensity`, `Cadence`, `TriggerMethod`, `Activity`, `Notes`)\n\t\t\t\t\t\t\tVALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) { $stmt->bind_param("sdddiiiiiiis", $StartTime, $TotalTime, $Distance, $MaxSpeed, $Calories, $AvgHR, $MaxHR, $Intensity, $Cadence, $TriggerMethod, $Activity, $Notes); $StartTime = $lap["StartTime"]->format("Y-m-d\\TH:i:sT"); $TotalTime = $lap["TotalTimeSeconds"]; $Distance = $lap["DistanceMeters"]; $MaxSpeed = $lap["MaximumSpeed"]; $Calories = $lap["Calories"]; $AvgHR = $lap["AverageHeartRateBpm"]; $MaxHR = $lap["MaximumHeartRateBpm"]; $Intensity = strtolower($lap["Intensity"]) == "resting" ? 2 : 1; $Cadence = $lap["Cadence"]; $TriggerMethod = $this->triggerID($lap["TriggerMethod"]); $Activity = $parent_id !== NULL ? $parent_id : "1"; $Notes = $lap["Notes"]; if ($stmt->execute() === FALSE) { die("Error: " . $stmt->error); } else { array_push($ids, mysqli_insert_id($conn)); } } } $stmt->close(); return $ids; }
/** * Save trackpoints data into database. */ public function algorithm($data, $parent_id) { $db = \utils\DB\Database::getInstance(); $conn = $db->getConnection(); $ids = array(); foreach ($data as $point) { $point = $point->getVars(); if ($stmt = $conn->prepare("INSERT INTO `gps_db`.`TrackPoint_t` (`Time`, `AltitudeMeters`, `DistanceMeters`, `HeartRateBpm`, `Cadence`, `SensorState`, `Track`)\n\t\t\t\t\t\t\tVALUES (?, ?, ?, ?, ?, ?, ?)")) { $stmt->bind_param("sddiiii", $Time, $Altitude, $Distance, $HR, $Cadence, $SensorState, $Track); $Time = $point["Time"]->format("Y-m-d\\TH:i:sT"); $Altitude = $point["AltitudeMeters"]; $Distance = $point["DistanceMeters"]; $HR = $point["HeartRateBpm"]; $Cadence = $point["Cadence"]; $SensorState = $point["SensorState"]; $Track = $parent_id !== NULL ? $parent_id : "1"; if ($stmt->execute() === FALSE) { die("Error: " . $stmt->error); } else { if ($point["Position"] !== NULL && $point["Position"]->getLatitude() !== NULL) { array_push($ids, mysqli_insert_id($conn)); } } } } $stmt->close(); return $ids; }
/** * Save positions data into database. */ public function algorithm($data, $parent_id) { $db = \utils\DB\Database::getInstance(); $conn = $db->getConnection(); $ids = array(); if ($stmt = $conn->prepare("INSERT INTO `gps_db`.`Position_t` (`LatitudeDegrees`, `LongitudeDegrees`, `TrackPoint`) VALUES (?, ?, ?)")) { $stmt->bind_param("ddi", $lat, $lon, $trkpt); $lat = $data->getLatitude(); $lon = $data->getLongitude(); $trkpt = $parent_id; if ($stmt->execute() === FALSE) { die("Error: " . $stmt->error); } } $stmt->close(); }
/** * Save activity data into database. */ public function algorithm($data, $parent_id) { $db = \utils\DB\Database::getInstance(); $conn = $db->getConnection(); // $conn->sql("INSERT INTO `gps_db`.`ActivityList_t` (`ID`) VALUES (NULL);"); if ($stmt = $conn->prepare("INSERT INTO `gps_db`.`Activity_t` (`Sport`, `Id`, `ActivityList`, `Notes`, `Creator`) \n\t\t\t\t\t\t\tVALUES (?, ?, ?, ?, ?)")) { $stmt->bind_param("isiss", $sport, $id, $activity, $note, $creator); $sport = strtolower($data["Sport"]) === "running" ? 1 : (strtolower($data["Sport"]) === "biking" ? 2 : 3); $id = $data["Id"]->format("Y-m-d\\TH:i:sT"); $activity = $parent_id !== NULL ? $parent_id : "1"; $note = $data["Notes"]; $creator = $data["Creator"]; if ($stmt->execute() === FALSE) { die("Error: " . $stmt->error); } $stmt->close(); } return mysqli_insert_id($conn); }
/** * Save tracks data into database. */ public function algorithm($data, $parent_id) { $db = \utils\DB\Database::getInstance(); $conn = $db->getConnection(); $ids = array(); foreach ($data as $track) { if ($stmt = $conn->prepare("INSERT INTO `gps_db`.`Track_t` (`Lap`) VALUES (?)")) { $stmt->bind_param("i", $lap); $lap = $parent_id; if ($stmt->execute() === FALSE) { die("Error: " . $stmt->error); } else { array_push($ids, mysqli_insert_id($conn)); } } } $stmt->close(); return $ids; }
/** * Constructor of class ModelA. * * @return void */ public function __construct() { $db = \utils\DB\Database::getInstance(); $this->conn = $db->getConnection(); }