File size: 2,139 Bytes
4b82103
 
 
 
 
 
 
 
 
eb03e55
 
4b82103
 
 
eb03e55
4b82103
 
 
 
eb03e55
 
4b82103
 
 
 
47e542b
 
4b82103
47e542b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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