Exemple #1
0
        /// <summary>
        /// Select the functiona based upon the request specification
        /// </summary>
        private async Task <MemoryStream> SelectFunction(Dictionary <string, dynamic> config, MemoryStream rowdatastream, int reqHash)
        {
            Logger.Info($"{reqHash} - Start DataRobot");
            DataRobotRestRequest dr = new DataRobotRestRequest(reqHash);

            string api_token = Convert.ToString(config["auth_config"]["api_token"]);

            MemoryStream result = new MemoryStream();

            switch (config["request_type"])
            {
            case "createproject":
                Logger.Info($"{reqHash} - Create Project");
                string project_name = Convert.ToString(config["project_name"]);

                var zippedstream = await CompressStream(rowdatastream, project_name, reqHash);

                Logger.Info($"{reqHash} - Zipped Data Size: {zippedstream.Length}");

                string endpoint = Convert.ToString(config["auth_config"]["endpoint"]);
                if (endpoint.Substring(endpoint.Length - 2) != "/")
                {
                    endpoint = endpoint + "/";
                }

                result = await dr.CreateProjectsAsync(endpoint, api_token, zippedstream, project_name, project_name + ".zip");

                break;

            case "predictapi":
                Logger.Info($"{reqHash} - Predict API");
                string datarobot_key = null;
                if (config["auth_config"].ContainsKey("datarobot_key"))
                {
                    datarobot_key = Convert.ToString(config["auth_config"]["datarobot_key"]);
                }

                string username      = Convert.ToString(config["auth_config"]["username"]);
                string host          = Convert.ToString(config["auth_config"]["endpoint"]);
                string project_id    = null;
                string model_id      = null;
                string deployment_id = null;

                if (config.ContainsKey("deployment_id"))
                {
                    deployment_id = Convert.ToString(config["deployment_id"]);
                }

                if (config.ContainsKey("project_id") && config.ContainsKey("model_id"))
                {
                    project_id = Convert.ToString(config["project_id"]);
                    model_id   = Convert.ToString(config["model_id"]);
                }

                int    maxCodes      = 0;
                double thresholdHigh = 0;
                double thresholdLow  = 0;
                bool   explain       = false;

                if (config.ContainsKey("explain"))
                {
                    maxCodes      = config["explain"]["max_codes"];
                    thresholdHigh = config["explain"]["threshold_high"];
                    thresholdLow  = config["explain"]["threshold_low"];
                    explain       = true;
                }

                result = await dr.PredictApiAsync(rowdatastream, api_token, datarobot_key, username, host, deployment_id : deployment_id, project_id : project_id, model_id : model_id, explain : explain, maxCodes : maxCodes, thresholdHigh : thresholdHigh, thresholdLow : thresholdLow);

                break;

            case "timeseries":
                Logger.Info($"{reqHash} - Time Series Prediction API");
                datarobot_key = null;
                if (config["auth_config"].ContainsKey("datarobot_key"))
                {
                    datarobot_key = Convert.ToString(config["auth_config"]["datarobot_key"]);
                }

                username      = Convert.ToString(config["auth_config"]["username"]);
                host          = Convert.ToString(config["auth_config"]["endpoint"]);
                project_id    = null;
                model_id      = null;
                deployment_id = null;
                string forecast_point = null;

                if (config.ContainsKey("deployment_id"))
                {
                    deployment_id = Convert.ToString(config["deployment_id"]);
                }

                if (config.ContainsKey("project_id") && config.ContainsKey("model_id"))
                {
                    project_id = Convert.ToString(config["project_id"]);
                    model_id   = Convert.ToString(config["model_id"]);
                }

                if (config.ContainsKey("forecast_point"))
                {
                    //forecast_point = Convert.ToString(config["forecast_point"]);
                    forecast_point = config["forecast_point"].ToString("s");
                }


                result = await dr.TimeSeriesAsync(rowdatastream, api_token, datarobot_key, username, host, deployment_id : deployment_id, project_id : project_id, model_id : model_id, forecast_point : forecast_point);

                break;

            default:
                break;
            }

            Logger.Info($"{reqHash} - DataRobot Finish");
            return(result);
        }
        /// <summary>
        /// Select the functiona based upon the request specification
        /// </summary>
        private async Task <MemoryStream> SelectFunction(RequestSpecification config, MemoryStream rowdatastream, int reqHash)
        {
            Logger.Info($"{reqHash} - Start DataRobot");
            DataRobotRestRequest dr = new DataRobotRestRequest(reqHash);

            string api_token     = Convert.ToString(config.auth_config.api_token);
            string datarobot_key = config.auth_config.datarobot_key;

            string host          = config.auth_config.endpoint;
            string project_id    = config.project_id;
            string model_id      = config.model_id;
            string deployment_id = config.deployment_id;
            string keyField      = config.keyfield;

            MemoryStream result = new MemoryStream();

            switch (config.request_type)
            {
            case "createproject":
                Logger.Info($"{reqHash} - Create Project");
                string project_name = Convert.ToString(config.project_name);

                var zippedstream = await CompressStream(rowdatastream, project_name, reqHash);

                Logger.Info($"{reqHash} - Zipped Data Size: {zippedstream.Length}");

                string endpoint = Convert.ToString(config.auth_config.endpoint);
                if (endpoint.Substring(endpoint.Length - 2) != "/")
                {
                    endpoint = endpoint + "/";
                }

                result = await dr.CreateProjectsAsync(endpoint, api_token, zippedstream, project_name, project_name + ".zip");

                break;

            case "predictapi":
                Logger.Info($"{reqHash} - Predict API");



                int    maxCodes      = 0;
                double thresholdHigh = 0;
                double thresholdLow  = 0;
                bool   explain       = false;

                if (config.explain != null)
                {
                    maxCodes      = config.explain.max_codes;
                    thresholdHigh = config.explain.threshold_high;
                    thresholdLow  = config.explain.threshold_low;
                    explain       = true;
                }

                result = await dr.PredictApiAsync(rowdatastream, api_token, datarobot_key, host, deployment_id : deployment_id, project_id : project_id, model_id : model_id, keyField : keyField, explain : explain, maxCodes : maxCodes, thresholdHigh : thresholdHigh, thresholdLow : thresholdLow);

                break;

            case "timeseries":
                Logger.Info($"{reqHash} - Time Series Prediction API");

                string forecast_point = null;



                if (config.forecast_point != null)
                {
                    forecast_point = Convert.ToString(config.forecast_point);
                    //forecast_point = config.forecast_point.ToString("s");
                }


                result = await dr.TimeSeriesAsync(rowdatastream, api_token, datarobot_key, host, deployment_id : deployment_id, project_id : project_id, model_id : model_id, forecast_point : forecast_point);

                break;

            default:
                break;
            }

            Logger.Info($"{reqHash} - DataRobot Finish");
            return(result);
        }