Skip to content

Commit

Permalink
Merge pull request #2 from Ths2-9Y-LqJt6/0.2
Browse files Browse the repository at this point in the history
0.2
  • Loading branch information
Ths2-9Y-LqJt6 authored Mar 23, 2017
2 parents 1768f3b + 200d4b4 commit ffcec69
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 5 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# YANPIWS
Yet Another Pi Weather Station (YANPIWS)- My explorations in getting a Rasberry Pi showing local time and weather
Yet Another Pi Weather Station (YANPIWS) - My explorations in getting a Rasberry Pi showing local time and weather

![](./screenshot.png)

## Background

Expand Down Expand Up @@ -81,5 +83,5 @@ DATE,ID,TEMP,HUMIDITY
```

## Version History

0.1 - Mar 22, 2017 - parsing data, writing to CSV, crude readme, no html output
* 0.2 - Mar 23, 2017 - reading CSV, super basic HTML output
* 0.1 - Mar 22, 2017 - parsing data, writing to CSV, crude readme, no html output
62 changes: 62 additions & 0 deletions data/2017-03-22
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,65 @@
2017-03-22 23:26:22,109,57.92,25
2017-03-22 23:26:55,211,72.5,34
2017-03-22 23:27:10,109,57.92,25
2017-03-22 23:35:43,211,72.5,34
2017-03-22 23:35:58,109,57.74,25
2017-03-22 23:36:31,211,72.5,34
2017-03-22 23:36:46,109,57.56,25
2017-03-22 23:37:19,211,72.5,34
2017-03-22 23:37:34,109,57.74,26
2017-03-22 23:38:07,211,72.5,34
2017-03-22 23:38:22,109,57.56,25
2017-03-22 23:38:55,211,72.5,34
2017-03-22 23:39:10,109,57.56,25
2017-03-22 23:39:43,211,72.5,34
2017-03-22 23:39:58,109,57.56,26
2017-03-22 23:40:31,211,72.5,34
2017-03-22 23:40:46,109,57.56,25
2017-03-22 23:41:19,211,72.5,34
2017-03-22 23:41:34,109,57.56,26
2017-03-22 23:42:07,211,72.5,34
2017-03-22 23:42:22,109,57.56,26
2017-03-22 23:42:55,211,72.5,34
2017-03-22 23:43:10,109,57.56,26
2017-03-22 23:43:43,211,72.5,34
2017-03-22 23:43:58,109,57.56,26
2017-03-22 23:44:31,211,72.5,34
2017-03-22 23:44:46,109,57.56,26
2017-03-22 23:45:19,211,72.5,34
2017-03-22 23:45:34,109,57.38,26
2017-03-22 23:46:07,211,72.5,34
2017-03-22 23:46:22,109,57.38,26
2017-03-22 23:46:55,211,72.5,34
2017-03-22 23:47:09,109,57.38,26
2017-03-22 23:47:43,211,72.5,34
2017-03-22 23:47:58,109,57.38,26
2017-03-22 23:48:31,211,72.5,34
2017-03-22 23:48:46,109,57.38,26
2017-03-22 23:49:19,211,72.5,34
2017-03-22 23:49:34,109,57.38,26
2017-03-22 23:50:07,211,72.5,34
2017-03-22 23:50:22,109,57.38,26
2017-03-22 23:50:55,211,72.5,34
2017-03-22 23:51:10,109,57.38,26
2017-03-22 23:51:43,211,72.5,34
2017-03-22 23:51:58,109,57.38,26
2017-03-22 23:52:31,211,72.5,34
2017-03-22 23:52:46,109,57.2,26
2017-03-22 23:53:19,211,72.5,34
2017-03-22 23:53:34,109,57.2,26
2017-03-22 23:54:07,211,72.5,34
2017-03-22 23:54:21,109,57.2,27
2017-03-22 23:54:55,211,72.5,34
2017-03-22 23:55:10,109,57.2,26
2017-03-22 23:55:43,211,72.5,34
2017-03-22 23:55:58,109,57.2,26
2017-03-22 23:56:31,211,72.5,34
2017-03-22 23:56:46,109,57.2,26
2017-03-22 23:57:19,211,72.5,34
2017-03-22 23:57:34,109,57.02,26
2017-03-22 23:58:07,211,72.5,34
2017-03-22 23:58:22,109,57.02,26
2017-03-22 23:58:55,211,72.5,34
2017-03-22 23:59:10,109,57.02,26
2017-03-22 23:59:43,211,72.5,34
2017-03-22 23:59:57,109,57.02,26
20 changes: 20 additions & 0 deletions data/2017-03-23
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
2017-03-23 00:06:55,211,72.32,38
2017-03-23 00:07:09,109,56.84,27
2017-03-23 00:07:43,211,72.32,38
2017-03-23 00:07:58,109,56.84,27
2017-03-23 00:08:31,211,72.32,38
2017-03-23 00:08:46,109,56.84,27
2017-03-23 00:09:19,211,72.32,38
2017-03-23 00:09:34,109,56.84,27
2017-03-23 00:10:07,211,72.32,38
2017-03-23 00:10:22,109,56.84,27
2017-03-23 00:10:55,211,72.32,38
2017-03-23 00:11:10,109,56.66,27
2017-03-23 00:11:43,211,72.32,38
2017-03-23 00:11:58,109,56.84,28
2017-03-23 00:12:31,211,72.32,38
2017-03-23 00:12:46,109,56.84,28
2017-03-23 00:13:19,211,72.32,38
2017-03-23 00:13:34,109,56.66,27
2017-03-23 00:14:07,211,72.32,38
2017-03-23 00:14:22,109,56.84,28
36 changes: 36 additions & 0 deletions get_data.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Assuming a CSV of this structure:
* 2017-03-22 23:11:43,211,72.5,34
* Return a multi-dimensional array like this:
*
*Array(
* [211] => Array(
* [2017-03-22 23:08:31] => Array(
* [0] => 2017-03-22 23:08:31
* [1] => 211
* [2] => 72.5
* [3] => 34
* )
*
* @param string $file where CSV data is
* @return array of formatted CSV data
*/

function getData($file){
if (is_file($file) && is_readable($file)){
$data = file($file);
$goodData = array();
foreach ($data as $line){
$lineArray = explode(",", $line);
$goodData[$lineArray[1]][$lineArray[0]] = $lineArray;
}
foreach (array_keys($goodData) as $id){
asort($goodData[$id]);
}

return $goodData;
} else {
return array();
}
}
27 changes: 27 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
require_once ("get_data.php");
$today = date('Y-m-d', time());
$time = date('h:i:s A', time());
$date = date('l jS \of F Y', time());
$allData = getData("./data/" . $today);

$labels = array(
'211' => 'Inside',
'109' => 'Outside',
);

$currentTempHtml = '';
foreach (array_keys($allData) as $key){
$temp = array_pop($allData[$key])[2];
$label = $labels[$key];
$currentTempHtml .= "<strong>{$temp}°</strong> $label <br />\n";
}

?>

<link rel="stylesheet" type="text/css" href="styles.css" />

<p><?php echo $date ?></p>
<p><?php echo $time ?></p>
<p><?php echo $currentTempHtml ?></p>

4 changes: 2 additions & 2 deletions parse_and_save.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ function cleanseData($data)
*/
function saveArrayToCsv($path, $file, $array)
{
if (is_dir($path) && is_writable($path . '/' . $file) && is_array($array) && sizeof($array) > 0) {
if (is_dir($path) && is_array($array) && sizeof($array) > 0) {
echo 'It\'s ' . $array[2] . ' at ID ' . $array[1] . " - data written to " . $path . '/' . $file ."\n";
file_put_contents($path . '/' . $file, implode(',' , $array) . "\n",FILE_APPEND);
} else {
echo "failed to write to $path - not a dir, not writable or invalid/empty array passed :(";
echo "failed to write to {$path}/{$file} - not a dir, not writable or invalid/empty array passed :(";
}
}

Binary file added screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
body {
margin: 10px;
padding: 10px;
background-color: black;
color: white;
font-size: 20pt;
font-family: sans-serif;
}

0 comments on commit ffcec69

Please sign in to comment.