<commit_before>assert = null

do -> # To not pollute the namespace
  # We want to use assert everywhere on the server side
  require = __meteor_bootstrap__.require
  assert = require 'assert'

  ARXIV_DATA = 'https://github.com/peerlibrary/peerlibrary-data/raw/master/data.json'

  Meteor.startup ->
    if Meteor.users.find().count() == 0 and Publications.find().count() == 0
      console.log "Populate database with sample data"

      console.log "Populating users"

      Accounts.createUser
        email: '<EMAIL>'
        username: 'carl-sagan'
        password: '<PASSWORD>'
        profile:
          firstName: 'Carl'
          lastName: 'Sagan'
          position: 'Professor of Physics'
          institution: 'Cornell University'

      console.log "Populating publications"

      console.log "Downloading arXiv data"

      publications = Meteor.http.get ARXIV_DATA,
        timeout: 10000 # ms

      if publications.error
        throw publications.error
      else if publications.statusCode != 200
        throw new Meteor.Error 500, "Downloading failed"

      publications = JSON.parse(publications.content)

      console.log "Importing arXiv data"

      for publication in publications
        assert.equal publication.source, 'arXiv', "#{ publication.foreignId }: #{ publication.source }"

        # TODO: Map msc2010, acm1998, and foreignCategories to tags
        _.extend publication,
          tags: [publication.source]

        Publications.insert publication<commit_msg>Say when we finish importing.<commit_after>assert = null

do -> # To not pollute the namespace
  # We want to use assert everywhere on the server side
  require = __meteor_bootstrap__.require
  assert = require 'assert'

  ARXIV_DATA = 'https://github.com/peerlibrary/peerlibrary-data/raw/master/data.json'

  Meteor.startup ->
    if Meteor.users.find().count() == 0 and Publications.find().count() == 0
      console.log "Populate database with sample data"

      console.log "Populating users"

      Accounts.createUser
        email: '<EMAIL>'
        username: 'carl-sagan'
        password: '<PASSWORD>'
        profile:
          firstName: 'Carl'
          lastName: 'Sagan'
          position: 'Professor of Physics'
          institution: 'Cornell University'

      console.log "Populating publications"

      console.log "Downloading arXiv data"

      publications = Meteor.http.get ARXIV_DATA,
        timeout: 10000 # ms

      if publications.error
        throw publications.error
      else if publications.statusCode != 200
        throw new Meteor.Error 500, "Downloading failed"

      publications = JSON.parse(publications.content)

      console.log "Importing arXiv data"

      for publication in publications
        assert.equal publication.source, 'arXiv', "#{ publication.foreignId }: #{ publication.source }"

        # TODO: Map msc2010, acm1998, and foreignCategories to tags
        _.extend publication,
          tags: [publication.source]

        Publications.insert publication

      console.log "Done"
{'fraction_non_alphanumeric': 0.09186351706036745, 'fraction_numerical': 0.013779527559055118, 'mean_word_length': 2.6734939759036145, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2324171', 'n_tokens_mistral': 902, 'n_tokens_neox': 800, 'n_words': 237}