File size: 1,597 Bytes
e454685 |
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 |
from datetime import datetime, timedelta
from retrain_save_soil import soil_model
from Retrain_Crop_Recommendation import crop_reco
from retrain_Crop_yield import Crop_yel
from retrain_sum_insured import sumin
from retrain_gross_premium import grop
import pandas as pd
import time
count = 0
def clear_feedback_data(csv_filename):
headings = ['timestamp', 'briefit', 'feedbacko']
pd.DataFrame(columns=headings).to_csv(csv_filename, index=False)
def read_ratings_from_csv(csv_filename):
try:
ratings_df = pd.read_csv(csv_filename)
return ratings_df
except FileNotFoundError:
return pd.DataFrame()
def calculate_average_rating(ratings_df):
if not ratings_df.empty:
return ratings_df['briefit'].mean()
return None
def check_and_retrain_model_if_needed(csv_filename):
ratings_df = read_ratings_from_csv(csv_filename)
ratings_df['timestamp'] = pd.to_datetime(ratings_df['timestamp'])
last_month = datetime.now() - timedelta(weeks=4)
recent_ratings = ratings_df[ratings_df['timestamp'] >= last_month]
average_rating = calculate_average_rating(recent_ratings)
if average_rating is not None and average_rating < 2.5:
soil_model()
crop_reco()
sumin()
Crop_yel()
grop()
clear_feedback_data(csv_filename)
print(f"Model retrained due to average rating below 2.5 (Average Rating: {average_rating})")
csv_filename = 'feedbacko.csv'
while (count ==0):
count+=1
check_and_retrain_model_if_needed(csv_filename)
# time.sleep(24 * 60 * 60)
|