Tuesday, 26 November 2024

MORE ADVANCED CHESS DATABASE SORTING

We've already had a look at ways of sorting a chess database using ChessBase. Let's quickly recap: in ChessBase you can sort a database based on the game date or the tournament start date. One or the other, but you can't combine the two, or add in more sort options as you can in more sophisticated items of software such as spreadsheets.

Just yesterday I needed to sort an old file of games from Division 3 of the 4NCL (British Team League), season 2001/2. There were 12 teams of eight players taking part in a all-play-all, round robin event between October 2001 and May 2002. I like to pack as much meaningful information into the Tournament field as possible, so I decided on the following standard name...

4NCL/2001-02/D3/xxx-yyy

... thus showing the league name, the season, the division, plus short codes (represented here as xxx and yyy) for the two teams involved in the match (e.g. WS = Warwickshire Select or PP2 = Poisoned Pawns 2nd team). Of course, this latter information can also be stored in the White Team and Black Team fields, but I like to have it visible in the tournament index.

I also use the round and sub-round fields, where the former is self-explanatory and the latter is used to show the board number within the individual match. My desired overall sort order is of course chronological. I like to group individual matches together in board order, top to bottom, as per the following image...

Image 1: the desired sort order for the 4NCL 2001/2 Division 3 games. Each eight-game match is grouped together with a discrete name, round by round, and in board order, top to bottom.

Image 1 above shows you the desired end product with the relevant data for each game, in what is probably the most logical order. 

That's how we want the database sorted, but let's suppose our starting point was the same database but in a completely random order, e.g. as shown below in Image 2...
Image 2: here's the same database but in scrambled order. What we want to achieve is to transform the random order of Image 2 into the logical sequence shown in Image 1.

OK, how to go about sorting the random order of Image 2 into the logical order shown in Image 1. 

HOW NOT TO SORT THIS DATABASE...


One thing we might try is to click (twice) on the Date tab, which produces the following...

Image 3: the database shown after double-clicking on the Date tab (encircled in red). But it's not the sort order we want as it groups all the board 1s together (see the column indicated by the arrow) rather than showing all the boards of each match grouped together. 

If you look closely at Image 3 you can see that our simple sort using the Date field has not worked as it groups together all the board 1s for a particular date, then all the board 2s, etc, etc. That's not what we want.

HOW TO SORT THIS DATABASE... SUCCESSFULLY, THIS TIME


OK, so let's go back to the start and see if ChessBase's built-in Sort Database function can do the trick. Go to the CB database window...

Image 4: using the built-in ChessBase sort function. Right-click on the database you want to sort, move the mouse down to TOOLS and then click where you see SORT DATABASE.

As explained in a previous post, you can sort a database from the database window. Highlight (single-left-mouse-click) the database you wish to sort, then right-mouse-click to display a further drop-down menu, move the mouse pointer to where it says TOOLS, which opens up a further drop-down menu, move the mouse pointer across to where it says SORT DATABASE and left-mouse-click.

You will be asked to choose between an ascending and descending sort - default is ascending so just click on OK.

Now if you go back and look at the database, you'll find yourself it looks like Image 1. Yes, it's good news, the operation was successful. Congratulations, you are now the proud owner of a logically-ordered sort database.

Here's how ChessBase have documented the Sort Database facility in the Advanced Database Management section of their CB14 Help pages.

Sort database
Sort the games of a database according on year and tournament only and fixes this sort order. You have the choice between ascending or descending. This function is maintained from the CB 8 program because some users do not like to see that some functions are disappeared.

There you have it (in slightly sub-standard English): the tournament field is an integral part of the sort and helps to put the games in the order we need. (I was slightly perturbed to read the last sentence which seems to hint that the ChessBase company itself is not committed to the idea of retaining this function - which I would have thought was essential - but have, perhaps reluctantly, bowed to user pressure. Maybe I'm reading too much into it.)

WHAT HAPPENS IF YOU DON'T INCLUDE CODES FOR TEAMS...


Let's consider what happens if the tournament field doesn't include those team codes.

You will recall that we built in short codes denoting the teams into the tournament field, e.g. WS = Warwickshire Select, GUI3 = Guildford 3rd team. The underlying reason for including these codes was to make ChessBase's built-in sort function do the job properly. 

Or so I thought... before going on I should add that all of the games in this database have the White Team and Black Team fields filled in as you can see from this image of the Team index tag...

Image 5: the Team index tag shows the team names with dates and flags,
and tells us that all 480 games in the database have this information.

Now the test database includes the team fields but doesn't have short codes for the teams in the tournament field, so it shows as exactly the same for every game, thus 4NCL/2001-02/D3, indicating the identity of the competition, the season and the division of the league.
Image 6: the test database in random order, showing you the simplified tournament identifier, minus the short team codes, but showing full team information in the White Team and Black Team fields, as indicated by the red arrows.
Now we can run ChessBase's built-in Sort Database again (see Image 4 above) and see what happens.

Here I was agreeably surprised. Having read the CB14 Help information, I thought it might simply refer to the tournament field - now the same for all games, so no longer useful for sorting - and then refer to the date field and the round/sub-round data, producing a similar failure to the one shown in Image 3, with all the board ones grouped together in each round.

But I was wrong! It worked perfectly and produced the following result...

Image 7: a perfect sort, showing games grouped into matches, in board order. 

There you have it: ChessBase's sort worked exactly as required, grouping matches correctly in board order. And a bit of later testing showed me that it works correctly because it makes reference to the team names saved with each game and is 'clever' enough to use them to group games together into discrete matches. That seems to indicate that, to achieve a logical sort of a team chess database, you need either to supply different tournament fields for each match played or else make sure every game has the two teams identified.

A caveat: CB functions can differ between different versions of the software, and it is also important to apply all the software updates that are available. It is quite possible that earlier versions won't produce the same result.

A THIRD SCENARIO - NO TEAM NAMES


What happens when the games don't have team names for the players or different tournament data for each individual match? In those circumstances the sort function doesn't have anything to work from other than game date plus round/board numbers. So once again it gives you all the round 1, board 1s, followed by the round 1, board 2s, etc, which is not what is required.

A popular work-around in these circumstances is to edit the sub-round data so that the sort works. So, using our 4NCL example, you attribute a notional number between 1 and 6 to each of the six first-round matches. So for the first match you enter the sub-round data for board 1 as "11", board 2 as "12", etc, up to "18" for the bottom board. Then for the second match of that match you enter the top board sub-round data as "21" and the rest of the boards similarly "22", "23", etc. You can see that the software will then happily sort them into the desired order. But it's an unsatisfactory bodge of a solution, of course. If you publish games like this, end users may be puzzled as to what the significance of the sub-round data is.

That's it for this post. Good ChessBasing to all my readers.









No comments:

Post a Comment