<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/. */

import * as _ from 'lodash';
import { Line, ChartComponentProps } from 'react-chartjs-2';
import { ChartData, ChartDataSets, ChartPoint, ChartTooltipItem } from 'chart.js';
import * as moment from 'moment';
import { connect } from 'react-redux';
import getGraphColor from '../utils/getGraphColor';
import { State } from '../types/redux/state';


function mapStateToProps(state: State) {
	const timeInterval = state.graph.timeInterval;
	const datasets: ChartDataSets[] = [];

	// Add all meters data to the chart
	for (const meterID of state.graph.selectedMeters) {
		const byMeterID = state.readings.line.byMeterID[meterID];
		if (byMeterID !== undefined) {
			const readingsData = byMeterID[timeInterval.toString()];
			if (readingsData !== undefined && !readingsData.isFetching) {
				const label = state.meters.byMeterID[meterID].name;
				if (readingsData.readings === undefined) {
					throw new Error('Unacceptable condition: readingsData.readings is undefined.');
				}

				const dataPoints: ChartPoint[] = _.values(readingsData.readings).map(
					(v: [number, number]) => ({ x: v[0], y: v[1] })
				);

				datasets.push({
					label,
					data: dataPoints,
					fill: false,
					borderColor: getGraphColor(label)
				});
			}
		}
	}

	// Add all groups data to the chart
	for (const groupID of state.graph.selectedGroups) {
		const byGroupID = state.readings.line.byGroupID[groupID];
		if (byGroupID !== undefined) {
			const readingsData = byGroupID[timeInterval.toString()];
			if (readingsData !== undefined && !readingsData.isFetching) {
				const label = state.groups.byGroupID[groupID].name;
				if (readingsData.readings === undefined) {
					throw new Error('Unacceptable condition: readingsData.readings is undefined.');
				}

				const dataPoints: ChartPoint[] = _.values(readingsData.readings).map(
					(v: [number, number]) => ({ x: v[0], y: parseInt(v[1].toFixed(2)) })
				);

				datasets.push({
					label,
					data: dataPoints,
					fill: false,
					borderColor: getGraphColor(label)
				});
			}
		}<commit_msg>Fix a bug where group line readings were rounded to integers<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/. */

import * as _ from 'lodash';
import { Line, ChartComponentProps } from 'react-chartjs-2';
import { ChartData, ChartDataSets, ChartPoint, ChartTooltipItem } from 'chart.js';
import * as moment from 'moment';
import { connect } from 'react-redux';
import getGraphColor from '../utils/getGraphColor';
import { State } from '../types/redux/state';


function mapStateToProps(state: State) {
	const timeInterval = state.graph.timeInterval;
	const datasets: ChartDataSets[] = [];

	// Add all meters data to the chart
	for (const meterID of state.graph.selectedMeters) {
		const byMeterID = state.readings.line.byMeterID[meterID];
		if (byMeterID !== undefined) {
			const readingsData = byMeterID[timeInterval.toString()];
			if (readingsData !== undefined && !readingsData.isFetching) {
				const label = state.meters.byMeterID[meterID].name;
				if (readingsData.readings === undefined) {
					throw new Error('Unacceptable condition: readingsData.readings is undefined.');
				}

				const dataPoints: ChartPoint[] = _.values(readingsData.readings).map(
					(v: [number, number]) => ({ x: v[0], y: v[1] })
				);

				datasets.push({
					label,
					data: dataPoints,
					fill: false,
					borderColor: getGraphColor(label)
				});
			}
		}
	}

	// Add all groups data to the chart
	for (const groupID of state.graph.selectedGroups) {
		const byGroupID = state.readings.line.byGroupID[groupID];
		if (byGroupID !== undefined) {
			const readingsData = byGroupID[timeInterval.toString()];
			if (readingsData !== undefined && !readingsData.isFetching) {
				const label = state.groups.byGroupID[groupID].name;
				if (readingsData.readings === undefined) {
					throw new Error('Unacceptable condition: readingsData.readings is undefined.');
				}

				const dataPoints: ChartPoint[] = _.values(readingsData.readings).map(
					(v: [number, number]) => ({ x: v[0], y: v[1] })
				);

				datasets.push({
					label,
					data: dataPoints,
					fill: false,
					borderColor: getGraphColor(label)
				});
			}
		}
{'fraction_non_alphanumeric': 0.13317244405440984, 'fraction_numerical': 0.004168494953927161, 'mean_word_length': 3.6806981519507187, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '6431846', 'n_tokens_mistral': 1666, 'n_tokens_neox': 1417, 'n_words': 392}