Skip to content

Commit

Permalink
Huge dashboard refactor + preselect of the watch on call to actions #36
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuNls committed Jan 4, 2016
1 parent 3171dd1 commit b41fffb
Show file tree
Hide file tree
Showing 15 changed files with 247 additions and 254 deletions.
27 changes: 21 additions & 6 deletions application/controllers/Measures.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,10 @@ private function constructMeasurePage(){
$this->_headerData['headerClass'] = 'blue';
$this->load->view('header', $this->_headerData);

$this->_bodyData['watches'] = $this->watch->getWatches(
$this->session->userdata('userId'));
$this->_bodyData['allMeasure'] = $this->measure->getMeasuresByUser(
$this->session->userdata('userId'), $this->_bodyData['watches']);
$this->session->userdata('userId'));

$this->load->view('measure/all', $this->_bodyData);
$this->load->view('measure/dashboard', $this->_bodyData);

$this->load->view('footer');
}
Expand Down Expand Up @@ -94,7 +92,7 @@ public function add_watch(){
*/
public function delete_watch(){

if($this->expectsPost(array('deleteWatch'))){
if($this->expectsPost(array('watchId'))){

if ($this->watch->deleteWatch($this->watchId)) {
$this->_bodyData['success'] = 'Watch successfully deleted!';
Expand Down Expand Up @@ -148,18 +146,35 @@ public function new_watch() {
*/
public function new_measure() {

$this->_bodyData['watches'] = $this->watch->getWatches(
$this->session->userdata('userId'));

$this->event->add(MEASURE_LOAD);

$this->_headerData['headerClass'] = 'blue';
$this->load->view('header', $this->_headerData);

$this->_bodyData['watches'] = $this->watch->getWatches($this->session->userdata('userId'));
$this->load->view('measure/new-measure', $this->_bodyData);
$this->load->view('measure/audio.php');

$this->load->view('footer');
}

/**
* Serves the new measure form (1/2) for a watch
* with existing measures.
*/
public function new_measure_for_watch(){

if($this->expectsPost(array('watchId'))){

$this->_bodyData['selected_watch'] = $this->watchId;

$this->new_measure();

}
}

/**
* Serves the new accuracy form (2/2)
*/
Expand Down
79 changes: 35 additions & 44 deletions application/models/Measure.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,46 +35,17 @@ function __construct() {
* Get the last measure of each $userWatches
*
* @param int $userId id of the user
* @param array $userWatches watches of the user
* @return array The last measure per $userWatches for $userId
* @return array The last measure per of $userId
*/
function getMeasuresByUser($userId, $userWatches) {

$data = array();

if (is_array($userWatches) && sizeof($userWatches) > 0) {

foreach ($userWatches as $watch) {
//Get measure couple that are on measure or accuracy status
$watchMeasures = $this->select()
->join("watch", "watch.watchId = ".$watch->watchId)
->where('measure.watchId', $watch->watchId)
->where('(`statusId` = 1 OR `statusId` = 2)', null, false)
->find_all();

if ($watchMeasures) {

foreach ($watchMeasures as $watchMeasure) {

//If the first measure is less than 12 hours old
if ($watchMeasure->statusId === "1" &&
(((time()-$watchMeasure->measureReferenceTime)/3600) < 12)) {

$watchMeasure->statusId = 1.5;
$ellapsedTime = ((time()-$watchMeasure->measureReferenceTime)/3600);
$watchMeasure->accuracy = round(12-round($ellapsedTime, 1));
if ($watchMeasure->accuracy <= 1) {
$watchMeasure->accuracy = " < 1";
}
}

array_push($data, $watchMeasure);
}
}
}
}

return $data;
function getMeasuresByUser($userId) {

return $this->select()
->join("watch", "watch.watchId = measure.watchId
AND measure.statusId < 3", "right")
->where("watch.userId", $userId)
->where("watch.status <", 4)
->group_by("watch.watchId")
->find_all();
}

/**
Expand All @@ -96,11 +67,31 @@ public function computeAccuracy($watchMeasure) {
$wasArray = true;
}

$userDelta = $watchMeasure->accuracyUserTime-$watchMeasure->measureUserTime;
$refDelta = $watchMeasure->accuracyReferenceTime-$watchMeasure->measureReferenceTime;
$accuracy = ($userDelta*86400/$refDelta)-86400;
$accuracy = sprintf("%.1f", $accuracy);
$watchMeasure->accuracy = $accuracy;
//Compute the accuracy if all the data are available
//Both measure have been performed
if(is_numeric($watchMeasure->accuracyUserTime)
&& is_numeric($watchMeasure->measureUserTime)
&& is_numeric($watchMeasure->accuracyReferenceTime)
&& is_numeric($watchMeasure->measureReferenceTime))
{
$userDelta = $watchMeasure->accuracyUserTime-$watchMeasure->measureUserTime;
$refDelta = $watchMeasure->accuracyReferenceTime-$watchMeasure->measureReferenceTime;
$accuracy = ($userDelta*86400/$refDelta)-86400;
$accuracy = sprintf("%.1f", $accuracy);
$watchMeasure->accuracy = $accuracy;
}

//Compute 1.5 status. When a measure is less than 12 hours old
if ($watchMeasure->statusId === "1" &&
(((time()-$watchMeasure->measureReferenceTime)/3600) < 12)) {

$watchMeasure->statusId = 1.5;
$ellapsedTime = ((time()-$watchMeasure->measureReferenceTime)/3600);
$watchMeasure->accuracy = round(12-round($ellapsedTime, 1));
if ($watchMeasure->accuracy <= 1) {
$watchMeasure->accuracy = " < 1";
}
}

//If the measure was an array,
//I typecast it back to array.
Expand Down
3 changes: 1 addition & 2 deletions application/models/Watch.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ function getWatches($userId) {
->where('status', 1)
->order_by('brand', 'asc')
->find_all();

}

/**
Expand All @@ -89,7 +88,7 @@ function getWatchByMeasureId($measureId){
* Soft delete watch $watchId
*
* @param int $watchId The watch to delete
* @return boolean
* @return boolean
*/
function deleteWatch($watchId) {
$data = array('status' => 4);
Expand Down
196 changes: 0 additions & 196 deletions application/views/measure/all.php

This file was deleted.

Loading

0 comments on commit b41fffb

Please sign in to comment.