provenience-0.1.0.0: Computations that automatically track data dependencies

Copyright(c) Olaf Klinke
LicenseGPL-3
Maintainerolaf.klinke@phymetric.de
Stabilityexperimental
Safe HaskellSafe
LanguageHaskell2010

Data.Spreadsheet

Contents

Description

Various formats for spreadsheet exist, e.g. the open office (xlsx) format, the Microsoft SpreadsheetML format, the binary Microsoft xls format and CSV.

This module defines the least common denominator of static cell data. The intention is to use chunks of rows as alternative representation type in your ProvenienceT transformer. After performing the computation, extract all the spreasheet chunks and combine into a worksheet using chunksToSheet.

For example, in order to use the types of the xlsx package which exports the Cell and CellMap types, you should provide the following instances.

instance ToCell Cell where
instance ToSheet StaticRow CellMap where
   rowMap = Data.Map.fromList . foldMap (\(rowidx,row) -> map (\(colidx,val) -> ((fromIntegral rowidx,fromIntegral colidx),staticCell val)) row)

where the first instance aids in writing the second instance. Then you can use SheetChunk as alternative representation and produce a CellMap using chunksToSheet.

Synopsis

Speadsheet type classes

class ToCell cell where Source #

Cell type supporting static values: Booleans, Numbers, Text and Time.

Instances
ToCell Text Source #

for building CSV data

Instance details

Defined in Data.Spreadsheet

ToCell StaticCellValue Source # 
Instance details

Defined in Data.Spreadsheet

class ToRow cell row where Source #

A row holding several cells

Minimal complete definition

cellMap

Methods

cellList :: Traversable f => f cell -> row Source #

default is to number consecutively from 1

cellMap :: Traversable f => f (Word64, cell) -> row Source #

Instances
ToRow Text Text Source #

separates cells with semicolons

Instance details

Defined in Data.Spreadsheet

ToRow StaticCellValue Text Source # 
Instance details

Defined in Data.Spreadsheet

ToRow cell [(Word64, cell)] Source # 
Instance details

Defined in Data.Spreadsheet

Methods

cellList :: Traversable f => f cell -> [(Word64, cell)] Source #

cellMap :: Traversable f => f (Word64, cell) -> [(Word64, cell)] Source #

class ToSheet row sheet where Source #

A worksheet sheet holding several rows. Assemble a worksheet from cells using e.g. either of

import Control.Arrow (second)
rowMap  . fmap (second cellMap)
rowList . fmap cellList

Minimal complete definition

rowMap

Methods

rowList :: Traversable f => f row -> sheet Source #

default is to number consecutively from 1

rowMap :: Traversable f => f (Word64, row) -> sheet Source #

Instances
ToSheet Text Text Source #

separates rows by newlines

Instance details

Defined in Data.Spreadsheet

ToSheet row [(Word64, row)] Source # 
Instance details

Defined in Data.Spreadsheet

Methods

rowList :: Traversable f => f row -> [(Word64, row)] Source #

rowMap :: Traversable f => f (Word64, row) -> [(Word64, row)] Source #

Concrete spreadsheet types

cellBool :: ToCell cell => Bool -> cell Source #

cellNumber :: ToCell cell => Rational -> cell Source #

cellText :: ToCell cell => String -> cell Source #

cellTime :: ToCell cell => ZonedTime -> cell Source #

type StaticRow = [(Word64, StaticCellValue)] Source #

generic row type: list of cells with column numbers

type StaticSheet = [(Word64, StaticRow)] Source #

generic sheet type: list of rows with row numbers

type SheetChunk = Seq StaticRow Source #

Part of a spreadsheet which does not yet know its absolute row numbers.

chunksToSheet :: (Traversable f, Traversable chunk, Monoid (chunk (Word64, row)), ToSheet row sheet) => f (chunk row) -> sheet Source #

Combine several chunks into a worksheet, e.g.

chunksToSheet :: [SheetChunk] -> StaticSheet