Graticule Hoppers

From Geohashing
Revision as of 15:38, 9 November 2021 by Fippe (talk | contribs) (Graticule Hoppers)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The following table will show Geohashers by their number of reached graticules. Those with over 100 graticules have earned the Graticule Hopper achievement.

Methodology and Limitations

This page is generated by looking at the year pages. This page is only as good as the year pages, which in turn depend on the expedition summaries template generated by AperfectBot. An expedition's graticule is counted for you, if your profile is linked from the expedition's day's subtemplate, and if the expedition is in the coordinates reached category.

Retrohashes and Hashscots are excluded.

A Geohasher's name is displayed in lowercase if their profile transcludes the lowercase template.

Check out the program's source code.

Table

User Σ Graticules

Source code

The following program generates this page:

#!/bin/bash

# Copyright 2021 Fippe
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

api="https://geohashing.site/api.php?action=query&format=json"
lowercaseAPI="$api&prop=transcludedin&tiprop=title&tilimit=500&titles=Template:Lowercase&tinamespace=2"
hashscotAPI="$api&list=categorymembers&cmprop=title&cmnamespace=2&cmlimit=500&cmtitle=Category:Hashscots"
categoryAPI="$api&list=categorymembers&cmprop=title&cmlimit=500&cmtitle=Category"

dir="/tmp/geohashingstats"
mkdir -p "$dir"

currentyear=$(date +%Y)

function urldecode {
    sed "s@+@ @g;s@%@\\\\x@g" | xargs -0 printf "%b"
}

function urldecodeFile {
    grep "%" "$1" | urldecode
    grep -v "%" "$1"
}

function convertGlobalhashes {
    mkdir -p "$dir/info"

    grep "global;User" "$dir/users-by-expedition" | cut -d " " -f 1 | while read -r date
        do test -s "$dir/info/$date" || curl -so "$dir/info/$date" "https://data.geohashing.info/hash/$date.json"
        graticule=$(cat "$dir/info/$date" | jq -r '.global |(.lat|tostring) + "\n" + (.lng|tostring)' | cut -d "." -f 1 | tr "\n" " " | xargs)
        echo "s|$date global|$date $graticule|g"
    done > "$dir/globalhashes.sed"
    
    sed -f "$dir/globalhashes.sed" -i "$dir/users-by-expedition"
}

function getData {
    for category in "Coordinates_reached"
        do echo -n > "$dir/$category"
        cmcontinue="0"
        while [ "$cmcontinue" != "null" ]
            do curl -so "$dir/tmp" "$categoryAPI:$category&cmcontinue=$cmcontinue"
            cmcontinue=$(cat "$dir/tmp" | jq -r ".continue.cmcontinue")
            cat "$dir/tmp" | jq -r ".query.categorymembers[].title" | sed -e "s/\(.*\)/^\1;/g" >> "$dir/$category"
        done
        rm "$dir/tmp"
    done

    for year in $(seq 2008 $currentyear)
        do curl -so "$dir/$year.html" "https://geohashing.site/geohashing/$year"
    done

    curl -s "$lowercaseAPI" | jq -r '.query.pages[].transcludedin[].title' | cut -d ":" -f 2 | while read -r line
        do lowercase=$(echo "$line" | awk '{$1=tolower(substr($1,0,1))substr($1,2)}1')
        echo "s|User:$line|User:$lowercase|g" | tr " " "_"
    done > "$dir/lowercase"

    curl -s "$hashscotAPI" | jq -r ".query[][].title" | sed -e "s/User:\(.*\)/\1/g" > "$dir/hashscots"
}

function genTable {
    cat "$dir/"*".html" | grep -i -e '</\?TABLE\|</\?TD\|</\?TR\|</\?TH' | sed 's/^[\ \t]*//g' | tr -d '\n' | sed 's/<\/TR[^>]*>/\n/Ig' | sed 's/<\/\?\(TABLE\|TR\)[^>]*>//Ig' | sed 's/^<T[DH][^>]*>\|<\/\?T[DH][^>]*>$//Ig' | sed -e 's/<\/T[DH][^>]*><T[DH][^>]*>/@/Ig' | cut -d "@" -f 1-2 | sed -e "s/\(<a[^>]*>\)\(<[^>]*>\)/\1/g" -e "s|</[^>]*></a>|</a>|g" | grep -o "<[^@]*@\(<a[^>]*>[^>]*>,\? \?\)*" | sed -e 's/<a href="\(.geohashing.\|.index.php.title=\)\([^&"]*\)[^"]*" \(class="[^"]*" \)\?title="[^"]*">[^>]*>/\2/g' | tr "@" ";" > "$dir/users-by-expedition.tmp"
    urldecodeFile "$dir/users-by-expedition.tmp" | sed -f "$dir/lowercase" | tr "_" " " | sed '$!s/$/,/' | grep -f "$dir/$1" > "$dir/users-by-expedition"
    convertGlobalhashes
    grep -o "User:[^,]*" "$dir/users-by-expedition" | sort | uniq -c | cut -d " " -f 2- | sed -e "s/[ \t]*\([^ \t]*\) \(.*\)/\2/g" | cut -d ":" -f 2- | grep -xvf "$dir/hashscots" > "$dir/users"
    rm "$dir/users-by-expedition.tmp"
    
    echo "{|class=\"wikitable sortable center zebra\""
    echo '!User!!Σ!!Graticules'
    
    cat "$dir/users" | while read -r user
        do graticules=$(grep -F "User:$user," "$dir/users-by-expedition" | cut -d " " -f 2- | cut -d ";" -f 1 | sort -u -k1 -n -k2 -n)
        echo "$graticules" | wc -l | tr -d "\n"
        echo -n "#[[User:$user|$user]]#"
        echo "$graticules" | tr " " "," | while read -r g; do echo -n "[[$g]]; "; done | head -c -2
        echo
    done | sort -rn | while IFS='#' read -r number user graticules
        do echo "|-"
        echo "|$user||$number||$graticules"
    done
    
    echo "|}"
}

function gen {
    date -u +"The following table shows Geohashers by their number of reached graticules as of %F %T. __TOC__"
    echo -e "==Methodology and Limitations==\nThis page is generated by looking at the [[Template:YearNav|year pages]]. This page is only as good as the year pages, which in turn depend on the [[Template:Expedition summaries|expedition summaries template]] generated by [[User:AperfectBot|AperfectBot]]. An expedition's graticule is counted for you, if your profile is linked from the expedition's day's subtemplate, and if the expedition is in the [[:Category:Coordinates reached|coordinates reached]] category.\n\nRetrohashes and [[:Category:Hashscots|Hashscots]] are excluded.\n\nA Geohasher's name is displayed in lowercase if their profile transcludes the [[Template:Lowercase|lowercase template]].\n\nCheck out the [[#Source code|program's source code]].\n\n==Table=="

    genTable "Coordinates_reached"

    echo "==Source code=="
    echo "The following program generates this page:<pre"">$(cat "$0")</pre"">"
    echo "[[Category:Graticule hopper achievement]]"
}

getData
gen | tee "$dir/graticulehoppers.wiki"