diff options
author | Joris | 2015-10-04 20:48:32 +0200 |
---|---|---|
committer | Joris | 2015-10-04 20:48:32 +0200 |
commit | 8c24464a4bd0a486cd0ddf846d3b5a323a7aaa9a (patch) | |
tree | cdd1bb79846b3d8865d833a122152528b03a4746 /src/client/Model/Payers.elm | |
parent | 303dfd66c6434e19ba226a133a35a74a557b3e93 (diff) |
Using incomes to compute a fair computation to designate the payer
Diffstat (limited to 'src/client/Model/Payers.elm')
-rw-r--r-- | src/client/Model/Payers.elm | 59 |
1 files changed, 0 insertions, 59 deletions
diff --git a/src/client/Model/Payers.elm b/src/client/Model/Payers.elm deleted file mode 100644 index 983e7b3..0000000 --- a/src/client/Model/Payers.elm +++ /dev/null @@ -1,59 +0,0 @@ -module Model.Payers - ( Payers - , ExceedingPayer - , payersDecoder - , updatePayers - , getOrderedExceedingPayers - ) where - -import Json.Decode as Json exposing (..) -import Dict exposing (..) -import List -import Maybe - -import Model.User exposing (UserId, userIdDecoder) - -type alias Payers = Dict UserId Int - -payersDecoder : Decoder Payers -payersDecoder = Json.map Dict.fromList (list payerDecoder) - -payerDecoder : Decoder (UserId, Int) -payerDecoder = - object2 (,) - ("userId" := userIdDecoder) - ("totalPayment" := int) - -updatePayers : Payers -> UserId -> Int -> Payers -updatePayers payers userId amountDiff = - Dict.update - userId - (\mbAmount -> - case mbAmount of - Just amount -> Just (amount + amountDiff) - Nothing -> Nothing - ) - payers - -type alias ExceedingPayer = - { userId : UserId - , amount : Int - } - -getOrderedExceedingPayers : Payers -> List ExceedingPayer -getOrderedExceedingPayers payers = - let orderedPayers = - Dict.toList payers - |> List.map (\(userId, amount) -> ExceedingPayer userId amount) - |> List.sortBy .amount - maybeMinAmount = - List.head orderedPayers - |> Maybe.map .amount - in case maybeMinAmount of - Just minAmount -> - orderedPayers - |> List.map (\payer -> { payer | amount <- payer.amount - minAmount }) - |> List.filter (\payer -> payer.amount /= 0) - |> List.reverse - Nothing -> - [] |