Replaced DisplayAble instance for Rational with auxiliary function rounding to Fixed E3
This commit is contained in:
parent
96edf7dff3
commit
09e072c6e3
@ -316,9 +316,9 @@ Correctors: Korrektoren
|
|||||||
CorState: Status
|
CorState: Status
|
||||||
CorByTut: Zuteilung nach Tutorium
|
CorByTut: Zuteilung nach Tutorium
|
||||||
CorProportion: Anteil
|
CorProportion: Anteil
|
||||||
CorByProportionOnly proportion@Rational: #{display proportion} Anteile
|
CorByProportionOnly proportion@Rational: #{rationalToFixed3 proportion} Anteile
|
||||||
CorByProportionIncludingTutorial proportion@Rational: #{display proportion} Anteile - Tutorium
|
CorByProportionIncludingTutorial proportion@Rational: #{rationalToFixed3 proportion} Anteile - Tutorium
|
||||||
CorByProportionExcludingTutorial proportion@Rational: #{display proportion} Anteile + Tutorium
|
CorByProportionExcludingTutorial proportion@Rational: #{rationalToFixed3 proportion} Anteile + Tutorium
|
||||||
|
|
||||||
RowCount count@Int64: #{count} #{pluralDE count "passender Eintrag" "passende Einträge"} insgesamt
|
RowCount count@Int64: #{count} #{pluralDE count "passender Eintrag" "passende Einträge"} insgesamt
|
||||||
DeleteRow: Entfernen
|
DeleteRow: Entfernen
|
||||||
|
|||||||
@ -350,6 +350,12 @@ instance HasResolution a => ToMessage (Fixed a) where
|
|||||||
toMessage = toMessage . showFixed True
|
toMessage = toMessage . showFixed True
|
||||||
|
|
||||||
|
|
||||||
|
-- Do not use toMessage on Rationals and round them automatically. Instead, use rationalToFixed3 (declared in src/Utils.hs) to convert a Rational to Fixed E3!
|
||||||
|
-- instance ToMessage Rational where
|
||||||
|
-- toMessage = toMessage . fromRational'
|
||||||
|
-- where fromRational' = fromRational :: Rational -> Fixed E3
|
||||||
|
|
||||||
|
|
||||||
newtype ErrorResponseTitle = ErrorResponseTitle ErrorResponse
|
newtype ErrorResponseTitle = ErrorResponseTitle ErrorResponse
|
||||||
embedRenderMessageVariant ''UniWorX ''ErrorResponseTitle ("ErrorResponseTitle" <>)
|
embedRenderMessageVariant ''UniWorX ''ErrorResponseTitle ("ErrorResponseTitle" <>)
|
||||||
|
|
||||||
|
|||||||
@ -16,7 +16,6 @@ import qualified Yesod.Auth.Util.PasswordStore as PWStore
|
|||||||
type Count = Sum Integer
|
type Count = Sum Integer
|
||||||
type Points = Centi
|
type Points = Centi
|
||||||
|
|
||||||
|
|
||||||
type Email = Text
|
type Email = Text
|
||||||
|
|
||||||
type SchoolName = CI Text
|
type SchoolName = CI Text
|
||||||
@ -32,4 +31,4 @@ type PWHashAlgorithm = ByteString -> PWStore.Salt -> Int -> ByteString
|
|||||||
type InstanceId = UUID
|
type InstanceId = UUID
|
||||||
type ClusterId = UUID
|
type ClusterId = UUID
|
||||||
type TokenId = UUID
|
type TokenId = UUID
|
||||||
type TermCandidateIncidence = UUID
|
type TermCandidateIncidence = UUID
|
||||||
18
src/Utils.hs
18
src/Utils.hs
@ -30,7 +30,6 @@ import Text.Blaze (Markup, ToMarkup)
|
|||||||
|
|
||||||
import Data.Char (isDigit, isSpace, isAscii)
|
import Data.Char (isDigit, isSpace, isAscii)
|
||||||
import Data.Text (dropWhileEnd, takeWhileEnd, justifyRight)
|
import Data.Text (dropWhileEnd, takeWhileEnd, justifyRight)
|
||||||
import Numeric (showFFloat)
|
|
||||||
|
|
||||||
import Data.Set (Set)
|
import Data.Set (Set)
|
||||||
import qualified Data.Set as Set
|
import qualified Data.Set as Set
|
||||||
@ -248,21 +247,8 @@ class DisplayAble a where
|
|||||||
default display :: Show a => a -> Text
|
default display :: Show a => a -> Text
|
||||||
display = pack . show
|
display = pack . show
|
||||||
|
|
||||||
instance DisplayAble Rational where
|
rationalToFixed3 :: Rational -> Fixed E3
|
||||||
display r = showFFloat (Just 2) (rat2float r) ""
|
rationalToFixed3 = fromRational
|
||||||
& pack
|
|
||||||
& dropWhileEnd ('0'==)
|
|
||||||
& dropWhileEnd ('.'==)
|
|
||||||
where
|
|
||||||
rat2float :: Rational -> Double
|
|
||||||
rat2float = fromRational
|
|
||||||
|
|
||||||
{- We do not want DisplayAble for every Show-Class:
|
|
||||||
We want to explicitly verify that the resulting text can be displayed to the User!
|
|
||||||
For example: UTCTime values were shown without proper format rendering!
|
|
||||||
instance {-# OVERLAPPABLE #-} Show a => DisplayAble a where -- The easy way out of UndecidableInstances (TypeFamilies would have been proper, but are much more complicated)
|
|
||||||
display = pack . show
|
|
||||||
-}
|
|
||||||
|
|
||||||
textPercent :: Real a => a -> Text -- slow, maybe use Data.Double.Conversion.Text.toFixed instead?
|
textPercent :: Real a => a -> Text -- slow, maybe use Data.Double.Conversion.Text.toFixed instead?
|
||||||
textPercent x = lz <> pack (show rx) <> "%"
|
textPercent x = lz <> pack (show rx) <> "%"
|
||||||
|
|||||||
Reference in New Issue
Block a user