Add dumb conversion functions to A2, expand A2 checks

This commit is contained in:
Ivaylo Ivanov 2021-10-28 16:43:39 +02:00
parent 512026a34c
commit 90818eee64

View File

@ -1,5 +1,8 @@
module Angabe2 where
import Data.List
import Data.Maybe
{- 1. Vervollstaendigen Sie gemaess Angabentext!
2. Vervollständigen Sie auch die vorgegebenen Kommentaranfänge!
3. Loeschen Sie keine Deklarationen aus diesem Rahmenprogramm, auch nicht die Modulanweisug!
@ -90,16 +93,83 @@ is_date_valid (d, u)
| monat d == Feb =
let y = jahr d in
let t = tag d in
if y `mod` 4 /= 0 && t > XXVIII then False
if y `mod` 4 /= 0 && (day_to_num t) > (day_to_num XXVIII) then False
else
if y `mod` 100 == 0 && y `mod` 400 /= 0 then False
else
if t > XXIX then False
if (day_to_num t) > (day_to_num XXIX) then False
else True
| tag d > XXX && not(monat d `elem` full_months) = False
| tag d > XXXI = False
| (day_to_num (tag d)) > (day_to_num XXX) && not(monat d `elem` full_months) = False
| otherwise = True
-- Dumb conversion functions
hour_to_num :: Stunde -> Nat1
hour_to_num Eins = 1
hour_to_num Zwei = 2
hour_to_num Drei = 3
hour_to_num Vier = 4
hour_to_num Fuenf = 5
hour_to_num Sechs = 6
hour_to_num Sieben = 7
hour_to_num Acht = 8
hour_to_num Neun = 9
hour_to_num Zehn = 10
hour_to_num Elf = 11
hour_to_num Zwoelf = 12
vhds_to_num :: VHDS -> Nat1
vhds_to_num Schlag = 0
vhds_to_num Viertel = 15
vhds_to_num Halb = 30
vhds_to_num Dreiviertel = 45
day_to_num :: Tag -> Nat1
day_to_num I = 1
day_to_num II = 2
day_to_num III = 3
day_to_num IV = 4
day_to_num V = 5
day_to_num VI = 6
day_to_num VII = 7
day_to_num VIII = 8
day_to_num IX = 9
day_to_num X = 10
day_to_num XI = 11
day_to_num XII = 12
day_to_num XIII = 13
day_to_num XIV = 14
day_to_num XV = 15
day_to_num XVI = 16
day_to_num XVII = 17
day_to_num XVIII = 18
day_to_num XIX = 19
day_to_num XX = 20
day_to_num XXI = 21
day_to_num XXII = 22
day_to_num XXIII = 23
day_to_num XXIV = 24
day_to_num XXV = 25
day_to_num XXVI = 26
day_to_num XXVII = 27
day_to_num XXVIII = 28
day_to_num XXIX = 29
day_to_num XXX = 30
day_to_num XXXI = 31
month_to_num :: Monat -> Nat1
month_to_num Jan = 1
month_to_num Feb = 2
month_to_num Mar = 3
month_to_num Apr = 4
month_to_num Mai = 5
month_to_num Jun = 6
month_to_num Jul = 7
month_to_num Aug = 8
month_to_num Sep = 9
month_to_num Okt = 10
month_to_num Nov = 11
month_to_num Dez = 12
-- Aufgabe A.2
{- Knapp, aber gut nachvollziehbar geht einzulassen folgendermassen vor:
...
@ -126,8 +196,25 @@ should_allow p DreiG k = check_cert_validity p k
check_cert_validity :: Person -> Kontrollzeitpunkt -> Kontrollergebnis
check_cert_validity p k
| not(is_date_valid k) = Ungueltig
| is_tested p && not(is_date_valid ((datum (dreig_status p)), (uhrzeit (dreig_status p)))) = Ungueltig
| otherwise = Einlassen
| is_tested p && (is_test_fresh (dreig_status p) k) = Einlassen
| is_vaccinated p && is_vaccine_fresh (dreig_status p) = Einlassen
| was_sick p = Einlassen
| otherwise = Abweisen
is_test_fresh :: DreiG_Status -> Kontrollzeitpunkt -> Bool
is_test_fresh g k
| not(is_date_valid ((datum g), (uhrzeit g))) = False
| testart g == Antigen = False
| otherwise = True
is_vaccine_fresh :: DreiG_Status -> Bool
is_vaccine_fresh g
| impfstoff g == JundJ =
if ((anzahl g) == Einmal || (anzahl g) == Zweimal) then True
else False
| otherwise =
if (anzahl g) == Zweimal then True
else False
-- Aufgabe A.3