[2024-08-16] Add Abbey Road, The Hobbit, transatlantic flight and history of life on Earth

This commit is contained in:
Andrew Conlin 2024-08-18 10:18:39 +01:00
parent 4af1e7b745
commit f1c63d0ecf
2 changed files with 155 additions and 19 deletions

View File

@ -5,20 +5,36 @@
</head>
<body>
<div class="content">
<h1><strong><strong>It is currently <span class="red">{{ nowTime }}</span> on <span class="orange">{{ nowDate }}</span>.</strong></strong></h1><br>
<h2>
We are <span class="green">{{ yearPercent }}%</span> of the way through {{ year }}.<br><br>
<progress id="file" max="100" value="{{ yearPercent }}">{{ yearPercent }}%</progress><br>
<h2><strong><strong>It is currently <button>{{ nowTime }}</button> on <button>{{ nowDate }}</button>.</strong></strong></h2>
<h3>
We are <button>{{ yearPercent }}%</button> of the way through {{ year }}.<br>
<progress max="100" value="{{ yearPercent }}">{{ yearPercent }}%</progress>
</h3>
<strong>To put that into context, if the year was:</strong><br>
<br>
</h2>
To put that into context:<br>
If the year were<br>
a 90 minute football match,<br>
it would be the {{ footballMinute }}th minute.<br>
a 40 hour work week,<br>
it would be {{ workTime }} on {{ workDay }}.<br>
a marathon,<br>
you would have {{ marathonMile }} miles to go.<br>
<div class="left">
⚽ a 90 minute football match, it would be the {{ footballMinute }}th minute.
</div><br>
<div class="right">
🕘 a 40 hour work week, it would be {{ workTime }} on {{ workDay }}.
</div><br>
<div class="left">
🏃 a marathon, you would have {{ marathonMile }} miles to go.
</div><br>
<div class="right">
🪲 Abbey Road, you would be listening to "{{ abbeyRoadSong }}"
</div><br>
<div class="left">
🗡️ The Hobbit, Bilbo would be {{ hobbitChapter }}.
</div><br>
<div class="right">
✈️ a flight from London to New York, you would be about <a href="https://www.openstreetmap.org/?mlat={{ lat }}&mlon={{ long }}.00#map=4/{{ lat }}/{{ long }}">here</a>.
</div><br>
<div class="left">
🧬 the history of life on Earth, {{ homoSapiens }}
</div><br>
<footer>
</footer>
</div>
</body>
</html>

View File

@ -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)