revMedia ALPHA .. Financial Chart script

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Sun Nov 08, 2009 1:59 pm

Simon,
glad it worked for you.

For file reading/writing you have the URL option, which does it in one command and the
open file
read from file
close file
sequence which gives you more control over what portion of the file you want.
Re dictionary. Which I often find very helpful in the dictionary is the See also section. It often leads to related topics. And then a dictionary is, well a dictionary. You somehow need to know the words you want to look up.

Since you apparently like Markers in graphics here are some more I did for the heck of it (I especially like the Questionmark for questionable data :) just make shure that the markerfilled is set to false.

Code: Select all

on mouseUp
   --set the markerpoints of grc "adjusted close" to makeCross()
   set the markerpoints of grc "adjusted close" to makeQuestionMark()
   set the markerfillcolor of grc "adjusted close" to    "" --red -- sets the fill of the marker
   set the hiliteColor of grc "adjusted close" to blue -- sets the 'line color of the marker
   set the markerLIneSize of grc "adjusted close" to 1 -- adjust the linesize of the marker
   set the linesize of grc "adjusted close" to 0 -- make the lines invisible
   set the markerfilled of grc "adjusted close" to false -- makes the fill of markers visible or invisible
end mouseUp

function makeSquareBox
   -- you can change the form of the markerpoints here
   return \
          "-2,-2" & cr &\
   "2,-2" & cr &\
   "2,2" & cr &\
   "-2,2" & cr &\
   "-2,-2" 
end makeSquareBox

function makeQuestionMark
   return -3,1 & cr & -2,-2 & cr & -1,-3 & cr & 0,-3 & cr & 1,-2 & cr & 2,-2 & cr & 3,0 & cr & 3,2 & cr & 2,2 & cr & 1,3 & cr & 0, 3 & cr & 0,4  & cr &  0, 7 & cr &  cr &\
           0,9 & cr & -1,10  & cr & 0,11 & cr & 1,10 & cr & 0,9
     
end makeQuestionMark

--function makeAQuestion
--   return 0,-3 & cr & 0,3 & cr & cr & 3,0 & cr & -3,0
--end makeAQuestion

function makeDiamond
   return \
          "-3,0" & cr &\
   "0,-3" & cr & \
          "+3,0" & cr &\
   "0,+3" & cr & \
          "-3,0"
end makeDiamond

function makeCross
   return \
          "0,-3" & cr &\
   "0,3" & cr & cr &\
   "3,0" & cr &\
   "-3,0" 
end makeCross

function makeX
      return \
          "-3,-3" & cr &\
   "+3,+3" & cr & cr &\
   "+3,-3" & cr &\
   "-3,+3" 
end makeX
again, this will work on the original line chart. But of course the different markers work in any irregular polygon graphic. Just change "set the markerpoints of grc "adjusted close" to makeCross()" to the appropriate function (makeCross(), makeX(), makeSquareBox(), makeDiamond() )
regards
Bernd

Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Post by Simon Knight » Sun Nov 08, 2009 8:01 pm

Bernd,

How on earth are you doing these "points"? Is it graph paper or do you have an application that allows you to draw a shape then extract the co-ordinates? I shall enjoy using your points in my CSV graph plotter app in the very near future.

I think that one of my problems with the syntax of Revolution is that I have become use to, dare I say it, a more conventional syntax where x=x+1 is allowed. The revolution version of put x+1 into x seems so very different. Here's a dumb question : what is the language called?

However I am enjoying experimenting with Revolution and I am impressed by its speed of operation.
best wishes
Skids

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Tue Nov 10, 2009 1:34 pm

Simon,
How on earth are you doing these "points"?
actually I did it while I was on a train for the weekend, the perfect place to do stuff like this.
Is it graph paper or do you have an application
neither, (in my head) but your question gave me the idea to do a little utility

MakeMarkers Utility

that I uploaded to RevOnline (the new => Rev version 3.5)
Give it a try and tell me what you think.
what is the language called?
I think the official name is RevTalk. The XTalks are a group of high level languages that try use a more english like syntax. To my knowledge this started with Hypercard/Hypertalk on the Mac in 87. And one thing people coming from other languages find confusing is that you put everything into a container. This container is not typed. I.e whether you put text, integers, floating point, or binary data into that container is from a user perspective all just the same container. This does add overhead to the Interpreter, but makes life a lot easier for the Coder. You just have to get used to it and you might actually like it.

Another big adjustment seems to be the message path. Where is a message generated and where does it travel. It can be intercepted by a script in different stages of the message path and even passed on. It is well worth to read up on it in the User Manual.

And thank you for reopening this dormant thread. I missed this thread when it originated, but liked the stock quotes revlet. This gave me the opportunity to look closer into this.
regards
Bernd

Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Post by Simon Knight » Tue Nov 10, 2009 2:12 pm

Bernd,

I always like working on a train journey its just a shame that the UK rail system is in such a poor state and so expensive that it is almost always easier to use the car.

With your help have created a working application that processes and plots data points from a CSV file which was my original aim. I use the "Frame" object as the visual key to the size of the final graph and I use the relativepoints property as I want all the graphs to display 24 hours across the x axis and 20 minutes up the y axis, I found that using the points property caused the graph to change its scale. I also discovered that the size of the markerpoint used changes the overall size of the graph polygon causing some of the data points at either end of the x axis to be plotted just outside the bounds of the original Frame object, I'm living with this feature but I guess I could resize the polygon to the Frame size minus the width of the markerpoint.

I did a comparison of processing speed with the same (original) application written in RealBasic. The compiled RB app takes 1.2 seconds to process the input file whereas the RevTalk version takes 0.7 seconds to do the same. This result is the reverse of what I was expecting as my 1980 computing science states that compiled should be faster then interpreted. It is worth noting that the RB version uses many more lines of code than the Revolution version.

I have started looking at the tutorials to try and gather how best to use stacks and cards. I am also keen to discover how to store useful routines for re-use in other projects (i.e. as I can in RB by creating a class). For instance am I able to create a subclass of "Frame" that includes the code to draw a graph inside the "Frame", do I group the Frame with the polygon or do I create the polygon in code or do I just write instructions to the user (me in six months time) just to add a polygon for each set of data points required? So many questions....

So much to do ....
best wishes
Skids

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Tue Nov 10, 2009 3:12 pm

Simon,
I am a poor XTalk coder so I have to take guesses at object classes. One thing people do to have reusable code is to write a library.
A library is a stack that has in it's stack script handlers that are generic enough to be reusable. This library stack is called and put into the message hierarchy by "start using stack "myLibraryName"". This is the closest I can think of to an object class.
You also can break out routines you use frequently in a stack and make them functions or commands. The way I did with the makeMarkerPoint() fuctions. These dont have to live in the script that uses them, you could put them into the the stack script and that way they are accesible from every card and every control.

Glad you like the speed of Rev. Actually I also find it amazing. Unless you are using thousands of datapoints .7 seconds looks like it could be even faster. Thinks to watch out for is screen redraws. If you encapsulate the setting of the point with a lock screen/unlock screen it might speed things up. And then there are tricks for parsing data that give you an order of magnitude difference. While

Code: Select all

repeat for i= 1 to xxx 
put line i of yyy into zzz
is ok but it makes Rev count the lines or whatever chunk every time around
a lot faster would be

Code: Select all

repeat for each line aLine in yyy
put aLine into zzz
The difference is that you dont know which line is processed and aLine has just the content of the line in question but a counter that is incrementet by one tells you what line you are working on if you need that information. Rev keeps a internal pointer in the case of repeat for each, that makes it faster.

Code: Select all

put 0 into temp
add 1 to temp
is faster if you "initialize" temp with 0 and it is faster then

Code: Select all

put 0 into temp
put temp + 1 into temp
All this is only noticeable if you have rather large datasets.
for the add/put example for a million times add is 150 millisecond and put 250 milliseconds. If you dont "initialize" temp with 0 then add is 230 milliseconds and put stays at 250 millisecs. It seems that in this case Rev has an idea that it is numbers you want to process.
do I group the Frame with the polygon
well grouping does not create a subclass. What you could do to the "frame" is to put code into it that takes care of setting the graphics inside the frame if you indicate what graphic to place and where in parameters passed. You could also put code into the frame that automates the creation of a graphic object and placing it into the frame. That all depends on the type of date you have and the amount of user interaction you need. It is hard to say in general terms what is the best.
If you want I could take a look at your code if you email your stack and some sample data. You find my email in RevOnline if you click on my name (search for bernd)

regards
Bernd

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Tue Nov 10, 2009 4:29 pm

Simon,
I also discovered that the size of the markerpoint used changes the overall size of the graph polygon causing some of the data points at either end of the x axis to be plotted just outside the bounds
If you issue the adjustement code after setting the markerpoints again then they will fit into the frame. Like in

Code: Select all

set the rect of graphic "myChart" to the rect of grc "myFrame"
and in case you are wondering where Rev Online is: you access it in the Rev's toolbar.
regards
Bernd

Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Post by Simon Knight » Wed Nov 11, 2009 4:17 pm

Bernd,

I have attempted to send you an email with my scatter graph stack attached.

I am stuck with the following problem. I use a polygon to create a scatter point graph. Before I set the points I set the size of the polygon to width 800 height 500 taken from the size of the graphic "Frame" on the stack. Unfortunately when the polygon is redrawn to display the points it changes its size. If a data set is processed that includes all four corners the polygon grows to 808 by 508 possibly a function of the graphic used to mark the point. If another data set is used where there is no data for the first 50% of the x-axis then the polygon shrinks to a rectangle that is just large enough for the points. If the small rectangle is now resized to the required size the plot data scales up to fill all of the new rectangle which is not what is required. I have tried various methods of moving the polygon but I still get a graph with points that are plotted outside the original frame graphic.
Is there a simple way of just drawing to the screen using a keyboard character?
best wishes
Skids

Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Post by Simon Knight » Wed Nov 11, 2009 5:14 pm

Hi,
It always seems to help to write a problem down. Writing my previous post caused be to rethink the problem and my new code now scales the data rather than attempting to resize the polygon. The result is a graph that is scaled to fit inside the "Frame" graphic but which allows points to be plotted to the edge of the Frame.
best wishes
Skids

Post Reply