<commit_before>mongoose = require('mongoose')
Section = require('./section.coffee').schema
async = require('async')

reportSchema = mongoose.Schema(
  title: String
  brief: String
  period: String
  sections: [Section]
)

reportSchema.statics.findFatReport = (id, callback) ->
  Section = require('./section.coffee').model
  Narrative = require('./narrative.coffee').model
  Visualisation = require('./visualisation.coffee').model

  # Make ID object consistent
  if typeof id == 'object' && id.constructor.name != "ObjectID"
    id = id._id

  Report
    .findOne(_id: id)
    .populate('sections.indicator')
    .exec( (err, report) ->
      if err?
        console.log "error populating report"
        return callback(err, null)

      report = report.toObject()
      fetchResultFunctions = []
      for theSection, theIndex in report.sections
        (->
          index = theIndex
          section = theSection
          fetchResultFunctions.push (callback) -><commit_msg>Throw an error for missing reports<commit_after>mongoose = require('mongoose')
Section = require('./section.coffee').schema
async = require('async')

reportSchema = mongoose.Schema(
  title: String
  brief: String
  period: String
  sections: [Section]
)

reportSchema.statics.findFatReport = (id, callback) ->
  Section = require('./section.coffee').model
  Narrative = require('./narrative.coffee').model
  Visualisation = require('./visualisation.coffee').model

  # Make ID object consistent
  if typeof id == 'object' && id.constructor.name != "ObjectID"
    id = id._id

  Report
    .findOne(_id: id)
    .populate('sections.indicator')
    .exec( (err, report) ->
      if err?
        console.log "error populating report"
        return callback(err, null)

      unless report?
        return callback({message: "Report does not exist"}, {})

      report = report.toObject()
      fetchResultFunctions = []
      for theSection, theIndex in report.sections
        (->
          index = theIndex
          section = theSection
          fetchResultFunctions.push (callback) ->
{'fraction_non_alphanumeric': 0.12614789753504108, 'fraction_numerical': 0.0, 'mean_word_length': 3.027237354085603, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1976694', 'n_tokens_mistral': 596, 'n_tokens_neox': 585, 'n_words': 147}