Skip to content

Commit 25b883e

Browse files
committed
try out the decision table object with a few known tables
1 parent f8243a8 commit 25b883e

File tree

4 files changed

+594
-2
lines changed

4 files changed

+594
-2
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env python
2+
"""
3+
Provides helper functions for decision tables in SSVC.
4+
"""
5+
6+
# Copyright (c) 2025 Carnegie Mellon University.
7+
# NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE
8+
# ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN "AS-IS" BASIS.
9+
# CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND,
10+
# EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT
11+
# NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR
12+
# MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE
13+
# OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE
14+
# ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM
15+
# PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT.
16+
# Licensed under a MIT (SEI)-style license, please see LICENSE or contact
17+
# permission@sei.cmu.edu for full terms.
18+
# [DISTRIBUTION STATEMENT A] This material has been approved for
19+
# public release and unlimited distribution. Please see Copyright notice
20+
# for non-US Government use and distribution.
21+
# This Software includes and/or makes use of Third-Party Software each
22+
# subject to its own license.
23+
# DM24-0278
24+
25+
from ssvc.decision_tables.base import decision_table_to_longform_df
26+
27+
28+
def write_csv(
29+
decision_table: "DecisionTable",
30+
csvfile: str,
31+
child_tree: bool = False,
32+
index: bool = False,
33+
):
34+
import os
35+
36+
# write longform csv to file
37+
file_path = os.path.abspath(__file__)
38+
project_base_path = os.path.abspath(
39+
os.path.join(os.path.dirname(file_path), "..", "..", "..")
40+
)
41+
42+
parts = ["data", "csvs"]
43+
if child_tree:
44+
parts.append("child_trees")
45+
46+
target_dir = os.path.join(project_base_path, *parts)
47+
assert os.path.exists(target_dir), f"Target directory {target_dir} does not exist."
48+
49+
csv_path = os.path.join(target_dir, csvfile)
50+
51+
with open(csv_path, "w") as fp:
52+
fp.write(decision_table_to_longform_df(decision_table).to_csv(index=index))
53+
54+
55+
def main():
56+
pass
57+
58+
59+
if __name__ == "__main__":
60+
main()
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
#!/usr/bin/env python
2+
"""
3+
Models the Human Impact decision table for SSVC.
4+
"""
5+
# Copyright (c) 2025 Carnegie Mellon University.
6+
# NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE
7+
# ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN "AS-IS" BASIS.
8+
# CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND,
9+
# EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT
10+
# NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR
11+
# MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE
12+
# OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE
13+
# ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM
14+
# PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT.
15+
# Licensed under a MIT (SEI)-style license, please see LICENSE or contact
16+
# permission@sei.cmu.edu for full terms.
17+
# [DISTRIBUTION STATEMENT A] This material has been approved for
18+
# public release and unlimited distribution. Please see Copyright notice
19+
# for non-US Government use and distribution.
20+
# This Software includes and/or makes use of Third-Party Software each
21+
# subject to its own license.
22+
# DM24-0278
23+
24+
from ssvc.decision_points.ssvc.human_impact import LATEST as HumanImpact
25+
from ssvc.decision_points.ssvc.mission_impact import LATEST as MissionImpact
26+
from ssvc.decision_points.ssvc.safety_impact import SAFETY_IMPACT_1 as SituatedSafetyImpact
27+
from ssvc.decision_tables.base import DecisionTable, dpdict_to_combination_list
28+
from ssvc.decision_tables.helpers import write_csv
29+
30+
dp_dict = {dp.id: dp for dp in [SituatedSafetyImpact, MissionImpact, HumanImpact]}
31+
32+
for combo in dpdict_to_combination_list(dp_dict,exclude=HumanImpact.id):
33+
print(combo)
34+
35+
HUMAN_IMPACT_1 = DecisionTable(
36+
name = "Human Impact",
37+
namespace = "ssvc",
38+
description = "Human Impact decision table for SSVC",
39+
version = "1.0.0",
40+
decision_points = {dp.id: dp for dp in [SituatedSafetyImpact,MissionImpact,HumanImpact]},
41+
outcome = HumanImpact.id,
42+
mapping = [
43+
{
44+
"ssvc:SI:1.0.0": "N",
45+
"ssvc:MI:2.0.0": "D",
46+
"ssvc:HI:2.0.1": "L"
47+
},
48+
{
49+
"ssvc:SI:1.0.0": "N",
50+
"ssvc:MI:2.0.0": "MSC",
51+
"ssvc:HI:2.0.1": "L"
52+
},
53+
{
54+
"ssvc:SI:1.0.0": "N",
55+
"ssvc:MI:2.0.0": "MEF",
56+
"ssvc:HI:2.0.1": "M"
57+
},
58+
{
59+
"ssvc:SI:1.0.0": "N",
60+
"ssvc:MI:2.0.0": "MF",
61+
"ssvc:HI:2.0.1": "VH"
62+
},
63+
{
64+
"ssvc:SI:1.0.0": "M",
65+
"ssvc:MI:2.0.0": "D",
66+
"ssvc:HI:2.0.1": "L"
67+
},
68+
{
69+
"ssvc:SI:1.0.0": "M",
70+
"ssvc:MI:2.0.0": "MSC",
71+
"ssvc:HI:2.0.1": "L"
72+
},
73+
{
74+
"ssvc:SI:1.0.0": "M",
75+
"ssvc:MI:2.0.0": "MEF",
76+
"ssvc:HI:2.0.1": "M"
77+
},
78+
{
79+
"ssvc:SI:1.0.0": "M",
80+
"ssvc:MI:2.0.0": "MF",
81+
"ssvc:HI:2.0.1": "VH"
82+
},
83+
{
84+
"ssvc:SI:1.0.0": "J",
85+
"ssvc:MI:2.0.0": "D",
86+
"ssvc:HI:2.0.1": "M"
87+
},
88+
{
89+
"ssvc:SI:1.0.0": "J",
90+
"ssvc:MI:2.0.0": "MSC",
91+
"ssvc:HI:2.0.1": "M"
92+
},
93+
{
94+
"ssvc:SI:1.0.0": "J",
95+
"ssvc:MI:2.0.0": "MEF",
96+
"ssvc:HI:2.0.1": "H"
97+
},
98+
{
99+
"ssvc:SI:1.0.0": "J",
100+
"ssvc:MI:2.0.0": "MF",
101+
"ssvc:HI:2.0.1": "VH"
102+
},
103+
{
104+
"ssvc:SI:1.0.0": "H",
105+
"ssvc:MI:2.0.0": "D",
106+
"ssvc:HI:2.0.1": "H"
107+
},
108+
{
109+
"ssvc:SI:1.0.0": "H",
110+
"ssvc:MI:2.0.0": "MSC",
111+
"ssvc:HI:2.0.1": "H"
112+
},
113+
{
114+
"ssvc:SI:1.0.0": "H",
115+
"ssvc:MI:2.0.0": "MEF",
116+
"ssvc:HI:2.0.1": "H"
117+
},
118+
{
119+
"ssvc:SI:1.0.0": "H",
120+
"ssvc:MI:2.0.0": "MF",
121+
"ssvc:HI:2.0.1": "VH"
122+
},
123+
{
124+
"ssvc:SI:1.0.0": "C",
125+
"ssvc:MI:2.0.0": "D",
126+
"ssvc:HI:2.0.1": "VH"
127+
},
128+
{
129+
"ssvc:SI:1.0.0": "C",
130+
"ssvc:MI:2.0.0": "MSC",
131+
"ssvc:HI:2.0.1": "VH"
132+
},
133+
{
134+
"ssvc:SI:1.0.0": "C",
135+
"ssvc:MI:2.0.0": "MEF",
136+
"ssvc:HI:2.0.1": "VH"
137+
},
138+
{
139+
"ssvc:SI:1.0.0": "C",
140+
"ssvc:MI:2.0.0": "MF",
141+
"ssvc:HI:2.0.1": "VH"
142+
}
143+
]
144+
)
145+
146+
VERSIONS = [HUMAN_IMPACT_1,]
147+
LATEST = HUMAN_IMPACT_1
148+
149+
def main():
150+
151+
print("## Human Impact Decision Table Object")
152+
print()
153+
print(HUMAN_IMPACT_1.model_dump_json(indent=2))
154+
155+
print("## Human Impact Decision Table Longform DataFrame CSV")
156+
print()
157+
from ssvc.decision_tables.base import decision_table_to_longform_df
158+
print(decision_table_to_longform_df(HUMAN_IMPACT_1).to_csv(index=False))
159+
160+
csvfile = "human-impact.csv"
161+
write_csv(HUMAN_IMPACT_1,csvfile)
162+
163+
164+
if __name__ == '__main__':
165+
main()

0 commit comments

Comments
 (0)