Question
PLEASE DO NOT SPAM THE QUESTION I WILL AUTOMATICALLY DISLIKE IT (THANKS) Build a script (Python) that reads the saved csv called RiskResults.csv .This requires
PLEASE DO NOT SPAM THE QUESTION I WILL AUTOMATICALLY DISLIKE IT (THANKS)
Build a script (Python) that reads the saved csv called RiskResults.csv.This requires using a matrix-like data structure (using a dictionary) to store the various data in a permeant file.
code:
# Define a mapping of severity and probability to threat value
threat_map = {
"Emergency": {"Frequent": 16, "Probable": 14, "Unlikely": 11, "Rare": 8},
"Major": {"Frequent": 14, "Probable": 11, "Unlikely": 8, "Rare": 5},
"Moderate": {"Frequent": 11, "Probable": 8, "Unlikely": 5, "Rare": 2},
"Minor": {"Frequent": 5, "Probable": 2, "Unlikely": 1, "Rare": 0}
}
# Initialize a list to store the threats information
threats = []
# Open the CSV file and read the data into a list of dictionaries
with open("RiskResults.csv") as file:
# Skip the header line
next(file)
for line in file:
parts = line.strip().split(",")
# Unpack the data into separate variables
ID, start_time, end_time, description, severity, probability = parts
# Calculate the threat value based on the mapping
threat_value = threat_map[severity][probability]
# Create a dictionary to store the threat information
threat = {
"ID": ID,
"start_time": start_time,
"end_time": end_time,
"description": description,
"severity": severity,
"probability": probability,
"threat_value": threat_value
}
# Add the threat information to the list
threats.append(threat)
# Iterate over the list of threats and output a recommendation for each threat
for threat in threats:
threat_value = threat["threat_value"]
if threat_value
# Threat value should not be less than or equal to 0
print("Logging Error - check the data provided as this threat value is invalid.")
elif threat_value
print("Minor issue likely, increasing security is not recommended due to costs involved")
elif threat_value
print("Issue will require increase in security and access controls. Adding to Backlog for further planning.")
else:
print("Major bug or issue - sending email to sysadmin, infosec chief, and IT manager.")
RiskResults.csv
ID Start time Completion time Provide a "Description of the Risk" Select its severity Select its Probability Category 1 1/7/2023 12:03 1/7/2023 12:11 Internal employee sabotaging or leaking confidential data Major Unlikely People 2 1/12/2023 9:51 1/12/2023 9:54 Sensitive data over home network (potentially unsecured) Major Frequent Network 3 1/12/2023 10:16 1/12/2023 10:16 There is no security system protecting the house. Moderate Unlikely Physical 4 1/12/2023 10:13 1/12/2023 10:16 Natural disaster in florida Emergency Frequent Disaster 5 1/12/2023 10:16 1/12/2023 10:16 Hurricane Emergency Likely Disaster 6 1/12/2023 10:16 1/12/2023 10:16 Natural disaster Moderate Unlikely Disaster 7 1/12/2023 10:16 1/12/2023 10:16 Hurricane Emergency Unlikely Disaster 8 1/12/2023 10:16 1/12/2023 10:16 Baseball smashing through a window Minor Unlikely Physical 9 1/12/2023 10:16 1/12/2023 10:26 Building Maintenance Major Unlikely Maintenance 10 1/12/2023 10:12 1/12/2023 10:29 Flooding Emergency Probable Disaster
- Create Severity and Probability Dictionaries - Read CSV file into list of dictionaries - Using DictReader with csv library - Loop through above (for) and check values for severity and probability - display message for row based on total from values - Calculates a value based on the impact and probability - Emergency, Frequent = 16 to - Minor, Unlikely =1 - Recommend a dictionary here but can use if/elif/else or function calls (dictionary might look like:) Probability ={ "Frequent" : 16, "Probable": 14} Severity ={ "Emergency" } - Check that value by category with - the severity - the probability - Can use dictionary here (category: value) or scalar variables (or no variables if just evaluating the condition) - Displays a recommendation of action based on the value of the new threats added - Generic Recommendations (values don't matter - use what you think would be an emergency): - 0 or less: "Logging Error - check the data provided as this threat value is invalid." - between 0 and 4: "Minor issue likely, increasing security is not recommended due to costs involved" - between 5 and 15: "Issue will require increase in security and access controls. Adding to Backlog for further planning." - 16+: "Maior bug or issue - sending email to sysadmin, infosec chief. and IT managerStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started