acowley / Frames

Data frames for tabular data.
Other
297 stars 41 forks source link

explicitly configure types #151

Open teto opened 4 years ago

teto commented 4 years ago

I export network packet captures to csv via tshark (www.wireshark.org). I know in advance all the types (Word32, lists of TCP flag etc) as well as the CSV column. Thus I would like to explicitly pass the column names and their associated types but Frams' tutorials all seem to rely on inference ?

Basically I would like something like this I guess: https://github.com/acowley/Frames/pull/50

Is there any way to achieve this with current Frames

NB: Would be nice to reference in README a list of FOSS projects using Frames (to get some examples to work from). Thanks for the project !

teto commented 4 years ago

related: https://github.com/acowley/Frames/pull/71

teto commented 3 years ago

I am trying to use the explicit PR but I get an error:

src/Pcap.hs:181:1: error:
    • Expected kind ‘[(GHC.Types.Symbol, *)]’,
        but ‘rs_ar1g’ has kind ‘[*]’
    • In the first argument of ‘Record’, namely ‘rs_ar1g’
      In the type signature:
        frameNumber :: forall f_ar1f rs_ar1g.
                       (Functor f_ar1f,
                        RElem FrameNumber rs_ar1g (Data.Vinyl.TypeLevel.RIndex FrameNumber rs_ar1g)) =>
                       (GHC.Word.Word64 -> f_ar1f GHC.Word.Word64)
                       -> Record rs_ar1g -> f_ar1f (Record rs_ar1g)
    |
181 | tableTypesExplicit'

Basically I have a list of fields

baseFields = [
    ("packetid", TsharkFieldDesc "frame.number" [t|Word64|] Nothing False)
     ("ifname", TsharkFieldDesc "frame.interface_name" [t|String|] Nothing False),
...
]

then I call the

tableTypesExplicit'
  (getTypes baseFields)
  ((rowGen "data/test-simple.csv")
  { rowTypeName = "Packet"
        , separator = ","
    })
    "data/test-simple.csv"

getTypes :: [(String, TsharkFieldDesc)] -> [Q Type]
getTypes = map (\(_, x) -> colType x)

I assume my [t|Word64|] is not the type expected but not sure how to create one of (GHC.Types.Symbol, *)