示例#1
0
 /**
  * @covers Aclivo\Kpi\UpDirector::getDirection
  * @covers Aclivo\Kpi\UpDirector::goodDirection
  * @covers Aclivo\Kpi\UpDirector::betterDirection
  * @covers Aclivo\Kpi\UpDirector::badDirection
  * @covers Aclivo\Kpi\UpDirector::worseDirection
  */
 public function testGetDirection()
 {
     $datapoint = new DataPoint();
     $datapoint->setActual(100);
     $datapoint->setTarget(100);
     $datapoint->setMargin(0.2);
     $director = new UpDirector();
     $this->assertEquals(Directions::GOOD, $director->getDirection($datapoint));
     $datapoint->setActual(105);
     $this->assertEquals(Directions::GOOD, $director->getDirection($datapoint));
     $datapoint->setActual(121);
     $this->assertEquals(Directions::BETTER, $director->getDirection($datapoint));
     $datapoint->setActual(98);
     $this->assertEquals(Directions::BAD, $director->getDirection($datapoint));
     $datapoint->setActual(70);
     $this->assertEquals(Directions::WORSE, $director->getDirection($datapoint));
 }
示例#2
0
文件: ViewTest.php 项目: aclivo/kpi
 /**
  * @covers Aclivo\Kpi\View::setTotalizer
  * @covers Aclivo\Kpi\View::getTotal
  */
 public function testSetTotalizer()
 {
     $actual = 0;
     $points = array();
     for ($x = 1; $x <= 5; $x++) {
         $dp = new DataPoint();
         $dp->setActual($x * 100);
         $actual += $x * 100;
         $dp->setTarget($x * 100);
         $dp->setMargin(0.1);
         $points[] = $dp;
     }
     $view = new View();
     $view->setDataPoints($points);
     $totalizer = new SumTotalizer();
     $view->setTotalizer($totalizer);
     $this->assertEquals($actual, $view->getTotal()->getActual());
 }
示例#3
0
 public static function unitTest()
 {
     $response = '';
     $response .= "<br/>starting Data Point tests <br/>";
     $response .= 'Testing updateUserDataPoint: ';
     DataPoint::updateUserDataPoint(TEST_USER_ID, DataPoint::$BLOOD_PRESSURE, '121/50');
     $value = DataPoint::getValueForDataPoint(DataPoint::$BLOOD_PRESSURE, TEST_USER_ID);
     if ($value == '121/50') {
         $response .= 'Passed';
     } else {
         $response .= 'Failed';
     }
     $response .= '<br/>';
     $response .= 'Testing getHistoryListForDataPoint: ';
     $dataPointList = DataPoint::getHistoryListForDataPointAsArray(DataPoint::$BLOOD_PRESSURE, TEST_USER_ID);
     if (sizeof($dataPointList) > 0) {
         $response .= 'Passed';
     } else {
         $response .= 'Failed';
     }
     $response .= '<br/>';
     $response .= 'Testing deleteDataPointHistory: ';
     DataPoint::deleteDataPointHistory(TEST_USER_ID, DataPoint::$BLOOD_PRESSURE);
     $dataPointList = DataPoint::getHistoryListForDataPointAsArray(DataPoint::$BLOOD_PRESSURE, TEST_USER_ID);
     if (sizeof($dataPointList) == 0) {
         $response .= 'Passed';
     } else {
         $response .= 'Failed';
     }
     $response .= '<br/>';
     return $response;
 }
 protected function resolveDatapointMessages($messages)
 {
     $idArray = array();
     foreach ($messages as $message) {
         try {
             $messageBody = new SimpleXMLElement($message['definition']);
             $idArray[] = $message['id'];
             $dataPoint = new DataPoint();
             if ($message['operation'] == 'DELETE') {
                 $result = $this->getBeaconDatapointService()->deleteDatapointByName($message['name']);
                 if ($result > 0) {
                     $idArray[] = $message['id'];
                 }
                 continue;
             }
             if ($message['operation'] == 'UPDATE') {
                 $dataPoint = $this->getBeaconDatapointService()->getDatapointByName($message['name']);
                 if ($dataPoint == null || !$dataPoint) {
                     $dataPoint = new DataPoint();
                 }
             }
             $dataPoint->setName($message['name']);
             $dataPoint->setDefinition($message['definition']);
             $dataPoint->setDataPointType($this->getBeaconDatapointService()->getDatapointTypeByName($messageBody['type'])->getFirst());
             $dataPoint->save();
         } catch (Exception $exc) {
             echo $exc->getTraceAsString();
         }
     }
     return $idArray;
 }
示例#5
0
            $provider_response = postRequest(AUTH_SERVER . '/emails/send-email/kick_tracker-admin_alert', $provider_data);
            if (!isset($response->status) || $response->status != 'success' || (!isset($provider_response->status) || $provider_response->status != 'success')) {
                Log::user("Error sending irregular kick count email");
                exit;
            }
            // once email is sent, update the last time a kick email was sent
            User::updateKickEmailTime($userId);
        }
        if ($curNumKicks >= 10) {
            Log::user("Silently updating last sent email time so avoid getting a forgotten kick tracker email");
            User::updateKickEmailTime($userId);
        }
        boldError("Success");
        echo json_encode(array('status' => 'success', 'numKicks' => $curNumKicks, 'timesBeenEmailed' => $timesBeenEmailed));
    }
} elseif ($_SERVER['REQUEST_METHOD'] == 'GET') {
    // get a date time for two hours ago
    $twoHoursAgo = new DateTime();
    $twoHoursAgo->sub(new DateInterval("PT2H"));
    // get the most recent reset time, though it's stored as a string
    $lastResetTime = DataPoint::getValueForDataPoint(DataPoint::$BABY_KICK_RESET, $userId);
    // so convert it back to a DateTime so you can compare it
    $lastResetTime = DateTime::createFromFormat(DATABASE_DATETIME_FORMAT, $lastResetTime);
    // if the reset time is less than two hours ago, compare kicks to reset time
    if ($lastResetTime > $twoHoursAgo) {
        $numKicks = DataPoint::getNumDataPointsWithinReset(DataPoint::$BABY_KICK, $userId);
    } else {
        $numKicks = DataPoint::getNumDataPointsWithinTwoHours(DataPoint::$BABY_KICK, $userId);
    }
    echo (string) $numKicks;
}