-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* rank-diff init * tabs * floodMap seems to work. Starting optimized floodCount now * rank --edges * fmt * diff might be done? lazy record was nice * keep * cleanup and set up diff-only pr * diff html * sort by abs Down * diff2text * add hable to extra-deps for CI * cleaning up
- Loading branch information
Showing
5 changed files
with
154 additions
and
20 deletions.
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
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,89 @@ | ||
module Graphex.Diff where | ||
|
||
import Control.Arrow (second) | ||
import Control.Parallel.Strategies (NFData) | ||
import Data.List (sortOn) | ||
import Data.Map (Map) | ||
import qualified Data.Map as Map | ||
import Data.Monoid (Sum (..)) | ||
import Data.Ord (Down (..)) | ||
import Data.Semialign | ||
import Data.Text (Text) | ||
import qualified Data.Text as T | ||
import Data.Tuple (swap) | ||
import Hable | ||
import Prelude hiding (div) | ||
import Text.Blaze.Html5 | ||
|
||
import Graphex | ||
|
||
data Diff a = Diff | ||
{ netNodes :: Int | ||
, nodes :: Map a Int | ||
|
||
, netReversedNodes :: Int | ||
, reversedNodes :: Map a Int | ||
} deriving stock (Show) | ||
|
||
diff :: NFData a => Ord a => Graph a -> Graph a -> Diff a | ||
diff g1 g2 = Diff{..} | ||
where | ||
g1rev = reverseEdges g1 | ||
g2rev = reverseEdges g2 | ||
|
||
r1 = rankings g1 | ||
r2 = rankings g2 | ||
|
||
r1rev = rankings g1rev | ||
r2rev = rankings g2rev | ||
|
||
doDiff x y = | ||
let x' = Map.fromList $ fmap (second (Sum . negate) . swap) x | ||
y' = Map.fromList $ fmap (second Sum . swap) y | ||
in Map.filter (/= 0) $ Map.map getSum $ salign x' y' | ||
|
||
nodes = doDiff r1 r2 | ||
netNodes = sum nodes | ||
|
||
reversedNodes = doDiff r1rev r2rev | ||
netReversedNodes = sum reversedNodes | ||
|
||
diffFoldFor :: Ord a => Monoid b => (Diff a -> Map a Int) -> Diff a -> ((a, Int) -> b) -> b | ||
diffFoldFor getter d = flip foldMap (sortOn (Down . abs . snd) $ Map.toList $ getter d) | ||
|
||
diff2html :: Diff Text -> Html | ||
diff2html d = mconcat | ||
[ div $ mconcat | ||
[ "Net change in transitive import dependencies: ", toHtml (netNodes d) | ||
, details $ table $ mconcat | ||
[ tr $ mconcat | ||
[ th "Module", th "Change" ] | ||
, diffFoldFor nodes d $ \(m, net) -> | ||
tr $ mconcat | ||
[ td $ toHtml m, td $ toHtml net ] | ||
] | ||
] | ||
, div $ mconcat | ||
[ "Net change in reverse transitive import dependencies: ", toHtml (netReversedNodes d) | ||
, details $ table $ mconcat | ||
[ tr $ mconcat | ||
[ th "Module", th "Change" ] | ||
, diffFoldFor reversedNodes d $ \(m, net) -> | ||
tr $ mconcat | ||
[ td $ toHtml m, td $ toHtml net ] | ||
] | ||
] | ||
] | ||
|
||
diff2text :: Diff Text -> Text | ||
diff2text d = T.pack $ unlines | ||
[ unwords ["Net change in transitive import dependencies:", show (netNodes d)] | ||
, hable defaultConfig $ (diffHeader :) $ diffFoldFor nodes d $ \(m, net) -> | ||
[[T.unpack m, show net]] | ||
, unwords ["Net change in reverse transitive import dependencies:", show (netReversedNodes d)] | ||
, hable defaultConfig $ (diffHeader :) $ diffFoldFor reversedNodes d $ \(m, net) -> | ||
[[T.unpack m, show net]] | ||
] | ||
|
||
diffHeader :: [String] | ||
diffHeader = ["Module", "Change"] |
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 |
---|---|---|
|
@@ -66,3 +66,6 @@ extra-deps: [] | |
# compiler-check: newer-minor | ||
nix: | ||
packages: [zlib] | ||
|
||
extra-deps: | ||
- hable-0.3.1 |
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