GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 68.4% 52 / 0 / 76
Functions: 30.8% 4 / 0 / 13
Branches: 71.2% 99 / 0 / 139

src/cli/RunCommand.cpp
Line Branch Exec Source
1 /***********************************************************************************************************************
2 * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC.
3 * See also https://openstudio.net/license
4 ***********************************************************************************************************************/
5
6 #include "RunCommand.hpp"
7 #include "../utilities/filetypes/ForwardTranslatorOptions.hpp"
8 #include "../workflow/WorkflowRunOptions.hpp"
9
10 #include "../workflow/OSWorkflow.hpp"
11 #include "../scriptengine/ScriptEngine.hpp"
12
13 // CLI/App.hpp must be included after ScriptEngine.hpp so that windows.h (and winnls.h) is
14 // pulled in before CLI11's windef.h, avoiding a missing LCTYPE in boost/regex's w32_regex_traits.hpp.
15 // https://github.com/NatLabRockies/OpenStudio/pull/5606#issuecomment-4391907202
16 #include <CLI/App.hpp>
17
18 #include <cstdint>
19 #include <fmt/format.h>
20
21 #include <memory>
22
23 namespace openstudio {
24 namespace cli {
25
26 262 void setupRunOptions(CLI::App* parentApp, ScriptEngineInstance& ruby, ScriptEngineInstance& python) {
27 /// Set up a subcommand and capture a shared_ptr to a struct that holds all its options.
28 /// The variables of the struct are bound to the CLI options.
29 /// We use a shared ptr so that the addresses of the variables remain for binding,
30 /// You could return the shared pointer if you wanted to access the values in main.
31
32 // TODO: modify utilities/filetypes/RunOptions.hpp and use that instead
33
1/1
✓ Branch 1 taken 262 times.
262 auto opt = std::make_shared<WorkflowRunOptions>();
34
35
3/3
✓ Branch 1 taken 262 times.
✓ Branch 4 taken 262 times.
✓ Branch 7 taken 262 times.
1048 auto* const app = parentApp->add_subcommand("run", "Executes an OpenStudio Workflow file");
36
37
4/4
✓ Branch 1 taken 262 times.
✓ Branch 5 taken 262 times.
✓ Branch 8 taken 262 times.
✓ Branch 11 taken 262 times.
1572 app->add_option("-w,--workflow", opt->osw_path, "Specify the FILE path to the workflow to run")->option_text("FILE");
38
39
4/4
✓ Branch 1 taken 262 times.
✓ Branch 4 taken 262 times.
✓ Branch 7 taken 262 times.
✓ Branch 10 taken 262 times.
1310 app->add_flag(
40 "-m,--measures_only",
41 524 [opt](std::int64_t val) {
42 // fmt::print("val={}\n", val);
43 1 opt->no_simulation = (val == 1);
44 1 },
45 "Only run the OpenStudio and EnergyPlus measures");
46
47
3/3
✓ Branch 1 taken 262 times.
✓ Branch 5 taken 262 times.
✓ Branch 8 taken 262 times.
1048 app->add_flag("-p,--postprocess_only", opt->post_process_only, "Only run the reporting measures");
48
49
4/4
✓ Branch 1 taken 262 times.
✓ Branch 4 taken 262 times.
✓ Branch 7 taken 262 times.
✓ Branch 10 taken 262 times.
1310 app->add_flag(
50
0/4
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
524 "--export-epJSON", [opt](std::int64_t val) { (val != 0) && opt->runOptions.setEpjson((val == 1)); },
51 "export epJSON file format. The default is IDF");
52
53
4/4
✓ Branch 1 taken 262 times.
✓ Branch 5 taken 262 times.
✓ Branch 8 taken 262 times.
✓ Branch 11 taken 262 times.
1572 app->add_option("-s,--socket", opt->socket_port, "Pipe status messages to a socket on localhost PORT")->option_text("PORT");
54
55 auto* stdout_opt =
56
3/3
✓ Branch 1 taken 262 times.
✓ Branch 5 taken 262 times.
✓ Branch 8 taken 262 times.
1048 app->add_flag("--show-stdout", opt->show_stdout, "Prints the output of the workflow run in real time to the console, including E+ output")
57
2/2
✓ Branch 1 taken 262 times.
✓ Branch 4 taken 262 times.
786 ->group("Stdout Options");
58
2/2
✓ Branch 1 taken 262 times.
✓ Branch 5 taken 262 times.
524 app->add_flag("--add-timings", opt->add_timings, "Print the start, end and elapsed times of each state of the simulation.")
59
2/2
✓ Branch 1 taken 262 times.
✓ Branch 4 taken 262 times.
786 ->needs(stdout_opt)
60
2/2
✓ Branch 1 taken 262 times.
✓ Branch 4 taken 262 times.
786 ->group("Stdout Options");
61 app
62
2/2
✓ Branch 1 taken 262 times.
✓ Branch 5 taken 262 times.
524 ->add_flag("--style-stdout", opt->style_stdout,
63 "Style the stdout output to more clearly show the start and end of each state of the simulation.")
64
2/2
✓ Branch 1 taken 262 times.
✓ Branch 4 taken 262 times.
786 ->needs(stdout_opt)
65
2/2
✓ Branch 1 taken 262 times.
✓ Branch 4 taken 262 times.
786 ->group("Stdout Options");
66
67
4/4
✓ Branch 1 taken 262 times.
✓ Branch 4 taken 262 times.
✓ Branch 7 taken 262 times.
✓ Branch 10 taken 262 times.
1310 app->add_flag(
68
2/4
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 7 times.
✗ Branch 9 not taken.
531 "--debug", [opt](std::int64_t val) { (val != 0) && opt->runOptions.setDebug((val == 1)); },
69 "Includes additional outputs for debugging failing workflows and does not clean up the run directory");
70
71 // FT options
72 static constexpr auto ftGroupName = "Forward Translator Options";
73 app
74
4/4
✓ Branch 1 taken 262 times.
✓ Branch 4 taken 262 times.
✓ Branch 7 taken 262 times.
✓ Branch 10 taken 262 times.
1310 ->add_flag(
75 "--runcontrolspecialdays,!--no-runcontrolspecialdays",
76 524 [opt](std::int64_t val) {
77 ✗ if (val != 0) {
78 ✗ opt->runOptions.forwardTranslatorOptions().setKeepRunControlSpecialDays((val == 1));
79 }
80 ✗ },
81 "Include RunControlSpecialDays (Holidays) [Default: True]")
82
2/2
✓ Branch 1 taken 262 times.
✓ Branch 4 taken 262 times.
786 ->group(ftGroupName);
83
84 app
85
4/4
✓ Branch 1 taken 262 times.
✓ Branch 4 taken 262 times.
✓ Branch 7 taken 262 times.
✓ Branch 10 taken 262 times.
1310 ->add_flag(
86 "--set-ip-tabular-output",
87 524 [opt](std::int64_t val) {
88 ✗ if (val != 0) {
89 ✗ opt->runOptions.forwardTranslatorOptions().setIPTabularOutput((val == 1));
90 }
91 ✗ },
92 "Request IP units from E+ Tabular (HTML) Report [Default: False]")
93
2/2
✓ Branch 1 taken 262 times.
✓ Branch 4 taken 262 times.
786 ->group(ftGroupName);
94
95 app
96
4/4
✓ Branch 1 taken 262 times.
✓ Branch 4 taken 262 times.
✓ Branch 7 taken 262 times.
✓ Branch 10 taken 262 times.
1310 ->add_flag(
97 "--lifecyclecosts,!--no-lifecyclecosts",
98 524 [opt](std::int64_t val) {
99 ✗ if (val != 0) {
100 ✗ opt->runOptions.forwardTranslatorOptions().setExcludeLCCObjects((val != 1));
101 }
102 ✗ },
103 "Include LifeCycleCosts [Default: True]")
104
2/2
✓ Branch 1 taken 262 times.
✓ Branch 4 taken 262 times.
786 ->group(ftGroupName);
105
106 app
107
4/4
✓ Branch 1 taken 262 times.
✓ Branch 4 taken 262 times.
✓ Branch 7 taken 262 times.
✓ Branch 10 taken 262 times.
1310 ->add_flag(
108 "--sqlite-output,!--no-sqlite-output",
109 524 [opt](std::int64_t val) {
110 ✗ if (val != 0) {
111 ✗ opt->runOptions.forwardTranslatorOptions().setExcludeSQliteOutputReport((val != 1));
112 }
113 ✗ },
114 "Request Output:SQLite from E+ [Default: True]")
115
2/2
✓ Branch 1 taken 262 times.
✓ Branch 4 taken 262 times.
786 ->group(ftGroupName);
116
117 app
118
4/4
✓ Branch 1 taken 262 times.
✓ Branch 4 taken 262 times.
✓ Branch 7 taken 262 times.
✓ Branch 10 taken 262 times.
1310 ->add_flag(
119 "--html-output,!--no-html-output",
120 524 [opt](std::int64_t val) {
121 ✗ if (val != 0) {
122 ✗ opt->runOptions.forwardTranslatorOptions().setExcludeHTMLOutputReport((val != 1));
123 }
124 ✗ },
125 "Request Output:Table:SummaryReports from E+ [Default: True]")
126
2/2
✓ Branch 1 taken 262 times.
✓ Branch 4 taken 262 times.
786 ->group(ftGroupName);
127
128 app
129
4/4
✓ Branch 1 taken 262 times.
✓ Branch 4 taken 262 times.
✓ Branch 7 taken 262 times.
✓ Branch 10 taken 262 times.
1310 ->add_flag(
130 "--space-translation,!--no-space-translation",
131 524 [opt](std::int64_t val) {
132 ✗ if (val != 0) {
133 ✗ opt->runOptions.forwardTranslatorOptions().setExcludeSpaceTranslation((val != 1));
134 }
135 ✗ },
136 "Add individual E+ Space [Default: True]")
137
2/2
✓ Branch 1 taken 262 times.
✓ Branch 4 taken 262 times.
786 ->group(ftGroupName);
138
139 app
140
4/4
✓ Branch 1 taken 262 times.
✓ Branch 4 taken 262 times.
✓ Branch 7 taken 262 times.
✓ Branch 10 taken 262 times.
1310 ->add_flag(
141 "--space-load-instances,!--no-space-load-instances",
142 524 [opt](std::int64_t val) {
143 ✗ if (val != 0) {
144 ✗ opt->runOptions.forwardTranslatorOptions().setExcludeSpaceLoadInstances((val != 1));
145 }
146 ✗ },
147 "Translate SpaceLoads (People, Lights, ElectricEquipment, etc) to the E+ Instance / Definition object pairs [Default: True]")
148
2/2
✓ Branch 1 taken 262 times.
✓ Branch 4 taken 262 times.
786 ->group(ftGroupName);
149
150 app
151
4/4
✓ Branch 1 taken 262 times.
✓ Branch 4 taken 262 times.
✓ Branch 7 taken 262 times.
✓ Branch 10 taken 262 times.
1310 ->add_flag(
152 "--construction-assignment-sets,!--no-construction-assignment-sets",
153 524 [opt](std::int64_t val) {
154 ✗ if (val != 0) {
155 ✗ opt->runOptions.forwardTranslatorOptions().setExcludeConstructionAssignmentSets((val != 1));
156 }
157 ✗ },
158 "Translate DefaultConstructionSets to the E+ ConstructionAssignmentSet objects referenced by Space/Building [Default: True]")
159
2/2
✓ Branch 1 taken 262 times.
✓ Branch 4 taken 262 times.
786 ->group(ftGroupName);
160
161 // Subcommand callback
162
1/3
✓ Branch 2 taken 262 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
262 app->callback([opt, &ruby, &python] {
163
1/1
✓ Branch 2 taken 22 times.
22 openstudio::OSWorkflow workflow(*opt, ruby, python);
164
3/3
✓ Branch 1 taken 22 times.
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 17 times.
22 if (!workflow.run()) {
165 5 std::exit(1);
166 }
167 17 });
168 262 }
169
170 } // namespace cli
171 } // namespace openstudio
172