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

pretty printing/ASCII visualization of encoded rows #2

Open
ocramz opened this issue May 5, 2019 · 3 comments
Open

pretty printing/ASCII visualization of encoded rows #2

ocramz opened this issue May 5, 2019 · 3 comments
Labels
enhancement 🚀 New feature or request help wanted Extra attention is needed P1 High priority UX
Milestone

Comments

@ocramz
Copy link
Owner

ocramz commented May 5, 2019

e.g. ascii :

+-------------+-----------------+
| Person      | House           |
+-------+-----+-------+---------+
| Name  | Age | Color | Price   |
+-------+-----+-------+---------+
| David | 63  | Green | $170000 |
| Ava   | 34  | Blue  | $115000 |
| Sonia | 12  | Green | $150000 |
+-------+-----+-------+---------+

https://hackage.haskell.org/package/colonnade-1.2.0.1/docs/Colonnade.html#g:10

@ocramz ocramz added the enhancement 🚀 New feature or request label May 20, 2019
@ocramz ocramz changed the title ASCII visualization of encoded rows pretty printing/ASCII visualization of encoded rows May 20, 2019
@ocramz
Copy link
Owner Author

ocramz commented Oct 8, 2020

generate CSV header from the type with generics-sop metadata

@ocramz
Copy link
Owner Author

ocramz commented Oct 19, 2020

After a fair bit of trial and error, header produces a
simple representation of an arbitrary type which can be pretty-printed
as a tree :

data A = MkA Int deriving (Eq, Show, G.Generic, Heidi)
data B = MkB Int Char deriving (Eq, Show, G.Generic, Heidi)
data B2 = MkB2 { b21 :: Int, b22 :: Char } deriving (Eq, Show, G.Generic, Heidi)
data C = MkC1 {c1 :: Int} | MkC2 A | MkC3 () deriving (Eq, Show, G.Generic, Heidi)
data R = MkR { r1 :: B2, r2 :: C , r3 :: B } deriving (Eq, Show, G.Generic, Heidi)
λ> printBox $ headerBox $ header (Proxy @R)
                       R                        
------------------------------------------------
                      MkR                       
                       R                        
------------*------------*----------------------
     r1     |     r3     |          r2          
     B2           B                 C           
 ----------   ----------   ------+------+------ 
    MkB2         MkB        MkC3 | MkC1 | MkC2  
     B2           B          ()    Int     A    
 ----*-----   ----*-----                  ---   
 b21 | b22     _0 |  _1                   MkA   
 Int   Char   Int   Char                  Int   

@ocramz ocramz added the help wanted Extra attention is needed label Oct 19, 2020
@ocramz
Copy link
Owner Author

ocramz commented Oct 19, 2020

In case someone else wants to move this forward, my thinking so far is as follows:

  • header computes a rose tree representation of a type, and only requires a Generic and an empty instance of HasHeader (populated automatically via the Generic instance) (see https://github.com/ocramz/heidi/blob/master/src/Core/Data/Frame/PrettyPrint.hs#L152 )
  • similarly, encode uses the generic representation of a value and produces a corresponding representation; values however (i.e. data rows) are "flattened" from rose trees into one-level deep tries, keyed by lists of elements (https://github.com/ocramz/heidi/blob/master/src/Data/Generics/Encode/Internal.hs#L101). This flat representation makes lookup and traversal convenient. A heidi dataframe is produced by encodeing all values in a list.
  • the rose trees produced by header are convenient for pretty-printing the sum-of-products structure of general Haskell ADTs, as seen above (implementation at https://github.com/ocramz/heidi/blob/master/src/Core/Data/Frame/PrettyPrint.hs#L91 )
  • additionally, the trees produced by header contain all possible combination of keys that might appear in encoded values, which is why Header values can be used in the Show instance of an encoded dataframe:
    • take few rows (e.g. 10) for each value, perform lookup using the Header keys and render in the corresponding column, under the header

@ocramz ocramz added this to the release 0.1 milestone Oct 20, 2020
@ocramz ocramz added P1 High priority UX labels Jun 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement 🚀 New feature or request help wanted Extra attention is needed P1 High priority UX
Projects
None yet
Development

No branches or pull requests

1 participant