<commit_before>var application_root = __dirname,
    express = require("express"),
    path = require("path"),
    mongoose = require('mongoose'),
    bodyParser = require('body-parser'),
    methodOverride = require('method-override'),
    morgan = require('morgan');

mongoose.Promise = require('bluebird');



var app = express();

// database
console.log("Connecting to db...");
mongoose.connect(process.env.MONGO);

// config
app.use(bodyParser.json());
app.use(methodOverride());
app.use(express.static(path.join(application_root, "public")));
app.use(clientErrorHandler);
app.use(errorHandler);
app.use(morgan('combined'));


var Schema = mongoose.Schema; //Schema.ObjectId

// Schemas

var Advisors = new Schema({
    name: { type: String, required: [true, "Must have a name"] },
    status: { 
        type: String, 
        required: [true, "Must have a status"], 
        enum: ["Busy", "Available", "Unavailable"] ,
        default: "Unavailable"
      },
    turnOverRate: { type: Number },
    avgPerHour: { type: Number },
    modified: { type: Date, default: Date.now }
});

var AdvisorModel = mongoose.model('Advisor', Advisors);

var Students = new Schema({
    name: { 
      type: String, 
      required: [true, "Must have a student name"],
      min: 2,
      max: 50
    },
    phoneNumber: { 
      type: Number, 
      validate: function(phoneNumber) { return phoneNumber.length == 10 }
    },
    studenId: { type: Number, required: [true, "Student ID is required"] },
    modified: { type: Date, default: Date.now }
});


// Appoinments Model
var Appointment = new Schema({
    description: { 
      type: String, 
      required: [true, 'Description required'],
      min: 5,
      max: 100
    },
    student: [Students],
    advisorId: { 
      type: String, 
      required: [true, 'Advisor required for appoinment'],
      validate: {
          validator: function(advisorId) {
            var promise = AdvisorModel.findById(advisorId).exec();
            promise.then(function(advisor) {
              return advisor.status == 'Available' || advisor.satus == 'Busy';
            })
            .catch(function(err) {
              return false;
           })},
          message : '{VALUE} is not a valid advisor!'
        }
    },
    state: { 
      type: String,
      enum: ['Waiting', 'In Progress', 'done'],
      default: 'Waiting',
    },
    type: { 
        type: String, 
        enum: ['Advising', 'Drop', 'Other'],
        required: 'Wrong Appointment Type or No appoinment Type'
    },
    extraInfo: { type: String },
    position: { type: Number, default: -1 },
    modified: { type: Date, default: Date.now }
});


var AppointmentModel = mongoose.model('Appointment', Appointment);

/* Appoinment Document 
{  
  "description": "I need to DROP",    
  "type": "Drop",
  "student": [{
    "name": "<NAME>",
    "studenId": 10005959
  }],
  "advisorId" : "5833af88321f5f26ccd9231b",
  "extraInfo": "Hey, where is Dr. Beckers office?"
}
*/

/* Advisor Document
    {
        "name": "Barach",
        "status": "Busy"
    }
*/


// Queue stuff
console.log("Initializing queue...");
var queue = [];

var promise = AppointmentModel.find().exec() 

promise.then(function(appoinments) {
  console.log("Saved queue");
  console.log(appoinments);
  for(var i = 0; i < appoinments.length; i++) {
    var pos = appoinments[i].position;
    queue[pos] = appoinments[i];
  }
})
.catch(function(err) {
  console.log(err);
  console.log("Could not recover stored state");
});

function dequeue_app(idx) {<commit_msg>fixed queue restroing to only restore active apps<commit_after>var application_root = __dirname,
    express = require("express"),
    path = require("path"),
    mongoose = require('mongoose'),
    bodyParser = require('body-parser'),
    methodOverride = require('method-override'),
    morgan = require('morgan');

mongoose.Promise = require('bluebird');



var app = express();

// database
console.log("Connecting to db...");
mongoose.connect(process.env.MONGO);

// config
app.use(bodyParser.json());
app.use(methodOverride());
app.use(express.static(path.join(application_root, "public")));
app.use(clientErrorHandler);
app.use(errorHandler);
app.use(morgan('combined'));


var Schema = mongoose.Schema; //Schema.ObjectId

// Schemas

var Advisors = new Schema({
    name: { type: String, required: [true, "Must have a name"] },
    status: { 
        type: String, 
        required: [true, "Must have a status"], 
        enum: ["Busy", "Available", "Unavailable"] ,
        default: "Unavailable"
      },
    turnOverRate: { type: Number },
    avgPerHour: { type: Number },
    modified: { type: Date, default: Date.now }
});

var AdvisorModel = mongoose.model('Advisor', Advisors);

var Students = new Schema({
    name: { 
      type: String, 
      required: [true, "Must have a student name"],
      min: 2,
      max: 50
    },
    phoneNumber: { 
      type: Number, 
      validate: function(phoneNumber) { return phoneNumber.length == 10 }
    },
    studenId: { type: Number, required: [true, "Student ID is required"] },
    modified: { type: Date, default: Date.now }
});


// Appoinments Model
var Appointment = new Schema({
    description: { 
      type: String, 
      required: [true, 'Description required'],
      min: 5,
      max: 100
    },
    student: [Students],
    advisorId: { 
      type: String, 
      required: [true, 'Advisor required for appoinment'],
      validate: {
          validator: function(advisorId) {
            var promise = AdvisorModel.findById(advisorId).exec();
            promise.then(function(advisor) {
              return advisor.status == 'Available' || advisor.satus == 'Busy';
            })
            .catch(function(err) {
              return false;
           })},
          message : '{VALUE} is not a valid advisor!'
        }
    },
    state: { 
      type: String,
      enum: ['Waiting', 'In Progress', 'Done'],
      default: 'Waiting',
    },
    type: { 
        type: String, 
        enum: ['Advising', 'Drop', 'Other'],
        required: 'Wrong Appointment Type or No appoinment Type'
    },
    extraInfo: { type: String },
    position: { type: Number, default: -1 },
    modified: { type: Date, default: Date.now }
});


var AppointmentModel = mongoose.model('Appointment', Appointment);

/* Appoinment Document 
{  
  "description": "I need to DROP",    
  "type": "Drop",
  "student": [{
    "name": "<NAME>",
    "studenId": 10005959
  }],
  "advisorId" : "5833af88321f5f26ccd9231b",
  "extraInfo": "Hey, where is Dr. Beckers office?"
  "state": "Waiting" ( optional or for updates)
}
*/

/* Advisor Document
    {
        "name": "Barach",
        "status": "Busy"
    }
*/


// Queue stuff
console.log("Initializing queue...");
var queue = [];

var promise = AppointmentModel.find().exec() 

promise.then(function(appoinments) {
  console.log("Saved queue");
  console.log(appoinments);
  for(var i = 0; i < appoinments.length; i++) {
    if(appoinment.state !== "Done") {
      var pos = appoinments[i].position;
      queue[pos] = appoinments[i];
    }
  }
})
.catch(function(err) {
  console.log(err);
  console.log("Could not recover stored state");
});

function dequeue_app(idx) {
{'fraction_non_alphanumeric': 0.15768380320619127, 'fraction_numerical': 0.009673852957435046, 'mean_word_length': 2.8069437138348237, 'pattern_counts': {'":': 17, '<': 7, '<?xml version=': 0, '>': 5, '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': '5534324', 'n_tokens_mistral': 2364, 'n_tokens_neox': 2281, 'n_words': 565}