added file writing flush callto clean up file writing and prevent file overflow for new experiments

This commit is contained in:
cs-powell
2025-07-11 20:45:49 -04:00
parent 537bc9474e
commit dcfff34b36
3 changed files with 12 additions and 4 deletions

3
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,3 @@
{
"cmake.sourceDirectory": "/Users/flyingtopher/Desktop/Code Citadel/School/2. Research/Fork Clone/XPlaneConnectCSP/C"
}

View File

@@ -6,8 +6,6 @@ import math
from geographiclib.geodesic import Geodesic as geo
from rich import print
# Initialize XPlaneConnect client
class scaleFactor():
SCALEYOKEPULL = 10

View File

@@ -216,6 +216,7 @@ def log(cogModel, file,timeElapsed):
mainString[len(mainString)-1] = "\n"
finalString = "".join(mainString)
file.write(finalString)
file.flush()
# file.write(str(timeElapsed) + "," + str(data[0][0]) + "," + str(data[1][0]) + "," + str(data[2][0]) + "," + str(data[3][0]) +"\n")
@@ -322,7 +323,7 @@ def setUp():
def cleanUp(count,title):
now = datetime.datetime
# shutil.copy("/Users/flyingtopher/X-Plane 11/Data.txt", "/Users/flyingtopher/Desktop/Test Destination/" + title + "_"+ count + "_" + str(now.now()) + "_" + ".txt")
shutil.copy("/Users/flyingtopher/X-Plane 11/Data.txt", "/Users/flyingtopher/Desktop/Test Destination/Current Experiment/" + title + "_"+ str(count) + "_" + ".txt")
shutil.copy("/Users/flyingtopher/X-Plane 11/Data.txt", "/Users/flyingtopher/Desktop/Test Destination/Current Experiment/" + str(count)+ "_" + title + ".txt")
print("CLEAN UP: Data File Deleted and Reset")
specialPrint("Data File Ready",False,messageType.REGULAR)
@@ -358,6 +359,8 @@ def ex():
experimentCount = int(startAt)
header = "Cycle Time,Latitude, Longitude, Altitude, Pitch, Roll\n"
file2 = open("/Users/flyingtopher/Desktop/Test Destination/Current Experiment/CurrentExperimentList.txt", 'w')
file2.write(str(title) + "\n")
startTime = time.time()
"""
Experiment Loop
"""
@@ -366,12 +369,16 @@ def ex():
file = open("/Users/flyingtopher/X-Plane 11/Data.txt", 'a')
file.write(str(header)) #Write Header to File$
currentConditions = experimentConditionMatrix[experimentCount]
file2.write(str(experimentCount) +" // " + str(currentConditions) + "\n")
file2.write(str(experimentCount) +" // " + str(currentConditions))
file2.flush()
exitExperimentLoop = runExperiment(title,currentConditions,allowPrinting,isNewExperiment,experimentCount,file)
if(exitExperimentLoop):
break
cleanUp(experimentCount,title)
experimentCount+=1
endTime = time.time()
elapsed = endTime-startTime
file2.write(" " + str(elapsed) + "\n")
# pag.alert(text="Experiment " + str(experimentCount+1) + " complete. Starting new Experiment", title="EXPERIMENT STATUS UPDATE")
"""
End of Experiments