In [172]:
import os
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
In [173]:
from IPython.display import display
from IPython.display import HTML
import IPython.core.display as di # Example: di.display_html('<h3>%s:</h3>' % str, raw=True)
# This line will hide code by default when the notebook is exported as HTML
di.display_html('<script>jQuery(function() {if (jQuery("body.notebook_app").length == 0) { jQuery("div.input").toggle(); jQuery(".prompt").toggle();}});</script>', raw=True)
# This line will add a button to toggle visibility of code blocks, for use with the HTML export version
di.display_html('''<button onclick="jQuery('div.input').toggle(); jQuery('.prompt').toggle();">Toggle code</button>''', raw=True)
In [174]:
# nice, interactive plotting.
%matplotlib notebook
In [175]:
# if KSPDIR is set, load the telemetry file from the game directory. Otherwise, load from current directory
if "KSPDIR" in os.environ:
telemetry_file = os.path.join(os.environ["KSPDIR"], r"GameData\Telemetry\Trajectories.csv")
else:
telemetry_file = "Trajectories.csv"
In [176]:
data = pd.read_csv(telemetry_file, sep='\t')
data.fillna(method="ffill", inplace=True) # fill everything we can with the previous value
In [177]:
# show all channels for a summary
time = data.columns.str.contains('_time')
calls = data.columns.str.contains('_calls')
dt = data.loc[:,time]
dc = data.loc[:,calls]
ax = dt.plot(legend=True)
ax.set_ylabel("Execution time (ms)");
ax = dc.plot(ax=ax, secondary_y=True, legend=True)
ax.set_ylabel("Number of calls per frame");
plt.xlabel("Frames")
plt.title("Summary")
plt.show()
In [178]:
ax = dt.plot(legend=True)
ax.set_ylabel("Execution time (ms)");
plt.xlabel("Frames")
plt.title("Execution time summary")
plt.show()
In [179]:
np.max(dt)
Out[179]:
In [180]:
np.sum(dt) / dt.index[-1]
Out[180]:
In [184]:
ax = dc.plot(legend=True)
ax.set_ylabel("Number of calls");
plt.xlabel("Frames")
plt.title("Number of calls per frame summary")
plt.show()
In [182]:
np.max(dc)
Out[182]:
In [183]:
np.sum(dc) / dc.index[-1]
Out[183]:
In [ ]: