Is there a standard text mode tool to render heatmaps for arbitrary numeric data?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












For the curiosity's sake I created a script to visualize Git history week/hour-of-day basis timestamps in order to collect some stats. The following script



#!/bin/bash

# Declare the global heatmap hashmap
declare -A HEATMAP

# Composes a key in a form of a <WEEKDAY:1><HOUR:02>
function key
local WEEKDAY="$1"
local HOUR="$2"
echo -n "$WEEKDAY"
if [[ "$HOUR" -lt 10 ]]; then
echo -n '0'
fi
echo "$HOUR"


# Generate a sequence of weekdays (Mon-Sat,Sun)
function generate_weekdays
seq 1 6
seq 0 0


# Generate a sequence of hours in day (00-23)
function generate_hours
seq 0 23


# Initialize and fill the heatmap with zeroes
for WEEKDAY in $(generate_weekdays); do
for HOUR in $(generate_hours); do
HEATMAP[$(key "$WEEKDAY" "$HOUR")]=0
done
done

# Read the stats into the heatmap
MAX_PEAK=1
while read WEEKDAY_HOUR; do
HEATMAP["$WEEKDAY_HOUR"]=$(($HEATMAP["$WEEKDAY_HOUR"] + 1))
if [[ $HEATMAP["$WEEKDAY_HOUR"] -gt "$MAX_PEAK" ]]; then
MAX_PEAK=$HEATMAP["$WEEKDAY_HOUR"]
fi
done < <(git rev-list --date=format:'%w%H' --pretty='format:%ad' $@ | awk 'NR % 2 == 0')

# Render the heatmap
RATIO=0
for WEEKDAY in $(generate_weekdays); do
for HOUR in $(generate_hours); do
RATIO=$((100 * $HEATMAP[$(key "$WEEKDAY" "$HOUR")] / $MAX_PEAK))
if [[ "$RATIO" -eq 0 ]]; then echo -ne 'e[38;5;236m'
elif [[ "$RATIO" -lt 10 ]]; then echo -ne 'e[38;5;107m'
elif [[ "$RATIO" -lt 20 ]]; then echo -ne 'e[38;5;22m'
elif [[ "$RATIO" -lt 30 ]]; then echo -ne 'e[38;5;28m'
elif [[ "$RATIO" -lt 40 ]]; then echo -ne 'e[38;5;70m'
elif [[ "$RATIO" -lt 50 ]]; then echo -ne 'e[38;5;190m'
elif [[ "$RATIO" -lt 60 ]]; then echo -ne 'e[38;5;226m'
elif [[ "$RATIO" -lt 70 ]]; then echo -ne 'e[38;5;220m'
elif [[ "$RATIO" -lt 80 ]]; then echo -ne 'e[38;5;214m'
elif [[ "$RATIO" -lt 90 ]]; then echo -ne 'e[38;5;208m'
elif [[ "$RATIO" -lt 100 ]]; then echo -ne 'e[38;5;160m'
elif [[ "$RATIO" -eq 100 ]]; then echo -ne 'e[38;5;196m'; fi
echo -n '*'
echo -ne 'e[0m'
done
echo
done


invoked as ./git-heatmap --all produces a sample output as depicted below (not at a Linux machine currently, running on Windows/MinGW with the Fixedsys font, I prefer squares, u2BC0, to asterisks, but Fixedsys cannot render the squares that I find much nicer):



./git-heatmap --all example output



Since the script does three jobs:



  • consumes Git weekday/hour-of-day timestamps output,

  • calculates the stats,

  • and renders the heatmap

... I'm wondering is there something like a standard tool that calculates/renders something similar to the heatmap above? My script processes the following sample data supplied by Git:





100
101
420
517
...


where the first digit designates a weekday, and the second and the third digits designate a day hour. Thanks.









share







New contributor




lsh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.























    up vote
    0
    down vote

    favorite












    For the curiosity's sake I created a script to visualize Git history week/hour-of-day basis timestamps in order to collect some stats. The following script



    #!/bin/bash

    # Declare the global heatmap hashmap
    declare -A HEATMAP

    # Composes a key in a form of a <WEEKDAY:1><HOUR:02>
    function key
    local WEEKDAY="$1"
    local HOUR="$2"
    echo -n "$WEEKDAY"
    if [[ "$HOUR" -lt 10 ]]; then
    echo -n '0'
    fi
    echo "$HOUR"


    # Generate a sequence of weekdays (Mon-Sat,Sun)
    function generate_weekdays
    seq 1 6
    seq 0 0


    # Generate a sequence of hours in day (00-23)
    function generate_hours
    seq 0 23


    # Initialize and fill the heatmap with zeroes
    for WEEKDAY in $(generate_weekdays); do
    for HOUR in $(generate_hours); do
    HEATMAP[$(key "$WEEKDAY" "$HOUR")]=0
    done
    done

    # Read the stats into the heatmap
    MAX_PEAK=1
    while read WEEKDAY_HOUR; do
    HEATMAP["$WEEKDAY_HOUR"]=$(($HEATMAP["$WEEKDAY_HOUR"] + 1))
    if [[ $HEATMAP["$WEEKDAY_HOUR"] -gt "$MAX_PEAK" ]]; then
    MAX_PEAK=$HEATMAP["$WEEKDAY_HOUR"]
    fi
    done < <(git rev-list --date=format:'%w%H' --pretty='format:%ad' $@ | awk 'NR % 2 == 0')

    # Render the heatmap
    RATIO=0
    for WEEKDAY in $(generate_weekdays); do
    for HOUR in $(generate_hours); do
    RATIO=$((100 * $HEATMAP[$(key "$WEEKDAY" "$HOUR")] / $MAX_PEAK))
    if [[ "$RATIO" -eq 0 ]]; then echo -ne 'e[38;5;236m'
    elif [[ "$RATIO" -lt 10 ]]; then echo -ne 'e[38;5;107m'
    elif [[ "$RATIO" -lt 20 ]]; then echo -ne 'e[38;5;22m'
    elif [[ "$RATIO" -lt 30 ]]; then echo -ne 'e[38;5;28m'
    elif [[ "$RATIO" -lt 40 ]]; then echo -ne 'e[38;5;70m'
    elif [[ "$RATIO" -lt 50 ]]; then echo -ne 'e[38;5;190m'
    elif [[ "$RATIO" -lt 60 ]]; then echo -ne 'e[38;5;226m'
    elif [[ "$RATIO" -lt 70 ]]; then echo -ne 'e[38;5;220m'
    elif [[ "$RATIO" -lt 80 ]]; then echo -ne 'e[38;5;214m'
    elif [[ "$RATIO" -lt 90 ]]; then echo -ne 'e[38;5;208m'
    elif [[ "$RATIO" -lt 100 ]]; then echo -ne 'e[38;5;160m'
    elif [[ "$RATIO" -eq 100 ]]; then echo -ne 'e[38;5;196m'; fi
    echo -n '*'
    echo -ne 'e[0m'
    done
    echo
    done


    invoked as ./git-heatmap --all produces a sample output as depicted below (not at a Linux machine currently, running on Windows/MinGW with the Fixedsys font, I prefer squares, u2BC0, to asterisks, but Fixedsys cannot render the squares that I find much nicer):



    ./git-heatmap --all example output



    Since the script does three jobs:



    • consumes Git weekday/hour-of-day timestamps output,

    • calculates the stats,

    • and renders the heatmap

    ... I'm wondering is there something like a standard tool that calculates/renders something similar to the heatmap above? My script processes the following sample data supplied by Git:





    100
    101
    420
    517
    ...


    where the first digit designates a weekday, and the second and the third digits designate a day hour. Thanks.









    share







    New contributor




    lsh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      For the curiosity's sake I created a script to visualize Git history week/hour-of-day basis timestamps in order to collect some stats. The following script



      #!/bin/bash

      # Declare the global heatmap hashmap
      declare -A HEATMAP

      # Composes a key in a form of a <WEEKDAY:1><HOUR:02>
      function key
      local WEEKDAY="$1"
      local HOUR="$2"
      echo -n "$WEEKDAY"
      if [[ "$HOUR" -lt 10 ]]; then
      echo -n '0'
      fi
      echo "$HOUR"


      # Generate a sequence of weekdays (Mon-Sat,Sun)
      function generate_weekdays
      seq 1 6
      seq 0 0


      # Generate a sequence of hours in day (00-23)
      function generate_hours
      seq 0 23


      # Initialize and fill the heatmap with zeroes
      for WEEKDAY in $(generate_weekdays); do
      for HOUR in $(generate_hours); do
      HEATMAP[$(key "$WEEKDAY" "$HOUR")]=0
      done
      done

      # Read the stats into the heatmap
      MAX_PEAK=1
      while read WEEKDAY_HOUR; do
      HEATMAP["$WEEKDAY_HOUR"]=$(($HEATMAP["$WEEKDAY_HOUR"] + 1))
      if [[ $HEATMAP["$WEEKDAY_HOUR"] -gt "$MAX_PEAK" ]]; then
      MAX_PEAK=$HEATMAP["$WEEKDAY_HOUR"]
      fi
      done < <(git rev-list --date=format:'%w%H' --pretty='format:%ad' $@ | awk 'NR % 2 == 0')

      # Render the heatmap
      RATIO=0
      for WEEKDAY in $(generate_weekdays); do
      for HOUR in $(generate_hours); do
      RATIO=$((100 * $HEATMAP[$(key "$WEEKDAY" "$HOUR")] / $MAX_PEAK))
      if [[ "$RATIO" -eq 0 ]]; then echo -ne 'e[38;5;236m'
      elif [[ "$RATIO" -lt 10 ]]; then echo -ne 'e[38;5;107m'
      elif [[ "$RATIO" -lt 20 ]]; then echo -ne 'e[38;5;22m'
      elif [[ "$RATIO" -lt 30 ]]; then echo -ne 'e[38;5;28m'
      elif [[ "$RATIO" -lt 40 ]]; then echo -ne 'e[38;5;70m'
      elif [[ "$RATIO" -lt 50 ]]; then echo -ne 'e[38;5;190m'
      elif [[ "$RATIO" -lt 60 ]]; then echo -ne 'e[38;5;226m'
      elif [[ "$RATIO" -lt 70 ]]; then echo -ne 'e[38;5;220m'
      elif [[ "$RATIO" -lt 80 ]]; then echo -ne 'e[38;5;214m'
      elif [[ "$RATIO" -lt 90 ]]; then echo -ne 'e[38;5;208m'
      elif [[ "$RATIO" -lt 100 ]]; then echo -ne 'e[38;5;160m'
      elif [[ "$RATIO" -eq 100 ]]; then echo -ne 'e[38;5;196m'; fi
      echo -n '*'
      echo -ne 'e[0m'
      done
      echo
      done


      invoked as ./git-heatmap --all produces a sample output as depicted below (not at a Linux machine currently, running on Windows/MinGW with the Fixedsys font, I prefer squares, u2BC0, to asterisks, but Fixedsys cannot render the squares that I find much nicer):



      ./git-heatmap --all example output



      Since the script does three jobs:



      • consumes Git weekday/hour-of-day timestamps output,

      • calculates the stats,

      • and renders the heatmap

      ... I'm wondering is there something like a standard tool that calculates/renders something similar to the heatmap above? My script processes the following sample data supplied by Git:





      100
      101
      420
      517
      ...


      where the first digit designates a weekday, and the second and the third digits designate a day hour. Thanks.









      share







      New contributor




      lsh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      For the curiosity's sake I created a script to visualize Git history week/hour-of-day basis timestamps in order to collect some stats. The following script



      #!/bin/bash

      # Declare the global heatmap hashmap
      declare -A HEATMAP

      # Composes a key in a form of a <WEEKDAY:1><HOUR:02>
      function key
      local WEEKDAY="$1"
      local HOUR="$2"
      echo -n "$WEEKDAY"
      if [[ "$HOUR" -lt 10 ]]; then
      echo -n '0'
      fi
      echo "$HOUR"


      # Generate a sequence of weekdays (Mon-Sat,Sun)
      function generate_weekdays
      seq 1 6
      seq 0 0


      # Generate a sequence of hours in day (00-23)
      function generate_hours
      seq 0 23


      # Initialize and fill the heatmap with zeroes
      for WEEKDAY in $(generate_weekdays); do
      for HOUR in $(generate_hours); do
      HEATMAP[$(key "$WEEKDAY" "$HOUR")]=0
      done
      done

      # Read the stats into the heatmap
      MAX_PEAK=1
      while read WEEKDAY_HOUR; do
      HEATMAP["$WEEKDAY_HOUR"]=$(($HEATMAP["$WEEKDAY_HOUR"] + 1))
      if [[ $HEATMAP["$WEEKDAY_HOUR"] -gt "$MAX_PEAK" ]]; then
      MAX_PEAK=$HEATMAP["$WEEKDAY_HOUR"]
      fi
      done < <(git rev-list --date=format:'%w%H' --pretty='format:%ad' $@ | awk 'NR % 2 == 0')

      # Render the heatmap
      RATIO=0
      for WEEKDAY in $(generate_weekdays); do
      for HOUR in $(generate_hours); do
      RATIO=$((100 * $HEATMAP[$(key "$WEEKDAY" "$HOUR")] / $MAX_PEAK))
      if [[ "$RATIO" -eq 0 ]]; then echo -ne 'e[38;5;236m'
      elif [[ "$RATIO" -lt 10 ]]; then echo -ne 'e[38;5;107m'
      elif [[ "$RATIO" -lt 20 ]]; then echo -ne 'e[38;5;22m'
      elif [[ "$RATIO" -lt 30 ]]; then echo -ne 'e[38;5;28m'
      elif [[ "$RATIO" -lt 40 ]]; then echo -ne 'e[38;5;70m'
      elif [[ "$RATIO" -lt 50 ]]; then echo -ne 'e[38;5;190m'
      elif [[ "$RATIO" -lt 60 ]]; then echo -ne 'e[38;5;226m'
      elif [[ "$RATIO" -lt 70 ]]; then echo -ne 'e[38;5;220m'
      elif [[ "$RATIO" -lt 80 ]]; then echo -ne 'e[38;5;214m'
      elif [[ "$RATIO" -lt 90 ]]; then echo -ne 'e[38;5;208m'
      elif [[ "$RATIO" -lt 100 ]]; then echo -ne 'e[38;5;160m'
      elif [[ "$RATIO" -eq 100 ]]; then echo -ne 'e[38;5;196m'; fi
      echo -n '*'
      echo -ne 'e[0m'
      done
      echo
      done


      invoked as ./git-heatmap --all produces a sample output as depicted below (not at a Linux machine currently, running on Windows/MinGW with the Fixedsys font, I prefer squares, u2BC0, to asterisks, but Fixedsys cannot render the squares that I find much nicer):



      ./git-heatmap --all example output



      Since the script does three jobs:



      • consumes Git weekday/hour-of-day timestamps output,

      • calculates the stats,

      • and renders the heatmap

      ... I'm wondering is there something like a standard tool that calculates/renders something similar to the heatmap above? My script processes the following sample data supplied by Git:





      100
      101
      420
      517
      ...


      where the first digit designates a weekday, and the second and the third digits designate a day hour. Thanks.







      git data





      share







      New contributor




      lsh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share







      New contributor




      lsh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share



      share






      New contributor




      lsh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 1 min ago









      lsh

      1




      1




      New contributor




      lsh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      lsh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      lsh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.

























          active

          oldest

          votes











          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );






          lsh is a new contributor. Be nice, and check out our Code of Conduct.









           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f480010%2fis-there-a-standard-text-mode-tool-to-render-heatmaps-for-arbitrary-numeric-data%23new-answer', 'question_page');

          );

          Post as a guest



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          lsh is a new contributor. Be nice, and check out our Code of Conduct.









           

          draft saved


          draft discarded


















          lsh is a new contributor. Be nice, and check out our Code of Conduct.












          lsh is a new contributor. Be nice, and check out our Code of Conduct.











          lsh is a new contributor. Be nice, and check out our Code of Conduct.













           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f480010%2fis-there-a-standard-text-mode-tool-to-render-heatmaps-for-arbitrary-numeric-data%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Bahrain

          Postfix configuration issue with fips on centos 7; mailgun relay