<commit_before>/**
 * Created by rcartier13 on 3/3/14.
 */

var db = require('../dao/db');
var fs = require('fs');

var ballot = require('./mappers/ballot');
var ballotLineResult = require('./mappers/ballotLineResult');
var ballotResponse = require('./mappers/ballotResponse');
var candidate = require('./mappers/candidate');
var contest = require('./mappers/contest');
var contestResult = require('./mappers/contestResult');
var customBallot = require('./mappers/customBallot');
var evs = require('./mappers/earlyVoteSite');
var election = require('./mappers/election');
var electionAdmin = require('./mappers/electionAdmin');
var electionOfficial = require('./mappers/electionOfficial');
var district = require('./mappers/electoralDistrict');
var locality = require('./mappers/locality');
var pollingLocation = require('./mappers/pollingLocation');
var precinct = require('./mappers/precinct');
var precinctSplit = require('./mappers/precinctSplit');
var referendum = require('./mappers/referendum');
var source = require('./mappers/source');
var state = require('./mappers/state');
var streetSegment = require('./mappers/streetSegment');

var config = require('../config');
var mongoose = require('mongoose');
var schemas = require('../dao/schemas');
var moment = require('moment');

//schemas.initSchemas(mongoose);
//mongoose.connect(config.mongoose.connectionString);

function Instance() {
  return {
    once: false,
    sent: 0,
    written: 0,
    finished: false,
    streetSegmentCallback: null,
    stream: null
  }
}

var functionCalls = [
  ballot.ballotExport,
  ballotLineResult.ballotLineResultExport,
  ballotResponse.ballotResponseExport,
  candidate.candidateExport,
  contest.contestExport,
  contestResult.contestResultExport,
  customBallot.customBallotExport,
  evs.earlyVoteSitesExport,
  election.electionExport,
  electionAdmin.electionAdminExport,
  electionOfficial.electionOfficialExport,
  district.electoralDistrictExport,
  locality.localityExport,
  pollingLocation.pollingLocationExport,
  precinct.precinctExport,
  precinctSplit.precinctSplitExport,
  referendum.referendumExport,
  source.sourceExport,
  state.stateExport,
  streetSegment.streetSegmentExport
];

// test_feed:
// NC: 531dcf317ccecb5a23000004
//createXml(schemas.types.ObjectId('531dcf317ccecb5a23000004'));

function createXml(feedId, feedName, feedFolder, instance, callback) {

  if(instance.stream != null) {
    callback(400);
    return;
  }

  var dirLoc = './exported-feeds/' + feedFolder + '/';
  var fileLoc = './exported-feeds/' + feedFolder + '/' + feedName + '.xml';
  if( !fs.existsSync(dirLoc) )
    fs.mkdirSync(dirLoc);
  instance.stream = fs.createWriteStream(fileLoc); //moment().format('YYYYMMDDHHmmss') +
  callback(undefined, fileLoc)<commit_msg>updated the exporter so that if the top level directory doesnt exist it now makes it.<commit_after>/**
 * Created by rcartier13 on 3/3/14.
 */

var db = require('../dao/db');
var fs = require('fs');

var ballot = require('./mappers/ballot');
var ballotLineResult = require('./mappers/ballotLineResult');
var ballotResponse = require('./mappers/ballotResponse');
var candidate = require('./mappers/candidate');
var contest = require('./mappers/contest');
var contestResult = require('./mappers/contestResult');
var customBallot = require('./mappers/customBallot');
var evs = require('./mappers/earlyVoteSite');
var election = require('./mappers/election');
var electionAdmin = require('./mappers/electionAdmin');
var electionOfficial = require('./mappers/electionOfficial');
var district = require('./mappers/electoralDistrict');
var locality = require('./mappers/locality');
var pollingLocation = require('./mappers/pollingLocation');
var precinct = require('./mappers/precinct');
var precinctSplit = require('./mappers/precinctSplit');
var referendum = require('./mappers/referendum');
var source = require('./mappers/source');
var state = require('./mappers/state');
var streetSegment = require('./mappers/streetSegment');

var config = require('../config');
var mongoose = require('mongoose');
var schemas = require('../dao/schemas');
var moment = require('moment');

//schemas.initSchemas(mongoose);
//mongoose.connect(config.mongoose.connectionString);

function Instance() {
  return {
    once: false,
    sent: 0,
    written: 0,
    finished: false,
    streetSegmentCallback: null,
    stream: null
  }
}

var functionCalls = [
  ballot.ballotExport,
  ballotLineResult.ballotLineResultExport,
  ballotResponse.ballotResponseExport,
  candidate.candidateExport,
  contest.contestExport,
  contestResult.contestResultExport,
  customBallot.customBallotExport,
  evs.earlyVoteSitesExport,
  election.electionExport,
  electionAdmin.electionAdminExport,
  electionOfficial.electionOfficialExport,
  district.electoralDistrictExport,
  locality.localityExport,
  pollingLocation.pollingLocationExport,
  precinct.precinctExport,
  precinctSplit.precinctSplitExport,
  referendum.referendumExport,
  source.sourceExport,
  state.stateExport,
  streetSegment.streetSegmentExport
];

// test_feed:
// NC: 531dcf317ccecb5a23000004
//createXml(schemas.types.ObjectId('531dcf317ccecb5a23000004'));

function createXml(feedId, feedName, feedFolder, instance, callback) {

  if(instance.stream != null) {
    callback(400);
    return;
  }

  var firstDirLoc = './exported-feeds/';
  var dirLoc = './exported-feeds/' + feedFolder + '/';
  var fileLoc = './exported-feeds/' + feedFolder + '/' + feedName + '.xml';
  if( !fs.existsSync(firstDirLoc) )
    fs.mkdirSync(firstDirLoc);
  if( !fs.existsSync(dirLoc) )
    fs.mkdirSync(dirLoc);
  instance.stream = fs.createWriteStream(fileLoc); //moment().format('YYYYMMDDHHmmss') +
  callback(undefined, fileLoc)
{'fraction_non_alphanumeric': 0.14577513966480446, 'fraction_numerical': 0.01431564245810056, 'mean_word_length': 5.166846071044134, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '5868130', 'n_tokens_mistral': 1824, 'n_tokens_neox': 1732, 'n_words': 330}