设置参考编号并将其与文本文件中的其他数据进行比较
Setting a reference number and comparing that to other data in textfile
该项目基于眼动仪。让我简要介绍一下项目背后的想法,以便更好地理解我的问题。
我有Tobii C眼动仪的硬件。这个眼动仪将能够给出我正在看的地方的 X、Y 坐标。但是这个装置非常敏感。当我看 1 个点时,眼动仪会发出许多不同的坐标数据,但在我发现的 ± 100
范围内。即使你盯着一个点,你的眼睛也会不停地移动,因此会给出很多数据。然后将这么多数据(浮点数)保存在文本文件中。现在我只需要 1 个数据(X 坐标)表示我正在注视的 1 个点,而不是 ± 100
范围内的许多数据并将其移动到新的文本文件。
我不知道我应该如何编写代码来做到这一点。
这些是文本文件中的 float
个数字。
200
201
198
202
250
278
310
315
360
389
500
568
579
590
当我盯着点1时,数据是200-300
,在± 100
范围内。我想将 200
设置为参考点用下一个数字减去自身并检查结果值是否在 100
内,如果是,则删除它们。参考点应继续对以下数字执行此操作,直到它超出 ± 100
范围。一旦超出 100
范围,现在数字是 310
,那么现在这个数字是下一个参考点,做同样的事情并用下面的数字相减,并检查结果值是否在 [=18 之内=].一旦超出 100
范围,下一个数字是 500
,现在,这是新的参考点,并执行相同的操作。那是我的objective。简而言之,参考点应该移动到一个新文件中。
到目前为止,这是我的代码,它获取注视坐标并将它们存储在文本文件中。
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Tobii.Interaction;
namespace ConsoleApp1
{
class Program
{
private static void programintro()
{
Console.WriteLine("Press Any Keys To Start");
}
public static void Main(string[] args)
{
programintro();
Console.ReadKey();
double currentX = 0.0;
double currentY = 0.0;
double timeStampCurrent = 0.0;
double diffX = 0.0;
double diffY = 0.0;
int counter = 0;
var host = new Host();
host.EnableConnection();
var gazePointDataStream = host.Streams.CreateGazePointDataStream();
gazePointDataStream.GazePoint((gazePointX, gazePointY, timestamp) =>
{
diffX = gazePointX - currentX;
diffY = gazePointY - currentY;
currentX = gazePointX;
currentY = gazePointY;
timeStampCurrent = timestamp;
if (diffX > 100 || diffX <= -100 || diffY >= 100 || diffY <= -100)
{
counter++;
using (StreamWriter writer = new StreamWriter("C: \Users\Student\Desktop\FYP 2019\ConsoleApp1\ConsoleApp1\Data\TextFile1.txt", true))
{
writer.WriteLine("Recorded Data " + counter + "\n=================================================================================================================\nX: {0} Y:{1}\nData collected at {2}", currentX, currentY, timeStampCurrent);
writer.WriteLine("=================================================================================================================");
}
Console.WriteLine("Recorded Data " + counter + "\n=================================================================================================================\nX: {0} Y:{1}\nData collected at {2}", currentX, currentY, timeStampCurrent);
Console.WriteLine("=================================================================================================================");
}
});
//host.DisableConnection();
while (true)
{
if (counter < 10)
{
continue;
}
else
{
Environment.Exit(0);
}
}
Now my Question is how do I code to read the text file and set a
reference number and subtracts itself with the next number and check
if the resultant value within 100
and have a new reference number if
it outside the ± 100
range. Those reference numbers are then stored in
a new text file.
根据您的示例数据,这里是仅获取相差超过 100 的数字的代码。
static void Main(string[] args)
{
string filename = @"C:\PowershellScripts\test.txt"; // INPUT FILE
String outputFile = @"C:\PowershellScripts\result.txt"; // OUTPUT FILE
string[] data = File.ReadAllLines(filename); // READING FORM FILE
int TotalLine = data.Length; // COUNT TOTAL NO OF ROWS
List<string> FinalList = new List<string>(); // INITIALIZE LIST FOR FINAL RESULT
if (TotalLine <= 0) // CHECK IF FILE HAS NO DATA
{
Console.WriteLine("No Data found !");
return;
}
double CurrentNumber = double.Parse(data[0]), NextNumber = 0, diff = 0; // INITIALIZE OF LOCAL VARIABLES, CURRENT NUMBER = FIRST NO FROM FILE
for (int cntr = 1; cntr < TotalLine; cntr++) // FOR LOOP FOR EACH LINE
{
NextNumber = double.Parse(data[cntr]); //PARSING NEXT NO
diff = CurrentNumber - NextNumber; // GETTING DIFFERENCE
if (diff <= 100 && diff >= -100) // MATCH THE DIFFERENCE
{
continue; // SKIP THE LOGIC IF DIFF IS LESS THEN 100
}
else
{
FinalList.Add(CurrentNumber.ToString()); // ADDING THE NO TO LIST
CurrentNumber = NextNumber; // POINTING TO NEXT NO
}
}
FinalList.Add(CurrentNumber.ToString()); // ADDING LAST NO.
foreach (string d in FinalList) // FOR EACH LOOP TO PRINT THE FINAL LIST
Console.WriteLine(d);
File.WriteAllLines(outputFile, FinalList); // SAVING TO THE FILE
}
以上程序将生成的输出是:
200
310
500
该项目基于眼动仪。让我简要介绍一下项目背后的想法,以便更好地理解我的问题。
我有Tobii C眼动仪的硬件。这个眼动仪将能够给出我正在看的地方的 X、Y 坐标。但是这个装置非常敏感。当我看 1 个点时,眼动仪会发出许多不同的坐标数据,但在我发现的 ± 100
范围内。即使你盯着一个点,你的眼睛也会不停地移动,因此会给出很多数据。然后将这么多数据(浮点数)保存在文本文件中。现在我只需要 1 个数据(X 坐标)表示我正在注视的 1 个点,而不是 ± 100
范围内的许多数据并将其移动到新的文本文件。
我不知道我应该如何编写代码来做到这一点。
这些是文本文件中的 float
个数字。
200
201
198
202
250
278
310
315
360
389
500
568
579
590
当我盯着点1时,数据是200-300
,在± 100
范围内。我想将 200
设置为参考点用下一个数字减去自身并检查结果值是否在 100
内,如果是,则删除它们。参考点应继续对以下数字执行此操作,直到它超出 ± 100
范围。一旦超出 100
范围,现在数字是 310
,那么现在这个数字是下一个参考点,做同样的事情并用下面的数字相减,并检查结果值是否在 [=18 之内=].一旦超出 100
范围,下一个数字是 500
,现在,这是新的参考点,并执行相同的操作。那是我的objective。简而言之,参考点应该移动到一个新文件中。
到目前为止,这是我的代码,它获取注视坐标并将它们存储在文本文件中。
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Tobii.Interaction;
namespace ConsoleApp1
{
class Program
{
private static void programintro()
{
Console.WriteLine("Press Any Keys To Start");
}
public static void Main(string[] args)
{
programintro();
Console.ReadKey();
double currentX = 0.0;
double currentY = 0.0;
double timeStampCurrent = 0.0;
double diffX = 0.0;
double diffY = 0.0;
int counter = 0;
var host = new Host();
host.EnableConnection();
var gazePointDataStream = host.Streams.CreateGazePointDataStream();
gazePointDataStream.GazePoint((gazePointX, gazePointY, timestamp) =>
{
diffX = gazePointX - currentX;
diffY = gazePointY - currentY;
currentX = gazePointX;
currentY = gazePointY;
timeStampCurrent = timestamp;
if (diffX > 100 || diffX <= -100 || diffY >= 100 || diffY <= -100)
{
counter++;
using (StreamWriter writer = new StreamWriter("C: \Users\Student\Desktop\FYP 2019\ConsoleApp1\ConsoleApp1\Data\TextFile1.txt", true))
{
writer.WriteLine("Recorded Data " + counter + "\n=================================================================================================================\nX: {0} Y:{1}\nData collected at {2}", currentX, currentY, timeStampCurrent);
writer.WriteLine("=================================================================================================================");
}
Console.WriteLine("Recorded Data " + counter + "\n=================================================================================================================\nX: {0} Y:{1}\nData collected at {2}", currentX, currentY, timeStampCurrent);
Console.WriteLine("=================================================================================================================");
}
});
//host.DisableConnection();
while (true)
{
if (counter < 10)
{
continue;
}
else
{
Environment.Exit(0);
}
}
Now my Question is how do I code to read the text file and set a reference number and subtracts itself with the next number and check if the resultant value within
100
and have a new reference number if it outside the± 100
range. Those reference numbers are then stored in a new text file.
根据您的示例数据,这里是仅获取相差超过 100 的数字的代码。
static void Main(string[] args) { string filename = @"C:\PowershellScripts\test.txt"; // INPUT FILE String outputFile = @"C:\PowershellScripts\result.txt"; // OUTPUT FILE string[] data = File.ReadAllLines(filename); // READING FORM FILE int TotalLine = data.Length; // COUNT TOTAL NO OF ROWS List<string> FinalList = new List<string>(); // INITIALIZE LIST FOR FINAL RESULT if (TotalLine <= 0) // CHECK IF FILE HAS NO DATA { Console.WriteLine("No Data found !"); return; } double CurrentNumber = double.Parse(data[0]), NextNumber = 0, diff = 0; // INITIALIZE OF LOCAL VARIABLES, CURRENT NUMBER = FIRST NO FROM FILE for (int cntr = 1; cntr < TotalLine; cntr++) // FOR LOOP FOR EACH LINE { NextNumber = double.Parse(data[cntr]); //PARSING NEXT NO diff = CurrentNumber - NextNumber; // GETTING DIFFERENCE if (diff <= 100 && diff >= -100) // MATCH THE DIFFERENCE { continue; // SKIP THE LOGIC IF DIFF IS LESS THEN 100 } else { FinalList.Add(CurrentNumber.ToString()); // ADDING THE NO TO LIST CurrentNumber = NextNumber; // POINTING TO NEXT NO } } FinalList.Add(CurrentNumber.ToString()); // ADDING LAST NO. foreach (string d in FinalList) // FOR EACH LOOP TO PRINT THE FINAL LIST Console.WriteLine(d); File.WriteAllLines(outputFile, FinalList); // SAVING TO THE FILE }
以上程序将生成的输出是:
200 310 500