Fix computation of top-ten countries

When computing the top-ten countries for a project, countries have
been ordered only by the counts for single days. The first ten
distinct countries were considered the top ten countries. Hence,
countries whose IPs had many edits on a single day once, but not so
many in total were favored over countries whose IPs had fewer edits
over a longer period with a higher total. In connection with using
DISTINCT and LIMIT, this gave inconsistent results.

So for example for sgwiki, gave 'Netherlands' (maximum count 4) before
'United States' (maximum count 5).

We now switched to proper GROUP BY and ordering by the sum of counts.

The query did not force a consistent way of cutting ties. We now cut
ties, by the end date (descending), and finally on the country name.

The query did not limit to rows for the 30 day window. So rows for
different periods could lead to wrongly favor a country. We now limit
to rows of the 30 day window.

Change-Id: I1731c8104b03b5ee92367b41b9e2887da2041f8e