Skip to Content

Pre-Score Dynamic Plugin

The Pre-Score Dynamic plugin is a plugin that is used to format the input to the predictor before when using Dynamic Interaction configurations. The Pre-Score Dynamic plugin is a default pre-predict plugin that is available in the ecosystem.Ai platform and can be extended to create custom pre-scoring logic plugins.

How does it work?

The Pre-Score Dynamic plugin loads the Dynamic Interaction configurations and pre-populates contextual variables on the params object that is carried through the runtime process.

Lookup virtual variables are derived into featuresObj by StageParamsDB after customer lookup and before this plugin runs. Current PreScoreDynamic does not call getVirtualVariables. See Virtual Variables.

Java Code

This Java class named PreScoreDynamic extends PreScoreSuper, which provides functionality that can be used across different pre-scoring plugins.

Then, there is a static method named getPrePredict(MongoClient mongoClient, JSONObject params, CqlSession session). This function takes three parameters: a MongoClient object (which is used to interact with a MongoDB database), a JSONObject object params (which is used the pass data through the runtime process), and a CqlSession object session (which provides a session for executing CQL commands on a Cassandra database.)

The function first checks if lookupDatabase is null, if it is then it returns the input params as is.

If lookupDatabase isn’t null, then the function uses getDynamicSettings to get the Dynamic Interaction configuration from the MongoDB database using the locations for the configurations contained in params, then populates contextual variables using getPrepopulateContextualVariables. Virtual-variable derivation for predictor.param.lookup already happened in StageParamsDB.

If any exception occurs during the execution of the function, it logs the error message (LOGGER.error()) including the UUID from the params and specifics of the failed dynamic parameters, also prints the stack trace of the exception (e.printStackTrace();). The function then returns the params object.

The following is the current PreScoreDynamic pattern (no getVirtualVariables call):

package com.ecosystem.plugin.customer; import com.datastax.oss.driver.api.core.CqlSession; import com.ecosystem.data.mongodb.MongoDBWorkerRead; import com.ecosystem.utils.GlobalSettings; import com.mongodb.client.MongoClient; import org.json.JSONObject; import java.io.IOException; /** * Add key/value to properties predictor.param.lookup to allow for contextual variable lookup: * dynamic_lookup: 'dynamic_lookup_just4u_v1' */ public class PreScoreDynamic extends PreScoreSuper { public PreScoreDynamic() throws Exception { } /** * Pre-pre predict */ public void getPrePredict() { } /** * getPostPredict * example setting in properties file (look for dynamic_lookup: 'dynamic_lookup_just4u'): * predictor.param.lookup={predictor:'justforyou',mojo:1,database:'mongodb',db:'vodacom',table:'fs_score_all_estore_gsm_recommender_rel_1',dynamic_lookup: 'dynamic_lookup_just4u',lookup:{"value":123,"key":"msisdn"},result:{parm1:'field1', parm2:'field2'}} * @param params * @param session * @return */ public static JSONObject getPrePredict(MongoClient mongoClient, JSONObject params, CqlSession session) throws IOException { if (lookupDatabase == null) return params; try { /** Load dynamic settings. Virtual variables were already derived by StageParamsDB. */ params = getDynamicSettings(mongoClient, params); /** Populate contextual variables by default based on settings. */ params = getPrepopulateContextualVariables(params); } catch (Exception e) { LOGGER.error("PreScoreDynamic:E001:UUID: " + params.get("uuid") + " Dynamic parameters failed: " + params.toString()); e.printStackTrace(); } return params; } }

Legacy (before 0.9.4.3)

Older plugins called getVirtualVariables(params) after getDynamicSettings. That path is obsolete when StageParamsDB already writes lookup virtuals into featuresObj. Keep the call only if you maintain a custom pre-score that must re-derive virtuals for an older runtime.

Last updated on