Skip to content

Commit 15f8781

Browse files
Qinghao ShiQinghao Shi
authored andcommitted
add function allow PyCADI can be set in settings.json
1 parent c972092 commit 15f8781

File tree

3 files changed

+41
-8
lines changed

3 files changed

+41
-8
lines changed

fm_agent/fm_config.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,28 @@ def get_all_configs (self):
4141
""" search every config for all the models in SETTINGS_FILE
4242
@return a dictionary for configs and models combination
4343
"""
44-
4544
all_config_dict={}
4645
for model in self.json_configs.keys():
4746
if model != "GLOBAL":
4847
all_config_dict[model]=self.get_configs(model)
4948

5049
return all_config_dict
51-
50+
51+
def get_PyCADI_path(self):
52+
""" get the PyCADI path from the config file
53+
@return PyCADI path if setting exist
54+
@return None if not exist
55+
"""
56+
if "PyCADI_path" in self.json_configs["GLOBAL"][self.os]:
57+
return self.json_configs["GLOBAL"][self.os]["PyCADI_path"]
58+
else:
59+
return None
60+
5261
def get_model_lib(self,model_name):
5362
""" get the model lib path and name from the config file
54-
@retrun full name and path to the model_lib
63+
@return full name and path to the model_lib
5564
@return None if not exist
5665
"""
57-
5866
if model_name not in self.json_configs:
5967
return None
6068

@@ -75,7 +83,6 @@ def get_configs (self,model_name):
7583
@return a dictionary of config_name:config_file for give model_name
7684
@return None if no config found
7785
"""
78-
7986
if model_name not in self.json_configs:
8087
return None
8188

@@ -99,7 +106,6 @@ def parse_params_file (self, config_file , in_module=True):
99106
@return if config_file format is wrong, function will throw SimulatorError
100107
@return if config_file been parsed successfully, will return a dictionary of parameters
101108
"""
102-
103109
if in_module:
104110
filepath = os.path.join( os.path.dirname(__file__) ,"configs" , config_file )
105111
else:

fm_agent/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"GLOBAL": {
33
"Windows":{
4+
"PyCADI_path": "C:\\Program Files\\ARM\\FastModelsPortfolio_11.4\\lib\\python27",
45
"model_lib_path": "C:\\work\\model_libs",
56
"configs": {
67
"DEFAULT": "DEFAULT.conf",
@@ -9,6 +10,7 @@
910
}
1011
},
1112
"Linux":{
13+
"PyCADI_path": "/home/user/ARM/FastModelsPortfolio_11.4/lib/python2.7/",
1214
"model_lib_path": "/home/user/model_libs",
1315
"configs": {
1416
"DEFAULT": "DEFAULT.conf",

fm_agent/utils.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,31 @@ def __prn_log(self, logger_level, text, timestamp=None):
5252
self.prn_txd = partial(__prn_log, self, 'TXD')
5353
self.prn_rxd = partial(__prn_log, self, 'RXD')
5454

55+
def get_PyCADI_path(self):
56+
""" get the PyCADI path from the config file
57+
@return PyCADI path if setting exist
58+
@return None if not exist
59+
"""
60+
if "PyCADI_path" in self.json_configs["GLOBAL"]:
61+
return self.json_configs["GLOBAL"][self.os]["PyCADI_path"]
62+
else:
63+
return None
64+
5565
def check_import():
5666
""" Append PVLIB_HOME to PATH, so import PyCADI fm.debug can be imported """
67+
warning_msgs = []
68+
from .fm_config import FastmodelConfig
69+
config = FastmodelConfig()
70+
71+
fm_pycadi_path = config.get_PyCADI_path()
72+
if fm_pycadi_path:
73+
if os.path.exists(fm_pycadi_path):
74+
sys.path.append(fm_pycadi_path)
75+
else:
76+
warning_msgs.append("Warning: Could not locate PyCADI_path '%s'" % fm_pycadi_path)
77+
else:
78+
warning_msgs.append("Warning: PyCADI_path not set in settings.json")
79+
5780
if 'PVLIB_HOME' in os.environ:
5881
#FastModels PyCADI have different folder on different host OS
5982
fm_pycadi_path1 = os.path.join(os.environ['PVLIB_HOME'], 'lib', 'python27')
@@ -63,13 +86,15 @@ def check_import():
6386
elif os.path.exists(fm_pycadi_path2):
6487
sys.path.append(fm_pycadi_path2)
6588
else:
66-
print "Warning: Could not locate PyCADI in PVLIB_HOME/lib/python27"
89+
warning_msgs.append("Warning: Could not locate PyCADI in PVLIB_HOME/lib/python27")
6790
else:
68-
print "Warning: PVLIB_HOME not exist, check your fastmodel installation!"
91+
warning_msgs.append("Warning: 'PVLIB_HOME' environment variable not been set.")
6992

7093
try:
7194
import fm.debug
7295
except ImportError as e:
96+
for warning in warning_msgs:
97+
print warning
7398
print "Error: Failed to import fast models PyCADI!!!"
7499
return False
75100
else:

0 commit comments

Comments
 (0)