Delay / utils.py
AjaykumarPilla's picture
Update utils.py
eb03e55 verified
import matplotlib.pyplot as plt
def validate_inputs(input_data):
"""
Validate input data for required fields and ranges.
"""
required_fields = [
"project_name", "phase", "task", "current_progress",
"task_expected_duration", "task_actual_duration", "workforce_gap",
"workforce_skill_level", "workforce_shift_hours", "weather_impact_score",
"weather_condition", "weather_forecast_date", "project_location"
]
for field in required_fields:
if not input_data[field]:
return f"Please select or fill in {field.replace('_', ' ').lower()}"
if not (0 <= input_data["current_progress"] <= 100):
return "Current progress must be between 0 and 100"
if not (0 <= input_data["workforce_gap"] <= 100):
return "Workforce gap must be between 0 and 100"
if not (0 <= input_data["weather_impact_score"] <= 100):
return "Weather impact score must be between 0 and 100"
return None
def generate_heatmap(delay_probability, label):
"""
Generate a Chart.js bar chart configuration to visualize delay probability.
Returns a Chart.js configuration dictionary.
"""
color = '#FF0000' if delay_probability > 75 else '#FFFF00' if delay_probability > 50 else '#00FF00'
chart_config = {
"type": "bar",
"data": {
"labels": [label],
"datasets": [{
"label": "Delay Probability (%)",
"data": [delay_probability],
"backgroundColor": [color],
"borderColor": ["#000000"],
"borderWidth": 1
}]
},
"options": {
"indexAxis": "y",
"scales": {
"x": {
"beginAtZero": True,
"max": 100,
"title": {"display": True, "text": "Delay Probability (%)"}
},
"y": {"title": {"display": True, "text": "Task"}}
},
"plugins": {
"title": {"display": True, "text": "Delay Risk Heatmap"}
}
}
}
return chart_config