<commit_before><-- <a href="/">Start Over</a>

<hr>

<div id="date-range" class="analytic-object">
    <%= @days.start_date.strftime("%b %d %Y") %> - <%= @days.end_date.strftime("%b %d %Y") %><br>
    <span><%= @days.num_days %> days</span>
</div>

<div id="total-tweets" class="analytic-object">
    Tweets<br>
    <span><%= @days.total_tweets %></span>
</div>

<div id="total-impressions" class="analytic-object">
    Impressions<br>
    <span><%= @days.total_impressions %></span>
    <b><%= @days.impressions_per_tweet %></b> per tweet
</div>

<div id="total-engagements" class="analytic-object">
    Engagements
    <span><%= @days.total_engagements %></span>
    <b><%= @days.engagements_per_tweet %></b> per tweet
</div>

<div id="optimal-post">
    Optimal Posting Time: <b><%= @top_time %> Pacific<b>
</div>

<h3>Weekly Impressions Heatmap</h3>
<div id="chart"></div>

 <script type="text/javascript">
      var margin = { top: 50, right: 0, bottom: 100, left: 100 },
          width = 800 - margin.left - margin.right,
          height = 400 - margin.top - margin.bottom,
          gridSize = Math.floor(width / 24),
          legendElementWidth = gridSize*2,
          buckets = 5,
          colors = ["#ffffff","#edf8b1","#7fcdbb","#1d91c0","#081d58"], // alternatively colorbrewer.YlGnBu[9]
          dayNames = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
          times = ["1a", "2a", "3a", "4a", "5a", "6a", "7a", "8a", "9a", "10a", "11a", "12a", "1p", "2p", "3p", "4p", "5p", "6p", "7p", "8p", "9p", "10p", "11p", "12p"];

      d3.csv("public/<%= @stats_file %>",
        function(d) {
          return {            
            day: +d.day,
            hour: +d.hour,
            value: +d.value
          };
        },
        function(error, data) {
          var colorScale = d3.scale.quantile()
              .domain([0, buckets - 1, d3.max(data, function (d) { return d.value; })])
              .range(colors);

          var svg = d3.select("#chart").append("svg")
              .attr("width", width + margin.left + margin.right)
              .attr("height", height + margin.top + margin.bottom)
              .append("g")
              .attr("transform", "translate(" + margin.left + "," + margin.top + ")");

          var dayLabels = svg.selectAll(".dayLabel")
              .data(dayNames)
              .enter().append("text")
                .text(function (d) { return d; })
                .attr("x", 0)
                .attr("y", function (d, i) { return i * gridSize; })
                .style("text-anchor", "end")
                .attr("transform", "translate(-6," + gridSize / 1.5 + ")")
                .attr("class", function (d, i) { return ((i >= 0 && i <= 4) ? "dayLabel mono axis axis-workweek" : "dayLabel mono axis"); });

          var timeLabels = svg.selectAll(".timeLabel")
              .data(times)
              .enter().append("text")
                .text(function(d) { return d; })
                .attr("x", function(d, i) { return i * gridSize; })
                .attr("y", 0)
                .style("text-anchor", "middle")
                .attr("transform", "translate(" + gridSize / 2 + ", -6)")
                .attr("class", function(d, i) { return ((i >= 7 && i <= 16) ? "timeLabel mono axis axis-worktime" : "timeLabel mono axis"); });

          var heatMap = svg.selectAll(".hour")
              .data(data)
              .enter().append("rect")
              .attr("x", function(d) { return (d.hour - 1) * gridSize; })
              .attr("y", function(d) { return (d.day - 1) * gridSize; })
              .attr("rx", 4)
              .attr("ry", 4)
              .attr("class", "hour bordered")
              .attr("width", gridSize)
              .attr("height", gridSize)
              .style("fill", colors[0]);

          heatMap.transition().duration(1000)
              .style("fill", function(d) { return colorScale(d.value); });

          heatMap.append("title").text(function(d) { return d.value; });
              
          var legend = svg.selectAll(".legend")
              .data([0].concat(colorScale.quantiles()), function(d) { return d; })
              .enter().append("g")
              .attr("class", "legend");

          legend.append("rect")
            .attr("x", function(d, i) { return legendElementWidth * i; })
            .attr("y", height)
            .attr("width", legendElementWidth)
            .attr("height", gridSize / 2)
            .style("fill", function(d, i) { return colors[i]; });

          legend.append("text")
            .attr("class", "mono")
            .text(function(d) { return "≥ " + Math.round(d); })
            .attr("x", function(d, i) { return legendElementWidth * i; })
            .attr("y", height + gridSize);
      });
    </script>

<commit_msg>Fixing bugs in the heatmap chart to properly render the days/hour headings and aligning the boxes with weekdays and work hours<commit_after><-- <a href="/">Start Over</a>

<hr>

<div id="date-range" class="analytic-object">
    <%= @days.start_date.strftime("%b %d %Y") %> - <%= @days.end_date.strftime("%b %d %Y") %><br>
    <span><%= @days.num_days %> days</span>
</div>

<div id="total-tweets" class="analytic-object">
    Tweets<br>
    <span><%= @days.total_tweets %></span>
</div>

<div id="total-impressions" class="analytic-object">
    Impressions<br>
    <span><%= @days.total_impressions %></span>
    <b><%= @days.impressions_per_tweet %></b> per tweet
</div>

<div id="total-engagements" class="analytic-object">
    Engagements
    <span><%= @days.total_engagements %></span>
    <b><%= @days.engagements_per_tweet %></b> per tweet
</div>

<div id="optimal-post">
    Optimal Posting Time: <b><%= @top_time %> Pacific<b>
</div>

<h3>Weekly Impressions Heatmap</h3>
<div id="chart"></div>

 <script type="text/javascript">
      var margin = { top: 50, right: 0, bottom: 100, left: 100 },
          width = 800 - margin.left - margin.right,
          height = 400 - margin.top - margin.bottom,
          gridSize = Math.floor(width / 24),
          legendElementWidth = gridSize*2,
          buckets = 5,
          colors = ["#ffffff","#edf8b1","#7fcdbb","#1d91c0","#081d58"], // alternatively colorbrewer.YlGnBu[9]
          dayNames = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
          times = ["12a", "1a", "2a", "3a", "4a", "5a", "6a", "7a", "8a", "9a", "10a", "11a", "12p", "1p", "2p", "3p", "4p", "5p", "6p", "7p", "8p", "9p", "10p", "11p"];

      d3.csv("public/<%= @stats_file %>",
        function(d) {
          return {            
            day: +d.day,
            hour: +d.hour,
            value: +d.value
          };
        },
        function(error, data) {
          var colorScale = d3.scale.quantile()
              .domain([0, buckets - 1, d3.max(data, function (d) { return d.value; })])
              .range(colors);

          var svg = d3.select("#chart").append("svg")
              .attr("width", width + margin.left + margin.right)
              .attr("height", height + margin.top + margin.bottom)
              .append("g")
              .attr("transform", "translate(" + margin.left + "," + margin.top + ")");

          var dayLabels = svg.selectAll(".dayLabel")
              .data(dayNames)
              .enter().append("text")
                .text(function (d) { return d; })
                .attr("x", 0)
                .attr("y", function (d, i) { 
                  return i * gridSize; 
                })
                .style("text-anchor", "end")
                .attr("transform", "translate(-6," + gridSize / 1.5 + ")")
                .attr("class", function (d, i) { return ((i >= 1 && i <= 5) ? "dayLabel mono axis axis-workweek" : "dayLabel mono axis"); });

          var timeLabels = svg.selectAll(".timeLabel")
              .data(times)
              .enter().append("text")
                .text(function(d) { return d; })
                .attr("x", function(d, i) { 
                  return i * gridSize; 
                })
                .attr("y", 0)
                .style("text-anchor", "middle")
                .attr("transform", "translate(" + gridSize / 2 + ", -6)")
                .attr("class", function(d, i) { return ((i >= 8 && i <= 18) ? "timeLabel mono axis axis-worktime" : "timeLabel mono axis"); });

          var heatMap = svg.selectAll(".hour")
              .data(data)
              .enter().append("rect")
              .attr("x", function(d) { return (d.hour - 1) * gridSize + gridSize; })
              .attr("y", function(d) { return (d.day - 1) * gridSize + gridSize; })
              .attr("rx", 4)
              .attr("ry", 4)
              .attr("class", "hour bordered")
              .attr("width", gridSize)
              .attr("height", gridSize)
              .style("fill", colors[0]);

          heatMap.transition().duration(1000)
              .style("fill", function(d) { return colorScale(d.value); });

          heatMap.append("title").text(function(d) { return d.value; });
              
          var legend = svg.selectAll(".legend")
              .data([0].concat(colorScale.quantiles()), function(d) { return d; })
              .enter().append("g")
              .attr("class", "legend");

          legend.append("rect")
            .attr("x", function(d, i) { return legendElementWidth * i; })
            .attr("y", height)
            .attr("width", legendElementWidth)
            .attr("height", gridSize / 2)
            .style("fill", function(d, i) { return colors[i]; });

          legend.append("text")
            .attr("class", "mono")
            .text(function(d) { return "≥ " + Math.round(d); })
            .attr("x", function(d, i) { return legendElementWidth * i; })
            .attr("y", height + gridSize);
      });
    </script>


{'fraction_non_alphanumeric': 0.19995912945744354, 'fraction_numerical': 0.019004802288750382, 'mean_word_length': 1.9642640823743185, 'pattern_counts': {'":': 0, '<': 101, '<?xml version=': 0, '>': 99, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3255665', 'n_tokens_mistral': 3350, 'n_tokens_neox': 3118, 'n_words': 688}