using System;
using System.Collections.Generic;
using System.Data;
using System.Runtime.Serialization;

namespace QC.CTDS.DM.DataStructures.OutputDataStructure;

[DataContract]
public class HistogramData : OutputData
{
	private string yAxisTitle = "Frequency";

	private string normalDistTitle = "Normal Dist";

	private string xAxisTitle;

	private DataTable dataTbl = new DataTable();

	private int histogramColumnStartIndex = -1;

	private int histogramColumnStopIndex = -1;

	private int normalDistColumnStartIndex = -1;

	private int normalDistColumnStopIndex = -1;

	private int limitColumnStartIndex = -1;

	private int limitColumnStopIndex = -1;

	private DataTable distributionTbl = new DataTable();

	private Dictionary<string, HistogramStatsData> statisticsDict = new Dictionary<string, HistogramStatsData>(StringComparer.Ordinal);

	private double meanRange = double.NaN;

	private double stdDevRange = double.NaN;

	private double minXAxis = double.NaN;

	private double maxXAxis = double.NaN;

	[DataMember]
	public string YAxisTitle
	{
		get
		{
			return yAxisTitle;
		}
		set
		{
			yAxisTitle = value;
		}
	}

	[DataMember]
	public string NormalDistTitle
	{
		get
		{
			return normalDistTitle;
		}
		set
		{
			normalDistTitle = value;
		}
	}

	[DataMember]
	public string XAxisTitle
	{
		get
		{
			return xAxisTitle;
		}
		set
		{
			xAxisTitle = value;
		}
	}

	public DataTable DataTbl
	{
		get
		{
			return dataTbl;
		}
		set
		{
			dataTbl = value;
		}
	}

	public int HistogramColumnStartIndex
	{
		get
		{
			return histogramColumnStartIndex;
		}
		set
		{
			histogramColumnStartIndex = value;
		}
	}

	public int HistogramColumnStopIndex
	{
		get
		{
			return histogramColumnStopIndex;
		}
		set
		{
			histogramColumnStopIndex = value;
		}
	}

	public int NormalDistColumnStartIndex
	{
		get
		{
			return normalDistColumnStartIndex;
		}
		set
		{
			normalDistColumnStartIndex = value;
		}
	}

	public int NormalDistColumnStopIndex
	{
		get
		{
			return normalDistColumnStopIndex;
		}
		set
		{
			normalDistColumnStopIndex = value;
		}
	}

	public int LimitColumnStartIndex
	{
		get
		{
			return limitColumnStartIndex;
		}
		set
		{
			limitColumnStartIndex = value;
		}
	}

	public int LimitColumnStopIndex
	{
		get
		{
			return limitColumnStopIndex;
		}
		set
		{
			limitColumnStopIndex = value;
		}
	}

	public DataTable DistributionTbl
	{
		get
		{
			return distributionTbl;
		}
		set
		{
			distributionTbl = value;
		}
	}

	public Dictionary<string, HistogramStatsData> StatisticsDict
	{
		get
		{
			return statisticsDict;
		}
		set
		{
			statisticsDict = value;
		}
	}

	public double MeanRange
	{
		get
		{
			return meanRange;
		}
		set
		{
		}
	}

	public double StdDevRange
	{
		get
		{
			return stdDevRange;
		}
		set
		{
		}
	}

	internal double MinXAxis
	{
		get
		{
			return minXAxis;
		}
		set
		{
			minXAxis = value;
		}
	}

	internal double MaxXAxis
	{
		get
		{
			return maxXAxis;
		}
		set
		{
			maxXAxis = value;
		}
	}

	[DataMember]
	public List<ChartSeries> HistogramChartSeries { get; set; }

	[DataMember]
	public List<string> XAxisValues { get; set; }

	public void CalculateMeanStdRange()
	{
		double num = double.NaN;
		double num2 = double.NaN;
		double num3 = double.NaN;
		double num4 = double.NaN;
		foreach (KeyValuePair<string, HistogramStatsData> item in statisticsDict)
		{
			if (!double.IsNaN(item.Value.Mean))
			{
				if (double.IsNaN(num))
				{
					num = item.Value.Mean;
				}
				else if (item.Value.Mean > num)
				{
					num = item.Value.Mean;
				}
				if (double.IsNaN(num2))
				{
					num2 = item.Value.Mean;
				}
				else if (item.Value.Mean < num2)
				{
					num2 = item.Value.Mean;
				}
			}
			if (!double.IsNaN(item.Value.StdDev))
			{
				if (double.IsNaN(num3))
				{
					num3 = item.Value.StdDev;
				}
				else if (item.Value.StdDev > num3)
				{
					num3 = item.Value.StdDev;
				}
				if (double.IsNaN(num4))
				{
					num4 = item.Value.StdDev;
				}
				else if (item.Value.StdDev < num4)
				{
					num4 = item.Value.StdDev;
				}
			}
		}
		if (!double.IsNaN(num) && !double.IsNaN(num2))
		{
			meanRange = num - num2;
		}
		if (!double.IsNaN(num3) && !double.IsNaN(num4))
		{
			stdDevRange = num3 - num4;
		}
	}
}
