> From: Sherlock, Ric
> 
> Another optimisation to consider is to convert the table of boxed data
> to an inverted table as per
> http://www.jsoftware.com/jwiki/Essays/Inverted%20Table

For Example:

NB. ===============================================================
NB. upd8forex.ijs Script

require 'xml/sax/x2j web/gethttp tables/dsv'

NB. Source of exchange rate data...
URL=: 'http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml'

x2jclass 'forex'

'Items' x2jDefn
  /              :=  table                   : table=: ,:'Currency';'Value'
  Cube/Cube/Cube :=  table=: table,cur;rte   : 'cur rte'=: atr'currency rate'
)

cocurrent 'base'
NB. Inverted Table definitions
NB. from http://www.jsoftware.com/jwiki/Essays/Inverted%20Table
ifa =: <@(>"1)@|:               NB. inverted from atoms
tassert=: 3 : 0
 assert. (1>:#$y) *. 32=3!:0 y  NB. boxed scalar or vector
 assert. 1=#~.#&>y              NB. same # items in each box (with at least one 
box)
 1
)
tfrom     =: <@[ {&.> ]
tindexof  =: i.&>~...@[ i.&|: i.&>

tget=: {:@[ >@tfrom~ {...@[ tindexof boxxo...@]

NB. update Currency Table
CurrencyTable=: makenum process_forex_ gethttp URL

CurrencyTable=: ifa }. CurrencyTable
tassert CurrencyTable
exrate=: CurrencyTable&tget
NB. ===============================================================


NB. Example Usage
NB. ===============================================================
   load '~temp/upd8forex.ijs'
   exrate 'CHF'
1.4144
   exrate 'CHF';'NZD';'GBP'
1.4144 1.7867 0.86805
NB. ===============================================================

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to