<commit_before>import {map} from "bluebird";
import flattendeep from "lodash.flattendeep";
import isequal from "lodash.isequal";
import moment from "moment";

import log from "../services/logger";
import {dispatch} from "../services/dispatcher";
import {findVirtualSensor, findSensorAggregate} from "../services/mongodb";

export async function replySensorMeasurements (decoratedSensor) {
    log.info({
        decoratedSensor
    });

    var sensors = await findVirtualSensor({_id: decoratedSensor.id});
    log.info({sensors});

    if (sensors) {
        var formulas = findFormulasDelta(decoratedSensor, sensors);
        log.info({formulas});

        const aggregatesByFormula = retrieveSensorData(formulas);

        await map(aggregatesByFormula, async (aggregateByFormula) => {

            log.debug({
                ids: aggregateByFormula.ids
            });

            const sensorsData = await findSensorAggregate({
                _id: {
                    $in: aggregateByFormula.ids
                }
            });

            log.info({sensorsData});

            await map(sensorsData, async (sensorData) => {

                const splittedValues = sensorData.measurementValues.split(",").filter(x => x);
                const splittedTimes = sensorData.measurementTimes.split(",").filter(x => x);

                await map(splittedValues, async (value, index) => {
                    const timestamp = splittedTimes[index];

                    const kinesisEvent = createKinesisEvent(sensorData, value, timestamp);

                    await dispatch("element inserted in collection readings", kinesisEvent);
                }, {concurrency: 0});
            });
        }, {concurrency: 0});
    }
}

export function findFormulasDelta (sensor, sensorCompare) {
    const sensor1 = sensor;
    const sensor2 = sensorCompare;
    var formulaDelta = sensor1.formulas.reduce((prev, formula) => {
        var finded = sensor2.formulas.find(x => {
            return x.formula === formula.formula &&
                isequal(x.measurementType.sort(), formula.measurementType.sort()) &&
                x.start === formula.start &&
                x.end === formula.end &&
                x.aggregationType === formula.aggregationType;
        });
        return finded ? [...prev] : [...prev, formula];
    }, []);<commit_msg>Change log level for sensorsData<commit_after>import {map} from "bluebird";
import flattendeep from "lodash.flattendeep";
import isequal from "lodash.isequal";
import moment from "moment";

import log from "../services/logger";
import {dispatch} from "../services/dispatcher";
import {findVirtualSensor, findSensorAggregate} from "../services/mongodb";

export async function replySensorMeasurements (decoratedSensor) {
    log.info({
        decoratedSensor
    });

    var sensors = await findVirtualSensor({_id: decoratedSensor.id});
    log.info({sensors});

    if (sensors) {
        var formulas = findFormulasDelta(decoratedSensor, sensors);
        log.info({formulas});

        const aggregatesByFormula = retrieveSensorData(formulas);

        await map(aggregatesByFormula, async (aggregateByFormula) => {

            log.debug({
                ids: aggregateByFormula.ids
            });

            const sensorsData = await findSensorAggregate({
                _id: {
                    $in: aggregateByFormula.ids
                }
            });

            log.debug({sensorsData});

            await map(sensorsData, async (sensorData) => {

                const splittedValues = sensorData.measurementValues.split(",").filter(x => x);
                const splittedTimes = sensorData.measurementTimes.split(",").filter(x => x);

                await map(splittedValues, async (value, index) => {
                    const timestamp = splittedTimes[index];

                    const kinesisEvent = createKinesisEvent(sensorData, value, timestamp);

                    await dispatch("element inserted in collection readings", kinesisEvent);
                }, {concurrency: 0});
            });
        }, {concurrency: 0});
    }
}

export function findFormulasDelta (sensor, sensorCompare) {
    const sensor1 = sensor;
    const sensor2 = sensorCompare;
    var formulaDelta = sensor1.formulas.reduce((prev, formula) => {
        var finded = sensor2.formulas.find(x => {
            return x.formula === formula.formula &&
                isequal(x.measurementType.sort(), formula.measurementType.sort()) &&
                x.start === formula.start &&
                x.end === formula.end &&
                x.aggregationType === formula.aggregationType;
        });
        return finded ? [...prev] : [...prev, formula];
    }, []);
{'fraction_non_alphanumeric': 0.12060939483707152, 'fraction_numerical': 0.0025391451544646637, 'mean_word_length': 2.294076655052265, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '3817422', 'n_tokens_mistral': 1270, 'n_tokens_neox': 1223, 'n_words': 278}