@sassoftware/restaflib
Advanced tools
Comparing version 2.1.0 to 2.1.1
{ | ||
"name": "@sassoftware/restaflib", | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"description": "collection of useful functions for common scenarios", | ||
@@ -5,0 +5,0 @@ "main": "./lib/restaflib.js", |
@@ -15,3 +15,3 @@ /* | ||
if (rc ne 0) then do; | ||
if (rc ne true) then do; | ||
results = {Errors= 'Unable to access ' ||caslib||'.'||name}; | ||
@@ -18,0 +18,0 @@ return results; |
@@ -10,2 +10,85 @@ /* | ||
/*------------------------------------------------*/ | ||
/*Does the tables exist and if not try to load it */ | ||
/* | ||
Typical usage: | ||
rc = checkAndLoadTable(caslib, name); | ||
if ( rc ne true) then do; | ||
...handle errors... | ||
end; | ||
else do; | ||
...your stuff... | ||
end; | ||
rc = true - the data is ready for use | ||
rc = false - the table could not be found | ||
rc = -1 - the caslib does not exist | ||
*/ | ||
/*------------------------------------------------*/ | ||
function checkAndLoadTable(caslib, name); | ||
/* verify caslib is there */ | ||
table.queryCaslib status=status result=result/ | ||
caslib = caslib; | ||
do k,v over result; /* to handle casuser[user] */ | ||
rc = v; | ||
end; | ||
if ( rc eq false ) then | ||
return -1; | ||
/* | ||
* Check to see if table is already loaded | ||
*/ | ||
action table.tableExists r=result/ | ||
caslib = caslib | ||
name = name; | ||
/* | ||
* if not loaded then try to load it | ||
*/ | ||
rc = true; | ||
if (result.exists eq 0) then do; | ||
path = lookupPath(caslib, name); | ||
if (path eq '*') then do; | ||
rc = false; | ||
end; | ||
else do; | ||
action table.loadTable status=status/ | ||
caslib = caslib | ||
source = path | ||
casout={caslib= caslib name=name}; | ||
if (status.statusCode ne 0 ) then rc = false; | ||
end; | ||
end; | ||
return rc; | ||
end; | ||
/* | ||
* return path to table | ||
*/ | ||
function lookupPath(caslib, name ) ; | ||
table.fileInfo r = result/ | ||
caslib=caslib; | ||
names = result.fileInfo[,4]; | ||
nameu = upcase(name)||'.SASHDAT'; | ||
cpath = '*'; | ||
count = 0; | ||
do n over names; | ||
if (upcase(n) eq nameu) then do; | ||
count = count + 1; | ||
if ( cpath eq '*') then do; | ||
cpath = n; | ||
end; | ||
end; | ||
end; | ||
if (count GT 1 ) then do; | ||
print 'Warning: ' count 'Files with names only different in case exist - First one chosen'; | ||
print 'Path: ' cpath ' will be used****'; | ||
end; | ||
r = cpath; | ||
return r; | ||
end; | ||
/*-----------------------------------------*/ | ||
@@ -132,32 +215,2 @@ /* isModel: is it model table */ | ||
function checkAndLoadTable(caslib, name); | ||
/* | ||
* Verify that the table is loaded | ||
*/ | ||
action table.tableExists r=result/ | ||
caslib = caslib | ||
name = name; | ||
/* | ||
* if necessary load the table | ||
*/ | ||
if ( result.exists eq 0) then do; | ||
path = lookupPath(caslib, name); | ||
if (path eq '*') then do; | ||
return 1; | ||
end; | ||
action table.loadTable status=status/ | ||
caslib = caslib | ||
source = path /*upcase(name) || '.sashdat' */ | ||
casout={caslib= caslib name=name}; | ||
return status.statusCode; | ||
end; | ||
else do; | ||
print name ' preloaded'; | ||
return 0; | ||
end; | ||
end; | ||
@@ -209,35 +262,3 @@ function dictToWhere(filter); | ||
function lookupPath(caslib, name ) ; | ||
table.fileInfo r = result/ | ||
caslib=caslib; | ||
names = result.fileInfo[,4]; | ||
nameu = upcase(name)||'.SASHDAT'; | ||
cpath = '*'; | ||
count = 0; | ||
do n over names; | ||
if (upcase(n) eq nameu) then do; | ||
count = count + 1; | ||
if ( cpath eq '*') then do; | ||
cpath = n; | ||
end; | ||
end; | ||
end; | ||
if (count eq 0 ) then do; | ||
print {Error: Table not found}; | ||
r = '*'; | ||
end; | ||
else do; | ||
if (count > 1 ) then do; | ||
print 'Warning: ' count 'Files with names only different in case exist - First one chosen'; | ||
end; | ||
print 'Path: ' cpath ' will be used****'; | ||
r = cpath; | ||
end; | ||
return r; | ||
end; | ||
` | ||
`; | ||
; | ||
@@ -244,0 +265,0 @@ return casl; |
@@ -9,84 +9,2 @@ /* | ||
let casl = ` | ||
/* | ||
cas mycas; | ||
proc cas; | ||
_args_1 = { | ||
path = '/describe', | ||
model = { caslib='models', name='cms_sdoh_risk_stratification_cluster'}, | ||
table = { caslib= "public", name = "cluster_test2"}, | ||
scenario = { | ||
SDOH_Physically_Unhealthy_Days_= 4.3, | ||
SDOH_Per_Adults_Bachelors = 19.6, | ||
SDOH_Unemployment_Rate = 9.6, | ||
SDOH_Median_Household_Income = 45493 | ||
} | ||
}; | ||
_args_2 = { | ||
path = '/score', | ||
model = { caslib='models', name='cms_sdoh_risk_stratification_cluster'}, | ||
table = { caslib= "public", name = "cluster_test2"}, | ||
scenario = { | ||
SDOH_Physically_Unhealthy_Days_ = 4.3, | ||
SDOH_Per_Adults_Bachelors = 19.6, | ||
SDOH_Unemployment_Rate = 9.6, | ||
SDOH_Median_Household_Income = 45493 | ||
} | ||
}; | ||
_args_3 = { | ||
path = '/describe', | ||
model = { caslib='modelstore', name='_LBP6S3ZAQGO614AJKDJT3AF93'}, | ||
table = { caslib='', name=''}, | ||
scenario = { | ||
sensor_ratio = 4.3, | ||
days_out_of_service = 5 | ||
} | ||
}; | ||
_args_4 = { | ||
path = '/score', | ||
model = { caslib='modelstore', name='_LBP6S3ZAQGO614AJKDJT3AF93'}, | ||
table = { caslib='', name=''}, | ||
scenario = { | ||
sensor_ratio = 4.3, | ||
days_out_of_service = 5 | ||
} | ||
}; | ||
_args_5 = { | ||
path = '/score', | ||
modelName= 'Gradient_Boosting_3f3c7c89_13ac_469e_a761_28ee066e5b87' | ||
model = { caslib='casuser', name='testdest'}, | ||
table = { caslib="", name=""}, | ||
scenario = { | ||
sensor_ratio = 4.3, | ||
days_out_of_service = 5 | ||
} | ||
}; | ||
_args_6 = { | ||
path = '/score', | ||
modelName= 'Gradient_Boosting_7adb0404_85e3_474d_9d03_1059ef7ae008' | ||
model = { caslib='public', name='testpublish'}, | ||
table = { caslib="", name=""}, | ||
scenario = { | ||
sensor_ratio = 4.3, | ||
days_out_of_service = 5 | ||
} | ||
}; | ||
result = runMain(_args_1); | ||
result = runMain(_args_2); | ||
result = runMain(_args_3); | ||
result = runMain(_args_4); | ||
result = runMain(_args_5); | ||
*/ | ||
result = runMain(_args_); | ||
@@ -99,3 +17,2 @@ send_response(result); | ||
r = {Error= 'No path'}; | ||
print _args_; | ||
if ( _args_.path eq '/selectors') then do; | ||
@@ -114,9 +31,16 @@ r = selectionLists(_args_.selectors, _args_.table.caslib, _args_.table.name); | ||
else if (_args_.path eq '/score') then do; | ||
r = runScoreCode(_args_.model, _args_.scenario, _args_.modelName); | ||
if( exists(_args_, 'modelName') eq false ) then | ||
modelname = ''; | ||
else modelName =_args_.modelName; | ||
r = runScoreCode(_args_.model, _args_.scenario, modelName); | ||
end; | ||
else do; | ||
r = {Errors = 'Invalid action option specified' || _args_.path}; | ||
r = {icasResults={Errors = 'Invalid action option specified' || _args_.path}, statusCode=404}; | ||
end; | ||
result = {casResults = r}; | ||
print r; | ||
if ( r.statusCode ne 0) then do; | ||
print r.icasResults; | ||
exit({severity=2,reason=6, status=r.iCasResults.Errors,statusCode=r.statusCode}); | ||
end; | ||
result = {casResults = r.icasResults}; | ||
print '***************************************************************'; | ||
@@ -134,5 +58,5 @@ print result; | ||
s = checkAndLoadTable(_args_.model.caslib, _args_.model.name); | ||
if ( s ne 0 ) then do; | ||
if ( s ne true) then do; | ||
results = {Errors= 'Unable to access ' ||_args_.model.caslib||'.'||_args_.model.name}; | ||
return results; | ||
return {icasResults=results, statusCode=404}; | ||
end; | ||
@@ -146,9 +70,9 @@ | ||
s = checkAndLoadTable(_args_.table.caslib, _args_.table.name); | ||
if ( s ne 0 ) then do; | ||
if ( s ne true ) then do; | ||
results = {Errors= 'Unable to access ' ||_args_.table.caslib||'.'||_args_.table.name}; | ||
return results; | ||
return {icasResults=results, statusCode=404}; | ||
end; | ||
r = contents( _args_.table.caslib, _args_.table.name); | ||
end; | ||
return r; | ||
return {icasResults= r, statusCode=0} ; | ||
end; | ||
@@ -173,6 +97,6 @@ | ||
s = checkAndLoadTable(model.caslib, model.name); | ||
if ( s ne 0 ) then do; | ||
if ( s ne true ) then do; | ||
results = {Errors= 'Unable to access ' ||model.caslib||'.'||model.name}; | ||
return results; | ||
end; | ||
return {icasResults=results, statusCode=404}; | ||
end; | ||
@@ -182,5 +106,5 @@ mtype = isModel(model.caslib, model.name); | ||
if ( mtype eq 'bad' ) then do; | ||
results = {Error= model.caslib||'.'||model.name || ' is not recognized as a valid supported model. Please check your values'} ; | ||
return results; | ||
end; | ||
results = {Error= model.caslib||'.'||model.name || ' is not recognized as a valid supported model. Please check your values'}; | ||
return {icasResults=results, statusCode=400}; | ||
end; | ||
destroyTable('casuser', 'input'); | ||
@@ -208,2 +132,7 @@ argsToTable(scenario, 'casuser', 'input'); | ||
print 'Scoring with d2'; | ||
if ( missing(modelName) eq true) then do; | ||
results = {Error= 'modelName is missing. Please check your values'}; | ||
return {icasResults=results, statusCode=400}; | ||
end; | ||
action ds2.runModel r = result/ | ||
@@ -221,3 +150,4 @@ modelTable = {caslib=model.caslib, name=model.name} | ||
rows = resultsToDict(result.Fetch); | ||
return rows; | ||
return {icasResults= rows, statusCode=0} ; | ||
end; | ||
@@ -228,2 +158,84 @@ | ||
return casl; | ||
}; | ||
}; | ||
/* | ||
cas mycas; | ||
proc cas; | ||
_args_1 = { | ||
path = '/describe', | ||
model = { caslib='models', name='cms_sdoh_risk_stratification_cluster'}, | ||
table = { caslib= "public", name = "cluster_test2"}, | ||
scenario = { | ||
SDOH_Physically_Unhealthy_Days_= 4.3, | ||
SDOH_Per_Adults_Bachelors = 19.6, | ||
SDOH_Unemployment_Rate = 9.6, | ||
SDOH_Median_Household_Income = 45493 | ||
} | ||
}; | ||
_args_2 = { | ||
path = '/score', | ||
model = { caslib='models', name='cms_sdoh_risk_stratification_cluster'}, | ||
table = { caslib= "public", name = "cluster_test2"}, | ||
scenario = { | ||
SDOH_Physically_Unhealthy_Days_ = 4.3, | ||
SDOH_Per_Adults_Bachelors = 19.6, | ||
SDOH_Unemployment_Rate = 9.6, | ||
SDOH_Median_Household_Income = 45493 | ||
} | ||
}; | ||
_args_3 = { | ||
path = '/describe', | ||
model = { caslib='modelstore', name='_LBP6S3ZAQGO614AJKDJT3AF93'}, | ||
table = { caslib='', name=''}, | ||
scenario = { | ||
sensor_ratio = 4.3, | ||
days_out_of_service = 5 | ||
} | ||
}; | ||
_args_4 = { | ||
path = '/score', | ||
model = { caslib='modelstore', name='_LBP6S3ZAQGO614AJKDJT3AF93'}, | ||
table = { caslib='', name=''}, | ||
scenario = { | ||
sensor_ratio = 4.3, | ||
days_out_of_service = 5 | ||
} | ||
}; | ||
_args_5 = { | ||
path = '/score', | ||
modelName= 'Gradient_Boosting_3f3c7c89_13ac_469e_a761_28ee066e5b87' | ||
model = { caslib='casuser', name='testdest'}, | ||
table = { caslib="", name=""}, | ||
scenario = { | ||
sensor_ratio = 4.3, | ||
days_out_of_service = 5 | ||
} | ||
}; | ||
_args_6 = { | ||
path = '/score', | ||
modelName= 'Gradient_Boosting_7adb0404_85e3_474d_9d03_1059ef7ae008' | ||
model = { caslib='public', name='testpublish'}, | ||
table = { caslib="", name=""}, | ||
scenario = { | ||
sensor_ratio = 4.3, | ||
days_out_of_service = 5 | ||
} | ||
}; | ||
result = runMain(_args_1); | ||
result = runMain(_args_2); | ||
result = runMain(_args_3); | ||
result = runMain(_args_4); | ||
result = runMain(_args_5); | ||
*/ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1204154
6853