Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
AutotestRegister.c
Go to the documentation of this file.
1// Script File
2
3
13
15class MeasurementFile
16{
18 // VARIABLES
19 private AutotestRegister m_parent; //< Register this file is made from
20 private string m_filePath; //< Path to physical file of this measurement
21 private ref FileHandle m_handle; //< Handle to physical file
22 private MeasurementType m_type; //< What type of measurement visualization this file will generate
23 private string m_graphHeader; //< Table header for graph type measurements
24 private bool m_containsNoData; //< Does this file contain any data or is it plain autotest header only (first line only)
25
26
27
29 // PUBLIC FUNCTIONS
31 // contains anything more than only autotest header (sets m_containsNoData)
32 void MeasurementFile(AutotestRegister parent, string path, FileMode mode, MeasurementType type)
33 {
34 m_type = type;
35 m_parent = parent;
36 m_filePath = path;
37
38 if(mode == FileMode.APPEND && FileIO.FileExists(path))
39 {
40 m_handle = FileIO.OpenFile(path, FileMode.READ);
41
42 int lineCount = 0;
43
44 string line;
45 while(m_handle.ReadLine(line) > 0)
46 {
47 lineCount++;
48 if(lineCount > 1)
49 break;
50 }
51 m_containsNoData = lineCount < 2;
52 m_handle.Close();
53 }
54 else
55 m_containsNoData = true;
56
57 m_handle = FileIO.OpenFile(m_filePath, mode);
58
59 }
61 void ~MeasurementFile()
62 {
63 if (!m_handle)
64 return;
65 if(IsChart() && m_containsNoData && m_graphHeader.Length() > 0)
66 m_handle.WriteLine(m_graphHeader);
67 m_handle.Close();
68 m_handle = null;
69 }
70
72 bool IsValid()
73 {
74 return m_handle;
75 }
76
78 string GetFilePath() { return m_filePath; }
79
81 // This muse be called before first AddData or generic header gets generated
82 void SetGraphHeader(string header)
83 {
84 if(!m_handle)
85 return;
86 m_graphHeader = header;
87 }
88
90 // With first data we append into file containing graph it automatically appends
91 // either set in SetGraphHeader or ig gets autogenerated
92 void AddData(string line)
93 {
94 if(!m_handle)
95 return;
96 if(IsChart() && m_containsNoData)
97 {
98 if(m_graphHeader.Length() > 0)
99 m_handle.WriteLine(m_graphHeader);
100 else
101 {
102 array<string> arr = new array<string>();
103 line.Split(",", arr, true);
104
105 string artificialHeader;
106 for(int i = 0; i < arr.Count(); ++i)
107 {
108 if(i != 0)
109 artificialHeader = string.Format("%1,%2", artificialHeader, i);
110 else
111 artificialHeader = string.Format("%1", i);
112 }
113 m_handle.WriteLine(artificialHeader);
114 }
115 }
116
117 m_containsNoData = false;
118 m_handle.WriteLine(line);
119 }
120
122 // It is used internally to find out if we should append graph header in this file.
123 bool IsChart()
124 {
125 return m_type == MeasurementType.GraphLine || m_type == MeasurementType.GraphBar;
126 }
127
128
130 // UNUSUAL
131
133 // Ignore it or you may breake the system
134 void AddHeader(string measurementTitle)
135 {
136 if(!m_handle || !m_containsNoData)
137 return;
138
139 if(m_type == MeasurementType.HeatMap)
140 {
141 m_handle.WriteLine(string.Format("%1;%2;heatmap", m_parent.GetAutotestPageName(), measurementTitle));
142 m_handle.WriteLine("x,y,FPS");
143 }
144 else if(m_type == MeasurementType.GraphLine)
145 m_handle.WriteLine(string.Format("%1;%2;chart;line", m_parent.GetAutotestPageName(), measurementTitle));
146 else if(m_type == MeasurementType.GraphBar)
147 m_handle.WriteLine(string.Format("%1;%2+chart;bar", m_parent.GetAutotestPageName(), measurementTitle));
148 else if(m_type == MeasurementType.HTML)
149 m_handle.WriteLine(string.Format("%1;%2;html", m_parent.GetAutotestPageName(), measurementTitle));
150 else if(m_type == MeasurementType.File)
151 m_handle.WriteLine(string.Format("%1;%2;file", m_parent.GetAutotestPageName(), measurementTitle));
152 else if(m_type == MeasurementType.Gallery)
153 m_handle.WriteLine(string.Format("%1;%2;gallery", m_parent.GetAutotestPageName(), measurementTitle));
154 }
155}
156
157
159class AutotestRegister
160{
162 // VARIABLES
163 protected string m_worldFileFolder;
164 protected string m_autotestPageName;
166 protected int m_testIndex = 0;
167
168
169
171 // PUBLIC FUNCTIONS
172
174 // This also handles persistent autotest indexing m_testIndex
175 void Init(string pageName)
176 {
177 m_autotestPageName = pageName;
178
179 m_worldFileFolder = "$logs:";
180
181 string mutliTestFile = string.Format("%1/%2", m_worldFileFolder, "last_test_index.log");
182 FileHandle tmp;
183 if(FileIO.FileExists(mutliTestFile))
184 {
185 tmp = FileIO.OpenFile(mutliTestFile, FileMode.READ);
186 string line;
187 tmp.ReadLine(line);
188 m_testIndex = line.ToInt() + 1;
189 tmp.Close();
190 }
191
192 tmp = FileIO.OpenFile(mutliTestFile, FileMode.WRITE);
193 if (tmp)
194 {
195 tmp.WriteLine(string.Format("%1", m_testIndex));
196 tmp.Close();
197 }
198 }
199
201 string GetAutotestPageName() { return m_autotestPageName; }
202
204 string GetWorldFileFolderPath() { return m_worldFileFolder; }
205
207 // if it is first time (first world) when autotest runs or we are in the middle of multistage/multiworld autotest
208 // in such case this will return >0 if it is first it will return 0. This is usefull when you want to for example
209 // delete some temporary files before running autotest measurements
210 int GetTestIndex()
211 {
212 return m_testIndex;
213 }
214
216 bool DoesMeasurementExist(string name)
217 {
218 return FileIO.FileExists(CreateMeasurementFilePath(name));
219 }
220
222 // If you set false into overwriteExisting it will try to open existing measurement file and append to PSVrTrackingQualityEnum
223 // In case there is none it will simply create new one and prepare autotest header into it so we can always AddData right away
224 //
225 // !!! Dont forget to store into ref !!!
226 MeasurementFile OpenMeasurementFile(string name, string measurementTitle, MeasurementType type, bool overwriteExisting = true)
227 {
228 MeasurementFile ret;
229
230 string measurementFilePath = CreateMeasurementFilePath(name);
231 if(overwriteExisting || !FileIO.FileExists(measurementFilePath))
232 {
233 ret = new MeasurementFile(this, measurementFilePath, FileMode.WRITE, type);
234 ret.AddHeader(measurementTitle);
235 }
236 else
237 {
238 ret = new MeasurementFile(this, measurementFilePath, FileMode.APPEND, type);
239 }
240
241 return ret;
242 }
243
245 // result page (under name "console.log" - link to it is also put at the end of results)
246 void UploadLogFileWithResults()
247 {
248 string logFilePath = string.Format("%1/console.log", m_worldFileFolder);
249 if(!FileIO.FileExists(logFilePath))
250 {
251 FileHandle logFileHandle = FileIO.OpenFile(logFilePath, FileMode.WRITE);
252 logFileHandle.WriteLine("Missing log file");
253 logFileHandle.Close();
254 }
255
256 ref MeasurementFile logFileUploader = OpenMeasurementFile("zzz_console_log_upload", "Console log", MeasurementType.File);
257 logFileUploader.AddData(logFilePath);
258 }
259
261 void SavePersistentData(string name, string data)
262 {
263 FileHandle tmp = FileIO.OpenFile(CreatePersistentFilePath(name), FileMode.WRITE);
264 tmp.WriteLine(data);
265 tmp.Close();
266 }
268 string LoadPersistentData(string name)
269 {
270 FileHandle tmp = FileIO.OpenFile(CreatePersistentFilePath(name), FileMode.READ);
271
272 string data;
273 tmp.ReadLine(data);
274
275 tmp.Close();
276 return data;
277 }
278
280 // dont forget that charts has +1 than you would probably expect because of chart header)
281 int GetNumberOfDataLines(string measurementName)
282 {
283 FileHandle tmp = FileIO.OpenFile(CreateMeasurementFilePath(measurementName), FileMode.READ);
284
285 int count = -1;
286
287 string lineContent;
288 while(tmp.ReadLine(lineContent) > 0)
289 count++;
290
291 tmp.Close();
292 return count;
293 }
294
296 int GetNumberOfWorldFiles()
297 {
298 array<string> files = {};
299 FileIO.FindFiles(files.Insert, m_worldFileFolder, ".ent");
300 return files.Count();
301 }
302
304 // PRIVATE FUNCTIONS
305 private string CreatePersistentFilePath(string name)
306 {
307 return string.Format("%1/%2", m_worldFileFolder, name);
308 }
309 private string CreateMeasurementFilePath(string name)
310 {
311 return string.Format("%1/%2.txt", m_worldFileFolder, name);
312 }
313}
string path
enum MeasurementType m_parent
Implementation of single measurement result file (dont forget to delete it after you are done or use ...
MeasurementType
@ File
@ GraphLine
@ Gallery
@ GraphBar
@ HTML
@ HeatMap
override void Init()
EDamageType type
Get all prefabs that have the spawner data
FileMode
Mode for opening file. See FileSystem::Open.
Definition FileMode.c:14