/** * Display graphs as embedded images. Graphs are noon to noon unless parameters are provided. Results undefined if bounds are narrower than data. * @param int $startHourPM earliest hour to show in graphs * @param int $endHourPM end bound of graphs */ public function displaygraphs($startHourPM = 0, $endHourAM = 0) { foreach ($this->data as $night) { $nightstart = strtotime($night['Start of Night']); $nightend = strtotime($night['End of Night']); //find noon of that day $noon = self::previous_noon($nightstart); //start at 9pm (adjust this if you have data earlier than this) //The right way to do this would be to actually check the data upfront and set the offset automatically $startoffset = 60 * 60 * $startHourPM; $starttime = $noon + $startoffset; //end data at noon $endoffset = 60 * 60 * (12 - $endHourAM); //find out how many intervals are needed to pad the data from noon $intervalseconds = 30; $pad_needed = round(($nightstart - $starttime) / $intervalseconds); $pad = str_repeat('0 ', $pad_needed); //put the padded data in an array for progressbar $sleepdata = explode(' ', $pad . $night['Detailed Sleep Graph']); //pad the array for the total number of hours $sleepdata = array_pad($sleepdata, (60 * 60 * 24 - $startoffset - $endoffset) / $intervalseconds, 0); //print((round($nightend-$nightstart)/30) . '-'. count($sleepdata).'<br>'); $progressbar = new ProgressBar($sleepdata, 1000, 50, ProgressBar::MODE_INTEGER, 'zeo'); print $night['Start of Night'] . ' ' . $progressbar->embedded_imagetag() . $night['End of Night'] . '<br>'; } }