n0bel / PiClock

A Fancy Clock built around a monitor and a Raspberry Pi
MIT License
568 stars 184 forks source link

moonphase calculation has a small error #111

Closed BertLindeman closed 5 years ago

BertLindeman commented 5 years ago

The calculation of the moon phase in the current PyQtPiClock.py:

Current code

def phase(f):
    pp = 'New Moon'
    if (f > 0.625):
        pp = 'Waxing Crescent'
    if (f > 0.1875):
        pp = 'First Quarter'
    if (f > 0.3125):
        pp = 'Waxing Gibbous'
    if (f > 0.4375):
        pp = 'Full Moon'
    if (f > 0.5625):
        pp = 'Waning Gibbous'
    if (f > 0.5625):
        pp = 'Waning Gibbous'
    if (f > 0.6875):
        pp = 'Third Quarter'
    if (f > 0.8125):
        pp = 'Waning Crecent'
    if (f > 0.9375):
        pp = 'New Moon'
    return pp

As this part of the code tests all values all the time, I also propose to reverse the ifs like this:

**Proposed code**

def phase(f):
    # Determine moon phase upon the decimal part of the lunation number
    # Darksky points in their doc to URL:
    # https://en.wikipedia.org/wiki/Lunation_Number
    # the values here are mid-values halfway between these ranges:
    # 0 for new moon, 0.25 for first quarter moon, 0.5 for full moon, and 0.75 for last quarter moon.
    if   (f > 0.9375):
            pp = 'New Moon'
    elif (f > 0.8125):
            pp = 'Waning Crecent'
    elif (f > 0.6875):
            pp = 'Third Quarter'
    elif (f > 0.5625):  ## BUG: was duplicate IF
            pp = 'Waning Gibbous'
    elif (f > 0.4375):
            pp = 'Full Moon'
    elif (f > 0.3125):
            pp = 'Waxing Gibbous'
    elif (f > 0.1875):
            pp = 'First Quarter'
    elif (f > 0.0625):  ## BUG: Zero added for this if was 0.625
            pp = 'Waxing Crescent'
    else:
            pp = 'New Moon'
    return pp

Have added a separate enhancement request #112 to take the moon phase text from the Config.py

n0bel commented 5 years ago

Great catch great work... Would you like to do a pull request?

BertLindeman commented 5 years ago

Uhrm.. Want yes Rather git-nitwit Will try to setup git somewhere..

n0bel commented 5 years ago

you can do it all directly from within github. Fork, edit, commit, pull request.

BertLindeman commented 5 years ago

Thanks! Just enough magic words to get me started.

BertLindeman commented 5 years ago

Looks like i made it ;-)

n0bel commented 5 years ago

Wonderful!

n0bel commented 5 years ago

Might as well do the other one

BertLindeman commented 5 years ago

Now I have the grip of it hihi

n0bel commented 5 years ago

@BertLindeman Thanks! All merged, plus a few other additions.. Great Work!

BertLindeman commented 5 years ago

Thank YOU 👍