Browse files

logger now generates a js file used to produce a temperature chart (s…

…ee example.png)
  • Loading branch information...
1 parent 21f343c commit c4464eeb8fab0f11cacedd06029d067b4eec165c @ronanguilloux committed Dec 3, 2012
Showing with 10 additions and 12 deletions.
  1. +1 −0 .gitignore
  2. BIN example.png
  3. +8 −2 src/TemperaturePi/Logger.php
  4. +1 −1 web/index.html
  5. +0 −9 web/js/data.js.php
View
1 .gitignore
@@ -1,4 +1,5 @@
resources/
+web/js/data.js
vendor/
composer.lock
composer.phar
View
BIN example.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
10 src/TemperaturePi/Logger.php
@@ -33,8 +33,14 @@ public function fetchAll()
public function writeJsDatas()
{
+ $jsFile = __DIR__ . "/../../web/js/data.js";
$datas = $this->fetchAll();
- var_dump($datas);
+ $jsContent = "var data = [['Date', 'Celsius']";
+ foreach($datas as $index=>$celsius) {
+ $jsContent .= "\n,[$index,$celsius]";
+ }
+ $jsContent .= "];";
+ file_put_contents($jsFile, $jsContent);
}
public function persist($reset = false)
@@ -47,7 +53,7 @@ public function persist($reset = false)
$this->exec('CREATE TABLE IF NOT EXISTS temperature (datetime DATETIME, celsius FLOAT)');
$this->exec("INSERT INTO temperature (datetime, celsius) VALUES (datetime('NOW'), " . $this->currentTemperature . ")");
- echo "\n" . date("d/m/Y H:i:s") . "|" . $this->currentTemperature;
+ //echo "\n" . date("d/m/Y H:i:s") . "|" . $this->currentTemperature;
$this->close();
}
View
2 web/index.html
@@ -1,7 +1,7 @@
<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
- <script type="text/javascript" src="js/data.js.php"></script>
+ <script type="text/javascript" src="js/data.js"></script>
<script type="text/javascript" src="js/main.js"></script>
</head>
<body>
View
9 web/js/data.js.php
@@ -1,9 +0,0 @@
-<?php
-echo "var data = [['Date', 'Celsius'],";
-echo "
- ['28', 20],
- ['29', 22],
- ['30', 25]
-";
-echo "];";
-

0 comments on commit c4464ee

Please sign in to comment.