Commit 4399ec5c authored by aakash.bedi's avatar aakash.bedi

configure postgres

parent 07cb2e46
...@@ -14,8 +14,8 @@ required_tz=$REQUIRED_TZ ...@@ -14,8 +14,8 @@ required_tz=$REQUIRED_TZ
start_relative=$START_RELATIVE start_relative=$START_RELATIVE
end_relative=$END_RELATIVE end_relative=$END_RELATIVE
[FORECAST_DATA] [POSTGRES_CRED]
days_of_degradation_prediction=$DAYS_OF_DEGRADATION_PREDICTION postgres_uri=$POSTGRES_URI
...@@ -6,4 +6,4 @@ DEFAULT_TZ="UTC" ...@@ -6,4 +6,4 @@ DEFAULT_TZ="UTC"
REQUIRED_TZ="Asia/Kolkata" REQUIRED_TZ="Asia/Kolkata"
START_RELATIVE=90 START_RELATIVE=90
END_RELATIVE=0 END_RELATIVE=0
DAYS_OF_DEGRADATION_PREDICTION=7 POSTGRES_URI=postgresql://ilens:iLens$456@192.168.0.207:5455/ilens_ai
No preview for this file type
...@@ -9,7 +9,6 @@ from loguru import logger ...@@ -9,7 +9,6 @@ from loguru import logger
_application_conf = f"./conf/application.conf" _application_conf = f"./conf/application.conf"
_default_conf = f"./config.env" _default_conf = f"./config.env"
data_conf = f"./conf/data.yml" data_conf = f"./conf/data.yml"
training_data = f"./data/training.csv"
load_dotenv(dotenv_path=_default_conf) load_dotenv(dotenv_path=_default_conf)
...@@ -51,21 +50,16 @@ class Kafka: ...@@ -51,21 +50,16 @@ class Kafka:
kafka_topic = config["KAFKA"]["kafka_topic"] kafka_topic = config["KAFKA"]["kafka_topic"]
class HistoricalData: class PostgresCred:
start_relative = config['HISTORICAL_DATA']['start_relative'] postgres_uri = config['POSTGRES_CRED']['postgres_uri']
end_relative = config['HISTORICAL_DATA']['end_relative']
class ForecastData:
days_of_degradation_prediction = config['FORECAST_DATA']['days_of_degradation_prediction']
class TimeZone: class TimeZone:
default_tz = config["TIMEZONE"]["default_tz"] default_tz = config["TIMEZONE"]["default_tz"]
required_tz = config["TIMEZONE"]["required_tz"] required_tz = config["TIMEZONE"]["required_tz"]
# Read the configuration file
# Read the configuration file
yml_file_path = "conf/" yml_file_path = "conf/"
try: try:
with open(os.path.join(yml_file_path, 'data.yml'), 'r') as engine_yml_file: with open(os.path.join(yml_file_path, 'data.yml'), 'r') as engine_yml_file:
......
from loguru import logger from loguru import logger
import pandas as pd import pandas as pd
from scripts.core.master_tables.dataframe_read import ReadData from scripts.constants.app_configuration import PostgresCred
class JoinTables: class JoinTables:
def __init__(self): def __init__(self):
self.base_path = f'data' self.base_path = f'data'
self.golden_batch = "Golden Batch"
def join_master(self, df_batch_master, df_batch_kpi_master, df_batch_material_master): def join_master(self, df_batch_master, df_batch_kpi_master, df_batch_material_master):
try: try:
...@@ -19,22 +20,21 @@ class JoinTables: ...@@ -19,22 +20,21 @@ class JoinTables:
min_bct_4 = df.loc[df['process_stage_id'] == 'P2E-STAGE-004', 'batch_cycle_time_minutes'].min() min_bct_4 = df.loc[df['process_stage_id'] == 'P2E-STAGE-004', 'batch_cycle_time_minutes'].min()
min_bct_5 = df.loc[df['process_stage_id'] == 'P2E-STAGE-005', 'batch_cycle_time_minutes'].min() min_bct_5 = df.loc[df['process_stage_id'] == 'P2E-STAGE-005', 'batch_cycle_time_minutes'].min()
df.loc[(df['process_stage_id'] == 'P2E-STAGE-001') & (df['batch_cycle_time_minutes'] == min_bct_1), df.loc[(df['process_stage_id'] == 'P2E-STAGE-001') & (df['batch_cycle_time_minutes'] == min_bct_1),
'golden_batch'] = 'Golden Batch' 'golden_batch'] = self.golden_batch
df.loc[(df['process_stage_id'] == 'P2E-STAGE-002') & (df['batch_cycle_time_minutes'] == min_bct_2), df.loc[(df['process_stage_id'] == 'P2E-STAGE-002') & (df['batch_cycle_time_minutes'] == min_bct_2),
'golden_batch'] = 'Golden Batch' 'golden_batch'] = self.golden_batch
df.loc[(df['process_stage_id'] == 'P2E-STAGE-003') & (df['batch_cycle_time_minutes'] == min_bct_3), df.loc[(df['process_stage_id'] == 'P2E-STAGE-003') & (df['batch_cycle_time_minutes'] == min_bct_3),
'golden_batch'] = 'Golden Batch' 'golden_batch'] = self.golden_batch
df.loc[(df['process_stage_id'] == 'P2E-STAGE-004') & (df['batch_cycle_time_minutes'] == min_bct_4), df.loc[(df['process_stage_id'] == 'P2E-STAGE-004') & (df['batch_cycle_time_minutes'] == min_bct_4),
'golden_batch'] = 'Golden Batch' 'golden_batch'] = self.golden_batch
df.loc[(df['process_stage_id'] == 'P2E-STAGE-005') & (df['batch_cycle_time_minutes'] == min_bct_5), df.loc[(df['process_stage_id'] == 'P2E-STAGE-005') & (df['batch_cycle_time_minutes'] == min_bct_5),
'golden_batch'] = 'Golden Batch' 'golden_batch'] = self.golden_batch
df.reset_index(drop=True, inplace=True) df.reset_index(drop=True, inplace=True)
df = df.round(2) df = df.round(2)
df.to_excel(f"{self.base_path}/t_batch_information_master.xlsx", index=False) df.to_excel(f"{self.base_path}/t_batch_information_master.xlsx", index=False)
logger.info(f'Pushing master_join to postgres') logger.info(f'Pushing master_join to postgres')
df.set_index('batch_no').to_sql("t_batch_information_master", df.set_index('batch_no').to_sql("t_batch_information_master", PostgresCred.postgres_uri,
"postgresql://ilens:iLens$456@192.168.0.207:5455/ilens_ai",
if_exists='replace') if_exists='replace')
logger.debug(f'Pushed master_join to postgres') logger.debug(f'Pushed master_join to postgres')
except Exception as e: except Exception as e:
logger.exception(f"Exception - {e}") logger.exception(f"Exception - {e}")
\ No newline at end of file
from loguru import logger from loguru import logger
import pandas as pd import pandas as pd
from scripts.core.master_tables.dataframe_read import ReadData from scripts.core.master_tables.dataframe_read import ReadData
from scripts.constants.app_configuration import PostgresCred
class BatchKpi: class BatchKpi:
...@@ -66,9 +67,7 @@ class BatchKpi: ...@@ -66,9 +67,7 @@ class BatchKpi:
df = df.round(2) df = df.round(2)
df.to_excel(f"{self.base_path}/t_batch_kpi_master.xlsx", index=False) df.to_excel(f"{self.base_path}/t_batch_kpi_master.xlsx", index=False)
logger.info(f'Pushing batch_kpi_master to postgres') logger.info(f'Pushing batch_kpi_master to postgres')
df.set_index('batch_no').to_sql("t_batch_kpi_master", df.set_index('batch_no').to_sql("t_batch_kpi_master", PostgresCred.postgres_uri, if_exists="replace")
"postgresql://ilens:iLens$456@192.168.0.207:5455/ilens_ai",
if_exists="replace")
logger.debug(f'Pushed batch_kpi_master to postgres') logger.debug(f'Pushed batch_kpi_master to postgres')
return df return df
except Exception as e: except Exception as e:
......
from loguru import logger from loguru import logger
import pandas as pd import pandas as pd
from scripts.core.master_tables.dataframe_read import ReadData from scripts.core.master_tables.dataframe_read import ReadData
from scripts.constants.app_configuration import PostgresCred
class BatchMaster: class BatchMaster:
...@@ -51,23 +52,23 @@ class BatchMaster: ...@@ -51,23 +52,23 @@ class BatchMaster:
df_stage_1, df_stage_2, df_stage_3, df_stage_4, df_stage_5 = ReadData().read_df() df_stage_1, df_stage_2, df_stage_3, df_stage_4, df_stage_5 = ReadData().read_df()
df_stage_1 = self.batch_master(df_stage_1, process_stage_name="Stage-01", df_stage_1 = self.batch_master(df_stage_1, process_stage_name="Stage-01",
process_stage_id="P2E-STAGE-001", process_stage_id="P2E-STAGE-001",
batch_product="P2E-Stage-01", ideal_batch_cycle_time_hr=720, batch_product="P2E-Stage-01", ideal_batch_cycle_time_hr=12,
batch_setup_time_hr=1) batch_setup_time_hr=1)
df_stage_2 = self.batch_master(df_stage_2, process_stage_name="Stage-02", df_stage_2 = self.batch_master(df_stage_2, process_stage_name="Stage-02",
process_stage_id="P2E-STAGE-002", process_stage_id="P2E-STAGE-002",
batch_product="P2E-Stage-02", ideal_batch_cycle_time_hr=1440, batch_product="P2E-Stage-02", ideal_batch_cycle_time_hr=24,
batch_setup_time_hr=1) batch_setup_time_hr=1)
df_stage_3 = self.batch_master(df_stage_3, process_stage_name="Stage-03", df_stage_3 = self.batch_master(df_stage_3, process_stage_name="Stage-03",
process_stage_id="P2E-STAGE-003", process_stage_id="P2E-STAGE-003",
batch_product="P2E-Stage-03", ideal_batch_cycle_time_hr=2880, batch_product="P2E-Stage-03", ideal_batch_cycle_time_hr=48,
batch_setup_time_hr=1) batch_setup_time_hr=1)
df_stage_4 = self.batch_master(df_stage_4, process_stage_name="Stage-04", df_stage_4 = self.batch_master(df_stage_4, process_stage_name="Stage-04",
process_stage_id="P2E-STAGE-004", process_stage_id="P2E-STAGE-004",
batch_product="P2E-Stage-04", ideal_batch_cycle_time_hr=7440, batch_product="P2E-Stage-04", ideal_batch_cycle_time_hr=124,
batch_setup_time_hr=1) batch_setup_time_hr=1)
df_stage_5 = self.batch_master(df_stage_5, process_stage_name="Stage-05", df_stage_5 = self.batch_master(df_stage_5, process_stage_name="Stage-05",
process_stage_id="P2E-STAGE-005", process_stage_id="P2E-STAGE-005",
batch_product="P2E-Stage-05", ideal_batch_cycle_time_hr=6570, batch_product="P2E-Stage-05", ideal_batch_cycle_time_hr=110,
batch_setup_time_hr=1) batch_setup_time_hr=1)
df = pd.concat([df_stage_1, df_stage_2, df_stage_3, df_stage_4, df_stage_5], axis=0) df = pd.concat([df_stage_1, df_stage_2, df_stage_3, df_stage_4, df_stage_5], axis=0)
...@@ -77,9 +78,7 @@ class BatchMaster: ...@@ -77,9 +78,7 @@ class BatchMaster:
df = df.round(2) df = df.round(2)
df.to_excel(f"{self.base_path}/t_batch_master.xlsx", index=False) df.to_excel(f"{self.base_path}/t_batch_master.xlsx", index=False)
logger.info(f'Pushing batch_master to postgres') logger.info(f'Pushing batch_master to postgres')
df.set_index('batch_no').to_sql("t_batch_master", df.set_index('batch_no').to_sql("t_batch_master", PostgresCred.postgres_uri, if_exists="replace")
"postgresql://ilens:iLens$456@192.168.0.207:5455/ilens_ai",
if_exists="replace")
logger.debug(f'Pushed batch_master to postgres') logger.debug(f'Pushed batch_master to postgres')
return df return df
......
from loguru import logger from loguru import logger
import pandas as pd import pandas as pd
from scripts.core.master_tables.dataframe_read import ReadData from scripts.core.master_tables.dataframe_read import ReadData
from scripts.constants.app_configuration import PostgresCred
class BatchMaterial: class BatchMaterial:
...@@ -71,9 +72,7 @@ class BatchMaterial: ...@@ -71,9 +72,7 @@ class BatchMaterial:
df = df.round(2) df = df.round(2)
df.to_excel(f"{self.base_path}/t_batch_material_master.xlsx", index=False) df.to_excel(f"{self.base_path}/t_batch_material_master.xlsx", index=False)
logger.info(f'Pushing batch_master to postgres') logger.info(f'Pushing batch_master to postgres')
df.set_index('batch_no').to_sql("t_batch_material_master", df.set_index('batch_no').to_sql("t_batch_material_master", PostgresCred.postgres_uri, if_exists="replace")
"postgresql://ilens:iLens$456@192.168.0.207:5455/ilens_ai",
if_exists="replace")
logger.debug(f'Pushed batch_master to postgres') logger.debug(f'Pushed batch_master to postgres')
return df return df
except Exception as e: except Exception as 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