#goats-2.tcl #(aka goats-devel.tcl for dev. versions) # # You will probably be disappointed if you read this source. All it does is # query the database for values which have been inserted by goats-requery.tcl # which is where the more fun stuff happens. # # Why is amzn_goats_url a function when a simple variable would do? Because # this code was created by stripping down a more complex system in which it # made sense. proc amzn_goats_url {} { return "http://s1.amazon.com/exec/varzea/pay/T1IPCIVVU7AQLY" } set amzn_url1 [amzn_goats_url] # # Get's the most recent value in the database. Clicking on the link to goats-requery.tcl # causes new values to be fetched and loaded into the DB. I think this SQL code looks a # little crufty, and there's probably a better way to do this. The nested select statement # means that (failing voodoo query optimization by Oracle) the table has to be "looked at" # twice to answer this query. Fortunately, it's indexed by insertion_date, which is what # is used to restrict in both cases. At any rate, this page gets hit less than 1000 times # per day, so the performance impact is negligable. # set sql_query "select distinct TO_CHAR(INSERTION_DATE,'DAY MON DD, HH:MI P.M.') as date_time, total_money, num_payments from goats_money where insertion_date = (select max(insertion_date) from goats_money)" db_1row get_latest $sql_query set page_content " [ad_header "Goats Rapacious Greed Tracker"]

Watch Goats Make Money

Help Goats Make Money

Goats is a truly glorious comic. You should give them money. Look how much other people have given.

As of $date_time, Goats has recieved \$$total_money from $num_payments separate payments.
This value gets updated every hour, or whenever someone clicks right here.

Ack! The Rapacious Greed Tracker was broken for a while there. Specifically, the part that queries Amazon for new data and stuffs it into the database was down. When the total money raised went over \$1,000, that introduced a comma into the value. That comma threw off the database. But I've got it back up again (no, not like that you sicko) and all is well.

I couldn't sleep today (wed-thu night), so I wrote this page to track toothgnip's rise to untold-of wealth. Updated! There is now better sleep-deprivation-induced frivolity! We have graphs. And everything's better with graphs. Total and Daily values are shown below. The text-format log is still there, too. This whole thing is very much unlike the Bill Gates Personal Wealth Clock , but vaguely inspired by it. Of course, Bill Gates is more evil than satan himself, and Goats isn't. Well, maybe Diablo is, but he's cute, so it's ok. Dammit. This script is built on the Ars Digita Community System using about 0.1% of the functionality available. After this update, over a full hour of coding has gone into this, so it's now a Finely-Polished Marvel of Software Engineering, which means that is has purty pitures. Enjoy!

New! (Feb 26) Enough time has passed that the hourly graph was getting silly. So now we have a daily graph. If you want the hourly graph, it's right here for your benefit.


Here are the daily results since I started running this:
" # This fetches the daily values. This actually slightly more complicated than one might # guess, because there are many different values fetched every day, and one values has # to be chosen. The naieve solution, which I used earlier, was to use the hourly automatic # update from 4:30 AM. This was not very robust, however, because if the automatic update # somehow didn't happen, or didn't happen on time, then there'd be no data for that day. # Worse, since the per-day values are produced from this data, omitting a day would cause # two days of change to be computed as a single day's change. This moves the problem from # mere missing data to wrong data, which is worse. # # This solution groups the data by date, and then selects the lowest values for each day. # This is relatively robust, since it will return meaninfull data as long as even one automatic # update is used. set sql_query " select TO_CHAR(insertion_date, 'YYYY-MM-DD') as insert_datetime, MIN(total_money) as total_money, MIN(num_payments) as num_payments from goats_money where graphable='Y' group by TO_CHAR(insertion_date, 'YYYY-MM-DD') order by insert_datetime desc" set previous $total_money # # Loop through the values returned and generate structured lists in the format which # gr_sidewise_bar_chart wants. Note that the daily value is obtained by subtracting # each day's total from the NEXT day's value (which is paradoxically called "previous") # since that has already been fetched. This is potentially confusing, but much easier # to code. Besides which, it means that the current day's value is automatigically a # running total of all money recieved today, since it's generated by subtracting the # lowest daily value from the current value db_foreach get_graphable $sql_query { # append detailed_log "
As of $insert_datetime, there was $total_money from $num_payments payments.\n" lappend graphlist [list $insert_datetime " " $total_money] lappend daily [list " " " " [expr $previous - $total_money]] set previous $total_money } if_no_rows { append page_content "there are previous graphable points in the database." } # Ars Digita toolkit function for producing HTML barchars. set total_graph [gr_sideways_bar_chart -non_percent_values_p t -display_scale_p f $graphlist] set daily_graph [gr_sideways_bar_chart -non_percent_values_p t -display_scale_p f $daily] append page_content "
Total $Daily $
$total_graph$daily_graph
Note to the nitpicky: The daily $ chart represents the total intake in the day following the time indicated, not the day preceding it. This makes my life easy. If you wish it were different, just slide the scale an day in your mind.

What sort of crazy wierdo would write this thing? I would. If you think of any improvements, e-mail me. eanderso@usa.net.


" db_release_unused_handles ns_return 200 text/html $page_content