<commit_before>get '/organizations/:id.zip' do
  204
end
get '/organizations/:id.txt' do
  204
end

get '/organizations/:id/map' do
  content_type 'application/json'

  JSON.dump({
    # @todo
  })
end

get '/organizations/:id/chart' do
  content_type 'application/json'

  JSON.dump({
    # @todo
  })
end

# @drupal Load node from Drupal.
get '/organizations/:id' do
  content_type 'application/json'

  result = connection[:organizations].find(_id: params[:id]).first

  # Some sites may not have any dates, making sites not comparable.
  site_ids = result['site_ids'].select{|site| site['date_first_cited'] || site['date_last_cited']}

  site_first = site_ids.min do |a,b|
    [a['date_first_cited'].try(:[], 'value'), a['date_last_cited'].try(:[], 'value')].reject(&:nil?).min <=>
    [b['date_first_cited'].try(:[], 'value'), b['date_last_cited'].try(:[], 'value')].reject(&:nil?).min
  end
  site_last = site_ids.max do |a,b|
    [a['date_first_cited'].try(:[], 'value'), a['date_last_cited'].try(:[], 'value')].reject(&:nil?).max <=>
    [b['date_first_cited'].try(:[], 'value'), b['date_last_cited'].try(:[], 'value')].reject(&:nil?).max
  end

  events = connection[:events].find({'perpetrator_organization_id.value' => result['_id']})
  children = connection[:organizations].find({'parent_ids.id.value' => result['_id']})
  commanders = []
  people = []

  # @todo Fake it until you can make it.
  if events.count.zero?
    events = [connection[:events].find({'perpretrator_name.value' => {'$exists' => true}}).first]
  end

  members = connection[:people].find({
    'memberships.organization_id.value' => result['_id'],
  })

  members.each do |member|
    member['memberships'].each do |membership|
      if membership['organization_id']['value'] == result['_id']
        item = {
          "id" => member['_id'],
          "name" => member['name'].try(:[], 'value'),
          "other_names" => member['other_names'].try(:[], 'value'),
          # @drupal Add events_count calculated field, equal to the events related to an organization during the membership of the person.
          "events_count" => 12, # @hardcoded
          "date_first_cited" => membership['date_first_cited'].try(:[], 'value'),
          "date_last_cited" => membership['date_last_cited'].try(:[], 'value'),
          "sources" => membership['organization_id']['sources'],
          "confidence" => membership['organization_id']['confidence'],
        }
        if membership['role'].try(:[], 'value') == 'Commander'
          commanders << item
        else
          people << item
        end<commit_msg>revert last commit<commit_after>get '/organizations/:id.zip' do
  204
end
get '/organizations/:id.txt' do
  204
end

get '/organizations/:id/map' do
  content_type 'application/json'

  JSON.dump({
    # @todo
  })
end

get '/organizations/:id/chart' do
  content_type 'application/json'

  JSON.dump({
    # @todo
  })
end

# @drupal Load node from Drupal.
get '/organizations/:id' do
  content_type 'application/json'

  result = connection[:organizations].find(_id: params[:id]).first

  # Some sites may not have any dates, making sites not comparable.
  site_ids = result['site_ids'].select{|site| site['date_first_cited'] || site['date_last_cited']}

  site_first = site_ids.min do |a,b|
    [a['date_first_cited'].try(:[], 'value'), a['date_last_cited'].try(:[], 'value')].reject(&:nil?).min <=>
    [b['date_first_cited'].try(:[], 'value'), b['date_last_cited'].try(:[], 'value')].reject(&:nil?).min
  end
  site_last = site_ids.max do |a,b|
    [a['date_first_cited'].try(:[], 'value'), a['date_last_cited'].try(:[], 'value')].reject(&:nil?).max <=>
    [b['date_first_cited'].try(:[], 'value'), b['date_last_cited'].try(:[], 'value')].reject(&:nil?).max
  end

  events = connection[:events].find({'perpetrator_organization_id.value' => result['_id']})
  children = connection[:organizations].find({'parent_ids.id.value' => result['_id']})
  commanders = []
  people = []

  # @todo Fake it until you can make it.
  if events.count.zero?
    events = [connection[:events].find.first]
  end

  members = connection[:people].find({
    'memberships.organization_id.value' => result['_id'],
  })

  members.each do |member|
    member['memberships'].each do |membership|
      if membership['organization_id']['value'] == result['_id']
        item = {
          "id" => member['_id'],
          "name" => member['name'].try(:[], 'value'),
          "other_names" => member['other_names'].try(:[], 'value'),
          # @drupal Add events_count calculated field, equal to the events related to an organization during the membership of the person.
          "events_count" => 12, # @hardcoded
          "date_first_cited" => membership['date_first_cited'].try(:[], 'value'),
          "date_last_cited" => membership['date_last_cited'].try(:[], 'value'),
          "sources" => membership['organization_id']['sources'],
          "confidence" => membership['organization_id']['confidence'],
        }
        if membership['role'].try(:[], 'value') == 'Commander'
          commanders << item
        else
          people << item
        end
{'fraction_non_alphanumeric': 0.19599455570678592, 'fraction_numerical': 0.003111024693758507, 'mean_word_length': 3.852830188679245, 'pattern_counts': {'":': 0, '<': 15, '<?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': '5354919', 'n_tokens_mistral': 1703, 'n_tokens_neox': 1680, 'n_words': 333}