// Abstract ------------------------------------------------------------------------------------------------------------------------------

This sample imports JSON data downloaded from fixer.io into statements.

// Examples ------------------------------------------------------------------------------------------------------------------------------

?- /spy(append,conversion)
spy : observing conversion
?- /import.json("./etc/data/usd.json",input)
import.json : ./etc/data/usd.json read in 0.003s.
spy : S conversion(USD, 1512691200, AUD, 1.330300) := 1.00 (700.000000)
spy : S conversion(USD, 1512691200, GBP, 0.745400) := 1.00 (700.000000)
spy : S conversion(USD, 1512691200, KRW, 1094.600000) := 1.00 (700.000000)
spy : S conversion(USD, 1512691200, RUB, 59.318000) := 1.00 (700.000000)
spy : S conversion(USD, 1512691200, BGN, 1.665600) := 1.00 (700.000000)
spy : S conversion(USD, 1512691200, BRL, 3.273300) := 1.00 (700.000000)
spy : S conversion(USD, 1512691200, CAD, 1.283600) := 1.00 (700.000000)
spy : S conversion(USD, 1512691200, CHF, 0.996760) := 1.00 (700.000000)
spy : S conversion(USD, 1512691200, CNY, 6.619700) := 1.00 (700.000000)
spy : S conversion(USD, 1512691200, CZK, 21.764000) := 1.00 (700.000000)
spy : S conversion(USD, 1512691200, DKK, 6.337700) := 1.00 (700.000000)
spy : S conversion(USD, 1512691200, HKD, 7.806300) := 1.00 (700.000000)
spy : S conversion(USD, 1512691200, INR, 64.451000) := 1.00 (700.000000)
spy : S conversion(USD, 1512691200, JPY, 113.490000) := 1.00 (700.000000)
spy : S conversion(USD, 1512691200, HRK, 6.429300) := 1.00 (700.000000)
spy : S conversion(USD, 1512691200, HUF, 267.840000) := 1.00 (700.000000)
spy : S conversion(USD, 1512691200, IDR, 13550) := 1.00 (700.000000)
spy : S conversion(USD, 1512691200, ILS, 3.521000) := 1.00 (700.000000)
spy : S conversion(USD, 1512691200, MXN, 18.924000) := 1.00 (700.000000)
spy : S conversion(USD, 1512691200, MYR, 4.088000) := 1.00 (700.000000)
spy : S conversion(USD, 1512691200, NOK, 8.317600) := 1.00 (700.000000)
spy : S conversion(USD, 1512691200, NZD, 1.461200) := 1.00 (700.000000)
spy : S conversion(USD, 1512691200, PHP, 50.533000) := 1.00 (700.000000)
spy : S conversion(USD, 1512691200, PLN, 3.578600) := 1.00 (700.000000)
spy : S conversion(USD, 1512691200, RON, 3.946200) := 1.00 (700.000000)
spy : S conversion(USD, 1512691200, TRY, 3.846400) := 1.00 (700.000000)
spy : S conversion(USD, 1512691200, ZAR, 13.660000) := 1.00 (700.000000)
spy : S conversion(USD, 1512691200, EUR, 0.851640) := 1.00 (700.000000)
spy : S conversion(USD, 1512691200, SEK, 8.496800) := 1.00 (700.000000)
spy : S conversion(USD, 1512691200, SGD, 1.353200) := 1.00 (700.000000)
spy : S conversion(USD, 1512691200, THB, 32.670000) := 1.00 (700.000000)
 
// Code ----------------------------------------------------------------------------------------------------------------------------------

date.to.num { // convert a string containing a date into a numerical value (compatible to %now)

    (:str,:num) :-  str.tokenize(:str,"-",:list),
                    lst.item(:list,0,:s.y), lst.item(:list,1,:s.m), lst.item(:list,2,:s.d),
                    str.tonum(:s.y,:y),str.tonum(:s.m,:m),str.tonum(:s.d,:d),
                    then(:y,:m,:d,:num);

}

process { // main

    () :-   @input(:f),
            frm.fetch(:f,base,:base), // fetch the base
            frm.fetch(:f,date,:s.date), console.puts(:s.date),#date.to.num(:s.date,:date), // fetch the date
            frm.fetch(:f,rates,:r), // fetch the rates
            #process.rates(:base,:date,:r); // call up the secondary elemental

}

process.rates { // process each rate and assert a conversion statement for each

    (:base,:date,:f) :- frm.fetch(:f,:l?[is.symbol],:v?[is.number]), // fetch the label of the currency and the number
                        assert(conversion(:base,:date,:l,:v),1.0f);  // assert the statement

}

// ---------------------------------------------------------------------------------------------------------------------------------------

[Home] [Email] [Twitter] [LinkedIn]