File size: 3,330 Bytes
d0c7e75
 
 
1661bec
 
 
d0c7e75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d6396d6
 
 
 
255cd27
d0c7e75
 
d6396d6
 
 
 
d0c7e75
 
 
 
 
 
 
 
 
1661bec
 
d0c7e75
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
from flask import Flask, request, render_template
import numpy as np
import pickle

app = Flask(__name__)

# Cloud Computing Weights and Max Marks
cc_weights = {
    'A1': 1, 'Q1': 1.5, 'A2': 1, 'Q2': 1.5, 'A3': 1,
    'A4': 4, 'Q3': 1.5, 'Mid': 35, 'AWS Labs': 3,
    'Q4': 1.25, 'A5': 4, 'Q5': 1.25, 'A6': 4, 'Final': 40
}
cc_max_marks = {
    'A1': 10, 'Q1': 21, 'A2': 10, 'Q2': 30, 'A3': 100,
    'A4': 10, 'Q3': 41, 'Mid': 35, 'AWS Labs': 10,
    'Q4': 40, 'A5': 100, 'Q5': 20, 'A6': 100, 'Final': 40
}

# ICT Weights and Max Marks
ict_weights = {
    'Q1': 2.625, 'Q2': 2.625, 'A1': 2, 'Q3': 2.625, 'Q4': 2.625,
    'Midterm': 35, 'Q5': 2.625, 'A2': 2, 'Q6': 2.625, 'Q7': 2.625,
    'Q8': 2.625, 'Final': 40
}
ict_max_marks = {
    'Q1': 30, 'Q2': 49, 'A1': 100, 'Q3': 30, 'Q4': 15,
    'Midterm': 35, 'Q5': 45, 'A2': 100, 'Q6': 32, 'Q7': 24,
    'Q8': 40, 'Final': 100
}

def normalize_input(input_activities, weights, max_marks):
    """
    Normalize the input activities based on weights and max marks.
    """
    normalized_activities = []
    for activity, score in input_activities.items():
        if score > 0:  # Ignore zeros
            normalized_score = (score / max_marks[activity]) * weights[activity]
            normalized_activities.append(normalized_score)
    return normalized_activities

def predict_final_score(input_activities, weights, max_marks, model_prefix):
    """
    Predict the final score based on input activities after normalization.
    """
    normalized_activities = normalize_input(input_activities, weights, max_marks)
    n = len(normalized_activities)

    if n == 0:
        return "No valid activities entered. Please provide scores greater than 0."

    try:
        with open(f"{model_prefix}_model_{n}_activities.pkl", "rb") as file:
            model = pickle.load(file)
    except FileNotFoundError:
        return f"No model available for {n} activities. Train the model first."

    input_array = np.array(normalized_activities).reshape(1, -1)
    predicted_score = model.predict(input_array)[0]
    return round(predicted_score, 2)

@app.route('/', methods=['GET', 'POST'])
def home():
    cc_predicted_score = None
    ict_predicted_score = None

    if request.method == 'POST':
        # Identify the form (Cloud Computing or ICT)
        form_type = request.form.get('form_type')

        if form_type == 'cloud_computing':
            input_activities = {
                activity: float(request.form.get(activity, 0) or 0)  # Default to 0 for empty inputs
                for activity in cc_weights.keys()
            }
            cc_predicted_score = predict_final_score(input_activities, cc_weights, cc_max_marks, "cloud_computing")

        elif form_type == 'ict':
            input_activities = {
                activity: float(request.form.get(activity, 0) or 0)  # Default to 0 for empty inputs
                for activity in ict_weights.keys()
            }
            ict_predicted_score = predict_final_score(input_activities, ict_weights, ict_max_marks, "ict")

    return render_template(
        'index.html',
        cc_max_marks=cc_max_marks,
        ict_max_marks=ict_max_marks,
        cc_predicted_score=cc_predicted_score,
        ict_predicted_score=ict_predicted_score
    )

if __name__ == '__main__':
    app.run(debug=False, port=5000)