<commit_before>// Building and returning the downloads objects.
// Currently returns only for download selection using dataset IDs.
var db = require('../../../database/pgp_db');
var pgp = db.$config.pgp;

const {
  sql, getparam, ifUndef
} = require('../../../src/neotomaapi.js');

const downloadsql = sql('../v2.0/helpers/download/downloadbydsid.sql');

function getdefault (chron) {
  function quickrank (chronrank) {
    let chronorder = [{ 'order': 1, 'agetype': 'Calendar years BP' },
      { 'order': 2, 'agetype': 'Calendar years AD/BC' },
      { 'order': 3, 'agetype': 'Calibrated radiocarbon years BP' },
      { 'order': 4, 'agetype': 'Varve years BP' },
      { 'order': 5, 'agetype': 'Radiocarbon years BP' }]

    const rank = chronorder.map(x => x['agetype']).indexOf(chronrank['chronology']['chronology']['modelagetype'])

    return chronorder[rank]['order']
  }

  var chrons = chron
    .filter(x => {
      try {
        return x['chronology']['chronology']['isdefault']
      } catch (error) {
        return false
      }
    })
    .sort((ela, elb) => quickrank(ela) > quickrank(elb))

  if (chrons.length === 0) {
    return null;
  } else {
    return chrons[0]['chronology']['chronologyid'];
  }
}

function downloadbyid (req, res, next) {
  let paramgrab = getparam(req)
  if (!paramgrab.success) {
    res.status(500)
      .json({
        status: 'failure',
        data: null,
        message: paramgrab.message
      });
  } else {
    var resultset = paramgrab.data

    var outobj = {
      'datasetid': ifUndef(resultset.datasetid, 'sep'),
      'offset': ifUndef(resultset.offset, 'int'),
      'limit': ifUndef(resultset.limit, 'int')
    };
    console.log(outobj)

    if (outobj.datasetid === null) {
      res.status(500)
        .json({
          status: 'failure',
          data: null,
          message: 'Must pass either queries or a comma separated integer sequence.'
        });
    } else {<commit_msg>Removed one console log.<commit_after>// Building and returning the downloads objects.
// Currently returns only for download selection using dataset IDs.
var db = require('../../../database/pgp_db');
var pgp = db.$config.pgp;

const {
  sql, getparam, ifUndef
} = require('../../../src/neotomaapi.js');

const downloadsql = sql('../v2.0/helpers/download/downloadbydsid.sql');

function getdefault (chron) {
  function quickrank (chronrank) {
    let chronorder = [{ 'order': 1, 'agetype': 'Calendar years BP' },
      { 'order': 2, 'agetype': 'Calendar years AD/BC' },
      { 'order': 3, 'agetype': 'Calibrated radiocarbon years BP' },
      { 'order': 4, 'agetype': 'Varve years BP' },
      { 'order': 5, 'agetype': 'Radiocarbon years BP' }]

    const rank = chronorder.map(x => x['agetype']).indexOf(chronrank['chronology']['chronology']['modelagetype'])

    return chronorder[rank]['order']
  }

  var chrons = chron
    .filter(x => {
      try {
        return x['chronology']['chronology']['isdefault']
      } catch (error) {
        return false
      }
    })
    .sort((ela, elb) => quickrank(ela) > quickrank(elb))

  if (chrons.length === 0) {
    return null;
  } else {
    return chrons[0]['chronology']['chronologyid'];
  }
}

function downloadbyid (req, res, next) {
  let paramgrab = getparam(req)
  if (!paramgrab.success) {
    res.status(500)
      .json({
        status: 'failure',
        data: null,
        message: paramgrab.message
      });
  } else {
    var resultset = paramgrab.data

    var outobj = {
      'datasetid': ifUndef(resultset.datasetid, 'sep'),
      'offset': ifUndef(resultset.offset, 'int'),
      'limit': ifUndef(resultset.limit, 'int')
    };

    if (outobj.datasetid === null) {
      res.status(500)
        .json({
          status: 'failure',
          data: null,
          message: 'Must pass either queries or a comma separated integer sequence.'
        });
    } else {
{'fraction_non_alphanumeric': 0.16722408026755853, 'fraction_numerical': 0.007718034473887317, 'mean_word_length': 2.7710960232783703, 'pattern_counts': {'":': 0, '<': 3, '<?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': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4020650', 'n_tokens_mistral': 1304, 'n_tokens_neox': 1243, 'n_words': 308}