<commit_before>import moment from 'moment';

function sort_events_by_duration(eventlist){
  eventlist.sort(function(a,b){
    if (a['duration'] < b['duration'])
      return 1;
    else
      return -1;
  });
}

function parse_chunks_to_apps(chunks) {
  /*
    This code is ugly and somewhat complex, will hopefully be moved to aw-server in the future
  */
  var applist = [];
  for (var app in chunks){
    var titlelist = [];
    var titles = chunks[app]["keyvals"]["title"]["values"];
    console.log(titles)
    for (var title in titles){
      titlelist.push({
        "title": title,
        "duration": titles[title]["duration"]["value"],
      })
    }
    sort_events_by_duration(titlelist);
    console.log(titlelist);
    applist.push({
      "name": app,
      "duration": chunks[app]["duration"]["value"],
    })
  }
  sort_events_by_duration(applist);<commit_msg>Fix for events without a duration<commit_after>import moment from 'moment';

function sort_events_by_duration(eventlist){
  eventlist.sort(function(a,b){
    if (a['duration'] < b['duration'])
      return 1;
    else
      return -1;
  });
}

function parse_chunks_to_apps(chunks) {
  /*
    This code is ugly and somewhat complex, will hopefully be moved to aw-server in the future
  */
  var applist = [];
  for (var app in chunks){
    var titlelist = [];
    var titles = chunks[app]["keyvals"]["title"]["values"];
    for (var title in titles){
      var t = { "title": title };
      if ("duration" in titles[title])
        t["duration"] = titles[title]["duration"]["value"];
      titlelist.push(t);
    }
    sort_events_by_duration(titlelist);
    var a = { "name": app };
    if ("duration" in chunks[app])
      a["duration"] = chunks[app]["duration"]["value"]
    applist.push(a);
  }
  sort_events_by_duration(applist);
{'fraction_non_alphanumeric': 0.15350635008282718, 'fraction_numerical': 0.0022087244616234127, 'mean_word_length': 3.334928229665072, 'pattern_counts': {'":': 6, '<': 5, '<?xml version=': 0, '>': 3, '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': '5417468', 'n_tokens_mistral': 578, 'n_tokens_neox': 589, 'n_words': 142}