Processing Comma separated files stock info

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
DNMurphy
Posts: 8
Joined: Mon Jun 01, 2009 7:36 pm

Processing Comma separated files stock info

Post by DNMurphy » Mon Jun 01, 2009 8:01 pm

HI, I have just picked up RR and want as an intial exercise to be able to Open a CSV file, read each record until the end; process each record ; write out new records based on input info to an output file and then close both.

The file records are basic stock info with Open, High, Low, Close prices, ticker symbol and date and time. I need to be able to compare dates and recognise earlier or later dates and times. Need to be able to manipulate the numbers in the Open High Low etc. Of course being a CSV file all the data is text, but I need the numbers and dates to do the processing.

the logic of what I want to do is very easy to specify but figuring out in RR how to do this is not.

can anyone give any pointers to specific RR facilities and syntax to do this. RR's documentation doesn't seem very helpful on this as yet (although I may eventually discover different as I dig around).

Separate but slightly related question: Does RR have any concept of User Defined Types, or record structures or similar? I would like to treat each line of the incoming file as a record (or struct in c or equivalent) but cannot see anything in RR that conforms to this.

TIA
Neil

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Post by mwieder » Mon Jun 01, 2009 8:30 pm

What I do in this situation is use the url command for file i/o to read and write the whole file at one time:

Code: Select all

put url ("file:" & tFileSpec) into tInputData
put tOutputData into url ("file:" & tFileSpec)
Then within those file commands I process each line:

Code: Select all

repeat for each line tLine in tInputData
  -- assuming the date is the sixth item in the line
  if item 6 of tLine < tTargetDate then
    -- do something
  end if
  put tLine & cr after tOutputData
end repeat
set the itemDelimiter to tab or comma, as appropriate

...and no, there isn't anything like a c struct, although rev does have hashes or associative arrays, and I use them similarly. You can't read or write a block at a time like you can with structs, but you can say

Code: Select all

put item 5 of tLine into tTickerSymbol
put item 1 of tLine into tData[tTickerSymbol]["Open"]
put item 2 of tLine into tData[tTickerSymbol]["High"]
put item 3 of tLine into tData[tTickerSymbol]["Low"]
put item 4 of tLine into tData[tTickerSymbol]["Close"]
and then tData[tTickerSymbol] has all the pertinent data for a given stock, i.e.,

Code: Select all

put tData["MSFT"]["Close"] into tMSFTClosingPrice

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Post by mwieder » Mon Jun 01, 2009 8:36 pm

And I'd also point you to the scripting conference proceedings at http://support.runrev.com/scriptingconferences/ (I really wish runrev had a link to these on their support pages), in particular Ken Ray's discussion of "How To Work With Files".

DNMurphy
Posts: 8
Joined: Mon Jun 01, 2009 7:36 pm

Post by DNMurphy » Mon Jun 01, 2009 10:47 pm

mwieder wrote:And I'd also point you to the scripting conference proceedings at http://support.runrev.com/scriptingconferences/ (I really wish runrev had a link to these on their support pages), in particular Ken Ray's discussion of "How To Work With Files".
Thanks for both items, very helpful. :D

Post Reply