darcsden :: dbp -> housetab-export -> blob

A program to dump the output of the old HouseTab's state from Happstack-state into a parseable format

root / HouseTab / Backup.hs

module HouseTab.Backup where

import HouseTab.State (HouseTab(..),HouseTabEntry(..),Person(..), HouseTabId)

type DumpFormat = ([(HouseTabId,String,String,String,String,String)],
                   [(String,Char,[(String,Double)])])

formatDump :: HouseTab -> DumpFormat
formatDump (HouseTab es ps) = (formatEntries es, formatPeople ps)
    where formatEntries ((HouseTabEntry id who what when howmuch whopays):es) = 
            (id,who,what,show when,show howmuch,whopays):(formatEntries es)
          formatEntries [] = []
          formatPeople ((Person name letter percs):ps) = 
            (name,letter,formatPercs percs):(formatPeople ps)
          formatPeople [] = []
          formatPercs ((d,p):ps) = (show d,p):(formatPercs ps)
          formatPercs [] = []


unFormatDump :: DumpFormat -> HouseTab
unFormatDump (entries,people) = HouseTab (unFormatEntries entries) (unFormatPeople people)
    where unFormatEntries ((id,who,what,when,howmuch,whopays):es) = 
              (HouseTabEntry id who what (read when) (read howmuch) whopays):(unFormatEntries es)
          unFormatEntries [] = []
          unFormatPeople ((name,letter,percs):ps) =
              (Person name letter (unFormatPercs percs)):(unFormatPeople ps)
          unFormatPeople [] = []
          unFormatPercs ((d,p):ps) = (read d,p):(unFormatPercs ps)
          unFormatPercs [] = []