BananaSauce commited on
Commit
fa82923
·
verified ·
1 Parent(s): dfff507

shows scenario

Browse files
Files changed (1) hide show
  1. multi_env_compare.py +68 -29
multi_env_compare.py CHANGED
@@ -8,6 +8,29 @@ import time
8
  def similar(a, b, threshold=0.9):
9
  return SequenceMatcher(None, a, b).ratio() > threshold
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  def perform_multi_env_analysis(uploaded_dataframes):
12
  # Concatenate all dataframes into a single dataframe
13
  combined_data = pd.concat(uploaded_dataframes, ignore_index=True)
@@ -66,10 +89,6 @@ def perform_multi_env_analysis(uploaded_dataframes):
66
  # Reorder columns
67
  grouped_data = grouped_data[['Environment', 'Functional area', 'Scenario name', 'Total', 'PASSED', 'FAILED']]
68
 
69
- # Display the grouped data
70
- st.write("### Scenario Counts by Environment and Functional Area")
71
- # st.dataframe(grouped_data.style.highlight_max(axis=0, subset=['Total', 'PASSED', 'FAILED']))
72
-
73
  # Display summary statistics
74
  st.write("### Summary Statistics")
75
  summary = grouped_data.groupby('Environment').agg({
@@ -86,14 +105,9 @@ def perform_multi_env_analysis(uploaded_dataframes):
86
  # Define scenarios_by_env here
87
  scenarios_by_env = {env: set(grouped_data[grouped_data['Environment'] == env]['Scenario name']) for env in selected_environments}
88
 
89
- # Debug: Print the number of scenarios in each environment
90
- for env, scenarios in scenarios_by_env.items():
91
- st.write(f"Number of scenarios in {env}: {len(scenarios)}")
92
-
93
  missing_scenarios = []
94
  mismatched_scenarios = []
95
 
96
- # New section for efficient inconsistency analysis
97
  st.write("### Inconsistent Scenario Count Analysis by Functional Area")
98
 
99
  if len(selected_environments) > 1:
@@ -113,31 +127,56 @@ def perform_multi_env_analysis(uploaded_dataframes):
113
  st.write(scenario_counts[area])
114
  st.write("\n")
115
 
116
- # Option to show detailed breakdown
117
- if st.checkbox("Show detailed scenario count breakdown"):
118
  st.write(scenario_counts)
119
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
  else:
121
  st.write("Please select at least two environments for comparison.")
122
 
123
- # Debug: Print the number of missing and mismatched scenarios
124
- st.write(f"Number of truly missing scenarios: {len(missing_scenarios)}")
125
- st.write(f"Number of scenarios with name differences: {len(mismatched_scenarios)}")
126
-
127
- if missing_scenarios:
128
- st.write("### Truly Missing Scenarios")
129
- missing_df = pd.DataFrame(missing_scenarios)
130
- st.dataframe(missing_df)
131
- else:
132
- st.write("No truly missing scenarios found across environments.")
133
-
134
- if mismatched_scenarios:
135
- st.write("### Scenarios with Name Differences")
136
- mismatched_df = pd.DataFrame(mismatched_scenarios)
137
- st.dataframe(mismatched_df)
138
- else:
139
- st.write("No scenarios with name differences found across environments.")
140
-
141
  def multi_env_compare_main():
142
  st.title("Multi-Environment Comparison")
143
 
 
8
  def similar(a, b, threshold=0.9):
9
  return SequenceMatcher(None, a, b).ratio() > threshold
10
 
11
+ def find_different_scenarios(grouped_data, area):
12
+ # Filter data for the specific functional area
13
+ area_data = grouped_data[grouped_data['Functional area'] == area]
14
+
15
+ # Get scenarios for each environment
16
+ scenarios_by_env = {env: set(area_data[area_data['Environment'] == env]['Scenario name'])
17
+ for env in area_data['Environment'].unique()}
18
+
19
+ # Find scenarios that are in one environment but not the other
20
+ diff_scenarios = []
21
+ envs = list(scenarios_by_env.keys())
22
+ for i in range(len(envs)):
23
+ for j in range(i+1, len(envs)):
24
+ env1, env2 = envs[i], envs[j]
25
+ diff = scenarios_by_env[env1] ^ scenarios_by_env[env2] # symmetric difference
26
+ for scenario in diff:
27
+ if scenario in scenarios_by_env[env1]:
28
+ diff_scenarios.append((scenario, env1, 'Present', env2, 'Missing'))
29
+ else:
30
+ diff_scenarios.append((scenario, env2, 'Present', env1, 'Missing'))
31
+
32
+ return diff_scenarios
33
+
34
  def perform_multi_env_analysis(uploaded_dataframes):
35
  # Concatenate all dataframes into a single dataframe
36
  combined_data = pd.concat(uploaded_dataframes, ignore_index=True)
 
89
  # Reorder columns
90
  grouped_data = grouped_data[['Environment', 'Functional area', 'Scenario name', 'Total', 'PASSED', 'FAILED']]
91
 
 
 
 
 
92
  # Display summary statistics
93
  st.write("### Summary Statistics")
94
  summary = grouped_data.groupby('Environment').agg({
 
105
  # Define scenarios_by_env here
106
  scenarios_by_env = {env: set(grouped_data[grouped_data['Environment'] == env]['Scenario name']) for env in selected_environments}
107
 
 
 
 
 
108
  missing_scenarios = []
109
  mismatched_scenarios = []
110
 
 
111
  st.write("### Inconsistent Scenario Count Analysis by Functional Area")
112
 
113
  if len(selected_environments) > 1:
 
127
  st.write(scenario_counts[area])
128
  st.write("\n")
129
 
130
+ # Option to show detailed breakdown with a unique key
131
+ if st.checkbox("Show detailed scenario count breakdown", key="show_detailed_breakdown"):
132
  st.write(scenario_counts)
133
 
134
+ # Add a selectbox for choosing the functional area to analyze
135
+ selected_area = st.selectbox("Select a functional area to analyze:",
136
+ options=[area for area, diff in inconsistent_areas.items() if diff > 0])
137
+
138
+ if selected_area:
139
+ st.write(f"### Detailed Analysis of Different Scenarios for '{selected_area}'")
140
+
141
+ # Get scenarios for each environment
142
+ scenarios_by_env = {env: set(filtered_data[(filtered_data['Environment'] == env) &
143
+ (filtered_data['Functional area'] == selected_area)]['Scenario name'])
144
+ for env in selected_environments}
145
+
146
+ # Find scenarios that are different between environments
147
+ all_scenarios = set.union(*scenarios_by_env.values())
148
+ diff_scenarios = [scenario for scenario in all_scenarios
149
+ if any(scenario not in env_scenarios for env_scenarios in scenarios_by_env.values())]
150
+
151
+ # Create a DataFrame to show presence/absence of scenarios
152
+ diff_df = pd.DataFrame(index=diff_scenarios, columns=selected_environments)
153
+ for scenario in diff_scenarios:
154
+ for env in selected_environments:
155
+ diff_df.at[scenario, env] = 'Present' if scenario in scenarios_by_env[env] else 'Missing'
156
+
157
+ diff_df.reset_index(inplace=True)
158
+ diff_df.rename(columns={'index': 'Scenario'}, inplace=True)
159
+
160
+ # Sort the DataFrame to show scenarios with differences first
161
+ diff_df['has_diff'] = diff_df.apply(lambda row: len(set(row[1:])) > 1, axis=1)
162
+ diff_df = diff_df.sort_values('has_diff', ascending=False).drop('has_diff', axis=1)
163
+
164
+ st.write(f"Number of scenarios that differ between environments: {len(diff_scenarios)}")
165
+
166
+ # Display the DataFrame
167
+ st.dataframe(diff_df)
168
+
169
+ # Provide a download button for the DataFrame
170
+ csv = diff_df.to_csv(index=False)
171
+ st.download_button(
172
+ label="Download CSV",
173
+ data=csv,
174
+ file_name=f"{selected_area}_scenario_comparison.csv",
175
+ mime="text/csv",
176
+ )
177
  else:
178
  st.write("Please select at least two environments for comparison.")
179
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
180
  def multi_env_compare_main():
181
  st.title("Multi-Environment Comparison")
182