def fm_data_manager_xl( xl, config_xl, query_manager_xl, source_connector_xl, data_loader_xl, data_formatter_xl, request, ) -> FMDataManager: dm = FMDataManager( cfg=config_xl, qm=query_manager_xl, sc=source_connector_xl, dl=data_loader_xl, df=data_formatter_xl, restore=request.param, ) if request.param is None: assets = to_df(get_value("project_state_assets", xl=xl)) type_curves = to_df(get_value("type_curves", xl=xl)) section_assumptions = to_df(get_value("section_assumptions", xl=xl)) external_settings = read_project_settings(string="sett_", xl=xl) dm.set_new_session( external_settings=external_settings, assets=assets, type_curves=type_curves, section_assumptions=section_assumptions, ) return dm
def debug_set_new_session(data_manager: FMDataManager, xl: w32 = None) -> FMDataManager: assets = to_df(get_value("project_state_assets", xl=xl)) type_curves = to_df(get_value("type_curves", xl=xl)) section_assumptions = to_df(get_value("section_assumptions", xl=xl)) data_manager.set_new_session(assets=assets, type_curves=type_curves, section_assumptions=section_assumptions) return data_manager
def create_fm_data_manager(restore=None): """ Creates a fm data manager using the xl instance passed. WARNING! dont change the wrapper order. :param restore: :param xl: :return: """ xl = xl_app() assets = to_df(get_value("project_state_assets", xl=xl)) if (assets.shape[0] == 0) and restore is None: message_box("Provide at least a section to start the analysis") return cfg = get_cached_object(get_value("data_obj_cfg")) source_connector = create_source_connector(xl=xl) query_manager = create_query_manager(xl=xl) data_loader = FMDataLoader() data_formatter = FMDataFormatter() dm = FMDataManager( cfg=cfg, qm=query_manager, sc=source_connector, dl=data_loader, df=data_formatter, restore=restore, ) return dm
def get_data(trigger): logging.info("Getting Data") xl = xl_app() set_formula("data_obj_manager", fn=create_fm_data_manager, xl=xl) data_manager = get_cached_object( get_value("data_obj_manager")) # type: FMDataManager assets = to_df(get_value("project_state_assets", xl=xl)) type_curves = to_df(get_value("type_curves", xl=xl)) section_assumptions = to_df(get_value("section_assumptions", xl=xl)) external_settings = read_project_settings(string="sett_", xl=xl) data_manager.set_new_session( external_settings=external_settings, assets=assets, type_curves=type_curves, section_assumptions=section_assumptions, ) data_manager.data_formatter.project_state_assets(xl=xl) data_manager.data_formatter.project_parameters(xl=xl)
def create_query_manager(xl=None): """ @type xl: win32com.client.Dispatch("Excel.Application") :param xl: :return: """ sql_queries = to_df(get_value("data_queries", xl=xl)) queries = list() for query in sql_queries.itertuples(): new_connection = Query(query.name, query.db, query.query, query.filter, query.function_call) queries.append(new_connection) query_manager = QueryManager(queries) return query_manager
def create_source_connector(xl=None): """ @type xl: win32com.client.Dispatch("Excel.Application") :param xl: :return: """ connection_settings = to_df(get_value("data_servers", xl=xl)) sql_cnxns = list() for cnxn in connection_settings.itertuples(): new_connection = SourceConnection( cnxn.db, cnxn.server, cnxn.driver, int(cnxn.port), os.environ[cnxn.user], os.environ[cnxn.pwd], cnxn.auth, ) sql_cnxns.append(new_connection) sql_manager = SourceConnector(sql_cnxns) return sql_manager
def map_columns_range(self, name: str, xl: w32 = None): address = get_address(name, xl=xl) excel_columns = make_columns_from_range(address) df_columns = to_df(get_value(name, xl=xl)).columns.values.tolist() return {key: value for key, value in zip(df_columns, excel_columns)}
def type_curves_xl(xl) -> pd.DataFrame: return to_df(get_value("type_curves", xl=xl))
def section_assumptions_xl(xl) -> pd.DataFrame: return to_df(get_value("section_assumptions", xl=xl))
def assets_xl(xl) -> pd.DataFrame: return to_df(get_value("project_state_assets", xl=xl))