From f1c63d0ecfc02e42dc223b6c68572220c13ac05d Mon Sep 17 00:00:00 2001 From: Andrew Conlin Date: Sun, 18 Aug 2024 10:18:39 +0100 Subject: [PATCH] [2024-08-16] Add Abbey Road, The Hobbit, transatlantic flight and history of life on Earth --- templates/index.html | 42 +++++++++----- year-progress.py | 132 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 155 insertions(+), 19 deletions(-) diff --git a/templates/index.html b/templates/index.html index 977281f..653ef9d 100644 --- a/templates/index.html +++ b/templates/index.html @@ -5,20 +5,36 @@
-

It is currently {{ nowTime }} on {{ nowDate }}.


-

- We are {{ yearPercent }}% of the way through {{ year }}.

- {{ yearPercent }}%
+

It is currently on .

+

+ We are of the way through {{ year }}.
+ {{ yearPercent }}% +

+ To put that into context, if the year was:

- - To put that into context:
- If the year were
- a 90 minute football match,
- it would be the {{ footballMinute }}th minute.
- a 40 hour work week,
- it would be {{ workTime }} on {{ workDay }}.
- a marathon,
- you would have {{ marathonMile }} miles to go.
+
+ ⚽ a 90 minute football match, it would be the {{ footballMinute }}th minute. +

+
+ 🕘 a 40 hour work week, it would be {{ workTime }} on {{ workDay }}. +

+
+ 🏃 a marathon, you would have {{ marathonMile }} miles to go. +

+
+ 🪲 Abbey Road, you would be listening to "{{ abbeyRoadSong }}" +

+
+ 🗡️ The Hobbit, Bilbo would be {{ hobbitChapter }}. +

+
+ ✈️ a flight from London to New York, you would be about here. +

+
+ 🧬 the history of life on Earth, {{ homoSapiens }} +

+
diff --git a/year-progress.py b/year-progress.py index b07b318..34f052a 100644 --- a/year-progress.py +++ b/year-progress.py @@ -17,15 +17,126 @@ def num2day(num): case 5: return "Friday" +def latLongToCartesian(lat,long): + lat = lat*math.pi/180 + long = long*math.pi/180 + x = math.cos(lat)*math.cos(long) + y = math.cos(lat)*math.sin(long) + z = math.sin(lat) + return x,y,z + +def cartesianToLatLong(x,y,z): + long = math.atan2(y,x) + hyp = math.sqrt(x*x + y*y) + lat = math.atan2(z,hyp) + + lat = lat*180/math.pi + long = long*180/math.pi + + return lat, long + + +def getPercentageLatLong(yearPercent,lat1,long1,lat2,long2): + # http://www.geomidpoint.com/calculation.html + x1, y1, z1 = latLongToCartesian(lat1,long1) + x2, y2, z2 = latLongToCartesian(lat2,long2) + + xmid = (x1*(1-yearPercent)+x2*yearPercent) + ymid = (y1*(1-yearPercent)+y2*yearPercent) + zmid = (z1*(1-yearPercent)+z2*yearPercent) + + latmid, longmid = cartesianToLatLong(xmid,ymid,zmid) + + return latmid, longmid + def workWeek(yearPercent): totalNumHours = 40*yearPercent numDays = totalNumHours/8 hoursIntoDay = (numDays - math.floor(numDays))*8 minutesIntoDay = round((hoursIntoDay - math.floor(hoursIntoDay))*60) + if minutesIntoDay > 59: + minutesIntoDay = 0 + hoursIntoDay += 1 workDatetime = datetime.datetime(year=1970,month=1,day=1,hour=math.floor(hoursIntoDay)+9,minute=minutesIntoDay) workTime = workDatetime.strftime("%-I:%M%p") return num2day(math.floor(numDays+1)), workTime +def abbeyRoad(yearPercent): + totalSeconds = 47*60+29 # 47 minutes 29 seconds + numSeconds = math.floor(totalSeconds*yearPercent); + # 4:19 + if numSeconds <= 4*60+19: + return "Come Together" + # 3:02 + elif numSeconds <= 259+(3*60+2): + return "Something" + # 3:27 + elif numSeconds <= 441+(3*60+27): + return "Maxwell's Silver Hammer" + #3:27 + elif numSeconds <= 648+(3*60+27): + return "Oh! Darling" + #2:50 + elif numSeconds <= 855+(2*60+50): + return "Octopus's Garden" + #7:47 + elif numSeconds <= 1025+(7*60+47): + return "I Want You (She's So Heavy)" + #3:05 + elif numSeconds <= 1492+(3*60+5): + return "Here Comes The Sun" + #2:45 + elif numSeconds <= 1677+(2*60+45): + return "Because" + #4:02 + elif numSeconds <= 1842+(4*60+2): + return "You Never Give Me Your Money" + #2:26 + elif numSeconds <= 2084+(2*60+26): + return "Sun King" + #1:06 + elif numSeconds <= 2230+(1*60+6): + return "Mean Mr. Mustard" + #1:12 + elif numSeconds <= 2296+(1*60+12): + return "Polythene Pam" + #1:58 + elif numSeconds <= 2368+(1*60+58): + return "She Came In Through The Bathroom Window" + #1:31 + elif numSeconds <= 2486+(1*60+31): + return "Golden Slumbers" + #1:36 + elif numSeconds <= 2577+(1*60+36): + return "Carry That Weight" + #2:21 + elif numSeconds <= 2673+(2*60+21): + return "The End" + #0:25 + else: + return "Her Majesty" + +def theHobbit(): + pass + +def transatlanticFlight(yearPercent): + lat1 = 51.470020 + long1 = -0.454295 + + lat2 = 40.641766 + long2 = -73.780968 + + lat, long = getPercentageLatLong(yearPercent,lat1,long1,lat2,long2) + return lat, long + +def getHomoSapiens(yearPercent): + totalYears = 4.3e9 + yearsUntilHumans = totalYears*(1-yearPercent) - 300e3 + if yearsUntilHumans >= 0: + return f"Homo Sapiens would evolve in ~{math.floor(yearsUntilHumans)} years." + else: + return f"Homo Sapiens have been around for ~{-math.floor(yearsUntilHumans)} years." + def getTemplate(): now = datetime.datetime.now() nowTime = now.strftime("%-I:%M%p") @@ -38,15 +149,19 @@ def getTemplate(): footballMinute = math.floor(yearPercent*90) workDay, workTime = workWeek(yearPercent) marathonMile = 26.2 - math.floor(yearPercent*26.2) + abbeyRoadSong = abbeyRoad(yearPercent) + hobbitChapter = "having an unexpected party" + lat, long = transatlanticFlight(yearPercent) + homoSapiens = getHomoSapiens(yearPercent) - return now.year, nowTime, nowDate, round(yearPercent*100,2), footballMinute, workDay, workTime, marathonMile + return now.year, nowTime, nowDate, round(yearPercent*100,2), footballMinute, workDay, workTime, marathonMile, abbeyRoadSong, hobbitChapter, lat, long, homoSapiens -#abbey road -#the hobbit +# Transatlantic flight +# History of the earth @app.route("/") -def hello_world(): - year, nowTime, nowDate, yearPercent, footballMinute, workDay, workTime, marathonMile = getTemplate() +def index(): + year, nowTime, nowDate, yearPercent, footballMinute, workDay, workTime, marathonMile, abbeyRoadSong, hobbitChapter, lat, long, homoSapiens = getTemplate() cssPath = url_for('static', filename='style.css') return render_template("index.html",\ cssPath=cssPath,\ @@ -57,4 +172,9 @@ def hello_world(): footballMinute=footballMinute,\ workDay=workDay,\ workTime=workTime,\ - marathonMile=marathonMile) + marathonMile=marathonMile,\ + abbeyRoadSong=abbeyRoadSong,\ + hobbitChapter=hobbitChapter,\ + lat=lat,\ + long=long,\ + homoSapiens=homoSapiens)