Commit 70010a88 authored by aakash.bedi's avatar aakash.bedi

added coefficient multiplication logic

parent 295c841d
Pipeline #59658 failed with stage
import pandas as pd
if __name__ == "__main__":
from dotenv import load_dotenv
load_dotenv(dotenv_path='config.env')
......@@ -18,22 +20,22 @@ start_date, end_date, start_timestamp, end_timestamp = KairosStartEndDate().star
def get_tag_details():
try:
df_raw_tags, df_predicted_tags = get_raw_predicted_tags()
df_raw_tags, df_predicted_tags, df_coefficients = get_raw_predicted_tags()
logger.info(f'raw tags dataframe shape - {df_raw_tags.shape}')
logger.info(f'predicted tags dataframe shape - {df_predicted_tags.shape}')
df = get_tags_data(df_input_tags=df_raw_tags, start_timestamp=start_timestamp, end_timestamp=end_timestamp)
logger.info(f'Shape of final df - {df.shape}')
df_kairos_data = get_tags_data(df_input_tags=df_raw_tags, start_timestamp=start_timestamp, end_timestamp=end_timestamp)
logger.info(f'Shape of final df - {df_kairos_data.shape}')
mppt_data = GetData()
df_mppt = mppt_data.current_voltage_mppt_data(df=df)
df_mppt = mppt_data.associate_inv_mppt_id(df=df_kairos_data)
df = mppt_data.multiply_mppt_coefficients(df_mppt=df_mppt, df_coefficients=df_coefficients)
data_preprocessing = DataPreprocessing()
df_mppt = data_preprocessing.remove_outliers(df=df_mppt, param_list=['tilt_irradiance', 'voltage_mppt',
df = data_preprocessing.remove_outliers(df=df, param_list=['tilt_irradiance', 'voltage_mppt',
'current_mppt'])
df_mppt, df_train, df_test = data_preprocessing.train_test_split(df=df_mppt)
get_training_inference = TrainingInference(df=df_mppt, df_train=df_train, df_test=df_test)
df, df_train, df_test = data_preprocessing.train_test_split(df=df)
get_training_inference = TrainingInference(df=df, df_train=df_train, df_test=df_test)
ai_modelling(df_train=df_train, get_training_inference=get_training_inference,
df_predicted_tags=df_predicted_tags)
except Exception as e:
......
......@@ -24,6 +24,12 @@ def ai_modelling(df_train, get_training_inference, df_predicted_tags):
df_result["timestamp"] = df_result["datetime"].values.astype(np.int64) / 10 ** 9
df_result["timestamp"] = df_result["timestamp"].astype('int')
df_result['hour'] = df_result['datetime'].dt.hour
df_result.loc[df_result['hour'].between(left=18, right=23, inclusive=True),
'predicted_current_mppt'] = 0
df_result.loc[df_result['hour'].between(left=0, right=5, inclusive=True),
'predicted_current_mppt'] = 0
df_result.drop(['hour'], axis=1, inplace=True)
CalculatedDataPush(df_result=df_result, final_tags_dict=final_dict).kafka_data_push()
logger.info(f'{final_dict}')
except Exception as e:
......
......@@ -4,7 +4,7 @@ from loguru import logger
class GetData:
@staticmethod
def current_voltage_mppt_data(df):
def associate_inv_mppt_id(df):
try:
current_column_list = [col_name for col_name in df if 'current' in col_name]
voltage_column_list = [col_name for col_name in df if 'voltage' in col_name]
......@@ -25,10 +25,24 @@ class GetData:
df_mppt = pd.concat([df_mppt, df_temp], axis=0)
df_mppt.reset_index(drop=True, inplace=True)
df_mppt.sort_values(['inv_id', 'mppt_id'], inplace=True)
df_mppt['inv_id_mppt_id'] = df_mppt['inv_id'] + '_' + df_mppt['mppt_id']
df_mppt.dropna(axis=0, inplace=True)
df_mppt.reset_index(drop=True, inplace=True)
return df_mppt
except Exception as e:
logger.exception(f'Exception - {e}')
@staticmethod
def multiply_mppt_coefficients(df_mppt, df_coefficients):
try:
df = pd.merge(df_mppt, df_coefficients, on='inv_id_mppt_id', how='left')
logger.debug(f'null rows after mppt coefficient multiplication - {df.isnull().sum()}')
df["coefficient"].fillna(1, inplace=True)
df.reset_index(drop=True, inplace=True)
df['current_mppt'] = df['current_mppt'] * df["coefficient"]
df.drop(['coefficient', 'inv_id_mppt_id'], axis=1, inplace=True)
return df
except Exception as e:
logger.exception(f'Exception - {e}')
......@@ -32,6 +32,15 @@ def get_raw_predicted_tags():
df_raw_tags.rename(columns={'index': 'tag_name'}, inplace=True)
df_predicted_tags.reset_index(inplace=True)
df_predicted_tags.rename(columns={'index': 'tag_name'}, inplace=True)
return df_raw_tags, df_predicted_tags
mppt_coefficients = mongo_conn.find_one({"$and": [{"id": "dalmia_string_level_tags"}, {"city": "ariyalur"},
{"tags_property": "mppt_coefficients"}]})
coefficients_dict = mppt_coefficients['input_data']
logger.info(f'req coefficients dict length - {len(coefficients_dict)}')
df_coefficients = pd.DataFrame.from_dict(coefficients_dict, orient='index')
df_coefficients.reset_index(inplace=True)
df_coefficients.rename(columns={'index': 'inv_id_mppt_id'}, inplace=True)
return df_raw_tags, df_predicted_tags, df_coefficients
except Exception as e:
logger.exception(f'Exception - {e}')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment