작업 조건 분석 기능 개발
This commit is contained in:
143
Assets/WorkSpace/Personal/JYM/WorkConditionsManager.cs
Normal file
143
Assets/WorkSpace/Personal/JYM/WorkConditionsManager.cs
Normal file
@@ -0,0 +1,143 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using WI;
|
||||
using System.Linq;
|
||||
using System;
|
||||
|
||||
public class GraphChartData
|
||||
{
|
||||
public List<string> timeData = new();
|
||||
public List<float> chartData = new();
|
||||
public GraphChartData()
|
||||
{
|
||||
}
|
||||
public GraphChartData(GraphChartData sampleGraph)
|
||||
{
|
||||
timeData = sampleGraph.timeData;
|
||||
chartData = sampleGraph.chartData;
|
||||
}
|
||||
}
|
||||
|
||||
public class WorkConditionsManager : MonoBehaviour, ISingle
|
||||
{
|
||||
public Dictionary<string, GraphChartData> graphDatas = new Dictionary<string, GraphChartData>();
|
||||
|
||||
public Dictionary<string, GraphChartData> mainChartDatas = new Dictionary<string, GraphChartData>();
|
||||
public Dictionary<string, GraphChartData> subChartDatas = new Dictionary<string, GraphChartData>();
|
||||
|
||||
public List<float> originPeakData = new();
|
||||
public List<float> originTemperatureData = new();
|
||||
public List<float> originHumidityData = new();
|
||||
public List<float> originCycleTimeData = new();
|
||||
|
||||
public List<string> mainChartLabels = new List<string>();
|
||||
public List<string> originChartLabels = new List<string>();
|
||||
|
||||
public int targetCount;
|
||||
|
||||
public Action<WorkConditionsData> onCompleteLoadData;
|
||||
public Action<List<string>> onSendChartLabels;
|
||||
public Action<Dictionary<string, GraphChartData>> onSendMainChartData;
|
||||
public Action<Dictionary<string, GraphChartData>> onSendSubChartData;
|
||||
|
||||
public void SetWorkConditionsData(WorkConditionsData workConditionsData)
|
||||
{
|
||||
SetGraphChartData(workConditionsData);
|
||||
}
|
||||
public void SetGraphChartData(WorkConditionsData workConditionsData)
|
||||
{
|
||||
graphDatas.Clear();
|
||||
mainChartLabels.Clear();
|
||||
|
||||
foreach (var row in workConditionsData.data.rows)
|
||||
{
|
||||
originPeakData.Add(ConvertStringToInt(row.C027));
|
||||
originTemperatureData.Add(ConvertStringToInt(row.TEMP01));
|
||||
originHumidityData.Add(ConvertStringToInt(row.HUMI01));
|
||||
originCycleTimeData.Add(ConvertStringToInt(row.C045));
|
||||
|
||||
originChartLabels.Add(row._time);
|
||||
}
|
||||
|
||||
graphDatas.Add("보압 (Peak)", DownSampleToFixedCount(originPeakData, originChartLabels, targetCount));
|
||||
graphDatas.Add("주변 온도", DownSampleToFixedCount(originTemperatureData, originChartLabels, targetCount));
|
||||
graphDatas.Add("주변 습도", DownSampleToFixedCount(originHumidityData, originChartLabels, targetCount));
|
||||
graphDatas.Add("싸이클 타임", DownSampleToFixedCount(originCycleTimeData, originChartLabels, targetCount));
|
||||
|
||||
mainChartLabels.AddRange(DownSampleToFixedCount(originChartLabels, 5));
|
||||
|
||||
onSendChartLabels?.Invoke(mainChartLabels);
|
||||
onCompleteLoadData?.Invoke(workConditionsData);
|
||||
}
|
||||
private int ConvertStringToInt(string stringData)
|
||||
{
|
||||
int.TryParse(stringData, out var result);
|
||||
return result;
|
||||
}
|
||||
public void ChangeMainChartData(string dataName)
|
||||
{
|
||||
subChartDatas.Clear();
|
||||
mainChartDatas.Clear();
|
||||
|
||||
foreach (var graphDataName in graphDatas.Keys)
|
||||
{
|
||||
if(graphDataName == dataName)
|
||||
{
|
||||
mainChartDatas.Add(graphDataName, graphDatas[graphDataName]);
|
||||
}
|
||||
else
|
||||
{
|
||||
subChartDatas.Add(graphDataName, graphDatas[graphDataName]);
|
||||
}
|
||||
}
|
||||
onSendMainChartData?.Invoke(mainChartDatas);
|
||||
onSendSubChartData?.Invoke(subChartDatas);
|
||||
}
|
||||
private GraphChartData DownSampleToFixedCount(List<float> chartData, List<string> dateTime, int targetCount)
|
||||
{
|
||||
var sampleGraph = new GraphChartData();
|
||||
|
||||
double interval = (double)chartData.Count / targetCount;
|
||||
|
||||
if (chartData.Count <= targetCount || targetCount <= 0)
|
||||
{
|
||||
sampleGraph.chartData.AddRange(chartData);
|
||||
sampleGraph.timeData.AddRange(dateTime);
|
||||
|
||||
return new GraphChartData(sampleGraph);
|
||||
}
|
||||
for (int i = 0; i < targetCount; i++)
|
||||
{
|
||||
int index = (int)Math.Round(i * interval);
|
||||
if (index >= chartData.Count)
|
||||
{
|
||||
index = chartData.Count - 1;
|
||||
}
|
||||
sampleGraph.chartData.Add(chartData[index]);
|
||||
sampleGraph.timeData.Add(dateTime[index]);
|
||||
}
|
||||
return new GraphChartData(sampleGraph);
|
||||
}
|
||||
private List<string> DownSampleToFixedCount(List<string> dateTime, int targetCount)
|
||||
{
|
||||
List<string> sampledData = new List<string>();
|
||||
|
||||
double interval = (double)dateTime.Count / targetCount;
|
||||
|
||||
if (dateTime.Count <= targetCount || targetCount <= 0)
|
||||
{
|
||||
return new List<string>(dateTime);
|
||||
}
|
||||
for (int i = 0; i < targetCount; i++)
|
||||
{
|
||||
int index = (int)Math.Round(i * interval);
|
||||
if (index >= dateTime.Count)
|
||||
{
|
||||
index = dateTime.Count - 1;
|
||||
}
|
||||
sampledData.Add(dateTime[index]);
|
||||
}
|
||||
return sampledData;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user