From 674b94938812e93958e991367c261337fe64f2f6 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Tue, 7 Jan 2020 16:22:52 +0100 Subject: [PATCH] fix: divide by zero --- messages/uniworx/de-de-formal.msg | 1 + messages/uniworx/en-eu.msg | 1 + src/Handler/Utils/Table/Cells.hs | 4 +++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/messages/uniworx/de-de-formal.msg b/messages/uniworx/de-de-formal.msg index dde4219b2..92b612528 100644 --- a/messages/uniworx/de-de-formal.msg +++ b/messages/uniworx/de-de-formal.msg @@ -1669,6 +1669,7 @@ CsvImportAborted: CSV-Import abgebrochen CsvImportExplanationLabel: Hinweise zum CSV-Import Proportion c@Text of@Text prop@Rational: #{c}/#{of} (#{rationalToFixed2 (100 * prop)}%) +ProportionNoRatio c@Text of@Text: #{c}/#{of} CourseUserCsvName tid@TermId ssh@SchoolId csh@CourseShorthand: #{foldCase (termToText (unTermKey tid))}-#{foldedCase (unSchoolKey ssh)}-#{foldedCase csh}-teilnehmer ExamUserCsvName tid@TermId ssh@SchoolId csh@CourseShorthand examn@ExamName: #{foldCase (termToText (unTermKey tid))}-#{foldedCase (unSchoolKey ssh)}-#{foldedCase csh}-#{foldedCase examn}-teilnehmer diff --git a/messages/uniworx/en-eu.msg b/messages/uniworx/en-eu.msg index 3810b4bbe..824c95333 100644 --- a/messages/uniworx/en-eu.msg +++ b/messages/uniworx/en-eu.msg @@ -1667,6 +1667,7 @@ CsvImportAborted: CSV import aborted CsvImportExplanationLabel: Informating regarding CSV import Proportion c of prop: #{c}/#{of} (#{rationalToFixed2 (100 * prop)}%) +ProportionNoRatio c of: #{c}/#{of} CourseUserCsvName tid ssh csh: #{foldCase (termToText (unTermKey tid))}-#{foldedCase (unSchoolKey ssh)}-#{foldedCase csh}-participants ExamUserCsvName tid ssh csh examn: #{foldCase (termToText (unTermKey tid))}-#{foldedCase (unSchoolKey ssh)}-#{foldedCase csh}-#{foldedCase examn}-participants diff --git a/src/Handler/Utils/Table/Cells.hs b/src/Handler/Utils/Table/Cells.hs index 295f6ceb6..5a53a8070 100644 --- a/src/Handler/Utils/Table/Cells.hs +++ b/src/Handler/Utils/Table/Cells.hs @@ -197,7 +197,9 @@ numCell :: (IsDBTable m a, ToMessage b) => b -> DBCell m a numCell = textCell . toMessage propCell :: (IsDBTable m a, Real b, ToMessage b) => b -> b -> DBCell m a -propCell curr max' = i18nCell $ MsgProportion (toMessage curr) (toMessage max') (toRational curr / toRational max') +propCell curr max' + | max' /= 0 = i18nCell $ MsgProportion (toMessage curr) (toMessage max') (toRational curr / toRational max') + | otherwise = i18nCell $ MsgProportionNoRatio (toMessage curr) (toMessage max') int64Cell :: IsDBTable m a => Int64-> DBCell m a int64Cell = numCell