summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@cryptonomic.net>2022-09-16 15:51:25 -0400
committerAndrew Cady <d@cryptonomic.net>2022-09-16 15:51:51 -0400
commit220af07dc4544705919eab6e6bf46aeaf8453db1 (patch)
treef7104cfa0bc07ef7ff7be6bfac10bfcbcd77cd49
parent80ddcbf5c59b9fd7537f5dbd48c506e422a9ac97 (diff)
begin implementation of calendar
-rw-r--r--CosmicCalendar.hs128
-rwxr-xr-xcountdown.hs23
-rw-r--r--package.yaml2
3 files changed, 131 insertions, 22 deletions
diff --git a/CosmicCalendar.hs b/CosmicCalendar.hs
new file mode 100644
index 0000000..a21c538
--- /dev/null
+++ b/CosmicCalendar.hs
@@ -0,0 +1,128 @@
1{-# OPTIONS_GHC
2 -Wall
3 -Wno-unused-imports
4 -Wno-unused-top-binds
5 -Wno-name-shadowing
6#-}
7{-# language NoImplicitPrelude #-}
8{-# language RecordWildCards #-}
9{-# language FlexibleContexts #-}
10{-# language TemplateHaskell #-}
11{-# language ViewPatterns #-}
12{-# language OverloadedStrings #-}
13{-# language QuasiQuotes #-}
14
15module CosmicCalendar where
16
17import Rebase.Prelude
18import qualified Rebase.Prelude as Prelude
19import Control.Lens hiding ((<|))
20import Data.Foldable (toList)
21import Data.Ratio
22import Text.Printf
23import Data.Time.LocalTime
24import Control.Monad.RWS
25import Data.Time.Calendar.OrdinalDate
26import Data.Text.Format.Numbers
27import NeatInterpolation
28import Data.Text (Text)
29
30import Rebase.Data.Map.Strict (Map)
31import qualified Rebase.Data.Map.Strict as Map
32
33-- 13.787±0.020 billion years. Source: https://en.wikipedia.org/wiki/Age_of_the_universe#cite_note-Planck_2018-2
34ageOfUniverseInYears :: Integer
35ageOfUniverseInYears = 13787 * 1000 * 1000
36
37daysPerYear :: NominalDiffTime
38daysPerYear = 365.2422
39
40lengthOfDay :: NominalDiffTime
41lengthOfDay = 24 * 60 * 60
42
43lengthOfYear :: NominalDiffTime
44lengthOfYear = daysPerYear * lengthOfDay
45
46ageOfUniverse :: NominalDiffTime
47ageOfUniverse = fromIntegral ageOfUniverseInYears * lengthOfYear
48
49data CalendarEntry = CalendarEntry {
50 calBeginTime :: NominalDiffTime,
51 calEndTime :: Maybe NominalDiffTime,
52 calTitle :: Text,
53 calDescription :: Text,
54 calReferences :: Text
55}
56
57theCalendar :: Map NominalDiffTime CalendarEntry
58theCalendar = Map.fromList $ map (\x -> (calBeginTime x, x)) theCalendarList
59
60thousandYears :: Rational -> NominalDiffTime
61thousandYears = (* (lengthOfYear * 1000)) . fromRational
62
63millionYears :: Rational -> NominalDiffTime
64millionYears = (* (lengthOfYear * 1000 * 1000)) . fromRational
65
66billionYears :: Rational -> NominalDiffTime
67billionYears = (* (lengthOfYear * 1000 * 1000 * 1000)) . fromRational
68
69thousandYearsAgo :: Rational -> NominalDiffTime
70thousandYearsAgo n = ageOfUniverse - (thousandYears n)
71
72millionYearsAgo :: Rational -> NominalDiffTime
73millionYearsAgo n = ageOfUniverse - (millionYears n)
74
75billionYearsAgo :: Rational -> NominalDiffTime
76billionYearsAgo n = ageOfUniverse - (billionYears n)
77
78afterBigBang :: NominalDiffTime -> NominalDiffTime
79afterBigBang = id
80
81theCalendarList :: [CalendarEntry]
82theCalendarList =
83 [
84 CalendarEntry (afterBigBang 0) Nothing "The Big Bang" "" "",
85 CalendarEntry (afterBigBang (thousandYears 370))
86 Nothing
87 "Recombination - the universe first becomes transparent"
88 recombinationDescription
89 recombinationReferences
90 ]
91 where
92 recombinationDescription = [text|
93 At about 370,000 years,[3][4][5][6] neutral hydrogen atoms finish forming
94 ("recombination"), and as a result the universe also became transparent
95 for the first time. The newly formed atoms—mainly hydrogen and helium with
96 traces of lithium—quickly reach their lowest energy state (ground state)
97 by releasing photons ("photon decoupling"), and these photons can still be
98 detected today as the cosmic microwave background (CMB). This is the
99 oldest direct observation we currently have of the universe.
100 |]
101 recombinationReferences = [text|
102 https://en.wikipedia.org/wiki/Chronology_of_the_universe#The_very_early_universe
103
104 3. Tanabashi, M. 2018, p. 358, chpt. 21.4.1: "Big-Bang Cosmology" (Revised
105 September 2017) by Keith A. Olive and John A. Peacock.
106
107 4. Notes: Edward L. Wright's Javascript Cosmology Calculator (last
108 modified 23 July 2018). With a default H 0 {\displaystyle H_{0}} H_{0} =
109 69.6 (based on WMAP9+SPT+ACT+6dFGS+BOSS/DR11+H0/Riess) parameters, the
110 calculated age of the universe with a redshift of z = 1100 is in agreement
111 with Olive and Peacock (about 370,000 years).
112
113 5. Hinshaw, Weiland & Hill 2009. See PDF: page 45, Table 7, Age at
114 decoupling, last column. Based on WMAP+BAO+SN parameters, the age of
115 decoupling occurred 376971+3162−3167 years after the Big Bang.
116
117 6. Ryden 2006, pp. 194–195. "Without going into the details of the
118 non-equilibrium physics, let's content ourselves by saying, in round
119 numbers, zdec ≈ 1100, corresponding to a temperature Tdec ≈ 3000 K, when
120 the age of the universe was tdec ≈ 350,000 yr in the Benchmark Model.
121 (...) The relevant times of various events around the time of
122 recombination are shown in Table 9.1. (...) Note that all these times are
123 approximate, and are dependent on the cosmological model you choose. (I
124 have chosen the Benchmark Model in calculating these numbers.)"
125
126 https://en.wikipedia.org/wiki/Recombination_(cosmology)#cite_note-2
127
128 |]
diff --git a/countdown.hs b/countdown.hs
index 232c04b..a446555 100755
--- a/countdown.hs
+++ b/countdown.hs
@@ -57,25 +57,7 @@ import Brick.Util (fg, bg, on, clamp)
57import Brick.Widgets.Core 57import Brick.Widgets.Core
58import Brick.Widgets.Table 58import Brick.Widgets.Table
59 59
60billion :: Integer 60import CosmicCalendar
61billion = 1000 * 1000 * 1000
62
63-- 13.787±0.020 billion years. Source: https://en.wikipedia.org/wiki/Age_of_the_universe#cite_note-Planck_2018-2
64
65ageOfUniverseInYears :: Integer
66ageOfUniverseInYears = 13787 * 1000 * 1000
67
68daysPerYear :: NominalDiffTime
69daysPerYear = 365.2422
70
71lengthOfYear :: NominalDiffTime
72lengthOfYear = daysPerYear * lengthOfDay
73
74lengthOfDay :: NominalDiffTime
75lengthOfDay = 24 * 60 * 60
76
77ageOfUniverse :: NominalDiffTime
78ageOfUniverse = fromIntegral ageOfUniverseInYears * lengthOfYear
79 61
80data CustomEvent = TimeChanged ZonedTime deriving Show 62data CustomEvent = TimeChanged ZonedTime deriving Show
81 63
@@ -412,9 +394,6 @@ theApp chan =
412 , appAttrMap = const theMap 394 , appAttrMap = const theMap
413 } 395 }
414 396
415zone :: TimeZone
416zone = unsafePerformIO getCurrentTimeZone
417
418main :: IO () 397main :: IO ()
419main = do 398main = do
420 chan <- newBChan 10 399 chan <- newBChan 10
diff --git a/package.yaml b/package.yaml
index d081cde..6b9e489 100644
--- a/package.yaml
+++ b/package.yaml
@@ -13,10 +13,12 @@ dependencies:
13- brick 13- brick
14- format-numbers 14- format-numbers
15- text 15- text
16- neat-interpolation
16 17
17executables: 18executables:
18 countdown: 19 countdown:
19 main: countdown.hs 20 main: countdown.hs
21 other-modules: CosmicCalendar
20 ghc-options: 22 ghc-options:
21 - -threaded 23 - -threaded
22 - -rtsopts 24 - -rtsopts