ΠΠ°ΠΊ ΡΠΎ Π½Π°ΠΏΠΈΡΠ°Π» ΠΎΡ Π½Π΅ΡΠΈΠ³ Π΄Π΅Π»Π°ΡΡ.
ΠΠΎΠΆΠ΅Ρ:
ΠΡΠΎΡΠΈΡΠ°ΡΡ Π»ΠΎΠ³ ΠΏΠΈΠ»ΠΎΡΠ°, ΠΈ Π²ΡΠ΄ΡΠ°ΡΡ ΠΈΠ· Π½Π΅Π³ΠΎ ΡΠΊΠΎΠ»ΡΠΊΠΎ Π²ΡΠ΅ΠΌΠ΅Π½ΠΈ Π·Π°Π½ΡΠ»ΠΈ Π°Π½Π΄ΠΎΠΊΠΈ, Π²Π°ΡΠΏΡ ΠΊ Π±Π΅Π»ΡΡ, Π²Π°ΡΠΏΡ ΠΎΡ Π±Π΅Π»ΡΠ° ΠΈ ΠΊΠΎΠΏΠΊΠ°.
ΠΠΈΡΠ°Π» ΡΡΠΎΠ±Ρ ΠΎΠΏΡΠΈΠΌΠΈΠ·ΠΈΡΠΎΠ²Π°ΡΡ ΡΠ°ΠΉΠΌΠ΅ΡΡ. Π Π΅Π·Π°Π»ΡΡ ΠΌΠΎΠΆΠ½ΠΎ ΠΏΠ΅ΠΉΡΡΠΈΡΡ Π² ΡΠΊΡΠ΅Π» ΠΈ ΡΠΈΡΠΎΠ²Π°ΡΡ Π³ΡΠ°ΡΠΈΠΊΠΈ
ΠΠΎΠΆΠ΅Ρ ΠΊΠΎΠΌΡ ΠΏΡΠΈΠ³ΠΎΠ΄ΠΈΡΡΡ.
ΠΠ»Ρ Π·Π°ΠΏΡΡΠΊΠ° Π½ΡΠΆΠ΅Π½ .net framework 4.0
ΠΡΠ³Π»ΡΠ΄ΠΈΡ ΠΊΠ°ΠΊ ΡΠΎ ΡΠ°ΠΊ:
Π‘ΠΊΠ°ΡΠ°ΡΡ:
ΠΡΡ
ΠΎΠ΄Π½ΠΈΠΊ:
Warning: Spoiler!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace PilotLogParser
{
public partial class Form1 : Form
{
string addLogString = "";
byte lastAction = 0;
byte newAction = 0;
string lastActionTime = "00:00:00";
string newActionTime = "00:00:00";
OpenFileDialog openFile = new OpenFileDialog();
string filePath = string.Empty;
int dataRow = 0;
string[] actionString = { "zero", "Starting", "Undocking", "Warping to Location", "Warping to Station", "Docking to Station", "Mining"};
List<List<int>> actionTimes = new List<List<int>>();
public Form1()
{
InitializeComponent();
for (int i = 0; i < actionString.Length; i++)
{
actionTimes.Add(new List<int>());
}
}
private void button1_Click(object sender, EventArgs e)
{
openFile.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
openFile.Title = "Select EVE pilot log file";
if (openFile.ShowDialog() == DialogResult.OK) filePath = openFile.FileName;
if (filePath != String.Empty)
{
dataGridViewLog.ColumnCount = 5;
dataGridViewLog.Columns[0].Name = "Action";
dataGridViewLog.Columns[1].Name = "Start time";
dataGridViewLog.Columns[2].Name = "End time";
dataGridViewLog.Columns[3].Name = "Elapsed sec";
dataGridViewLog.Columns[4].Name = "Elapsed time";
using (StreamReader reader = new StreamReader(filePath))
{
string line;
while ((line = reader.ReadLine()) != null)
{
if (line.IndexOf("Start New Log") != -1) { newAction = 1; newActionTime = line.Substring(0, 8); }
else if (line.IndexOf("Module:UndockSub") != -1) { newAction = 2; newActionTime = line.Substring(0, 8); }
else if (line.IndexOf("Module:WarpingToLocation") != -1) { newAction = 3; newActionTime = line.Substring(0, 8); }
else if (line.IndexOf("Module:WarpingToStation") != -1) { newAction = 4; newActionTime = line.Substring(0, 8); }
else if (line.IndexOf("Module:DockingToStation") != -1) { newAction = 5; newActionTime = line.Substring(0, 8); }
else if (line.IndexOf("Module:MiningLasersControl") != -1) { newAction = 6; newActionTime = line.Substring(0, 8); }
if (lastAction != newAction)
{
addLogString = actionString[lastAction] + ":" + lastActionTime + " - " + newActionTime + " (" + timeTaken(lastActionTime, newActionTime) + " sec. or " + secondsToTime(timeTaken(lastActionTime, newActionTime)) + ")\r\n";
//
//dataGridViewLog[1,dataGridViewLog.Rows.Count-1].Value = actionString[lastAction];
dataGridViewLog.Rows.Add();
dataGridViewLog.Rows[dataRow].Cells[0].Value = actionString[lastAction];
dataGridViewLog.Rows[dataRow].Cells[1].Value = lastActionTime;
dataGridViewLog.Rows[dataRow].Cells[2].Value = newActionTime;
dataGridViewLog.Rows[dataRow].Cells[3].Value = timeTaken(lastActionTime, newActionTime);
dataGridViewLog.Rows[dataRow].Cells[4].Value = secondsToTime(timeTaken(lastActionTime, newActionTime));
dataRow++;
actionTimes[lastAction].Add(timeTaken(lastActionTime, newActionTime));
lastAction = newAction;
lastActionTime = newActionTime;
}
else
{
addLogString = "";
}
if (addLogString != "")
{
textBoxLog.Text = textBoxLog.Text + addLogString;
}
}
dataGridViewResults.RowCount = actionString.Length;
dataGridViewResults.ColumnCount = 5;
dataGridViewResults.Columns[0].Name = "Action";
dataGridViewResults.Columns[1].Name = "Quantity";
dataGridViewResults.Columns[2].Name = "Min";
dataGridViewResults.Columns[3].Name = "Max";
dataGridViewResults.Columns[4].Name = "Avg";
for (int i = 0; i < actionString.Length; i++)
{
//actionTimes.Add(new List<int>());
dataGridViewResults[0, i].Value = actionString[i];
dataGridViewResults[1, i].Value = actionTimes[i].Count;
dataGridViewResults[2, i].Value = actionTimes[i].Min();
dataGridViewResults[3, i].Value = actionTimes[i].Max();
dataGridViewResults[4, i].Value = actionTimes[i].Average();
}
}
}
}
private int timeTaken(string lastActionTime, string newActionTime)
{
int lastActionTimeSeconds = 0;
int newActionTimeSeconds = 0;
int result;
lastActionTimeSeconds = (Convert.ToInt32(lastActionTime.Substring(0,2)) * 60 *60) + (Convert.ToInt32(lastActionTime.Substring(3,2)) * 60 ) + Convert.ToInt32(lastActionTime.Substring(6,2));
newActionTimeSeconds = (Convert.ToInt32(newActionTime.Substring(0, 2)) * 60 * 60) + (Convert.ToInt32(newActionTime.Substring(3, 2)) * 60) + Convert.ToInt32(newActionTime.Substring(6, 2));
if (newActionTimeSeconds > lastActionTimeSeconds)
{ result = newActionTimeSeconds - lastActionTimeSeconds; }
else
{
result = 24 * 60 * 60 - lastActionTimeSeconds + newActionTimeSeconds;
}
return result;
}
private string secondsToTime(int secondsToConvert)
{
int hour;
int min;
int sec;
string h_s, m_s, s_s;
hour = secondsToConvert / 3600;
min = (secondsToConvert - (hour * 3600)) / 60;
sec = secondsToConvert - (hour * 3600) - (min * 60);
if (hour <= 9) { h_s = "0" + hour; } else { h_s = hour.ToString(); }
if (min <= 9) { m_s = "0" + min; } else { m_s = min.ToString(); }
if (sec <= 9) { s_s = "0" + sec; } else { s_s = sec.ToString(); }
return h_s + ":" + m_s + ":" + s_s;
}
private void dataGridViewResults_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
}
}