-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
151 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dist-newstyle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Revision history for nika | ||
|
||
## 0.1.0.0 -- YYYY-mm-dd | ||
|
||
* First version. Released on an unsuspecting world. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
{-# language OverloadedStrings #-} | ||
{-# language ScopedTypeVariables #-} | ||
|
||
module CsvParser where | ||
|
||
import Data.ByteString (ByteString) | ||
import Data.Vector (Vector) | ||
|
||
import qualified Data.ByteString.Lazy as ByteStringLazy | ||
import qualified Data.Csv as Csv | ||
import qualified Data.Vector as Vector | ||
import Control.Monad (when) | ||
|
||
data PerfData = PerfData | ||
{ _branchName :: ByteString | ||
, _wallTime :: Int | ||
} deriving (Eq, Show) | ||
|
||
data ComparisonBranch = ComparisonBranch (ByteString, ByteString) deriving (Show) | ||
|
||
data CsvError | ||
= TooLittleInput | ||
| TooLittleDifferentBranchNames | ||
| BranchTooLittleInput ByteString | ||
| MoreThanTwoBranches | ||
|
||
instance Show CsvError where | ||
show TooLittleInput = "There are too little data to calculate the mean of the wall time." | ||
show TooLittleDifferentBranchNames = "There are less than 2 different branch names in the csv file." | ||
show (BranchTooLittleInput branchName) = "There are too little data to calculate the mean of the wall time for branch: " ++ show branchName | ||
show MoreThanTwoBranches = "There are more than 2 different branch names in the csv file." | ||
|
||
instance Csv.FromNamedRecord PerfData where | ||
parseNamedRecord r = PerfData <$> r Csv..: "branchName" <*> r Csv..: "wallTime" | ||
|
||
main1 :: IO () | ||
main1 = do | ||
csvData <- ByteStringLazy.readFile "perf.csv" | ||
case Csv.decodeByName csvData of | ||
Left err -> putStrLn err | ||
Right (_, v :: Vector PerfData) -> print (checkCsv v) | ||
|
||
numOfSample :: Int | ||
numOfSample = 2 | ||
|
||
checkCsv :: Vector PerfData -> Either CsvError (ComparisonBranch, Vector PerfData) | ||
checkCsv xs = if Vector.length xs < numOfSample * 2 then Left TooLittleInput else checkIfThirdBranchNameExist xs | ||
where | ||
checkIfThirdBranchNameExist :: Vector PerfData -> Either CsvError (ComparisonBranch, Vector PerfData) | ||
checkIfThirdBranchNameExist xs = do | ||
let branchNames = fmap _branchName xs | ||
let firstBranchName = Vector.head branchNames | ||
case Vector.find (/= firstBranchName) branchNames of | ||
Nothing -> Left TooLittleDifferentBranchNames | ||
Just secondBranchName -> case Vector.find (\bn -> (bn /= firstBranchName) && (bn /= secondBranchName)) branchNames of | ||
Just x -> Left MoreThanTwoBranches | ||
Nothing -> do | ||
let branchSamples = (checkBranchInputIsSufficient numOfSample xs) <$> [firstBranchName, secondBranchName] | ||
case branchSamples of | ||
[True, False] -> Left $ BranchTooLittleInput firstBranchName | ||
[False, True] -> Left $ BranchTooLittleInput secondBranchName | ||
[False, False] -> Left $ BranchTooLittleInput firstBranchName | ||
[True, True] -> Right (ComparisonBranch (firstBranchName, secondBranchName), xs) | ||
otherwise -> undefined | ||
|
||
checkBranchInputIsSufficient :: Int -> Vector PerfData -> ByteString -> Bool | ||
checkBranchInputIsSufficient n xs branchName = Vector.length (Vector.filter (\x -> _branchName x == branchName) xs) >= n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module Main where | ||
|
||
import CsvParser ( main1 ) | ||
|
||
main :: IO () | ||
main = main1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
cabal-version: 2.4 | ||
name: nika | ||
version: 0.1.0.0 | ||
|
||
-- A short (one-line) description of the package. | ||
-- synopsis: | ||
|
||
-- A longer description of the package. | ||
-- description: | ||
|
||
-- A URL where users can report bugs. | ||
-- bug-reports: | ||
|
||
-- The license under which the package is released. | ||
-- license: | ||
author: zypeh | ||
maintainer: zypeh@users.noreply.github.com | ||
|
||
-- A copyright notice. | ||
-- copyright: | ||
-- category: | ||
extra-source-files: | ||
CHANGELOG.md | ||
README.md | ||
|
||
executable nika | ||
main-is: Main.hs | ||
|
||
-- Modules included in this executable, other than Main. | ||
other-modules: | ||
CsvParser | ||
|
||
-- LANGUAGE extensions used by modules in this package. | ||
-- other-extensions: | ||
build-depends: base ^>=4.16.0.0 | ||
, bytestring | ||
, cassava | ||
, optparse-applicative | ||
, vector | ||
hs-source-dirs: app | ||
default-language: Haskell2010 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
branchName,wallTime | ||
feature,100 | ||
main,200 | ||
feature,104 | ||
main,201 |