<commit_before>var verbose_logging = (process.env.NODE_ENV !== "production");
var models  = require("../../models");
var express = require("express");
var router = express.Router();
var querystring = require("querystring");
var fs = require("fs");
var passport = require("passport");
passport.use(require("../../middleware/auth/passport-token.js").TokenStrategy);

router.route("/:guardian_id/checkins/:checkin_id/audio/:audio_id")
  .post(passport.authenticate("token",{session:false}), function(req, res) {

    models.Guardian
      .findOne( { where: { guid: req.params.guardian_id } })
      .then(function(dbGuardian){

        models.GuardianCheckIn
          .findOne( { where: { guid: req.params.checkin_id } })
          .then(function(dbCheckIn){

            models.GuardianAudio
              .findOne( { where: { guid: req.params.audio_id } })
              .then(function(dbAudio){

                dbAudio.analyzed_at = new Date();
                dbAudio.save();

                // This is not ideal... currently the python-based analysis sends a JSON array of detected events
                // in a separate text file. This file must thereby be downloaded into the temporary uploads directory
                // and then opened, parsed, and deleted afterward. It would obviously be better to have this same
                // JSON array sent along as a string in a POST field instead.
                fs.readFile(req.files.json.path, 'utf8', function(readFileError, data) {
                  if (readFileError) throw readFileError;
                  
                  var audioEvents = JSON.parse(data);

                  fs.unlink(req.files.json.path,function(e){if(e){console.log(e);}});

                  if (audioEvents.length > 0) {
                    console.log(audioEvents.length+" events to be saved...");
                    var savedEvents = [];<commit_msg>quotations update<commit_after>var verbose_logging = (process.env.NODE_ENV !== "production");
var models  = require("../../models");
var express = require("express");
var router = express.Router();
var querystring = require("querystring");
var fs = require("fs");
var passport = require("passport");
passport.use(require("../../middleware/auth/passport-token.js").TokenStrategy);

router.route("/:guardian_id/checkins/:checkin_id/audio/:audio_id")
  .post(passport.authenticate("token",{session:false}), function(req, res) {

    models.Guardian
      .findOne( { where: { guid: req.params.guardian_id } })
      .then(function(dbGuardian){

        models.GuardianCheckIn
          .findOne( { where: { guid: req.params.checkin_id } })
          .then(function(dbCheckIn){

            models.GuardianAudio
              .findOne( { where: { guid: req.params.audio_id } })
              .then(function(dbAudio){

                dbAudio.analyzed_at = new Date();
                dbAudio.save();

                // This is not ideal... currently the python-based analysis sends a JSON array of detected events
                // as a separate text file. This file must therefore be downloaded into the temporary uploads directory
                // and then opened, parsed, and deleted afterward. It would obviously be better to have this same
                // JSON array sent along as a string in a POST field instead.
                fs.readFile(req.files.json.path, "utf8", function(readFileError, data) {
                  if (readFileError) throw readFileError;
                  
                  var audioEvents = JSON.parse(data);

                  fs.unlink(req.files.json.path,function(e){if(e){console.log(e);}});

                  if (audioEvents.length > 0) {
                    console.log(audioEvents.length+" events to be saved...");
                    var savedEvents = [];
{'fraction_non_alphanumeric': 0.12717678100263852, 'fraction_numerical': 0.0010554089709762533, 'mean_word_length': 2.285095320623917, 'pattern_counts': {'":': 0, '<': 3, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '114129', 'n_tokens_mistral': 1047, 'n_tokens_neox': 992, 'n_words': 261}