Now that Maple 15 is out, I thought I should share this little application I made: GoalTracker.mw. It is an application partially inspired by the BMI tracker in Nintendo's WiiFit application; you could easily use it to track a weight loss goal. But it could also be used to track other quantifiable goals. I am posting it here mostly because it takes advantage of two new features in Maple 15.
The first feature is the ?Finance package. I, personally, don't really do any finance work, but I really like its tools for manipulating dates. In particular ?Finance:-TodaysDate returns the current date as a human readable string and ?Finance:-DayCount counts the number of days between to dates given as strings:
"April 20, 2011"
(**) Finance:-DayCount( Finance:-TodaysDate(), "Aug 5, 2011");
This allows you to store and display dates as human readable strings. This eliminates the need for a lot of annoying parsing when dealing with dates.
The other new feature is the ?DataTable document component which is a really convenient way to add persistent tabular data to a Maple document. It also allows you to view and edit that data. It is somewhat like a spreadsheet, except that there is an easily accessible Array storing all the data.
Putting these two together, it was easy to create a Maple application that allows you to track and chart goals. It looks like this (with some entirely fake weight data):
The red line is the line between the starting measure and the target measure on the target date. The grey line is the linear fit of the data. The relative positions of the red and grey lines tells you whether you are on track to end above or below your goal.
The component on the right is the DataTable displaying the contents of the two-dimensional Array . It can be used to edit the value of the Array, but to add new rows, I have set up the Update button at the top. The code attached to that the button looks like this:
updateData := proc()
local val, day, n;
# get today's measure from TextArea1
val := parse( DocumentTools:-GetProperty(TextArea1, value) );
n := op([1,2],[rtable_dims(DataTable0)]); # number of rows in the DataTable
# Starting date is stored in TextArea0
# compute the number of days since the starting day
day := Finance:-DayCount(DocumentTools:-GetProperty(TextArea0,value),
# The Array automatically grows as needed
DataTable0(n+1,1) := day;
DataTable0(n+1,2) := val;
# clear the text entry box
DocumentTools:-SetProperty(TextArea1, value, "");
# expand the DataTable Component to see the larger Array
if n < 15 then
DocumentTools:-SetProperty("DataTable0", visibleRows, n+1);
# force a display update of the DataTable
As you can see, updating the DataTable is as simple as assigning to its Array. Although, there is some bookkeeping at the end to make sure the DataTable is displayed nicely.
The code for generating the plot looks like this:
plottools:-line([DataTable0[1,1], DataTable0[1,2]], [Finance:-DayCount(DocumentTools:-GetProperty(TextArea0,value), DocumentTools:-GetProperty(TextArea2,value)), parse(DocumentTools:-GetProperty(TextArea3,value))], color=red, linestyle=dash, thickness=2, legend="Goal"),
plots:-listplot(DataTable0, color="Blue", thickness=3, legend="Data"),
plots:-pointplot(DataTable0, symbol=soliddiamond, symbolsize=20),
plot(CurveFitting:-LeastSquares(DataTable0, x),x=(min..max)(DataTable0[..,1]), thickness=2, color="Grey", linestyle=dash, legend="Trend"),
As you can see, the fact that the DataTable data can be accessed directly as an Array (instead of having to go through DocumentTools) allows you to have fairly concise code to read and manipulate the data. It also gives you a place to store data that will be saved when you save the worksheet and will not be cleared when you restart the Maple kernel.
If you find the the worksheet (which has some slightly fancier code than shown above) helpful in losing some of that winter weight, please let me know!