module TestUtils.BuildLargeTestData
( generateGoldenManySubjectsRw
, generateGoldenManySubjectsCw
, generateTestDataManySubjects
, generateTestDataManyEvents
, largeInputSize
) where
import Data.List (intercalate, sort)
import Text.Printf
import Text.Regex
largeInputSize :: Int
largeInputSize :: Int
largeInputSize = Int
1000
generateTestDataManySubjects :: String -> String -> IO ()
generateTestDataManySubjects :: [Char] -> [Char] -> IO ()
generateTestDataManySubjects [Char]
infilepath [Char]
outfilepath = do
[Char] -> [Char] -> ([[Char]] -> [[Char]]) -> IO ()
generateTestDataBase [Char]
infilepath [Char]
outfilepath (Regex -> [[Char]] -> [[Char]]
generateNewSubjs Regex
patientRe)
generateTestDataManyEvents :: String -> String -> IO ()
generateTestDataManyEvents :: [Char] -> [Char] -> IO ()
generateTestDataManyEvents [Char]
infilepath [Char]
outfilepath = do
[Char] -> [Char] -> ([[Char]] -> [[Char]]) -> IO ()
generateTestDataBase [Char]
infilepath [Char]
outfilepath [[Char]] -> [[Char]]
transform where
checkIfSubjA :: [Char] -> Bool
checkIfSubjA [Char]
s = ([Char]
s forall a. [a] -> Int -> a
!! Int
2 forall a. Eq a => a -> a -> Bool
== Char
'a') Bool -> Bool -> Bool
&& ([Char]
s forall a. [a] -> Int -> a
!! Int
3 forall a. Eq a => a -> a -> Bool
== Char
'"')
transform :: [[Char]] -> [[Char]]
transform = [[Char]] -> [[Char]]
generateNewEvents forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. (a -> Bool) -> [a] -> [a]
filter [Char] -> Bool
checkIfSubjA
generateGoldenManySubjectsRw :: String -> IO ()
generateGoldenManySubjectsRw :: [Char] -> IO ()
generateGoldenManySubjectsRw [Char]
outfilepath = [Char] -> [Char] -> IO ()
writeFile [Char]
outfilepath [Char]
concatLines where
concatLines :: [Char]
concatLines =
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[Char]]
goldenManySubjectsStart
forall a. [a] -> [a] -> [a]
++ forall a. [a] -> [[a]] -> [a]
intercalate [Char]
"," [[Char]]
goldenRwPatientManys
forall a. [a] -> [a] -> [a]
++ forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[Char]]
goldenRwEnd
generateGoldenManySubjectsCw :: String -> IO ()
generateGoldenManySubjectsCw :: [Char] -> IO ()
generateGoldenManySubjectsCw [Char]
outfilepath = [Char] -> [Char] -> IO ()
writeFile [Char]
outfilepath [Char]
concatLines where
concatLines :: [Char]
concatLines =
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[Char]]
goldenManySubjectsStart
forall a. [a] -> [a] -> [a]
++ forall a. [a] -> [[a]] -> [a]
intercalate [Char]
"," [[Char]]
goldenCwVarManys
forall a. [a] -> [a] -> [a]
++ [Char]
"],\"ids\":["
forall a. [a] -> [a] -> [a]
++ forall a. [a] -> [[a]] -> [a]
intercalate [Char]
"," [[Char]]
goldenCwPatientManys
forall a. [a] -> [a] -> [a]
++ forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[Char]]
goldenCwEnd
generateTestDataBase :: String -> String -> ([String] -> [String]) -> IO ()
generateTestDataBase :: [Char] -> [Char] -> ([[Char]] -> [[Char]]) -> IO ()
generateTestDataBase [Char]
infilePath [Char]
outfilePath [[Char]] -> [[Char]]
transform = do
[[Char]]
infileLines <- [Char] -> IO [[Char]]
readLines [Char]
infilePath
let updatedLines :: [[Char]]
updatedLines = [[Char]] -> [[Char]]
transform [[Char]]
infileLines
let concatLines :: [Char]
concatLines = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (\[Char]
x [Char]
y -> [Char]
x forall a. [a] -> [a] -> [a]
++ [Char]
"\n" forall a. [a] -> [a] -> [a]
++ [Char]
y) [Char]
"" [[Char]]
updatedLines
[Char] -> [Char] -> IO ()
writeFile [Char]
outfilePath [Char]
concatLines
generateNewSubjs :: Regex -> [String] -> [String]
generateNewSubjs :: Regex -> [[Char]] -> [[Char]]
generateNewSubjs Regex
re [[Char]]
lines = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap [Char] -> [[Char]]
updateIdsPtl [[Char]]
replacements
where
updateIdsPtl :: [Char] -> [[Char]]
updateIdsPtl [Char]
replacement = Regex -> [Char] -> [[Char]] -> [[Char]]
updateIds Regex
re [Char]
replacement [[Char]]
lines
replacements :: [[Char]]
replacements =
forall a b. (a -> b) -> [a] -> [b]
map ([Char] -> [Char]
constructReplacement forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [Char]
formatNum) [Int
0 .. (Int
largeInputSize forall a. Num a => a -> a -> a
- Int
1)]
updateIds :: Regex -> String -> [String] -> [String]
updateIds :: Regex -> [Char] -> [[Char]] -> [[Char]]
updateIds Regex
pat [Char]
replacement = forall a b. (a -> b) -> [a] -> [b]
map [Char] -> [Char]
subRegexPtl
where subRegexPtl :: [Char] -> [Char]
subRegexPtl [Char]
line = Regex -> [Char] -> [Char] -> [Char]
subRegex Regex
pat [Char]
line [Char]
replacement
generateNewEvents :: [String] -> [String]
generateNewEvents :: [[Char]] -> [[Char]]
generateNewEvents = forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Int -> a -> [a]
replicate Int
largeInputSize
goldenManySubjectsStart :: [String]
goldenManySubjectsStart :: [[Char]]
goldenManySubjectsStart =
[ [Char]
"{\"example\":[{\"attritionInfo\":[[{\"tag\":\"SubjectHasNoIndex\"},0],[{\"contents\":[1,\"dummy\"],\"tag\":\"ExcludedBy\"},0],[{\"tag\":\"Included\"},"
, forall a. Show a => a -> [Char]
show (Int
nValidSubj forall a. Num a => a -> a -> a
* Int
largeInputSize)
, [Char]
"]],\"totalSubjectsProcessed\":"
, forall a. Show a => a -> [Char]
show (Int
nValidSubj forall a. Num a => a -> a -> a
* Int
largeInputSize)
, [Char]
",\"totalUnitsProcessed\":"
, forall a. Show a => a -> [Char]
show (Int
nValidSubj forall a. Num a => a -> a -> a
* Int
largeInputSize)
, [Char]
"},{\"contents\":{\"attributes\":[{\"attrs\":{\"getDerivation\":\"\",\"getLongLabel\":\"another label\",\"getPurpose\":{\"getRole\":[\"Outcome\"],\"getTags\":[]},\"getShortLabel\":\"somelabel\"},\"name\":\"myVar1\",\"type\":\"Count\"},{\"attrs\":{\"getDerivation\":\"\",\"getLongLabel\":\"\",\"getPurpose\":{\"getRole\":[],\"getTags\":[]},\"getShortLabel\":\"\"},\"name\":\"myVar2\",\"type\":\"Bool\"}],\"cohortData\":["
]
goldenRwData :: [String]
goldenRwData :: [[Char]]
goldenRwData =
[ [Char]
"[[\"a\",[\"2010-07-06\",\"2010-07-07\"]],[5,true]]"
, [Char]
"[[\"b\",[\"2010-07-06\",\"2010-07-07\"]],[5,true]]"
]
goldenRwPatientManys :: [String]
goldenRwPatientManys :: [[Char]]
goldenRwPatientManys = forall a. Ord a => [a] -> [a]
sort forall a b. (a -> b) -> a -> b
$ Regex -> [[Char]] -> [[Char]]
generateNewSubjs Regex
patientRe [[Char]]
goldenRwData
goldenCwPatientEntries :: [String]
goldenCwPatientEntries :: [[Char]]
goldenCwPatientEntries =
[ [Char]
"[\"a\",[\"2010-07-06\",\"2010-07-07\"]]"
, [Char]
"[\"b\",[\"2010-07-06\",\"2010-07-07\"]]"
]
goldenCwPatientManys :: [String]
goldenCwPatientManys :: [[Char]]
goldenCwPatientManys = forall a. Ord a => [a] -> [a]
sort forall a b. (a -> b) -> a -> b
$ Regex -> [[Char]] -> [[Char]]
generateNewSubjs Regex
patientRe [[Char]]
goldenCwPatientEntries
goldenCwVarEntries :: [String]
goldenCwVarEntries :: [[Char]]
goldenCwVarEntries = [[Char]
"5,5", [Char]
"true,true"]
goldenCwVarManys :: [String]
goldenCwVarManys :: [[Char]]
goldenCwVarManys = forall a b. (a -> b) -> [a] -> [b]
map (\[Char]
s -> [Char]
"[" forall a. [a] -> [a] -> [a]
++ [Char] -> [Char]
replicateEntries [Char]
s forall a. [a] -> [a] -> [a]
++ [Char]
"]")
[[Char]]
goldenCwVarEntries
where replicateEntries :: [Char] -> [Char]
replicateEntries = forall a. [a] -> [[a]] -> [a]
intercalate [Char]
"," forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Int -> a -> [a]
replicate Int
largeInputSize
goldenRwEnd :: [String]
goldenRwEnd :: [[Char]]
goldenRwEnd = [[Char]
"]},\"tag\":\"RW\"}]}"]
goldenCwEnd :: [String]
goldenCwEnd :: [[Char]]
goldenCwEnd = [[Char]
"]},\"tag\":\"CW\"}]}"]
nValidSubj :: Int
nValidSubj :: Int
nValidSubj = Int
2
formatNum :: Int -> String
formatNum :: Int -> [Char]
formatNum = forall r. PrintfType r => [Char] -> r
printf ([Char]
"%0" forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show Int
numWidth forall a. [a] -> [a] -> [a]
++ [Char]
"d")
numWidth :: Int
numWidth :: Int
numWidth = forall (t :: * -> *) a. Foldable t => t a -> Int
length forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> [Char]
show (Int
largeInputSize forall a. Num a => a -> a -> a
- Int
1)
constructReplacement :: String -> String
constructReplacement :: [Char] -> [Char]
constructReplacement [Char]
label = [Char]
"\"\\1-" forall a. [a] -> [a] -> [a]
++ [Char]
label forall a. [a] -> [a] -> [a]
++ [Char]
"\""
readLines :: String -> IO [String]
readLines :: [Char] -> IO [[Char]]
readLines = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Char] -> [[Char]]
lines forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> IO [Char]
readFile
patientRe :: Regex
patientRe = [Char] -> Regex
mkRegex [Char]
"\"(a|b|c)\""