1

Re: Update verification status of multiple records

Here's my situation: I extracted all butterfly records from our Recorder 6 DB and sent to the county recorder in a spreadsheet. This contained several thousand records from mutliple surveys.

The county recorder went through them all and identified a few dozen that were suspect. For each of these I manually added a new determination showing that the record was 'considered incorrect'.

Now I want to add a new determination record for the rest showing that they are 'considered correct' so that their verification status will change from 'not verified' (because their current preferred determination is 'unconfirmed') to 'correct'.

Are there any add-in tools or SQL tricks that will help me update records in bulk to achieve this?

Rich

Richard Burkmar
Biodiversity Project Officer
Field Studies Council

2

Re: Update verification status of multiple records

Strangely enough I am working on a very similar problem. I'll send the Batch Update when I've finished polishing it off (it's mainly the work of Mike W - I'm just tweaking, honing and documenting it.)

The difference between what I am doing and what you're doing is that I am adding a new determination for all records of species named in a CSV. It wouldn't be too much of a stretch to modify what I've got to work on a list of taxon_occurrence_keys (I presume you exported the taxon_occurrence_keys for each record into your spreadsheet?) instead of a list of species names.

Charles Roper
Digital Development Manager | Field Studies Council
http://www.field-studies-council.org | https://twitter.com/charlesroper | https://twitter.com/fsc_digital

3 (edited by burkmarr 14-01-2010 07:44:33)

Re: Update verification status of multiple records

You are a gent Charles. I did export the taxon occurrence keys so it sounds as though I will be able to use this to solve my problem if it can be modified to work with them. If so, it will be a very, very useful batch update for this LRC. Thank you very much.

Richard Burkmar
Biodiversity Project Officer
Field Studies Council

4

Re: Update verification status of multiple records

I'd be really interested in seeing that batch update too Charles

Regards

Rob Large
Wildlife Sites Officer
Wiltshire & Swindon Biological Records Centre

5

Re: Update verification status of multiple records

I've put the batch update here:

http://gist.github.com/277373

After much testing, it now works, as far as I can tell. It broadly follows this procedure:

1. Load a CSV into a temp table.
2. Prepare the static variables that will be used for all of the new determinations.
3. Create a cursor that contains a list of taxon_occurrence_keys to add new determinations to.  The names in the CSV temp table are used to find the keys.
4. Iterate over each taxon_occurrence_key in the cursor creating a new determination for each and pointing the taxon occurrence to the new determination (i.e., make the new determination preferred)

The workflow behind this update is as follows:

We extracted all of the data we hold for a list of 'scarce' moths as defined by our county recorder for moths. He went through these data and marked ones he thought were incorrect, suspect or completely wrong. We then added the appropriate determinations by hand to these suspect records, the 'completely wrong' ones were marked as invalid rather than being deleted.

So the batch update take the list of scarce moths we provided and adds 'considered correct' determinations to all records that have not been determined otherwise by the county recorder. All records that have an 'Invalid' determination, whether by the county recorder or not, will be ignored.

The whole thing should probably be wrapped in a transaction in case anything goes wrong during the query. I'll add that next, perhaps.

If I've understood your scenario correctly, Richard, you're trying to do exactly the same thing only against a list of taxon_occurrence_keys, rather than a list of taxon names. This actually makes the update a little bit simpler: you just need to alter the cursor declaration a little bit. Here's a revised version of the update that should operate on a CSV that contains a list of taxon_occurrence_keys instead of a list of species names:

http://gist.github.com/277413

I've not tested this one, though, so I don't know if it'll work!

I should finish this by saying a BIG thank you to Mike Weideli without whose help I wouldn't have been able to do this. Cheers,  Mike!

Charles Roper
Digital Development Manager | Field Studies Council
http://www.field-studies-council.org | https://twitter.com/charlesroper | https://twitter.com/fsc_digital

6

Re: Update verification status of multiple records

I've just tested the second one on a largish dataset (~60k records) and it worked just fine, taking about 5 minutes to process. It wasn't a thorough test, though.

Charles Roper
Digital Development Manager | Field Studies Council
http://www.field-studies-council.org | https://twitter.com/charlesroper | https://twitter.com/fsc_digital

7

Re: Update verification status of multiple records

Nice work Charles!

Note for Lynn, can we have a recommended place to store user-contributed reports and batch updates please (plust other files, addins etc)? There is the files upload on the forum though that is not very organised. The new website has a list of the standard ones but not user-contributions.

Regards

John van Breda
Biodiverse IT

8

Re: Update verification status of multiple records

As a variation on Charles’ offering, Mike Weideli has written 2 xml reports and a batch update to enable users to update Recorder 6 with verification information and I have documented the process.

In summary the procedure is:
•    Run LcValidation2Generate.xml to generate an Excel file containing the species observations to be verified – this lists observations for a taxonomic group, a survey or a taxonomic group within a survey
•    Send it to the expert and ask them to append their information on verification
•    When the Excel file is returned, run LcValidation1Check.xml to check that the verification information appended to the file is valid, i.e. that it can be used to update the Recorder 6 database
•    Run LCValidation1.xml, the xml batch update, to update the Recorder 6 database with the verification information from the Excel file. This will add determinations to observations containing information from the expert, and make them the preferred determination.

I have uploaded these and the documentation to http://forums.nbn.org.uk/uploaded/LCValidation.zip. If you want to make use of them you will need to study the documentation and check that they do what you want. If not, you will need to modify them, or get one of us to modify them, which we would be happy to do for a modest fee. You will also need to test them. They come with the warning: The complexity of the Recorder 6 database enables the system to handle an extensive array of biological data for observations. This means that testing xml reports and batch updates for every possibility would be prohibitively time consuming. Thus users must test batch updates in particular to ensure that the changes made are as required.

It would be relatively easy to add additional fields to the report if these would be helpful to the expert. TOccs with Entry Date GT specified date V3.xml is included in the zip file to illustrate how to add some extra things. The report on observations to be verified might also be made slightly more sophisticated by ignoring records which have already been determined by the expert. This could be done either by specifying the expert or by ignoring anything where the Determiner is County Recorder or Specialist. It probably isn’t a good idea just to ignore records which are already marked as ‘Correct’ or ‘Considered correct’ as they may have come from sources which are not trusted. However, you could apply all sorts of rules here if it was considered appropriate. For example ignoring records marked ‘Correct’ where the LRC is the custodian, but reporting on others. 

With this version of the Batch Update the Determination_Type must always be entered, but to make life easier it could be modified to accept, say, ‘c’ as Determination_Type then translate this into ‘Correct’ when the batch update is run. As it stands records which have not been determined need to be deleted manually from the Excel file, but the batch update could easily be changed to ignore records with blank determination types.

Sally Rankin, JNCC Recorder Approved Expert
E-mail: s.rankin@btinternet.com
Telephone: 01491 578633
Mobile: 07941 207687

9

Re: Update verification status of multiple records

The link in the preceding post should be http://forums.nbn.org.uk/uploads.php?file=LCValidation.zip - sorry.

Sally Rankin, JNCC Recorder Approved Expert
E-mail: s.rankin@btinternet.com
Telephone: 01491 578633
Mobile: 07941 207687

10

Re: Update verification status of multiple records

On a related note, I'm sure I've used batch updates that work like a transaction: they run, allow you to inspect the result, then allow you to apply the result or discard and roll-back. Trouble is, I can remember where I saw this... was I imagining it?

Charles Roper
Digital Development Manager | Field Studies Council
http://www.field-studies-council.org | https://twitter.com/charlesroper | https://twitter.com/fsc_digital

11

Re: Update verification status of multiple records

I would have thought that, since the core of the update is just a chunk of SQL, then it should be possible to enclose the last part  (which does the update, insert and update) inside a normal T-SQL transaction (i.e. enclosed between BEGIN TRANSACTION and COMMIT TRANSACTION, with some error checking to manage the ROLLBACK TRANSACTION).

I haven't ever tried to make this work though (yet)

Rob Large
Wildlife Sites Officer
Wiltshire & Swindon Biological Records Centre

12 (edited by RobLarge 15-01-2010 16:52:06)

Re: Update verification status of multiple records

Having said that I can't find a syntax that works for the error trapping. I think this may depend on the version of SQLServer being used. I tried a TRY CATCH block checking for the value of XACT_STATE() in the catch (which is what I would do for SQL 2005), but it didn't like the TRY (we are using SQLserver  2000 I think) and I also tried IF @@ERROR <> 0 ROLLBACK TRANSACTION and it didn't like that either.

I can at least confirm that enclosing the section between OPEN CSV1_Cursor and DEALLOCATE CSV1_Cursor within BEGIN TRANSACTION and COMMIT TRANSACTION did not interfere with the functioning of the update.

Can anyone suggest how to trap errors and rollback?

Rob Large
Wildlife Sites Officer
Wiltshire & Swindon Biological Records Centre

13

Re: Update verification status of multiple records

Sincere thanks to Charles (and Mike Weideli) - I used your amended update Charles and it went through very quickly and successfully on about 5500 records. Thanks also to Sally for documenting the procedure using the other scripts - I will explore this workflow the very next time I carry out this kind of verification procedure - it should simpilfy the process even more.

Richard Burkmar
Biodiversity Project Officer
Field Studies Council

14

Re: Update verification status of multiple records

Hi All,

Just referring back to Charles' earlier point about being able to review the output of a batch update before applying the changes. You are right - this facility does exist if the batch update is configured in the correct way. Here is the relevant extract from the technical documentation:

If the batch update query returns a recordset containing a single field called “Count” then this defines the count of records updated by the batch updated (but not yet committed). The value returned in the output recordset from the query is displayed in a dialog with text “The batch update is about to change n records. Are you sure you want to proceed?” with Ok and Cancel buttons. If cancel is selected then the batch update is aborted and the screen is closed.
If the batch update query returns a recordset containing fields called “Table” and “Key” (which should define the filter required to display the updated records) then a dialog is displayed to the user on completion with text: “Would you like to review the records that have been updated?” and Yes and No buttons. If the user selects Yes then the recordset is used to create an external filter, the screens required to display the external filter are displayed (see section 1.16.7 for more information on this process), and each screen is filtered according to the content of the external filter.  If the recordset has a third column titled “Description” then this is used to supply the record description for each filtered record. Further information is given in the section entitled Recorder External Filters. If an external filter is applied from a batch update, then a message is displayed with text “When you have finished reviewing the updated records, please ensure you select Commit Updates or Cancel Updates from the Tools menu”. The Commit Updates and Cancel Updates menu options on the Tools menu are enabled and the transaction is left open. Recorder is then set to read only (the user temporarily is not allowed to add or edit any data, import data, or use the record cards). This lasts until the transaction is committed or rolled back. Whilst in this mode, if the user attempts to close the application then a message is displayed: “There are pending updates as a result of a batch update. Do you want to commit these updates before closing the application?” with Yes, No and Cancel buttons. Selecting Yes causes the transaction to commit and the application to close. Selecting No causes the transaction to roll back and the application to close. Selecting Cancel does not close the application.
If the batch update query returns both the Count recordset and the filter recordset, show a dialog with message "Would you like to review the n records that have been updated?" with Yes , No and Cancel buttons. Yes loads the filter, No commits the transaction, and Cancel rolls back the transaction.
If there is an error during the running of any batch update then the transaction is rolled back and a message describing the error is displayed to the user.

Best Wishes

John van Breda
Biodiverse IT

15

Re: Update verification status of multiple records

Thanks John that looks like very useful information. I am not entirely sure I understand the first part however. Any chance you could refer me to an example of an update which has been configured in this way?

Rob Large
Wildlife Sites Officer
Wiltshire & Swindon Biological Records Centre

16

Re: Update verification status of multiple records

Thanks John, very useful info.

As mentioned in the docs, there is a transaction involved but what I'm not clear on is whether this is handled automatically by Recorder, of if the transaction needs to be written into the SQL. If the transaction is handled by Recorder, do all batch updates get wrapped in a transaction, even if we don't trigger a pre-commit review stage as described above?

Is there any chance we can have the latest technical docs added to the website somewhere? The section on external filters sounds like it is worth a read too.

Charles Roper
Digital Development Manager | Field Studies Council
http://www.field-studies-council.org | https://twitter.com/charlesroper | https://twitter.com/fsc_digital

17

Re: Update verification status of multiple records

The docs are available at http://www.jncc.gov.uk/default.aspx?page=4907.

I can confirm the batch update is automatically wrapped in a transaction, which gets commited or rolled back depending on the outcome. That way a failed partial batch update should do no damage.

Rob, an example Batch Update which does this is JNCCDet1Determinations.xml. One thing I just noticed- make sure your recordset puts the [TABLE]  attribute first and [KEY] second, not the other way round or it won't work.

Cheers

John van Breda
Biodiverse IT

18

Re: Update verification status of multiple records

Thanks John, that makes much more sense now (and thanks for pointing out the technical docs, I admit I hadn't taken the time to explore every corner of the new Rec6 website yet).

Rob Large
Wildlife Sites Officer
Wiltshire & Swindon Biological Records Centre

19

Re: Update verification status of multiple records

An interesting thread, I've now got my copies of the tech docs and am please to see transaction files explored, something I made use of in R3 on many occasions. The batch updates now also all downloaded and ready for use/perusal. Hurrah.

Data Manger
Somerset Environmental Records Centre

20

Re: Update verification status of multiple records

With respect to the batch update scripts written by Mike and referred to by Sally (posting #8) I have found that the comment field is being truncated to 100 characters which is causing me quite some inconvenience.

I verified that the R6 determination comment field is capable of holding more than 100 characters by editing one manually. Is this something that can be easily fixed?

Rich

Richard Burkmar
Biodiversity Project Officer
Field Studies Council

21

Re: Update verification status of multiple records

Unforunately not very easily and certainly not conveniently. The maximum permitted field size which can be picked up from an Excel file is 100 characters. The only fix I have for this is to split the field into chunks of 100 characters and modify the batch update to concatenate these.

Mike Weideli

22

Re: Update verification status of multiple records

Okay not to worry - I have a workaround (I'm applying the same comment to multiple records, so I can just put a marker in and use SQL Server to replace the marker in the taxon_determination table with the full comment).

Which element of the architechture is responsible for the 100 character limit? Is this a Recorder limitation or a limitation of an API it uses?

Rich

Richard Burkmar
Biodiversity Project Officer
Field Studies Council

23

Re: Update verification status of multiple records

Another request for advice pertaining to the determination batch update procedure.

I extracted some 180,000 bird records (in several batches) towards the end of last year using this process and they went to the County Bird recorder for verification. They have been returned but I am tripping up when I try to import the new determinations with the 'Create new determination based on spreadsheet' XML batch update.

An SQL error prevents the script from running which turns out to be caused (I think) by TOKs in the determination CSV file no longer being present in the database. Clearly some of the bird records have been deleted from the database, during normal management of the records, since the extracts were made.

My question is how to overcome this. Can it be fixed by a tweak to the XML? Any other suggestions?

Rich

Richard Burkmar
Biodiversity Project Officer
Field Studies Council

24

Re: Update verification status of multiple records

Sorry to confuse things even more, but what happens when the expert marks a record as "considered incorrect", and enters the "correct name"?

The way I see it it will add a determination of the "correct name" but the determination type will be set to "considered incorrect"?

Charlie Barnes
Information Officer
Greater Lincolnshire Nature Partnership

25

Re: Update verification status of multiple records

I think that it would happen as you suggest Charlie and a number of our verifiers have set the fields in this way (despite instructions to the contrary) because it's intuitive. But it is a very trivial job to check for these situations and change the determination to 'considered correct' or 'correct' before running the batch update.

Richard Burkmar
Biodiversity Project Officer
Field Studies Council