Created
November 27, 2021 21:59
-
-
Save InsiderPhD/0b930b19deb4df31643d36f19035a0cd to your computer and use it in GitHub Desktop.
generates a temperature blanket from a csv of temps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<style> | |
</style> | |
<div> | |
<table> | |
<tbody> | |
<tr> | |
<?php | |
echo 30/3; | |
// based on Stylecraft special DK https://www.woolwarehouse.co.uk/yarn/stylecraft-special-dk-cloud-blue-1019-100g | |
// https://matkl.github.io/average-color/ | |
$hex = array("0", "#161827", "#4a749e","#a6c4d4", "#62a24a", "#c1901e","#dc5027", "#9f0b13", "#5c0b1d","#482860"); | |
$yarn = array("0", "Midnight", "Aster","Cloud Blue", "Grass Green", "Mustard","Spice", "Lipstick", "Claret","Proper Purple"); | |
for($i=0;$i<sizeof($hex);$i++) { | |
echo "<td style=\"background-color:" . $hex[$i] . "\">".$yarn[$i]." </td>"; | |
} | |
?> | |
</tr> | |
</tbody> | |
</table> | |
second table | |
</div> | |
<div> | |
<div style="width: 100%;border: black 1px solid;"> | |
<?php | |
$colourRange = array(); | |
if (($handle = fopen("temp20202021.csv", "r")) !== FALSE) { | |
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { | |
$date = $data[2]; | |
$max = $data[6]; | |
$avg = $data[7]; | |
$min = $data[8]; | |
$colour = 1; | |
for ($i=-5; $i < 30; $i=$i+5) | |
{ | |
if($avg>$i) { | |
$colour = $colour+1; | |
//echo $colour . "->" . $i ."<br/>"; | |
} | |
} | |
$colourRange[] = ($yarn[$colour]); | |
//> -10 | |
//-10<-5 | |
//-5<0 | |
//0<5 | |
//5<10 | |
//10<15 | |
//15<20 | |
//20<25 | |
//25<30 | |
//30+ | |
if($date != "Date") echo "<div style='height:10px;background: ".$hex[$colour]."'>"."</div>"; | |
} | |
fclose($handle); | |
} | |
$total = array_count_values($colourRange); | |
$rows = count($colourRange); | |
if(count($total)>0){ | |
foreach ($total as $key => $value) { | |
echo $key.' : '.$value.' ' . round($value/$rows*100,0). '%<br />'; | |
} | |
} | |
?> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment