102 lines
2.2 KiB
C++
102 lines
2.2 KiB
C++
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
#include "ENACSVReader.h"
|
|
|
|
// Sets default values
|
|
AENACSVReader::AENACSVReader()
|
|
{
|
|
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
|
PrimaryActorTick.bCanEverTick = true;
|
|
|
|
}
|
|
|
|
// Called when the game starts or when spawned
|
|
void AENACSVReader::BeginPlay()
|
|
{
|
|
Super::BeginPlay();
|
|
|
|
}
|
|
|
|
// Called every frame
|
|
void AENACSVReader::Tick(float DeltaTime)
|
|
{
|
|
Super::Tick(DeltaTime);
|
|
|
|
}
|
|
|
|
TArray<FString> AENACSVReader::SensorReadCSVFile(FString FileName)
|
|
{
|
|
TArray<FString> FileContents;
|
|
|
|
FString RootPath = FPaths::ProjectDir();
|
|
FString FilePath = FPaths::GetPath(RootPath) + TEXT("/") + FileName + TEXT(".csv");
|
|
FFileHelper::LoadFileToStringArray(FileContents, *FilePath);
|
|
|
|
return FileContents;
|
|
}
|
|
|
|
TArray<FSensorData> AENACSVReader::SensorParseCSVData(TArray<FString> FileContents)
|
|
{
|
|
TArray<FSensorData> SensorData;
|
|
|
|
FileContents.RemoveAt(0);
|
|
|
|
for (FString& Line : FileContents)
|
|
{
|
|
TArray<FString> Data;
|
|
Line.ParseIntoArray(Data, TEXT(","));
|
|
|
|
if (Data.Num() >= 3)
|
|
{
|
|
FSensorData Sensor;
|
|
Sensor.Timestamp = Data[0];
|
|
Sensor.BeadQualityClass = FCString::Atoi(*Data[1]);
|
|
Sensor.Score = FCString::Atof(*Data[2]);
|
|
|
|
SensorData.Add(Sensor);
|
|
}
|
|
}
|
|
|
|
return SensorData;
|
|
}
|
|
|
|
TArray<FString> AENACSVReader::LabelReadCSVFile(FString FileName)
|
|
{
|
|
TArray<FString> FileContents;
|
|
|
|
FString RootPath = FPaths::ProjectDir();
|
|
// TODO : 읽어오는 파일 구조 어딘지 파악 필요.
|
|
FString FilePath = FPaths::GetPath(RootPath) + TEXT("/") + FileName + TEXT(".csv");
|
|
FFileHelper::LoadFileToStringArray(FileContents, *FilePath);
|
|
|
|
return FileContents;
|
|
}
|
|
|
|
TArray<FLabelData> AENACSVReader::LabelParseCSVData(TArray<FString> FileContents)
|
|
{
|
|
TArray<FLabelData> LabelData;
|
|
|
|
FileContents.RemoveAt(0);
|
|
|
|
for (FString& Line : FileContents)
|
|
{
|
|
TArray<FString> Data;
|
|
Line.ParseIntoArray(Data, TEXT(","));
|
|
|
|
if (Data.Num() >= 5)
|
|
{
|
|
FLabelData Label;
|
|
Label.Timestamp = Data[0];
|
|
Label.Current = FCString::Atof(*Data[1]);
|
|
Label.Voltage = FCString::Atof(*Data[2]);
|
|
Label.Speed = FCString::Atof(*Data[3]);
|
|
Label.Temperature = FCString::Atof(*Data[4]);
|
|
|
|
LabelData.Add(Label);
|
|
}
|
|
}
|
|
|
|
return LabelData;
|
|
|
|
} |