<?xml version="1.0" encoding="utf-8"?><!-- generator="b2evolution/1.9.3" -->
<rss version="0.92">
	<channel>
		<title>Capital Trials at the Old Bailey</title>
					  <link>http://hcmc.uvic.ca/blogs/index.php?blog=36</link>
			  <description></description>
			  <language>en-CA</language>
			  <docs>http://backend.userland.com/rss092</docs>
			  			  <item>
			    <title>process 1820-1824 xls to xml</title>
			    <description> (Mins: 180) &lt;p&gt;SD sent me an spreadsheet with the 1820 to 1824 data in it. Found a little &quot;how-to&quot; file which explained the steps to turn that into an xml data file with schema for validating. Did the process and noticed that two of the fields had values swapped. Checked the xslt and sure enough &lt;br /&gt;
found this:&lt;/p&gt;

&lt;p&gt;&amp;lt;crime_normalized&amp;gt;&amp;lt;xsl:value-of select=&quot;Crime_Group&quot;/&amp;gt;&amp;lt;/crime_normalized&amp;gt;&lt;br /&gt;
&amp;lt;crime_group&amp;gt;&amp;lt;xsl:value-of select=&quot;Crime_Normalized&quot;/&amp;gt;&amp;lt;/crime_group&amp;gt;&lt;/p&gt;

&lt;p&gt;which I corrected to this:&lt;/p&gt;

&lt;p&gt;&amp;lt;crime_normalized&amp;gt;&amp;lt;xsl:value-of select=&quot;Crime_Normalized&quot;/&amp;gt;&amp;lt;/crime_normalized&amp;gt;&lt;br /&gt;
&amp;lt;crime_group&amp;gt;&amp;lt;xsl:value-of select=&quot;Crime_Group&quot;/&amp;gt;&amp;lt;/crime_group&amp;gt;&lt;/p&gt;

&lt;p&gt;Also noticed that the import changed all integer values to floating point, (e.g. 16 became 16.0), and only integers are valid in the various field (age, weeks, months, years etc.) Just did a grep search and replace to fix those.&lt;/p&gt;

&lt;p&gt;Huge majority of 100+ remaining invalid instances are mercy appeals where Simon has entered something like jury/prosecutor and the XML requires a separate mercy appeal for each proponent. &lt;/p&gt;

&lt;p&gt;XML file now with SD to make remaining corrections, then return to me, at which point I'll follow the rest of the how-to procedure to render back to relational data and upload to db. &lt;/p&gt;</description>
			    <link>http://hcmc.uvic.ca/blogs/index.php?blog=36&amp;title=process_1820_1824_xls_to_xml&amp;more=1&amp;c=1&amp;tb=1&amp;pb=1</link>
			  </item>
			  			  <item>
			    <title>dev frontend and backend</title>
			    <description> (Mins: 15) &lt;p&gt;Bailey dev frontend is in the lang02 account with an obvious folder name. As of this writing it is identical to the production frontend (in same account) and backup (on my Mac). &lt;/p&gt;

&lt;p&gt;Bailey dev backend is on HCMC's db server (production is on a university php server, database's name is baileydev. As of this writing, it is identical to the production db. Backup of that db (an SQL file) is on my Mac).&lt;/p&gt;</description>
			    <link>http://hcmc.uvic.ca/blogs/index.php?blog=36&amp;title=dev_frontend_and_backend&amp;more=1&amp;c=1&amp;tb=1&amp;pb=1</link>
			  </item>
			  			  <item>
			    <title>delete unwanted entries created by Importer</title>
			    <description> (Mins: 30) &lt;p&gt;In testing my modifications to the importer code, I created records which I had to delete. The importer typically adds records to these tables:&lt;br /&gt;
criminals&lt;br /&gt;
outcomes&lt;br /&gt;
respites&lt;br /&gt;
trials&lt;br /&gt;
crimes&lt;br /&gt;
trial_files&lt;br /&gt;
and may add records to these tables:&lt;br /&gt;
aliases&lt;br /&gt;
judge_respites&lt;br /&gt;
outcome_durations&lt;br /&gt;
execution_specials&lt;br /&gt;
mercy_appeals&lt;br /&gt;
When deleting spurious test records, to avoid foreign-key violation errors, I started with these tables:&lt;br /&gt;
crimes&lt;br /&gt;
trial_files&lt;br /&gt;
criminals&lt;/p&gt;
</description>
			    <link>http://hcmc.uvic.ca/blogs/index.php?blog=36&amp;title=delete_unwanted_entries_created_by_impor&amp;more=1&amp;c=1&amp;tb=1&amp;pb=1</link>
			  </item>
			  			  <item>
			    <title>fix incompatibility in table structure and importer</title>
			    <description> (Mins: 90) &lt;p&gt;Figured out the problem with the code in the Importer class, which Jamie confirmed. He had blogged the point of the code &lt;a href=&quot;http://hcmc.uvic.ca/blogs/index.php?blog=36&amp;amp;p=8531&amp;amp;more=1&amp;amp;c=1&amp;amp;tb=1&amp;amp;pb=1&quot;&gt;here&lt;/a&gt;. I missed that posting, but still would have need confirmation.&lt;/p&gt;

&lt;p&gt;The id attribute in the criminal element can be given a non-Null value (strictly a varchar(31)) by SD when he knows both trials refer to the same individual. Both criminal elements must have identical values for the id attribute. The syncCriminals method in the Importer uses that information to remove the duplicate entry in the criminals table and reconciles criminal_id_fk's in other tables.&lt;br /&gt;
The problem was that the tables did not have a field to hold that information. I created a duplicate_label field of type varchar(31), and modified the Importer code to refer to that field.&lt;/p&gt;

&lt;p&gt;I discovered a similar (though simpler) problem with the trials field. The importer code expects a case_reference field in that table, but there wasn't one, so I created one of type varchar(7). Jamie's instructions to SD are to use that when trials are in the same court session (), but in different trial_files, and he wants them associated (e.g. for a bunch of criminals tried for the same crime).&lt;br /&gt;
I don't see the code that handles that similar to the syncCriminal code, but the upload works. &lt;/p&gt;
</description>
			    <link>http://hcmc.uvic.ca/blogs/index.php?blog=36&amp;title=fix_incompatibility_in_table_structure_a&amp;more=1&amp;c=1&amp;tb=1&amp;pb=1</link>
			  </item>
			  			  <item>
			    <title>more on problem importing 1810-1819 data</title>
			    <description> (Mins: 120) 
&lt;p&gt;In the _importCriminal method, this block of code:&lt;br /&gt;
         if (isset($data-&gt;attributes()-&gt;id)) {&lt;br /&gt;
             $xmlId = $data-&gt;attributes()-&gt;id;&lt;br /&gt;
         } else {&lt;br /&gt;
             $xmlId = null;&lt;br /&gt;
         }&lt;br /&gt;
always returns null for $xmlId, as there are no attributes in any &lt;br /&gt;
instance of the criminal element in the data.&lt;/p&gt;

&lt;p&gt;In the criminals table, there is no field named &quot;xml_id&quot;, so any &lt;br /&gt;
reference to that field will throw an error.&lt;/p&gt;

&lt;p&gt;There is one such reference in _importCriminal:&lt;br /&gt;
         $new = array(&lt;br /&gt;
             'surname' =&gt; $data-&gt;surname,&lt;br /&gt;
             'given_name' =&gt; $data-&gt;given_names,&lt;br /&gt;
             'age' =&gt; $data-&gt;age,&lt;br /&gt;
             'gender_id_fk' =&gt; array_search(strtolower($data-&gt;gender), &lt;br /&gt;
$this-&gt;genderMap),&lt;br /&gt;
             'xml_id' =&gt; $xmlId&lt;br /&gt;
         );&lt;br /&gt;
	$id = $this-&gt;tables['criminals']-&gt;insert($new);&lt;/p&gt;

&lt;p&gt;and two references in one line in _syncCriminals:&lt;br /&gt;
         $records = &lt;br /&gt;
Zend_Db_Table::getDefaultAdapter()-&gt;fetchPairs('SELECT criminal_id, &lt;br /&gt;
xml_id FROM criminals WHERE xml_id IS NOT NULL');&lt;/p&gt;

&lt;p&gt;For the instance in _importCriminal, if I replace 'xml_id' with &lt;br /&gt;
'criminal_id' then the record is added to the criminals table, but of &lt;br /&gt;
course there is no field 'xml_id' so naturally no value for that field, &lt;br /&gt;
so I'm not sure if that's the desired behaviour.&lt;br /&gt;
For the instance in _syncCriminals, it makes no sense to simply replace &lt;br /&gt;
xml_id with criminal_id. I understand the logic of what syncCriminals is &lt;br /&gt;
supposed to do, but I don't see how that code can possibly not throw an &lt;br /&gt;
error. That line of code requires there be an xml_id field and a &lt;br /&gt;
criminal_id field in each record, but that's not the case.&lt;/p&gt;

&lt;p&gt;Is there supposed to be an xml_id field in the criminals table? I can't &lt;br /&gt;
find any instance of that table which has such a field. Even if I did, &lt;br /&gt;
as far as I can figure, the value in that field would be NULL in every &lt;br /&gt;
instance. I have found no instances in the data file of a criminal element with an id attribute.&lt;/p&gt;

&lt;p&gt;Wrote to Jamie again to see if any of this jogs his memory about the structure of the dev instance he was using. &lt;/p&gt;
</description>
			    <link>http://hcmc.uvic.ca/blogs/index.php?blog=36&amp;title=more_on_problem_importing_1810_1819_data&amp;more=1&amp;c=1&amp;tb=1&amp;pb=1</link>
			  </item>
			  			  <item>
			    <title>problem importing 1810-1819 data</title>
			    <description> (Mins: 180) &lt;p&gt;When I try to import the data file into the database using the importer.php class Jamie created, I get an error:&lt;br /&gt;
Fatal error: Uncaught exception 'PDOException' with message&lt;br /&gt;
'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'xml_id' in&lt;br /&gt;
'field list'' in&lt;br /&gt;
/home3/14/lang02/www/bailey_v2/includes/classes/Zend/Db/Statement/Pdo.php:228&lt;/p&gt;


&lt;p&gt;The table 'criminals' in the database (and thus the derived Zend_Db_Table object 'criminals') has these five fields:&lt;br /&gt;
criminal_id&lt;br /&gt;
surname&lt;br /&gt;
given_name&lt;br /&gt;
gender_id_fk&lt;br /&gt;
age&lt;br /&gt;
The importCriminal method in the real file and the testImportXml method in my test file create a variable $new which has 5 fields in it:&lt;br /&gt;
surname&lt;br /&gt;
given_name&lt;br /&gt;
gender_id_fk&lt;br /&gt;
age&lt;br /&gt;
xml_id&lt;/p&gt;

&lt;p&gt;When that array is inserted as a new record in the 'criminals' table, an error is generated. My guess is that's because the criminal_id field is automatically populated so we're trying to put 5 fields of data into a table with 4 fields. There is no field in the table for the &quot;xml_id&quot; value in the array.&lt;/p&gt;

&lt;p&gt;The new data file validates, and if I import one of the existing data files I get the same error, so I don't think the data is the problem.&lt;br /&gt;
If I comment out the insert statement, no errors in my test method.&lt;br /&gt;
If I get rid of the xml_id field in the $new array, no errors in my test method.&lt;/p&gt;

&lt;p&gt;Given that the value for the xml_id field is always null (as far as I can figure out as the element 'criminal' in the data has no attributes and specifically not an id attribute), I don't understand why it's being included in the insert at all. I'm guessing that the xml_id is used internally for the duration of processing only. It looks like its intended to be used in the method that resolves duplicate criminals.&lt;/p&gt;


&lt;p&gt;    public function importXml($file) {&lt;br /&gt;
        $contents = file_get_contents($file);&lt;br /&gt;
        $xml = new SimpleXMLElement($contents);&lt;br /&gt;
        foreach ($xml-&gt;trial_file as $i =&gt; $trialFile) {&lt;br /&gt;
            $criminalId = $this-&gt;_importCriminal($trialFile-&gt;criminal);&lt;br /&gt;
            .&lt;br /&gt;
            .&lt;br /&gt;
            .&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        .&lt;br /&gt;
        .&lt;br /&gt;
        .&lt;br /&gt;
        return true;&lt;br /&gt;
    }&lt;/p&gt;

&lt;p&gt;    protected function _importCriminal($data) {&lt;br /&gt;
        if (isset($data-&gt;attributes()-&gt;id)) {&lt;br /&gt;
            $xmlId = $data-&gt;attributes()-&gt;id;&lt;br /&gt;
        } else {&lt;br /&gt;
            $xmlId = null;&lt;br /&gt;
        }&lt;br /&gt;
            &lt;br /&gt;
        $new = array(&lt;br /&gt;
            'surname' =&gt; $data-&gt;surname,&lt;br /&gt;
            'given_name' =&gt; $data-&gt;given_names,&lt;br /&gt;
            'age' =&gt; $data-&gt;age,&lt;br /&gt;
            'gender_id_fk' =&gt; array_search(strtolower($data-&gt;gender), $this-&gt;genderMap),&lt;br /&gt;
            'xml_id' =&gt; $xmlId            &lt;br /&gt;
        );&lt;br /&gt;
        &lt;br /&gt;
        $id = $this-&gt;tables['criminals']-&gt;insert($new); /* error thrown here */&lt;br /&gt;
        &lt;br /&gt;
        $this-&gt;_importCriminalAliases($data-&gt;aliases-&gt;alias, $id);&lt;br /&gt;
        &lt;br /&gt;
        return $id;&lt;br /&gt;
    }&lt;/p&gt;

</description>
			    <link>http://hcmc.uvic.ca/blogs/index.php?blog=36&amp;title=problem_importing_1810_1819_data&amp;more=1&amp;c=1&amp;tb=1&amp;pb=1</link>
			  </item>
			  			  <item>
			    <title>Find SQL records which have identical values in two fields</title>
			    <description> (Mins: 60) &lt;p&gt;I had to find all instances of criminals in which both the given-name and surname fields are identical and the number of such duplicates&lt;/p&gt;

&lt;p&gt;Here's the SQL I used for the example:&lt;/p&gt;

&lt;p&gt;SELECT `surname`, `given_name`, COUNT(`surname`) AS Instances FROM criminals GROUP BY `surname`, `given_name` HAVING ( COUNT(`surname`) &gt; 1 ) AND ( COUNT(`given_name`) &gt; 1) &lt;/p&gt;

&lt;p&gt;and here's the same SQL with abstracted table and field names:&lt;/p&gt;

&lt;p&gt;SELECT `field1Name`, `field2Name`, COUNT(`field1Name`) AS Instances FROM tableName GROUP BY `field1Name`, `field2Name` HAVING ( COUNT(`field1Name`) &gt; 1 ) AND ( COUNT(`field2Name`) &gt; 1) &lt;/p&gt;
</description>
			    <link>http://hcmc.uvic.ca/blogs/index.php?blog=36&amp;title=find_sql_records_which_have_identical_va&amp;more=1&amp;c=1&amp;tb=1&amp;pb=1</link>
			  </item>
			  			  <item>
			    <title>Given names form field bug</title>
			    <description> (Mins: 120) &lt;p&gt;When I put a value into the given-names textfield in the search box and then tried to execute a search I got back an error message which began with the following:&lt;/p&gt;

&lt;p&gt;Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'c.given' in 'where clause'' &lt;/p&gt;

&lt;p&gt;It took a couple of hours wading through the form, and the json and zend code working with the form and the data model until I found this line of code in includes/classes/Search.php&lt;/p&gt;

&lt;p&gt;    protected function _prepareCriminals() {&lt;br /&gt;
        $this-&gt;_select-&gt;joinLeft(&lt;br /&gt;
            array('c' =&gt; 'criminals'),&lt;br /&gt;
            'c.criminal_id = tf.criminal_id_fk',&lt;br /&gt;
            array('c.criminal_id', 'c.surname', 'c.given_name', 'c.age')&lt;br /&gt;
        ); &lt;br /&gt;
        ...&lt;br /&gt;
        if ($this-&gt;inData('given-name')) {&lt;br /&gt;
            $this-&gt;_select-&gt;where('LOWER(c.given-name) LIKE ?', '%' . strtolower($this-&gt;_data['given-name']) . '%');&lt;br /&gt;
        }&lt;/p&gt;

&lt;p&gt;I changed one &quot;given-name&quot; to a &quot;given_name&quot; (see below) and the queries now seem to work:&lt;/p&gt;

&lt;p&gt;    protected function _prepareCriminals() {&lt;br /&gt;
        $this-&gt;_select-&gt;joinLeft(&lt;br /&gt;
            array('c' =&gt; 'criminals'),&lt;br /&gt;
            'c.criminal_id = tf.criminal_id_fk',&lt;br /&gt;
            array('c.criminal_id', 'c.surname', 'c.given_name', 'c.age')&lt;br /&gt;
        ); &lt;br /&gt;
        &lt;br /&gt;
        if ($this-&gt;inData('given-name')) {&lt;br /&gt;
            $this-&gt;_select-&gt;where('LOWER(c.given_name) LIKE ?', '%' . strtolower($this-&gt;_data['given-name']) . '%');&lt;br /&gt;
        }&lt;/p&gt;

&lt;p&gt;so, apparently because given-name was not a member of the c array, the instance of LOWER(c.given-name) was interpreted as LOWER(c.given)-name. name of course was null so presumably had no effect, resulting in c.given being the name of the field in the table to search, which of course doesn't exist generating the error I saw. &lt;/p&gt;
</description>
			    <link>http://hcmc.uvic.ca/blogs/index.php?blog=36&amp;title=given_names_form_field_bug&amp;more=1&amp;c=1&amp;tb=1&amp;pb=1</link>
			  </item>
			  			  <item>
			    <title>clean up year display in x-axis of flot graph</title>
			    <description> (Mins: 120) &lt;p&gt;Previously, if there were more than 20 years in the range of returned data, the years appearing along the x-axis in the flot graph overwrote each other. &lt;br /&gt;
I changed the init-flot.js file by replacing this:&lt;/p&gt;
&lt;pre&gt;
  xaxis: { 
    tickSize: 1,
    tickFormatter: function(val, axis) {
      if (!yearTotals[val]) {
        return val;
      } else {
        return val + '&amp;lt;br /&amp;gt;' + yearTotals[val];
      }
    }
  }
&lt;/pre&gt;

&lt;p&gt;with this:&lt;/p&gt;

&lt;pre&gt;
  xaxis: { 
    ticks: 20,
    tickDecimals: 0,
    tickFormatter: function(val, axis) {
      return '&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;' + val;
    }
  }
&lt;/pre&gt;

&lt;p&gt;The ticks limits the number of years explicitly labelled to a maximum of 20, thus taking care of the overlapping year display on the x-axis when there are lots of years in the chart. &lt;br /&gt;
The tickDecimals controls whether fractions of years get ticks on the x-axis. For small year ranges, if this is not set to 0, you get values like 1744.5 appearing, which is nonsensical for this dataset. &lt;br /&gt;
Since not all years get a tick on the x-axis, it didn't seem to make sense to display the total hits, so I've removed that from the tickFormatter. &lt;br /&gt;
I prefer the year label to be left justified to the left side of the column in the graph, rather than centered on the left side of the column, so I added those spaces to push the date to the left.&lt;/p&gt;

</description>
			    <link>http://hcmc.uvic.ca/blogs/index.php?blog=36&amp;title=clean_up_year_display_in_x_axis_of_flot_&amp;more=1&amp;c=1&amp;tb=1&amp;pb=1</link>
			  </item>
			  			  <item>
			    <title>getting familiar with code</title>
			    <description> (Mins: 240) Spent a few hours getting familiar with Jamie's code - in particular the jquery stuff. Made some trivial changes to the pagination output. Still need to look more closely at the data model and how the chart view / table view switching is done. Also will need to see if there's some way to make the labels on the x-axis easier to read as they are currently overlapping for data sets with lots of years in them. </description>
			    <link>http://hcmc.uvic.ca/blogs/index.php?blog=36&amp;title=getting_familiar_with_code&amp;more=1&amp;c=1&amp;tb=1&amp;pb=1</link>
			  </item>
			  	</channel>
</rss>
