<commit_before>mongo = require '../mongo'

exports.collect = (req, res) ->
    if req.get('content-type').indexOf('application/json') == -1
        throw new Error("Body request is not JSON.")

    jsonData = req.body
    mongo.dataCollection.insert(
        jsonData, {w:1}, (err, collection) ->
            console.log "Request terminated"
            if err
                console.log(err)
                res.send 500
            else
                res.send 200
    )<commit_msg>Added : Create a new sensor entry when we receive data from an unknown sensor<commit_after>mongo = require '../mongo'

exports.collect = (req, res) ->
    if req.get('content-type').indexOf('application/json') == -1
        throw new Error("Body request is not JSON.")

    jsonData = req.body
    console.log "COunting sensor"
    mongo.sensorCollection.count(
        {sensor_id : jsonData.sensor_id}, (err, count) ->
            if err
                console.log(err)
                res.send 500

            else if  count < 1
                console.log "Should add sensor"
                mongo.sensorCollection.insert(
                    {sensor_id : jsonData.sensor_id}, {w:1}, (err, collection) ->
                        console.log "Request terminated"
                        console.log(err)
                )
        )
    
    mongo.dataCollection.insert(
        jsonData, {w:1}, (err, collection) ->
            console.log "Request terminated"
            if err
                console.log(err)
                res.send 500
            else
                res.send 200
    )
{'fraction_non_alphanumeric': 0.10739102969046115, 'fraction_numerical': 0.013265950726468731, 'mean_word_length': 1.5384615384615385, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 9, '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': '4602627', 'n_tokens_mistral': 453, 'n_tokens_neox': 415, 'n_words': 112}