public async Task <IEnumerable <string> > GetRecommendationsAsync(string productId)
        {
            string modelName = ConfigurationHelpers.GetString("MachineLearning.ModelName");
            //The Azure ML service takes in a recommendation model name (trained ahead of time) and a product id
            string uri = string.Format("https://api.datamarket.azure.com/data.ashx/amla/mba/v1/Score?Id=%27{0}%27&Item=%27{1}%27", modelName, productId);

            try
            {
                //The Azure ML service returns a set of numbers, which indicate the recommended product id
                var response = await client.GetStringAsync(uri);

                AzureMLFrequentlyBoughtTogetherServiceResponse deserializedResponse = JsonConvert.DeserializeObject <AzureMLFrequentlyBoughtTogetherServiceResponse>(response);
                //When there is no recommendation, The Azure ML service returns a JSON object that does not contain ItemSet
                var recommendation = deserializedResponse.ItemSet;
                if (recommendation == null)
                {
                    return(Enumerable.Empty <string>());
                }
                else
                {
                    return(recommendation);
                }
            }
            catch (HttpRequestException e)
            {
                telemetry.TrackException(e);

                return(Enumerable.Empty <string>());
            }
        }
Esempio n. 2
0
 public ConfigurationWebsiteOptions(IConfiguration config, ITelemetryProvider log)
 {
     try
     {
         ShowRecommendations = Boolean.Parse(config["ShowRecommendations"]);
     }
     catch (InvalidCastException e)
     {
         log.TrackException(e);
     }
 }
 public ConfigurationWebsiteOptions(IConfiguration config, ITelemetryProvider log)
 {
     try
     {
         ShowRecommendations = Boolean.Parse(config["ShowRecommendations"]);
     }
     catch (InvalidCastException e)
     {
         log.TrackException(e);
     }
 }
Esempio n. 4
0
 public ConfigurationWebsiteOptions(IConfiguration config, ITelemetryProvider log)
 {
     try
     {
         ShowRecommendations = config.Get <bool>("ShowRecommendations");
     }
     catch (InvalidCastException e)
     {
         log.TrackException(e);
     }
 }
 public ConfigurationWebsiteOptions(IConfiguration config, ITelemetryProvider log)
 {
     try
     {
         ShowRecommendations = config.Get<bool>("ShowRecommendations");
     }
     catch (InvalidCastException e)
     {
         log.TrackException(e);
     }
 }
Esempio n. 6
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation($"AppInsightsAzureFunctionDemo Start: {DateTime.Now}");

            var timer = System.Diagnostics.Stopwatch.StartNew();

            // Add custom data to the event
            // customEvents | where timestamp > ago(7d) | order by timestamp desc
            // https://microsoft.github.io/AzureTipsAndTricks/blog/tip195.html
            var dictionary = new Dictionary <string, string>();

            dictionary.Add("Function", "My AppInsightsAzureFunctionDemo");
            dictionary.Add("Caller", "Toni Pohl");
            dictionary.Add("Description", "This is the Azure function using App Insights description");
            _provider.TrackEvent($"Event: Start {DateTime.Now}", dictionary);

            // track a numeric value
            // customMetrics | order by timestamp desc
            _provider.TrackMetric("Metric: Ticks based on current time", DateTime.Now.Ticks);

            // track an exception
            // exceptions | order by timestamp desc
            _provider.TrackException(new Exception($"Exception: at {DateTime.Now}"));

            // track long running external service call
            // dependencies | order by timestamp desc
            _provider.TrackDependency("myDependency", "MyType", "myCall 1", DateTime.Now, timer.Elapsed, true);

            // Done
            _provider.TrackEvent($"Event: End {DateTime.Now}");

            string responseMessage = $"AppInsightsAzureFunctionDemo End: {DateTime.Now}";

            log.LogInformation(responseMessage);

            return(new OkObjectResult(responseMessage));
        }