-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvertforMultiplot.hs
67 lines (56 loc) · 2.21 KB
/
convertforMultiplot.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import Data.List (transpose)
import Data.Maybe (listToMaybe)
main = do
analyses <- mapM analyseFile inputFileName
if (validateAnalysis analyses == False)
then error "The Files where not done with the same target value."
else do
writeFile "solvingLogs/outputCombination.txt" (combineAnalysis analyses)
data Analyses = Analyses { name :: String
, fittnessToReach :: Double
, valueList :: [Double]}
inputFileName :: [String]
inputFileName = map fileName [1..8]
where
fileName :: Int -> String
fileName n = "solvingLogs/output" ++ show n ++ ".txt"
analyseFile :: String -> IO (Analyses)
analyseFile filepath = do
file <- readFile filepath
let fileLines = lines file
return $ Analyses {name = filepath, fittnessToReach = (getMax . head) fileLines, valueList = getValues fileLines}
where
getValues :: [String] -> [Double]
getValues = map (read . (!! 1) . words) . validLines
validLines :: [String] -> [String]
validLines = filter (not . ('#' ==) . (head))
getMax :: String -> Double
getMax = read . last . words
validateAnalysis :: [Analyses] -> Bool
validateAnalysis = allEqual . map fittnessToReach
where
allEqual :: (Eq a) => [a] -> Bool
allEqual (x:xs) = all ((==) x) xs
combineAnalysis :: [Analyses] -> String
combineAnalysis analyses = unlines . (maxValue:) . (header:) $ collumsToTable (generationList:(map valueList analyses))
where
-- its meaningless wich list we choose to take maximum from, since we alreaddy assured they are all equal
maxValue :: String
maxValue = "# " ++ ((show . fittnessToReach . head) $ analyses)
header :: String
header = unwords ("Generation":(map name analyses))
generationList :: [Double]
generationList = [1..]
-- gets valuelists, return gnuplotable lines of values
-- When all of the lines after the first 1 are empty, the table will stop
collumsToTable :: (Show a) => [[a]] -> [String]
collumsToTable valueLists
| (all null . drop 1) valueLists = [] -- the first collum is an endless one
| otherwise = ((unwords . map showHead) valueLists):(collumsToTable . map secureTail) valueLists
where
showHead :: (Show a) => [a] -> String
showHead [] = "Nan"
showHead (x:_) = show x
secureTail :: [a] -> [a]
secureTail [] = []
secureTail (_:xs) = xs