diff options
author | Andrew Cady <d@cryptonomic.net> | 2022-09-16 15:51:25 -0400 |
---|---|---|
committer | Andrew Cady <d@cryptonomic.net> | 2022-09-16 15:51:51 -0400 |
commit | 220af07dc4544705919eab6e6bf46aeaf8453db1 (patch) | |
tree | f7104cfa0bc07ef7ff7be6bfac10bfcbcd77cd49 | |
parent | 80ddcbf5c59b9fd7537f5dbd48c506e422a9ac97 (diff) |
begin implementation of calendar
-rw-r--r-- | CosmicCalendar.hs | 128 | ||||
-rwxr-xr-x | countdown.hs | 23 | ||||
-rw-r--r-- | package.yaml | 2 |
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 | |||
15 | module CosmicCalendar where | ||
16 | |||
17 | import Rebase.Prelude | ||
18 | import qualified Rebase.Prelude as Prelude | ||
19 | import Control.Lens hiding ((<|)) | ||
20 | import Data.Foldable (toList) | ||
21 | import Data.Ratio | ||
22 | import Text.Printf | ||
23 | import Data.Time.LocalTime | ||
24 | import Control.Monad.RWS | ||
25 | import Data.Time.Calendar.OrdinalDate | ||
26 | import Data.Text.Format.Numbers | ||
27 | import NeatInterpolation | ||
28 | import Data.Text (Text) | ||
29 | |||
30 | import Rebase.Data.Map.Strict (Map) | ||
31 | import 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 | ||
34 | ageOfUniverseInYears :: Integer | ||
35 | ageOfUniverseInYears = 13787 * 1000 * 1000 | ||
36 | |||
37 | daysPerYear :: NominalDiffTime | ||
38 | daysPerYear = 365.2422 | ||
39 | |||
40 | lengthOfDay :: NominalDiffTime | ||
41 | lengthOfDay = 24 * 60 * 60 | ||
42 | |||
43 | lengthOfYear :: NominalDiffTime | ||
44 | lengthOfYear = daysPerYear * lengthOfDay | ||
45 | |||
46 | ageOfUniverse :: NominalDiffTime | ||
47 | ageOfUniverse = fromIntegral ageOfUniverseInYears * lengthOfYear | ||
48 | |||
49 | data CalendarEntry = CalendarEntry { | ||
50 | calBeginTime :: NominalDiffTime, | ||
51 | calEndTime :: Maybe NominalDiffTime, | ||
52 | calTitle :: Text, | ||
53 | calDescription :: Text, | ||
54 | calReferences :: Text | ||
55 | } | ||
56 | |||
57 | theCalendar :: Map NominalDiffTime CalendarEntry | ||
58 | theCalendar = Map.fromList $ map (\x -> (calBeginTime x, x)) theCalendarList | ||
59 | |||
60 | thousandYears :: Rational -> NominalDiffTime | ||
61 | thousandYears = (* (lengthOfYear * 1000)) . fromRational | ||
62 | |||
63 | millionYears :: Rational -> NominalDiffTime | ||
64 | millionYears = (* (lengthOfYear * 1000 * 1000)) . fromRational | ||
65 | |||
66 | billionYears :: Rational -> NominalDiffTime | ||
67 | billionYears = (* (lengthOfYear * 1000 * 1000 * 1000)) . fromRational | ||
68 | |||
69 | thousandYearsAgo :: Rational -> NominalDiffTime | ||
70 | thousandYearsAgo n = ageOfUniverse - (thousandYears n) | ||
71 | |||
72 | millionYearsAgo :: Rational -> NominalDiffTime | ||
73 | millionYearsAgo n = ageOfUniverse - (millionYears n) | ||
74 | |||
75 | billionYearsAgo :: Rational -> NominalDiffTime | ||
76 | billionYearsAgo n = ageOfUniverse - (billionYears n) | ||
77 | |||
78 | afterBigBang :: NominalDiffTime -> NominalDiffTime | ||
79 | afterBigBang = id | ||
80 | |||
81 | theCalendarList :: [CalendarEntry] | ||
82 | theCalendarList = | ||
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) | |||
57 | import Brick.Widgets.Core | 57 | import Brick.Widgets.Core |
58 | import Brick.Widgets.Table | 58 | import Brick.Widgets.Table |
59 | 59 | ||
60 | billion :: Integer | 60 | import CosmicCalendar |
61 | billion = 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 | |||
65 | ageOfUniverseInYears :: Integer | ||
66 | ageOfUniverseInYears = 13787 * 1000 * 1000 | ||
67 | |||
68 | daysPerYear :: NominalDiffTime | ||
69 | daysPerYear = 365.2422 | ||
70 | |||
71 | lengthOfYear :: NominalDiffTime | ||
72 | lengthOfYear = daysPerYear * lengthOfDay | ||
73 | |||
74 | lengthOfDay :: NominalDiffTime | ||
75 | lengthOfDay = 24 * 60 * 60 | ||
76 | |||
77 | ageOfUniverse :: NominalDiffTime | ||
78 | ageOfUniverse = fromIntegral ageOfUniverseInYears * lengthOfYear | ||
79 | 61 | ||
80 | data CustomEvent = TimeChanged ZonedTime deriving Show | 62 | data 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 | ||
415 | zone :: TimeZone | ||
416 | zone = unsafePerformIO getCurrentTimeZone | ||
417 | |||
418 | main :: IO () | 397 | main :: IO () |
419 | main = do | 398 | main = 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 | ||
17 | executables: | 18 | executables: |
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 |