Skip to content

Commit

Permalink
[#2013] randomize DRep list
Browse files Browse the repository at this point in the history
  • Loading branch information
j-dyczka committed Sep 19, 2024
1 parent 26400b3 commit 059b17e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions govtool/backend/src/VVA/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import Numeric.Natural (Natural)

import Servant.API
import Servant.Server
import System.Random (randomRIO)

import Text.Read (readMaybe)

Expand Down Expand Up @@ -151,8 +152,11 @@ drepList mSearchQuery statuses mSortMode mPage mPageSize = do
_ -> filter $ \Types.DRepRegistration {..} ->
mapDRepStatus dRepRegistrationStatus `elem` statuses

randomizedOrderList <- mapM (\_ -> randomRIO (0, 1 :: Double)) dreps

let sortDReps = case mSortMode of
Nothing -> id
Just Random -> (\list -> fmap snd $ sortOn fst $ Prelude.zip randomizedOrderList list)
Just VotingPower -> sortOn $ \Types.DRepRegistration {..} ->
Down dRepRegistrationVotingPower
Just RegistrationDate -> sortOn $ \Types.DRepRegistration {..} ->
Expand Down
2 changes: 1 addition & 1 deletion govtool/backend/src/VVA/API/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ instance ToParamSchema GovernanceActionType where
& enum_ ?~ map toJSON (enumFromTo minBound maxBound :: [GovernanceActionType])


data DRepSortMode = VotingPower | RegistrationDate | Status deriving (Bounded, Enum, Eq, Generic, Read, Show)
data DRepSortMode = Random | VotingPower | RegistrationDate | Status deriving (Bounded, Enum, Eq, Generic, Read, Show)

instance FromJSON DRepSortMode where
parseJSON (Aeson.String dRepSortMode) = pure $ fromJust $ readMaybe (Text.unpack dRepSortMode)
Expand Down
1 change: 1 addition & 0 deletions govtool/backend/vva-be.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ library
, http-client-tls
, vector
, async
, random

exposed-modules: VVA.Config
, VVA.CommandLine
Expand Down

0 comments on commit 059b17e

Please sign in to comment.