<commit_before>// construct query string
var params = d3.select("h1#api_key");
if (!params.empty()) {
  var api_key = params.attr('data-api_key');
  var uid_type = params.attr('data-uid_type');
  var uid = params.attr('data-uid');
  var query = encodeURI("/api/v5/articles?api_key=" + api_key + "&ids=" + uid + "&type=" + uid_type + "&info=detail");
}

// load the data from the ALM API
if (query) {
  d3.json(query, function(error, json) {
    if (error) return console.warn(error);

    eventViz(json);
  });
}

// add data to page
function eventViz(json) {
  d3.select("#loading-events").remove();

  var data = json['data'][0]['sources'];
  data = data.map( function(d) { return d.events_csl });
  data = d3.merge(data);

  if (data.length == 0) {
    d3.select("#results").text("")
      .insert("div")
      .attr("class", "alert alert-info")
      .text("No events found");
    return;
  }

  // generate iso8601 datetime for sorting, year for nesting
  data = data.map(function(d) {
    d["date"] = datePartsToDate(d["issued"]["date_parts"]);
    d["year"] = (d["date"]) ? d["date"].getUTCFullYear() : null;
    return d;
  });

  data = data.filter(function(d) { return d.year !== null });

  var page = 1;
  showEvents(data, page);
};

function showEvents(data, page) {
  data = data.sort(function(a, b) { return d3.descending(a.date, b.date); });

  var per_page = 50;
  var start = (page - 1) * per_page;
  var end = start + per_page;
  var paged_data = data.slice(start, end);

  d3.select("#results").html("");

  var nest_by_year = d3.nest()
    .key(function(d) { return d.year; })
    .sortKeys(d3.descending)
    .sortValues(function(a, b) { return d3.descending(a.date, b.date); })
    .entries(paged_data);

  for (var i=0; i<nest_by_year.length; i++) {
    year = nest_by_year[i];

    d3.select("#results").append("h2")
      .append("text")
      .text(year.key);

    for (var j=0; j<year.values.length; j++) {
      event = year.values[j];
      var event_text =
        (event["author"].length > 0 ? formattedAuthor(event["author"]) + ". " : "") +
        (event["container-title"].length > 0 ? "<em>" + event["container-title"] + "</em>. " : "") +
        formattedType(event["type"]) + ". " +
        formattedDate(event["date"], event["issued"]["date_parts"].length)  + ". ";

      d3.select("#results").append("h4")
        .attr("class", "article text discussed")
        .append("text")
        .html(event["title"]);
      d3.select("#results").append("p")
        .html(event_text)
        .append("a")
        .attr("href", function(d) { return event["url"]; })
        .append("text")
        .text(event["url"]);
    };
  };

  paginate(data, page);
};<commit_msg>ALM-679 color events based on group<commit_after>// construct query string
var params = d3.select("h1#api_key");
if (!params.empty()) {
  var api_key = params.attr('data-api_key');
  var uid_type = params.attr('data-uid_type');
  var uid = params.attr('data-uid');
  var query = encodeURI("/api/v5/articles?api_key=" + api_key + "&ids=" + uid + "&type=" + uid_type + "&info=detail");
}

// load the data from the ALM API
if (query) {
  d3.json(query, function(error, json) {
    if (error) return console.warn(error);

    eventViz(json);
  });
}

// add data to page
function eventViz(json) {
  d3.select("#loading-events").remove();

  var data = json['data'][0]['sources'];
  data = data.map( function(d) { return d.events_csl });
  data = d3.merge(data);

  if (data.length == 0) {
    d3.select("#results").text("")
      .insert("div")
      .attr("class", "alert alert-info")
      .text("No events found");
    return;
  }

  // generate iso8601 datetime for sorting, year for nesting
  data = data.map(function(d) {
    d["date"] = datePartsToDate(d["issued"]["date_parts"]);
    d["year"] = (d["date"]) ? d["date"].getUTCFullYear() : null;
    return d;
  });

  data = data.filter(function(d) { return d.year !== null });

  var page = 1;
  showEvents(data, page);
};

function showEvents(data, page) {
  data = data.sort(function(a, b) { return d3.descending(a.date, b.date); });

  var per_page = 50;
  var start = (page - 1) * per_page;
  var end = start + per_page;
  var paged_data = data.slice(start, end);

  d3.select("#results").html("");

  var nest_by_year = d3.nest()
    .key(function(d) { return d.year; })
    .sortKeys(d3.descending)
    .sortValues(function(a, b) { return d3.descending(a.date, b.date); })
    .entries(paged_data);

  for (var i=0; i<nest_by_year.length; i++) {
    year = nest_by_year[i];

    d3.select("#results").append("h2")
      .append("text")
      .text(year.key);

    for (var j=0; j<year.values.length; j++) {
      var event = year.values[j];
      var event_text =
        (event["author"].length > 0 ? formattedAuthor(event["author"]) + ". " : "") +
        (event["container-title"].length > 0 ? "<em>" + event["container-title"] + "</em>. " : "") +
        formattedType(event["type"]) + ". " +
        formattedDate(event["date"], event["issued"]["date_parts"].length)  + ". ";

      var sel_title = d3.select("#results").append("h4")
        .attr("class", "article")
        .append("text")
        .html(event["title"]);
      var sel_text = d3.select("#results").append("p")
        .html(event_text)
        .append("a")
        .attr("href", function(d) { return event["url"]; })
        .append("text")
        .text(event["url"]);

      sel_title.classed('text discussed', true);
    };
  };

  paginate(data, page);
};
{'fraction_non_alphanumeric': 0.2074235807860262, 'fraction_numerical': 0.011826783114992722, 'mean_word_length': 3.161241483724451, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '7472610', 'n_tokens_mistral': 1991, 'n_tokens_neox': 1935, 'n_words': 387}