<commit_before>$(document).ready( function(){
  var d = new Date();
  var today = d.getDay();
  var wday = d.getDay();
  var chart_bound = 'canada';
  var chart_commercial = false;
  var chart_wday = d.getDay();
  var chart_title;
  var chart_crossing;

  toggle_bound_button();

  $(".state").click(function(){
    $("body").data('state', $(this).attr('data'));
    $('.state').removeClass('active');
    $(this).addClass('active');
    filter_crossings();
  });

  $(".province").click(function(){
    $("body").data('province', $(this).attr('data'));
    $(".province").removeClass('active');
    $(this).addClass('active');
    filter_crossings();    
  });


  $(".day_select").click(function(){
    var clicked_button = $(this);
    $(".day_select").removeClass('active');
    clicked_button.addClass('active');
    chart_wday = clicked_button.attr('value');
    set_legend_text();
    requestData();
  });

  function filter_crossings(){
    var state = $("body").data('state');
    var province = $("body").data('province');
    $.get("filter_crossings", {state: state, province: province}, function(data){
      populate_crossings(data);
    });
  }


  var usa_icon = $("#us_icon");
  var canada_icon = $("#canada_icon");
  function toggle_bound_button(){
    var bound_button = $("#bound_button");
    var click_bound;
    if(chart_bound == 'canada'){
      $(".origin").html(usa_icon);
      $(".destination").html(canada_icon);
      click_bound = 'usa'
    }
    else{
      $(".origin").html(canada_icon);
      $(".destination").html(usa_icon);
      click_bound = 'canada'
    }
    bound_button.click(function(){
      bound_button.unbind();
      chart_bound = click_bound;
      requestData();
      toggle_bound_button();
    });
  };

  function set_legend_text(){
    var legend = $("#legend-recent");
    if(chart_wday == today){
      legend.text(" Today");
    }
    else{
      var weekday = $(".day_select.active").text()
      legend.text(" last "+weekday);
    }
  }

  function populate_crossings(data){
    $("#crossings").html("");
    if(data.length == 0){
      $("#crossings").append("<h4 class=\"list-group-item-heading\"> Sorry </h4> <p class=\"list-group-item-text\"> There are no crossings between this provicne and state </p> ");
    }
    $.each(data, function(i, crossing){
      var list_div = "<a href=\"#\" data-id="+crossing['id']+" class=\"list-group-item crossing-selector\">\
      <p class=\"list-group-item-text\"><b>"+crossing['title']+'</b></p>'+'<p class=\"list-group-item-text\">'+crossing['location']+"</p></a>";

      $("#crossings").append(list_div);
    });
    $(".crossing-selector").click(function(){
      $(".alert").remove();
      $('.list-group-item').removeClass('active');
      $(this).addClass("active");
      chart_crossing = $(this).data('id');
      requestData( $(this).data('id'), 'canada', false, wday);
    });
  }

  function requestData(){
    <% url = BorderTimes::Application.routes.url_helpers %>
    $.ajax({
      url: "<%= url.chart_data_path %>",
      type: "Get",
      dataType: "json",
      data: {
        bound: chart_bound, 
        id: chart_crossing,
        commercial: chart_commercial,
        wday: chart_wday
      },
      success: function(response, textStatus, xhr) {
        drawChart(response);
      }
    })
  }
  // var canvas = document.getElementById('chart');
  // var ctx = canvas.getContext("2d");
  // var chart = new Chart(ctx);

  function drawChart(response){
    d3.select("svg").selectAll("*").remove()

    var format = d3.time.format("%H"),
      bisectTime = d3.bisector(function(d) { return d; }).left;

    var chart_elem = d3.select("#chart"),
      WIDTH = $(".list-group-item")[0].offsetWidth,
      HEIGHT = 500,
      MARGINS = {
        top: 20,
        right: 20,
        bottom: 20,
        left: 50
      },

    xScale = d3.time.scale()
      .range([MARGINS.left, WIDTH - MARGINS.right])
      .domain([format.parse("0"), format.parse("23")]);
    yScale = d3.scale.linear()
      .range([HEIGHT - MARGINS.top, MARGINS.bottom])
      .domain([0,d3.max([d3.max(response.data.average), d3.max(response.data.recent)]) + 10]);

    d3.select("svg").attr("width", WIDTH).attr("height", HEIGHT)

    xAxis = d3.svg.axis().scale(xScale).ticks(12).tickFormat(d3.time.format("%I %p"));
    yAxis = d3.svg.axis().scale(yScale).orient("left").tickSize(-WIDTH, 0, 0);<commit_msg>small tweak<commit_after>$(document).ready( function(){
  var d = new Date();
  var today = d.getDay();
  var wday = d.getDay();
  var chart_bound = 'canada';
  var chart_commercial = false;
  var chart_wday = d.getDay();
  var chart_title;
  var chart_crossing;

  toggle_bound_button();

  $(".state").click(function(){
    $("body").data('state', $(this).attr('data'));
    $('.state').removeClass('active');
    $(this).addClass('active');
    filter_crossings();
  });

  $(".province").click(function(){
    $("body").data('province', $(this).attr('data'));
    $(".province").removeClass('active');
    $(this).addClass('active');
    filter_crossings();    
  });


  $(".day_select").click(function(){
    var clicked_button = $(this);
    $(".day_select").removeClass('active');
    clicked_button.addClass('active');
    chart_wday = clicked_button.attr('value');
    set_legend_text();
    requestData();
  });

  function filter_crossings(){
    var state = $("body").data('state');
    var province = $("body").data('province');
    $.get("filter_crossings", {state: state, province: province}, function(data){
      populate_crossings(data);
    });
  }


  var usa_icon = $("#us_icon");
  var canada_icon = $("#canada_icon");
  function toggle_bound_button(){
    var bound_button = $("#bound_button");
    var click_bound;
    if(chart_bound == 'canada'){
      $(".origin").html(usa_icon);
      $(".destination").html(canada_icon);
      click_bound = 'usa'
    }
    else{
      $(".origin").html(canada_icon);
      $(".destination").html(usa_icon);
      click_bound = 'canada'
    }
    bound_button.click(function(){
      bound_button.unbind();
      chart_bound = click_bound;
      requestData();
      toggle_bound_button();
    });
  };

  function set_legend_text(){
    var legend = $("#legend-recent");
    if(chart_wday == today){
      legend.text(" Today");
    }
    else{
      var weekday = $(".day_select.active").text()
      legend.text(" last "+weekday);
    }
  }

  function populate_crossings(data){
    $("#crossings").html("");
    if(data.length == 0){
      $("#crossings").append("<h4 class=\"list-group-item-heading\"> Sorry </h4> <p class=\"list-group-item-text\"> There are no crossings between this provicne and state </p> ");
    }
    $.each(data, function(i, crossing){
      var list_div = "<a href=\"#\" data-id="+crossing['id']+" class=\"list-group-item crossing-selector\">\
      <p class=\"list-group-item-text\"><b>"+crossing['title']+'</b></p>'+'<p class=\"list-group-item-text\">'+crossing['location']+"</p></a>";

      $("#crossings").append(list_div);
    });
    $(".crossing-selector").click(function(){
      $(".alert").remove();
      $('.list-group-item').removeClass('active');
      $(this).addClass("active");
      chart_crossing = $(this).data('id');
      requestData( $(this).data('id'), 'canada', false, wday);
    });
  }

  function requestData(){
    <% url = BorderTimes::Application.routes.url_helpers %>
    $.ajax({
      url: "<%= url.chart_data_path %>",
      type: "Get",
      dataType: "json",
      data: {
        bound: chart_bound, 
        id: chart_crossing,
        commercial: chart_commercial,
        wday: chart_wday
      },
      success: function(response, textStatus, xhr) {
        drawChart(response);
      }
    })
  }
  // var canvas = document.getElementById('chart');
  // var ctx = canvas.getContext("2d");
  // var chart = new Chart(ctx);

  function drawChart(response){
    d3.select("svg").selectAll("*").remove()

    var format = d3.time.format("%H"),
      bisectTime = d3.bisector(function(d) { return d; }).left;

    var chart_elem = d3.select("#chart"),
      WIDTH = $(".list-group-item")[0].offsetWidth,
      HEIGHT = 500,
      MARGINS = {
        top: 20,
        right: 20,
        bottom: 20,
        left: 50
      },

    xScale = d3.time.scale()
      .range([MARGINS.left, WIDTH - MARGINS.right])
      .domain([format.parse("0"), format.parse("23")]);
    yScale = d3.scale.linear()
      .range([HEIGHT - MARGINS.top, MARGINS.bottom])
      .domain([0,d3.max([d3.max(response.data.average), d3.max(response.data.recent)]) + 10]);

    d3.select("svg").attr("width", WIDTH).attr("height", HEIGHT)

    xAxis = d3.svg.axis().scale(xScale).ticks(12).tickFormat(d3.time.format("%I %p"));
    yAxis = d3.svg.axis().scale(yScale).orient("left").tickSize(70-WIDTH, 0, 0);
{'fraction_non_alphanumeric': 0.21080099841161787, 'fraction_numerical': 0.009076469253460404, 'mean_word_length': 3.1580188679245285, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, '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': '231235', 'n_tokens_mistral': 2978, 'n_tokens_neox': 2889, 'n_words': 484}