<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

const moment = require('moment');
const Meter = require('../../models/Meter');
const Reading = require('../../models/Reading');
const { log } = require('../../log');
const demuxCsvWithSingleColumnTimestamps = require('./csvDemux');
const loadArrayInput = require('./loadArrayInput');

async function insertObviusData(serialNumber, ipAddress, logfile) {
	// Get demultiplexed, parsed data from the CSV.
	const data = demuxCsvWithSingleColumnTimestamps(logfile);

	for (let i = 0; i < data.length; i++) {
		let meter;
		try {
			meter = await Meter.getByName(`${serialNumber}.${i}`);
		} catch (v) {
			meter = new Meter(undefined, `${serialNumber}.${i}`, ipAddress, true, Meter.type.OBVIUS, `OBVIUS ${serialNumber} COLUMN ${i}`);
			await meter.insert();
		}

		return loadArrayInput(dataRows = data[i],
							meterID = meter.id,
							mapRowToModel = row => {
							const startTimestamp = moment(rawReading[0], 'YYYY-MM-DD HH:mm:ss');
							const endTimestamp = startTimestamp.clone();
							endTimestamp.add(moment.duration(1, 'hours'));
							return [rawReading[1], startTimestamp, endTimestamp];
							},
							isCummulative = false,
							readingRepetition = 1,
							conditionSet = undefined,
							conn = conn);
	}<commit_msg>Fix bug<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

const moment = require('moment');
const Meter = require('../../models/Meter');
const Reading = require('../../models/Reading');
const { log } = require('../../log');
const demuxCsvWithSingleColumnTimestamps = require('./csvDemux');
const loadArrayInput = require('./loadArrayInput');

async function insertObviusData(serialNumber, ipAddress, logfile) {
	// Get demultiplexed, parsed data from the CSV.
	const data = demuxCsvWithSingleColumnTimestamps(logfile);

	for (let i = 0; i < data.length; i++) {
		let meter;
		try {
			meter = await Meter.getByName(`${serialNumber}.${i}`);
		} catch (v) {
			meter = new Meter(undefined, `${serialNumber}.${i}`, ipAddress, true, Meter.type.OBVIUS, `OBVIUS ${serialNumber} COLUMN ${i}`);
			await meter.insert();
		}

		return loadArrayInput(dataRows = data[i],
							meterID = meter.id,
							mapRowToModel = row => {
								const startTimestamp = moment(rawReading[0], 'YYYY-MM-DD HH:mm:ss');
								const endTimestamp = startTimestamp.clone();
								endTimestamp.add(moment.duration(1, 'hours'));
								return [rawReading[1], startTimestamp, endTimestamp];
							},
							isCummulative = false,
							readingRepetition = 1,
							conditionSet = undefined,
							conn = conn);
	}
{'fraction_non_alphanumeric': 0.15037593984962405, 'fraction_numerical': 0.006151742993848257, 'mean_word_length': 3.5450310559006213, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6645722', 'n_tokens_mistral': 1076, 'n_tokens_neox': 896, 'n_words': 251}