CityStats: table-building framework in place
I've now added a buildTables()
method to the wizardQuery
object, which creates the framework for building all the tables. A major difficulty was that I needed to open a connection to the db and keep it open throughout the process, to ensure that the temporary tables survive; however, some of the subsidiary processing for getting arrays of tracts also opened and closed a connection in the middle of this, and it turns out that if PHP finds an existing connection already open with the same parameters, it will use that connection instead of creating a new one, and then of course close it. I had to rewrite some of the city tract set object code so that it created arrays of tracts, indexed by year, when it was first instantiated, rather than calling on it to do that later.
With that out of the way, I now have a multi-dimensional array in place, indexed at the top level by year, and subsequently by city/tractset, holding a set of objects (class tableQueryUnit
), each of which knows its year, city, tract set and ethnicity groupings, and has created a temporary table based on them.
The next stage is to have those objects perform the normal calculations on their temporary tables to generate the three value arrays we need. I can't simply throw these tables at the original code written by JD, because that code is explicitly designed to create connections and dispose of them immediately; we need to keep connections alive in order to preserve our temporary tables until we've finished with them. So the next part of the procedure is to create analogues of JD's functions which can have a connection object passed to them as well as a table name. They don't need a $ctWhereClause
parameter, because the creation of our temporary tables has already taken care of that, so they should be a bit simpler in that respect.
All calculations done for a specific temporary table are concerned only with that table -- in other words, there is no interaction between tables. That means that one of my tableQueryUnit
objects can initiate all of the calculations which are relevant to it, and store the results in arrays of table cells, without any interaction outside of itself.