module Singular.Registry.FoldAdmission
( BatchEdge (..)
, AdmissionRefusal (..)
, BatchConsumption (..)
, foldAdmission
, batchConsumesCreated
, admissionReason
, admissionSource
, consumptionReason
, consumptionSource
, mintReason
, mintSource
) where
data BatchEdge
= BatchInsert
| BatchTerminate
| BatchOther
deriving stock (BatchEdge -> BatchEdge -> Bool
(BatchEdge -> BatchEdge -> Bool)
-> (BatchEdge -> BatchEdge -> Bool) -> Eq BatchEdge
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BatchEdge -> BatchEdge -> Bool
== :: BatchEdge -> BatchEdge -> Bool
$c/= :: BatchEdge -> BatchEdge -> Bool
/= :: BatchEdge -> BatchEdge -> Bool
Eq, Int -> BatchEdge -> ShowS
[BatchEdge] -> ShowS
BatchEdge -> String
(Int -> BatchEdge -> ShowS)
-> (BatchEdge -> String)
-> ([BatchEdge] -> ShowS)
-> Show BatchEdge
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BatchEdge -> ShowS
showsPrec :: Int -> BatchEdge -> ShowS
$cshow :: BatchEdge -> String
show :: BatchEdge -> String
$cshowList :: [BatchEdge] -> ShowS
showList :: [BatchEdge] -> ShowS
Show)
data AdmissionRefusal ref = AdmissionRefusal
{ forall ref. AdmissionRefusal ref -> ref
refusalRef :: ref
, forall ref. AdmissionRefusal ref -> Integer
refusalSubmittedAt :: Integer
, forall ref. AdmissionRefusal ref -> Integer
refusalDeadline :: Integer
, forall ref. AdmissionRefusal ref -> Integer
refusalBound :: Integer
}
deriving stock (AdmissionRefusal ref -> AdmissionRefusal ref -> Bool
(AdmissionRefusal ref -> AdmissionRefusal ref -> Bool)
-> (AdmissionRefusal ref -> AdmissionRefusal ref -> Bool)
-> Eq (AdmissionRefusal ref)
forall ref.
Eq ref =>
AdmissionRefusal ref -> AdmissionRefusal ref -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall ref.
Eq ref =>
AdmissionRefusal ref -> AdmissionRefusal ref -> Bool
== :: AdmissionRefusal ref -> AdmissionRefusal ref -> Bool
$c/= :: forall ref.
Eq ref =>
AdmissionRefusal ref -> AdmissionRefusal ref -> Bool
/= :: AdmissionRefusal ref -> AdmissionRefusal ref -> Bool
Eq, Int -> AdmissionRefusal ref -> ShowS
[AdmissionRefusal ref] -> ShowS
AdmissionRefusal ref -> String
(Int -> AdmissionRefusal ref -> ShowS)
-> (AdmissionRefusal ref -> String)
-> ([AdmissionRefusal ref] -> ShowS)
-> Show (AdmissionRefusal ref)
forall ref. Show ref => Int -> AdmissionRefusal ref -> ShowS
forall ref. Show ref => [AdmissionRefusal ref] -> ShowS
forall ref. Show ref => AdmissionRefusal ref -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall ref. Show ref => Int -> AdmissionRefusal ref -> ShowS
showsPrec :: Int -> AdmissionRefusal ref -> ShowS
$cshow :: forall ref. Show ref => AdmissionRefusal ref -> String
show :: AdmissionRefusal ref -> String
$cshowList :: forall ref. Show ref => [AdmissionRefusal ref] -> ShowS
showList :: [AdmissionRefusal ref] -> ShowS
Show)
data BatchConsumption ref key = BatchConsumption
{ forall ref key. BatchConsumption ref key -> ref
consumptionRef :: ref
, forall ref key. BatchConsumption ref key -> key
consumptionKey :: key
}
deriving stock (BatchConsumption ref key -> BatchConsumption ref key -> Bool
(BatchConsumption ref key -> BatchConsumption ref key -> Bool)
-> (BatchConsumption ref key -> BatchConsumption ref key -> Bool)
-> Eq (BatchConsumption ref key)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall ref key.
(Eq ref, Eq key) =>
BatchConsumption ref key -> BatchConsumption ref key -> Bool
$c== :: forall ref key.
(Eq ref, Eq key) =>
BatchConsumption ref key -> BatchConsumption ref key -> Bool
== :: BatchConsumption ref key -> BatchConsumption ref key -> Bool
$c/= :: forall ref key.
(Eq ref, Eq key) =>
BatchConsumption ref key -> BatchConsumption ref key -> Bool
/= :: BatchConsumption ref key -> BatchConsumption ref key -> Bool
Eq, Int -> BatchConsumption ref key -> ShowS
[BatchConsumption ref key] -> ShowS
BatchConsumption ref key -> String
(Int -> BatchConsumption ref key -> ShowS)
-> (BatchConsumption ref key -> String)
-> ([BatchConsumption ref key] -> ShowS)
-> Show (BatchConsumption ref key)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall ref key.
(Show ref, Show key) =>
Int -> BatchConsumption ref key -> ShowS
forall ref key.
(Show ref, Show key) =>
[BatchConsumption ref key] -> ShowS
forall ref key.
(Show ref, Show key) =>
BatchConsumption ref key -> String
$cshowsPrec :: forall ref key.
(Show ref, Show key) =>
Int -> BatchConsumption ref key -> ShowS
showsPrec :: Int -> BatchConsumption ref key -> ShowS
$cshow :: forall ref key.
(Show ref, Show key) =>
BatchConsumption ref key -> String
show :: BatchConsumption ref key -> String
$cshowList :: forall ref key.
(Show ref, Show key) =>
[BatchConsumption ref key] -> ShowS
showList :: [BatchConsumption ref key] -> ShowS
Show)
admissionReason :: String
admissionReason :: String
admissionReason = String
"not-phase1"
admissionSource :: String
admissionSource :: String
admissionSource = String
"model-refusal"
consumptionReason :: String
consumptionReason :: String
consumptionReason = String
"token-missing"
mintReason :: String
mintReason :: String
mintReason = String
"net-mint-mismatch"
mintSource :: String
mintSource :: String
mintSource = String
"model-refusal"
consumptionSource :: String
consumptionSource :: String
consumptionSource = String
"model-refusal"
foldAdmission
:: Integer -> Integer -> [(ref, Integer)] -> Maybe (AdmissionRefusal ref)
foldAdmission :: forall ref.
Integer
-> Integer -> [(ref, Integer)] -> Maybe (AdmissionRefusal ref)
foldAdmission Integer
processTime Integer
upperBound = [(ref, Integer)] -> Maybe (AdmissionRefusal ref)
forall {ref}. [(ref, Integer)] -> Maybe (AdmissionRefusal ref)
go
where
go :: [(ref, Integer)] -> Maybe (AdmissionRefusal ref)
go [] = Maybe (AdmissionRefusal ref)
forall a. Maybe a
Nothing
go ((ref
ref, Integer
submittedAt) : [(ref, Integer)]
rest)
| Integer
upperBound Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
<= Integer
submittedAt Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Integer
processTime = [(ref, Integer)] -> Maybe (AdmissionRefusal ref)
go [(ref, Integer)]
rest
| Bool
otherwise =
AdmissionRefusal ref -> Maybe (AdmissionRefusal ref)
forall a. a -> Maybe a
Just
( ref -> Integer -> Integer -> Integer -> AdmissionRefusal ref
forall ref.
ref -> Integer -> Integer -> Integer -> AdmissionRefusal ref
AdmissionRefusal
ref
ref
Integer
submittedAt
(Integer
submittedAt Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Integer
processTime)
Integer
upperBound
)
batchConsumesCreated
:: (Eq key)
=> [(ref, key, BatchEdge)] -> Maybe (BatchConsumption ref key)
batchConsumesCreated :: forall key ref.
Eq key =>
[(ref, key, BatchEdge)] -> Maybe (BatchConsumption ref key)
batchConsumesCreated = [key]
-> [(ref, key, BatchEdge)] -> Maybe (BatchConsumption ref key)
forall {key} {ref}.
Eq key =>
[key]
-> [(ref, key, BatchEdge)] -> Maybe (BatchConsumption ref key)
go []
where
go :: [key]
-> [(ref, key, BatchEdge)] -> Maybe (BatchConsumption ref key)
go [key]
_ [] = Maybe (BatchConsumption ref key)
forall a. Maybe a
Nothing
go [key]
created ((ref
ref, key
key, BatchEdge
edge) : [(ref, key, BatchEdge)]
rest) = case BatchEdge
edge of
BatchEdge
BatchTerminate
| key
key key -> [key] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [key]
created -> BatchConsumption ref key -> Maybe (BatchConsumption ref key)
forall a. a -> Maybe a
Just (ref -> key -> BatchConsumption ref key
forall ref key. ref -> key -> BatchConsumption ref key
BatchConsumption ref
ref key
key)
| Bool
otherwise -> [key]
-> [(ref, key, BatchEdge)] -> Maybe (BatchConsumption ref key)
go [key]
created [(ref, key, BatchEdge)]
rest
BatchEdge
BatchInsert -> [key]
-> [(ref, key, BatchEdge)] -> Maybe (BatchConsumption ref key)
go (key
key key -> [key] -> [key]
forall a. a -> [a] -> [a]
: [key]
created) [(ref, key, BatchEdge)]
rest
BatchEdge
BatchOther -> [key]
-> [(ref, key, BatchEdge)] -> Maybe (BatchConsumption ref key)
go [key]
created [(ref, key, BatchEdge)]
rest