Skip to content

Commit

Permalink
Fix cmake typo; enable plot standard tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
spahrenk committed Dec 16, 2024
1 parent cc7d0a8 commit 6f35518
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 83 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ if (NOT ${PROJECT_NAME}_DATA_MODEL_GENERATED)
include(poetry-install)
poetry_install(${pythonScriptDir})
execute_process(
COMMAND ${CMAKE_COMMAND} -E make_directory "${genCodeDir}"
COMMAND ${CMAKE_COMMAND} -E make_directory "${genOutDir}"

COMMAND ${GIT_EXECUTABLE} submodule update --init "${dataModelDir}"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
Expand Down
43 changes: 22 additions & 21 deletions scripts/python/plotting/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
var is_standard_test = false;
for (let test of test_index["tests"])
if (("name" in test) && ("group" in test))
if (test["name"].localeCompare(prefs["test_name"]) && test["group"].localeCompare("Standard tests"))
if (!test["name"].localeCompare(prefs["test_name"]) && !test["group"].localeCompare("Standard tests"))
{
is_standard_test = true;
break;
Expand Down Expand Up @@ -249,7 +249,7 @@
// set draw_profile dropdown
let draw_profile_dropdown = document.getElementById('draw_profile');
draw_profile_dropdown.value = prefs["draw_profile"];
draw_profile_dropdown.visible = is_standard_test;
draw_profile_dropdown.disabled= !is_standard_test;

set_menu_values(prefs);
await write_json_file("./prefs.json", prefs)
Expand All @@ -270,6 +270,11 @@

<script>
async function callPyServer(cmd, fst)
{
await fetch('http://localhost:8000/' + cmd + '?' + fst);
}

async function callPyServerJSON(cmd, fst)
{
const response = await fetch('http://localhost:8000/' + cmd + '?' + fst);
data = await response.json();
Expand All @@ -288,7 +293,7 @@
const test_form = document.getElementById('test_form');
const test_name = test_form.test_name.value;

var measured_filename = "";
var measured_filename = "none";

var prefs = await read_json_file("./prefs.json")

Expand All @@ -303,6 +308,7 @@
if (("group" in test) && !test["group"].localeCompare("Standard tests"))
{
is_standard_test = true;
test_dir = "none";
}
else
{
Expand Down Expand Up @@ -340,8 +346,8 @@
fst += '&model_name=' + model_name;
fst += '&build_dir=' + build_dir;
fst += '&draw_profile=' + draw_profile;
measure_results = await callPyServer("measure", fst)
simulated_filename = "test24hr_" + model_spec + "_" + model_name + ".csv";
await callPyServer("measure", fst)
simulated_filename = "test24hr_" + model_spec + "_" + model_name + ".csv";

document.getElementById("measure_results").style="display:block;"
document.getElementById("measure_results").height="1800px;"
Expand All @@ -353,15 +359,19 @@
fst += '&model_name=' + model_name;
fst += '&test_dir=' + test_dir;
fst += '&build_dir=' + build_dir;
simulate_results = await callPyServer("simulate", fst)
await callPyServer("simulate", fst)
simulated_filename = test_name + "_" + model_spec + "_" + model_name + ".csv";
}

fst = 'simulated_filename=' + simulated_filename;
fst = 'test_dir=' + test_dir;
fst += '&build_dir=' + build_dir;
fst += '&show_types=' + show_types;
fst += '&simulated_filename=' + simulated_filename;
fst += '&measured_filename=' + measured_filename;

plot_results = await callPyServer("plot", fst);
let energy_data = plot_results
plot_results = await callPyServerJSON("plot", fst);
let energy_data = plot_results["energy_data"];
const dash_port = plot_results["port_num"];

let energy_measured_p = document.getElementById("energy_measured")
if ("measuredE_Wh" in energy_data)
Expand Down Expand Up @@ -393,9 +403,11 @@
localStorage.setItem("build_dir", build_dir);
localStorage.setItem("test_name", test_name);

const port_string = "http://localhost:8050"
const port_string = "http://localhost:" + dash_port
document.getElementById("plots").src = port_string
document.getElementById("plots").style = "display:block;"

document.getElementById("test_btn").disabled = false;
}
</script>

Expand Down Expand Up @@ -464,17 +476,6 @@

</div>

<!-- content -->
<button id="measure_tab" class="collapsible">Measure</button>
<div class="content">
<form id="measure_form">


</form>

<object id="measure_results" data="" width=800 height=1800 style="display:none;"></object>
</div>

<script>
var coll = document.getElementsByClassName("collapsible");
var i;
Expand Down
32 changes: 12 additions & 20 deletions scripts/python/plotting/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
import dash_proc

# Runs a simulation and generates plot
def call_test(model_spec, model_name, test_dir, build_dir, show_types, measured_filename):

print("running simulation...")
simulate(model_spec, model_name, test_dir, build_dir)
def dash_plot(test_dir, build_dir, show_types, measured_filename, simulated_filename):

orig_dir = str(Path.cwd())
os.chdir(build_dir)
Expand All @@ -34,42 +31,37 @@ def call_test(model_spec, model_name, test_dir, build_dir, show_types, measured_
if not os.path.exists(output_dir):
os.mkdir(output_dir)

test_name = Path(test_dir).name
measured_path = ""
simulated_path = ""

if show_types & 1:
print("show measured")

measured_path = os.path.join(abs_repo_test_dir, test_dir, measured_filename)
if test_dir != "none":
print("show measured")
measured_path = os.path.join(abs_repo_test_dir, test_dir, measured_filename)

if show_types & 2:
print("show simulated")
simulated_path = os.path.join(output_dir, test_name + "_" + model_spec + "_" + model_name + ".csv")
simulated_path = os.path.join(output_dir, simulated_filename)

print("creating plot...")
print(f"measured_path: {measured_path}")
print(f"simulated__path: {simulated_path}")
plotter = plot(measured_path, simulated_path)
time.sleep(1)

if call_test.proc != -1:
if dash_plot.proc != -1:
print("killing current dash...")
call_test.proc.kill()
dash_plot.proc.kill()
time.sleep(1)

call_test.proc = mp.Process(target=dash_proc.dash_proc, args=(plotter.plot.figure, ), name='dash-proc')
dash_plot.proc = mp.Process(target=dash_proc.dash_proc, args=(plotter.plot.figure, ), name='dash-proc')
print("launching dash...")
call_test.proc.start()
dash_plot.proc.start()
time.sleep(1)

test_results = {}
test_results["energy_data"] = plotter.energy_data
test_results["port_num"] = 8050
return test_results

call_test.proc = -1

# Calls the 24-hr test function.
def call_measure(model_spec, model_name, build_dir, draw_profile):

measure(model_spec, model_name, build_dir, draw_profile)
return 'success'
dash_plot.proc = -1
2 changes: 1 addition & 1 deletion scripts/python/plotting/measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def measure(model_spec, model_name, build_dir, draw_profile):
os.mkdir(output_dir)

results_file = os.path.join(output_dir, "results.txt")
run_list = [app_cmd, 'measure', '-s', model_spec, '-m', model_name, '-d', output_dir, '-r', results_file, '-n']
run_list = [app_cmd, 'measure', '-s', model_spec, '-m', model_name, '-d', output_dir, '-r', results_file]
if draw_profile != "auto":
run_list.append('-p')
run_list.append(draw_profile)
Expand Down
2 changes: 1 addition & 1 deletion scripts/python/plotting/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def plot(measured_path, simulated_path):
plotter.read_measured(measured_path)
plotter.read_simulated(simulated_path)
plotter.draw()
return plotter.energy_data
return plotter

def write_plot(measured_path, simulated_path, plot_path):
plotter = Plotter()
Expand Down
2 changes: 1 addition & 1 deletion scripts/python/plotting/prefs.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"model_name": "LG_APHWC50", "model_spec": "Preset", "build_dir": "../../../build", "test_list": "Standard tests", "test_name": "Standard 24-hr test", "show_simulated": true, "show_measured": false, "draw_profile": "auto"}
{"model_name": "AquaThermAire", "model_spec": "Preset", "build_dir": "../../../build", "test_list": "Tests with data", "test_name": "villara_24hr67", "show_simulated": true, "show_measured": true, "draw_profile": "auto"}
89 changes: 51 additions & 38 deletions scripts/python/plotting/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,49 @@
from measure import measure
import json
from json import dumps
from main import dash_plot

PORT = 8000

dash_plot.proc = -1
class MyHandler(http.server.SimpleHTTPRequestHandler):
def do_GET(self):
if self.path.startswith('/simulate'):

if self.path.startswith('/read_json'):
query_components = urlparse.parse_qs(urlparse.urlparse(self.path).query)
filename = query_components.get('filename', [None])[0]
content = {}
with open(filename, "r") as json_file:
content = json.load(json_file)
json_file.close()

self.send_response(200)
self.send_header("Content-type", "application/json")
self.send_header("Content-Length", str(len(dumps(content))))
self.send_header("Access-Control-Allow-Origin", "*")
self.end_headers()

self.wfile.write(dumps(content).encode('utf-8'))
return

elif self.path.startswith('/write_json'):
query_components = urlparse.parse_qs(urlparse.urlparse(self.path).query)
filename = query_components.get('filename', [None])[0]
json_str = query_components.get('json_data', [None])[0]
print(json_str)
json_data = json.loads(json_str)
with open(filename, "w") as json_file:
#json_file.write(json_data)
json.dump(json_data, json_file)
json_file.close()

self.send_response(200)
self.send_header("Content-type", "text/html")
self.send_header("Access-Control-Allow-Origin", "*")
self.end_headers()
return

elif self.path.startswith('/simulate'):
query_components = urlparse.parse_qs(urlparse.urlparse(self.path).query)

model_spec = query_components.get('model_spec', [None])[0]
Expand All @@ -44,39 +81,31 @@ def do_GET(self):
build_dir = query_components.get('build_dir', [None])[0]
draw_profile = query_components.get('draw_profile', [None])[0]

response = measure(model_spec, model_name, build_dir, draw_profile)
measure(model_spec, model_name, build_dir, draw_profile)

self.send_response(200)
self.send_header("Content-type", "text/html")
self.send_header("Content-Length", "")
self.send_header("Access-Control-Allow-Origin", "*")
self.end_headers()
print("sent measure response")
return

elif self.path.startswith('/read_json'):
query_components = urlparse.parse_qs(urlparse.urlparse(self.path).query)
filename = query_components.get('filename', [None])[0]
content = {}
with open(filename, "r") as json_file:
content = json.load(json_file)
json_file.close()

self.send_response(200)
self.send_header("Content-type", "application/json")
self.send_header("Content-Length", str(len(dumps(content))))
self.send_header("Access-Control-Allow-Origin", "*")
self.end_headers()

self.wfile.write(dumps(content).encode('utf-8'))
return


if self.path.startswith('/plot'):
query_components = urlparse.parse_qs(urlparse.urlparse(self.path).query)

test_dir = query_components.get('test_dir', [None])[0]
build_dir = query_components.get('build_dir', [None])[0]
show_types = int(query_components.get('show_types', [None])[0])
simulated_filename = query_components.get('simulated_filename', [None])[0]
measured_filename= query_components.get('measured_filename', [None])[0]

response = plot(measured_filename, simulated_filename)
print(test_dir)
print(build_dir)
print(show_types)
print(simulated_filename)
print(measured_filename)
print("call dash plot")
response = dash_plot(test_dir, build_dir, show_types, measured_filename, simulated_filename)

self.send_response(200)
self.send_header("Content-type", "application/json")
Expand All @@ -88,22 +117,6 @@ def do_GET(self):
self.wfile.write(dumps(response).encode('utf-8'))
return

elif self.path.startswith('/write_json'):
query_components = urlparse.parse_qs(urlparse.urlparse(self.path).query)
filename = query_components.get('filename', [None])[0]
json_str = query_components.get('json_data', [None])[0]
print(json_str)
json_data = json.loads(json_str)
with open(filename, "w") as json_file:
#json_file.write(json_data)
json.dump(json_data, json_file)
json_file.close()

self.send_response(200)
self.send_header("Content-type", "text/html")
self.send_header("Access-Control-Allow-Origin", "*")
self.end_headers()
return

else:
super().do_GET()
Expand Down

0 comments on commit 6f35518

Please sign in to comment.