cloudy cloudy

Author Topic: Sunrise/Sunset script  (Read 31259 times)

0 Members and 1 Guest are viewing this topic.

Offline jmcmurry

  • Jim McMurry
  • Posts: 2,836
  • Mauston, WI, USA
  • OS/Browser:
  • Win XP
  • Firefox 18.0
    • Juneau County Weather
Re: Sunrise/Sunset script
« Reply #15 on: January 31, 2013, 03:24:06 PM »
Jerry,

It looks like you'll need to tweak the css in the code ... I had to do some funky stuff to get everything to display the way I wanted.  It looks like Rick's worked out ok.

- Jim

Forum Search and Google can be your best friends

Offline rrrick8

  • Posts: 359
  • Danville, Illinois
  • OS/Browser:
  • Win 7/Srvr 2008R2
  • Firefox 18.0
    • Vermilion County Weather
Re: Sunrise/Sunset script
« Reply #16 on: January 31, 2013, 03:33:44 PM »
Jerry,

It looks like you'll need to tweak the css in the code ... I had to do some funky stuff to get everything to display the way I wanted.  It looks like Rick's worked out ok.

- Jim

Yes, I had to move some things a bit and changed a few colors to match my site.
----------------------
Rick
EMA Severe Weather Manager
CWOP-CW9931 -  KILDANVI5

Offline jahuff

  • Posts: 972
  • Northern New Hampshire, USA
  • OS/Browser:
  • Win NT 6.2
  • MS IE 10.0
    • Weather Data Pittsburg, NH
Re: Sunrise/Sunset script
« Reply #17 on: January 31, 2013, 04:12:47 PM »
Hi Jerry,

I am still not getting the graph, I just get the placeholder "graph". I can't seem to get the code to work. Could you post your code.

Thanks

John

Online Martyn

  • Davis VP2+ FARS/solar/UV
  • Posts: 987
  • Bristol, UK
  • OS/Browser:
  • Win 7/Srvr 2008R2
  • Firefox 17.0
    • Horfield/Filton, Bristol, UK weather station
Re: Sunrise/Sunset script
« Reply #18 on: January 31, 2013, 05:24:22 PM »
I have it on my site now with code tweaks to fit my site colours/ layout, including rotating the chart to show daylight hours starting at the top (zero degrees) and adding the actual hours to the chart as well as percentages. I didn't get the chart to show until I put the Google API chart code all on one line without spaces.

« Last Edit: January 31, 2013, 11:50:12 PM by Martyn »
Martyn,
Bristol, UK

Twitter: https://twitter.com/HorfieldWeather
FB: https://www.facebook.com/bristolweather
CWOP: CW2888
WU: IBRISTOL3

Offline jahuff

  • Posts: 972
  • Northern New Hampshire, USA
  • OS/Browser:
  • Win NT 6.2
  • MS IE 10.0
    • Weather Data Pittsburg, NH
Re: Sunrise/Sunset script
« Reply #19 on: January 31, 2013, 06:19:54 PM »
Hi Martyn,

Thanks for the info. I got it working after several attempts, I just need to adjust things now.

Thanks again,

John

Offline gwwilk

  • Posts: 681
  • Lincoln, NE
  • OS/Browser:
  • Win 7/Srvr 2008R2
  • Chrome 24.0.1312.56
    • Southeast Lincoln Weather
Re: Sunrise/Sunset script
« Reply #20 on: January 31, 2013, 06:26:45 PM »
Jerry,

It looks like you'll need to tweak the css in the code ... I had to do some funky stuff to get everything to display the way I wanted.  It looks like Rick's worked out ok.

- Jim

You are so right, Jim!  I think I've got it the way I want it now.  My code allows for style switching, but it's a bit messy:
Code: [Select]
<p class="sideBarTitle"><?php langtrans('Daylight Hours'); ?></p>
    <div class="sideBarText" style="font-weight:lighter; font-size: 6.5pt; text-align: center; margin-bottom:-4px">
          <?php
            
//Make piechart
            
$testtime substr($hoursofpossibledaylight,0,2);
            
$testminute substr($hoursofpossibledaylight,-2,2);
            
$testminute=$testminute/60;
            
$testresult=$testtime+$testminute;
            
$testljus=round(($testresult/24)*100,1);
            
$testmorker=100-$testljus;
        
?>

            <span class="thisPage" style="position: relative; font-weight:lighter">
          <?php
            $time_arr 
explode(':'$hoursofpossibledaylight2);
            echo (int)
$time_arr[0] . " hrs " . (int)$time_arr[1] . " min";
            echo 
'<br/>of Daylight Today<br/>';
        
?>

            </span>
            <img style="margin-top:4px" src="http://chart.apis.google.com/chart?chs=100x60&amp;chma=0,0,0,0&amp;chd=t:<?php echo $testljus;?>,<?php echo $testmorker;?>&amp;cht=p3&amp;chp=1.6&amp;chf=bg,s,CCCCCC&amp;chco=FFD700,000000" alt="graph"/>
            <br />
            <span style="position:relative; float:left; margin-top:-36px; margin-left:20px; font-weight:lighter; color:#000000">        <!-- was -5 -->
                <?php echo $testljus "%"?>
            </span>
            <span style=" position:relative; float:right; margin-top:-36px; margin-right:20px; font-weight:lighter; color:#FFFFFF">      <!-- was 5 -->
                <?php echo $testmorker "%"?>
            </span>
            <span class="thisPage" style=" position:relative; font-weight:lighter; top:-8px">
        <?php
            
echo '<br/>Which is <br/>';
            
$time_arr explode(':'$changeinday);
            if (
substr($time_arr[0],0,1) != "-") {         // -0 when getting shorter
                
echo (int)$time_arr[1] . " min Longer";
            } else {
                echo (int)
$time_arr[1] . " min Shorter";
            }
            echo (
'<br />Than Yesterday');
        
?>

            </span>
      </div> 
Regards, Jerry Wilkins
gwwilk@inebraska.com

Offline mcrossley

  • Posts: 655
  • Wilmslow, Cheshire, UK
    • none
  • OS/Browser:
  • Win 7/Srvr 2008R2
  • Chrome 24.0.1312.56
    • WilmslowAstro Weather
Re: Sunrise/Sunset script
« Reply #21 on: January 31, 2013, 07:55:18 PM »
Neat, I've gone for a dead simple implementation on my index page as the hours info is already there.

I have also added in 'dusk' as pink sectors either side of daylight, and I rotate the chart to keep the day sector centred on 9 O'Clock.

All done client side in JavaScript on my page though.

http://weather.wilmslowastro.com/index.htm

Edit: the relevant bit of script is below (should be easy to convert to PHP) , I have two values available, "daylength" = sunrise-sunset time (hh:mm), and "daylightlength" = start of morning dusk to end of evening dusk (hh:mm). If both those values are not available in WD, then the calculation to centre the day sector may be useful?
Code: [Select]
dayPct = (+cumulus.daylength.split(':')[0] + cumulus.daylength.split(':')[1] / 60) / 24 * 100;
duskPct = (+cumulus.daylightlength.split(':')[0] + cumulus.daylightlength.split(':')[1] / 60) / 24 * 100;
duskPct -= dayPct;
nightPct = 100 - dayPct - duskPct;
duskPct /= 2;
cumulus.daylightChart = '<img src="http://chart.apis.google.com/chart?' +
'chs=75x75' +
'&amp;chtt=day/night' +
'&amp;chts=000000,12' +
'&amp;chma=0,0,0,0' +
'&amp;chd=t:' + duskPct + ',' + dayPct + ',' + duskPct + ',' + nightPct +
'&amp;cht=p3' +
'&amp;chp=' + (Math.PI - (dayPct + duskPct * 2) / 100 * Math.PI) +
'&amp;chf=bg,s,FFFFFF00' +
'&amp;chco=F046A1,FFD700,F046A1,303060' +
'" alt="day/night ratio"/>';
« Last Edit: February 01, 2013, 09:41:20 AM by mcrossley »
Mark

Offline aggets

  • Posts: 123
  • Sun Prairie, Wisconsin USA
  • OS/Browser:
  • Win 7/Srvr 2008R2
  • Firefox 18.0
    • Sun Prairie Weather
Re: Sunrise/Sunset script
« Reply #22 on: February 01, 2013, 09:34:02 AM »
Thanks Jim

Got it running on my sidebar http://www.sunprairieweather.com/

Andy

Offline gwwilk

  • Posts: 681
  • Lincoln, NE
  • OS/Browser:
  • Win 7/Srvr 2008R2
  • Chrome 24.0.1312.57
    • Southeast Lincoln Weather
Re: Sunrise/Sunset script
« Reply #23 on: February 04, 2013, 04:25:07 AM »
I should have warned you that my version of the script is set up for use in the menubar only.  The float:right style of the white text has put it at the far right of your page where white on white is obviously invisible.  Do you not plan to use it in the menubar?  Put it in your menubar as posted, and it should be just fine.
« Last Edit: February 04, 2013, 04:26:45 AM by gwwilk »
Regards, Jerry Wilkins
gwwilk@inebraska.com

Offline Bunty

  • Posts: 212
  • Stillwater, OK
  • OS/Browser:
  • Win 7/Srvr 2008R2
  • Firefox 19.0
    • Stillwater Weather
Re: Sunrise/Sunset script
« Reply #24 on: February 04, 2013, 11:40:18 AM »
I should have warned you that my version of the script is set up for use in the menubar only.  The float:right style of the white text has put it at the far right of your page where white on white is obviously invisible.  Do you not plan to use it in the menubar?  Put it in your menubar as posted, and it should be just fine.

Okay, thanks,  I got both percentage numbers showing in the pie showing on the test page.  Didn't want to do move it beyond the test page until I figured out how to get the minutes more sunshine showing other than 0.

Offline jmcmurry

  • Jim McMurry
  • Posts: 2,836
  • Mauston, WI, USA
  • OS/Browser:
  • Win XP
  • Firefox 18.0
    • Juneau County Weather
Re: Sunrise/Sunset script
« Reply #25 on: February 04, 2013, 12:06:06 PM »
I often see "0 min Longer", just give it a day or two and see what happens with that tag.

- Jim

Forum Search and Google can be your best friends

Offline gwwilk

  • Posts: 681
  • Lincoln, NE
  • OS/Browser:
  • Win 7/Srvr 2008R2
  • Chrome 24.0.1312.57
    • Southeast Lincoln Weather
Re: Sunrise/Sunset script
« Reply #26 on: February 04, 2013, 01:18:20 PM »
If you lived in higher latitudes you would see larger day-to-day differences :)  I show 2 min. longer daylight today.
Regards, Jerry Wilkins
gwwilk@inebraska.com

Offline niko

  • syzygy
  • Global Moderator
  • Posts: 28,170
  • Crystal Ball broken! Please post the URL.
  • Northern California, U.S.A.
  • OS/Browser:
  • Win 7/Srvr 2008R2
  • MS IE 9.0
Re: Sunrise/Sunset script
« Reply #27 on: February 04, 2013, 05:08:27 PM »
If you lived in higher latitudes you would see larger day-to-day differences :)  I show 2 min. longer daylight today.

I don't think that's the issue, tiggrweather is farther south than Stillwater OK and the tag is showing 1 minute, so I suspect there may be a problem with the Stillwater $changeinday tag. IIRC the WD change in day is driven by the solar max calculation, and not the rise/set times, so if solar isn't set up (I see Stillwater has zero for the solar readings) it may not work.

Offline gwwilk

  • Posts: 681
  • Lincoln, NE
  • OS/Browser:
  • Win 7/Srvr 2008R2
  • Chrome 24.0.1312.57
    • Southeast Lincoln Weather
Re: Sunrise/Sunset script
« Reply #28 on: February 04, 2013, 06:29:28 PM »
OK.  Thanks, Niko. #-o
Regards, Jerry Wilkins
gwwilk@inebraska.com

Offline Bunty

  • Posts: 212
  • Stillwater, OK
  • OS/Browser:
  • Win NT 6.2
  • Firefox 18.0
    • Stillwater Weather
Re: Sunrise/Sunset script
« Reply #29 on: February 04, 2013, 08:11:53 PM »
I don't think that's the issue, tiggrweather is farther south than Stillwater OK and the tag is showing 1 minute, so I suspect there may be a problem with the Stillwater $changeinday tag. IIRC the WD change in day is driven by the solar max calculation, and not the rise/set times, so if solar isn't set up (I see Stillwater has zero for the solar readings) it may not work.

While there's a lot to look over,  I've tried looking for likely looking settings for that in some of the saratoga files, but couldn't find anything.