Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

208 support metrics report generation #213

Merged
merged 84 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
1d68517
feat(report): add module
deemp Mar 19, 2024
67c6c38
refactor(metrics): generalize the metrics type
deemp Mar 20, 2024
57a9e6a
fix(metrics): division
deemp Mar 21, 2024
8f68046
fix(metrics): fromInteger
deemp Mar 21, 2024
09eae8d
refactor(metrics): give a more descriptive function name
deemp Mar 21, 2024
e6f6d4e
feat(package): add blaze
deemp Mar 21, 2024
af90da8
feat(report): support conversion to html
deemp Mar 21, 2024
d31e4a9
refactor(report): split into two modules
deemp Mar 21, 2024
f2070de
chore(cabal): update .cabal
deemp Mar 21, 2024
a2ec2a8
feat(cli): add command to generate a report
deemp Mar 21, 2024
074a6de
feat(report): add config for report
deemp Mar 21, 2024
a723402
feat(report):
deemp Mar 21, 2024
7143dc8
fix(report): align headers by center
deemp Mar 21, 2024
eddc31e
fix(report): apply autoprefixer
deemp Mar 21, 2024
c074608
refactor(report): group page-related config keys
deemp Mar 21, 2024
de1d4ab
feat(report): optional json report path
deemp Mar 21, 2024
c1f5cb9
feat(report): make json instances for report
deemp Mar 21, 2024
cbcaa81
fix(report): field names
deemp Mar 21, 2024
e70b88a
fix(cli):
deemp Mar 21, 2024
f41fc30
feat(cli): write json report if path is specified
deemp Mar 21, 2024
f84da06
fix(report): config
deemp Mar 21, 2024
3c6f1c8
fix(report): move directory
deemp Mar 21, 2024
9079eaa
feat(report): gitignore report.json
deemp Mar 21, 2024
bcf595f
fix(metrics): remove the metrics script because the report command ca…
deemp Mar 21, 2024
98be85f
refactor(report): rename config file
deemp Mar 21, 2024
5e8febe
refactor(pipeline): improve message printing
deemp Mar 21, 2024
70676b3
feat(pipeline): add step to generate a report
deemp Mar 21, 2024
abe73f3
fix(report): directory
deemp Mar 21, 2024
069fa6c
fix(report): gitignore any json
deemp Mar 21, 2024
a34669d
refactor(report): format with another fourmolu version
deemp Mar 21, 2024
5d61f5a
refactor(report):
deemp Mar 21, 2024
f18e21f
refactor(report): provide toString function
deemp Mar 21, 2024
e04a5e0
feat(report): bundle html, js, and css
deemp Mar 21, 2024
856285c
refactor(metrics): use safe numbers
deemp Mar 22, 2024
6e6bc66
refactor(report):
deemp Mar 22, 2024
84679d0
refactor(report html):
deemp Mar 22, 2024
2d8a64f
fix(metrics): json instances
deemp Mar 22, 2024
396a928
fix(metrics): division
deemp Mar 22, 2024
a51f344
fix(report): show percents
deemp Mar 22, 2024
a78af23
fix(cli): update functions
deemp Mar 22, 2024
76ed34a
feat(package): add scientific
deemp Mar 22, 2024
6dda973
refactor(cli): formatting issue
deemp Mar 22, 2024
055f169
refactor(metrics): add fractional instance for safenumber
deemp Mar 23, 2024
17b47fb
refactor(metrics): split into modules
deemp Mar 23, 2024
a813e7f
fix(report): imports
deemp Mar 23, 2024
f1fc195
fix(report): config format
deemp Mar 23, 2024
8f06471
fix(report): config
deemp Mar 23, 2024
218736e
fix(cli): remove unused option
deemp Mar 23, 2024
cac8a76
fix(report): import
deemp Mar 23, 2024
98d8cad
refactor(report): use uppercase letters in table head
deemp Mar 23, 2024
7c3a85f
fix(report): support markdown output
deemp Mar 23, 2024
8d0f1c1
fix(cli): write json, html, and markdown reports
deemp Mar 23, 2024
6fcd2a2
fix(package): update cabal file
deemp Mar 23, 2024
1a86006
fix(report): gitignore reports
deemp Mar 23, 2024
1971831
refactor(report): provide table description
deemp Mar 23, 2024
ec3afca
fix(cli): formatting issue
deemp Mar 23, 2024
d8f95ef
fix(test): imports
deemp Mar 23, 2024
e24d103
fix(test): formatting
deemp Mar 23, 2024
fde9b17
fix(report): metric name
deemp Mar 23, 2024
69de37a
fix(report): use 'not applicable' instead of 'nan'
deemp Mar 23, 2024
d52ed76
fix(report): description
deemp Mar 23, 2024
0986d9a
fix(report): class name
deemp Mar 23, 2024
623734c
refactor(cli, report): update terminology - refer to initial and norm…
deemp Mar 24, 2024
b17ce84
feat(package): add file-embed
deemp Mar 24, 2024
361ce95
feat(report): move report js and css inside package
deemp Mar 24, 2024
eb2977f
feat(package): add report js and css files to extra-source-files
deemp Mar 24, 2024
78c87f8
feat(report): add embedded js and css files
deemp Mar 24, 2024
c5be8b3
feat(report, cli): support optional input and output in report config
deemp Mar 24, 2024
d797f3a
fix(report): remove config input
deemp Mar 24, 2024
fb1bb40
feat(site): add docs for the report command
deemp Mar 24, 2024
f387a6f
feat(ci, report): generate a job summary
deemp Mar 23, 2024
35edf41
feat(ci): upload pipeline artifact
deemp Mar 24, 2024
4291cf2
fix(ci): run haddock as a part of stack setup
deemp Mar 24, 2024
c18c2cd
fix(ci): use faster stack-action
deemp Mar 24, 2024
af5284e
feat(ci): use pipeline artifact to deploy the report
deemp Mar 24, 2024
ec619ca
fix(ci): disable macos tests and add todos
deemp Mar 24, 2024
5ef32ed
refactor(ci): move haddock files together with other files
deemp Mar 24, 2024
57398c0
feat(report):
deemp Mar 24, 2024
7edfd51
fix(ci): upload artifacts on all platforms even if some previous step…
deemp Mar 25, 2024
6c00ebc
feat(ci):
deemp Mar 25, 2024
4054880
fix(report): text
deemp Mar 25, 2024
baf7ed2
fix(ci): write runner os in artifact names
deemp Mar 25, 2024
deccf61
fix(report): remove the details tag from markdown reports
deemp Mar 25, 2024
fa4e5ce
fix(ci): extend and format job summary
deemp Mar 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 67 additions & 9 deletions .github/workflows/ghc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,13 @@ jobs:
submodules: true

- name: 🧰 Setup Stack
uses: freckle/stack-action@v5
# TODO #208:10m replace with freckle/stack-action after https://github.com/freckle/stack-action/pull/69 is merged
uses: deemp/stack-action@main
with:
stack-build-arguments: ${{ github.ref_name != 'master' && '--fast' || '' }} --pedantic
test: ${{ matrix.os != 'windows-latest' }}
# TODO #213:10m enable macos test after https://github.com/objectionary/normalizer/issues/180 is resolved
# TODO #98:10m enable windows tests after https://github.com/objectionary/normalizer/issues/185 is resolved
test: ${{ matrix.os != 'windows-latest' && matrix.os != 'macos-latest'}}

- uses: actions/setup-node@v4
with:
Expand All @@ -75,6 +78,49 @@ jobs:
shell: bash
run: ./scripts/pipeline.sh

- name: Upload pipeline artifact
id: pipeline-artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: pipeline-${{ runner.os }}-${{ hashFiles('pipeline/eo/*.eo') }}
overwrite: true
path: |
pipeline
!pipeline/**/.eoc
!pipeline/yaml
report

- name: Write about the artifact in the job summary
if: always()
shell: bash
run: |
cat << EOF >> $GITHUB_STEP_SUMMARY
<h2>Artifact</h2>
<p>
The artifact
<a href="${{ steps.pipeline-artifact.outputs.artifact-url }}">
pipeline-${{ runner.os }}-${{ hashFiles('pipeline/eo/*.eo') }}
</a> contains files used or produced during the pipeline run:
</p>
<ul>
<li>EO and PHI programs</li>
<li>Reports</li>
</ul>
EOF

- name: Write the report in the job summary
if: success()
shell: bash
run: |
cat << EOF >> $GITHUB_STEP_SUMMARY
<h2>Report</h2>
<details>
<summary>Click to expand</summary>
$(cat report/report.md)
</details>
EOF

docs:
needs: pipeline
if: ${{ github.ref_name == 'master' }}
Expand All @@ -86,15 +132,17 @@ jobs:
uses: actions/checkout@v4

- name: 🧰 Setup Stack
uses: freckle/stack-action@v5
# TODO #208:10m replace with freckle/stack-action after https://github.com/freckle/stack-action/pull/69 is merged
uses: deemp/stack-action@main
with:
test: false
stack-build-arguments: --fast --haddock

- name: 🔨 Build Haddock Documentation (with Stack)
run: |
stack haddock
mkdir -p dist/haddock
mv $(stack path --local-doc-root)/* dist/haddock
- name: Download pipeline artifact
uses: actions/download-artifact@v4
with:
pattern: pipeline-${{ runner.os }}-*
merge-multiple: true

- name: Setup mdBook
uses: peaceiris/actions-mdbook@v1
Expand All @@ -103,12 +151,22 @@ jobs:

- name: Build site
run: |
ROOT=$PWD

mkdir -p dist/haddock
mv $(stack path --local-doc-root)/* dist/haddock

cd site/docs
mdbook build
mv docs ../../dist
cd ../..

cd ..
cd site
mv index.html ../dist
cd ..

mkdir -p dist/report
cp report/report.html dist/report/index.html

- name: 🚀 Publish Site
uses: JamesIves/github-pages-deploy-action@v4
Expand Down
79 changes: 73 additions & 6 deletions eo-phi-normalizer/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE OverloadedRecordDot #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ParallelListComp #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
Expand All @@ -24,26 +26,31 @@

module Main (main) where

import Control.Monad (unless, when)
import Control.Monad (forM, unless, when)
import Data.Foldable (forM_)

import Control.Exception (Exception (..), SomeException, catch, throw)
import Control.Lens ((^.))
import Data.Aeson (ToJSON)
import Data.Aeson.Encode.Pretty (Config (..), Indent (..), defConfig, encodePrettyToTextBuilder')
import Data.List (intercalate)
import Data.String.Interpolate (i, iii)
import Data.Text.Internal.Builder (toLazyText)
import Data.Text.Lazy.Lens
import Data.Text.Lazy as TL (unpack)
import Data.Yaml (decodeFileThrow)
import GHC.Generics (Generic)
import Language.EO.Phi (Bytes (Bytes), Object (Formation), Program (Program), parseProgram, printTree)
import Language.EO.Phi.Dataize (dataizeRecursively, dataizeRecursivelyChain, dataizeStep, dataizeStepChain)
import Language.EO.Phi.Metrics (ProgramMetrics, getProgramMetrics, splitPath)
import Language.EO.Phi.Metrics.Collect as Metrics (getProgramMetrics)
import Language.EO.Phi.Metrics.Data as Metrics (ProgramMetrics (..), splitPath)
import Language.EO.Phi.Report.Data (Report'InputConfig (..), Report'OutputConfig (..), ReportConfig (..), ReportItem (..), makeProgramReport, makeReport)
import Language.EO.Phi.Report.Html (ReportFormat (..), reportCSS, reportJS, toStringReport)
import Language.EO.Phi.Report.Html qualified as ReportHtml (ReportConfig (..))
import Language.EO.Phi.Rules.Common (ApplicationLimits (ApplicationLimits), applyRulesChainWith, applyRulesWith, defaultContext, objectSize, propagateName1)
import Language.EO.Phi.Rules.Yaml (RuleSet (rules, title), convertRuleNamed, parseRuleSetFromFile)
import Options.Applicative hiding (metavar)
import Options.Applicative qualified as Optparse (metavar)
import System.Directory (doesFileExist)
import System.Directory (createDirectoryIfMissing, doesFileExist)
import System.FilePath (takeDirectory)
import System.IO (IOMode (WriteMode), getContents', hFlush, hPutStr, hPutStrLn, openFile, stdout)

data CLI'TransformPhi = CLI'TransformPhi
Expand Down Expand Up @@ -74,10 +81,16 @@ data CLI'MetricsPhi = CLI'MetricsPhi
}
deriving (Show)

newtype CLI'ReportPhi = CLI'ReportPhi
{ configFile :: FilePath
}
deriving (Show)

data CLI
= CLI'TransformPhi' CLI'TransformPhi
| CLI'DataizePhi' CLI'DataizePhi
| CLI'MetricsPhi' CLI'MetricsPhi
| CLI'ReportPhi' CLI'ReportPhi
deriving (Show)

fileMetavarName :: String
Expand Down Expand Up @@ -150,6 +163,7 @@ data CommandParser = CommandParser
{ metrics :: Parser CLI'MetricsPhi
, transform :: Parser CLI'TransformPhi
, dataize :: Parser CLI'DataizePhi
, report :: Parser CLI'ReportPhi
}

commandParser :: CommandParser
Expand Down Expand Up @@ -185,11 +199,17 @@ commandParser =
recursive <- switch (long "recursive" <> help "Apply dataization + normalization recursively.")
chain <- switch (long "chain" <> help "Display all the intermediate steps.")
pure CLI'DataizePhi{..}
report = do
configFile <-
let file' = metavarName.file
in strOption (long "config" <> short 'c' <> metavar.file <> help [i|The #{file'} with a report configuration.|])
pure CLI'ReportPhi{..}

data CommandParserInfo = CommandParserInfo
{ metrics :: ParserInfo CLI
, transform :: ParserInfo CLI
, dataize :: ParserInfo CLI
, report :: ParserInfo CLI
}

commandParserInfo :: CommandParserInfo
Expand All @@ -198,12 +218,14 @@ commandParserInfo =
{ metrics = info (CLI'MetricsPhi' <$> commandParser.metrics) (progDesc "Collect metrics for a PHI program.")
, transform = info (CLI'TransformPhi' <$> commandParser.transform) (progDesc "Transform a PHI program.")
, dataize = info (CLI'DataizePhi' <$> commandParser.dataize) (progDesc "Dataize a PHI program.")
, report = info (CLI'ReportPhi' <$> commandParser.report) (progDesc "Generate reports about initial and normalized PHI programs.")
}

data CommandNames = CommandNames
{ transform :: String
, metrics :: String
, dataize :: String
, report :: String
}

commandNames :: CommandNames
Expand All @@ -212,6 +234,7 @@ commandNames =
{ transform = "transform"
, metrics = "metrics"
, dataize = "dataize"
, report = "report"
}

cli :: Parser CLI
Expand All @@ -220,6 +243,7 @@ cli =
( command commandNames.transform commandParserInfo.transform
<> command commandNames.metrics commandParserInfo.metrics
<> command commandNames.dataize commandParserInfo.dataize
<> command commandNames.report commandParserInfo.report
)

cliOpts :: ParserInfo CLI
Expand All @@ -235,7 +259,7 @@ data StructuredJSON = StructuredJSON
deriving (Generic, ToJSON)

encodeToJSONString :: (ToJSON a) => a -> String
encodeToJSONString = (^. unpacked) . toLazyText . encodePrettyToTextBuilder' defConfig{confIndent = Spaces 2}
encodeToJSONString = TL.unpack . toLazyText . encodePrettyToTextBuilder' defConfig{confIndent = Spaces 2}

pprefs :: ParserPrefs
pprefs = prefs (showHelpOnEmpty <> showHelpOnError)
Expand Down Expand Up @@ -389,3 +413,46 @@ main = do
Left obj -> logStrLn (printAsProgramOrAsObject obj)
Right (Bytes bytes) -> logStrLn bytes
)
CLI'ReportPhi' CLI'ReportPhi{..} -> do
reportConfig <- decodeFileThrow configFile

programReports <- forM reportConfig.items $ \item -> do
metricsPhi <- getMetrics item.bindingsPathPhi (Just item.phi)
metricsPhiNormalized <- getMetrics item.bindingsPathPhiNormalized (Just item.phiNormalized)
pure $ makeProgramReport reportConfig item metricsPhi metricsPhiNormalized

css <- maybe (pure reportCSS) readFile (reportConfig.input >>= (.css))
js <- maybe (pure reportJS) readFile (reportConfig.input >>= (.js))

let report = makeReport reportConfig programReports

reportConfigHtml =
ReportHtml.ReportConfig
{ expectedMetricsChange = reportConfig.expectedMetricsChange
, format =
ReportFormat'Html
{ ..
}
}
reportHtml = toStringReport reportConfigHtml report

reportJson = encodeToJSONString report

reportConfigMarkdown =
ReportHtml.ReportConfig
{ expectedMetricsChange = reportConfig.expectedMetricsChange
, format = ReportFormat'Markdown
}
reportMarkdown = toStringReport reportConfigMarkdown report

forM_ @[]
[ (x, y)
| (Just x, y) <-
[ (reportConfig.output.html, reportHtml)
, (reportConfig.output.json, reportJson)
, (reportConfig.output.markdown, reportMarkdown)
]
]
$ \(path, reportString) -> do
createDirectoryIfMissing True (takeDirectory path)
writeFile path reportString
19 changes: 18 additions & 1 deletion eo-phi-normalizer/eo-phi-normalizer.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ extra-source-files:
README.md
CHANGELOG.md
grammar/EO/Phi/Syntax.cf
report/main.js
report/styles.css

source-repository head
type: git
Expand All @@ -35,8 +37,11 @@ library
exposed-modules:
Language.EO.Phi
Language.EO.Phi.Dataize
Language.EO.Phi.Metrics
Language.EO.Phi.Metrics.Collect
Language.EO.Phi.Metrics.Data
Language.EO.Phi.Normalize
Language.EO.Phi.Report.Data
Language.EO.Phi.Report.Html
Language.EO.Phi.Rules.Common
Language.EO.Phi.Rules.PhiPaper
Language.EO.Phi.Rules.Yaml
Expand All @@ -62,11 +67,15 @@ library
aeson
, array >=0.5.5.0
, base >=4.7 && <5
, blaze-html
, blaze-markup
, directory
, file-embed
, filepath
, generic-lens
, lens
, mtl
, scientific
, string-interpolate
, template-haskell
, text
Expand All @@ -92,13 +101,17 @@ executable normalizer
, aeson-pretty
, array >=0.5.5.0
, base >=4.7 && <5
, blaze-html
, blaze-markup
, directory
, eo-phi-normalizer
, file-embed
, filepath
, generic-lens
, lens
, mtl
, optparse-applicative
, scientific
, string-interpolate
, template-haskell
, text
Expand Down Expand Up @@ -132,14 +145,18 @@ test-suite spec
, aeson
, array >=0.5.5.0
, base >=4.7 && <5
, blaze-html
, blaze-markup
, directory
, eo-phi-normalizer
, file-embed
, filepath
, generic-lens
, hspec
, hspec-discover
, lens
, mtl
, scientific
, string-interpolate
, template-haskell
, text
Expand Down
5 changes: 5 additions & 0 deletions eo-phi-normalizer/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ extra-source-files:
- README.md
- CHANGELOG.md
- grammar/EO/Phi/Syntax.cf
- report/*

verbatim:
cabal-version: 1.24
Expand Down Expand Up @@ -48,6 +49,10 @@ dependencies:
- generic-lens
- text
- template-haskell
- blaze-html
- blaze-markup
- scientific
- file-embed

default-extensions:
- ImportQualifiedPost
Expand Down
Loading
Loading