public PredictionSet GetPredictionDataSet(string name) { TableEntity entity = _az.GetRecord(container, partitionKey, name); PredictionSet predictionSets = MapTableEntityToPredictionSetModel(entity); return(predictionSets); }
public async Task <string> Predict(PredictionSet predictionSet) { var content = JsonConvert.SerializeObject(predictionSet); var response = await client.PostAsync("http://localhost:5010/Predict", new StringContent(content, Encoding.UTF8, "application/json")); var responseString = await response.Content.ReadAsStringAsync(); return(responseString); }
private TableEntity MapPredictionSetModelToTableEntity(PredictionSet predictionSet) { var entity = new TableEntity("PPDM", predictionSet.Name) { { "RuleUrl", predictionSet.RuleUrl }, { "Description", predictionSet.Description } }; return(entity); }
public List <PredictionSet> GetPredictionDataSets() { List <PredictionSet> predictionSets = new List <PredictionSet>(); Pageable <TableEntity> entities = _az.GetRecords(container); foreach (TableEntity entity in entities) { PredictionSet predictionSet = MapTableEntityToPredictionSetModel(entity); predictionSets.Add(predictionSet); } return(predictionSets); }
public async Task <ActionResult <string> > SaveRuleToFile(string RuleName, PredictionSet predictionSet) { try { GetStorageAccount(); RuleManagement rules = new RuleManagement(connectionString); await rules.SavePredictionSet(RuleName, predictionSet); } catch (Exception ex) { return(BadRequest()); } return(Ok($"OK")); }
private PredictionSet MapTableEntityToPredictionSetModel(TableEntity entity) { PredictionSet predictionSet = new PredictionSet(); predictionSet.Name = entity.RowKey; if (entity["Description"] != null) { predictionSet.Description = entity["Description"].ToString(); } if (entity["RuleUrl"] != null) { predictionSet.RuleUrl = entity["RuleUrl"].ToString(); } return(predictionSet); }
public async Task InsertPrediction(PredictionSet predictionSet, string predictionName) { if (string.IsNullOrEmpty(baseUrl)) { url = $"api/rules/RuleFile/{predictionName}"; } else { url = baseUrl.BuildFunctionUrl("SavePredictionSet", $"name={predictionName}", apiKey); } var response = await httpService.Post(url, predictionSet); if (!response.Success) { throw new ApplicationException(await response.GetBody()); } }
public async Task SavePredictionSet(string name, PredictionSet set) { List <RuleModel> rules = set.RuleSet; List <PredictionSet> tmpPredictionSets = _predictionSetData.GetPredictionDataSets(); if (tmpPredictionSets.FirstOrDefault(c => c.Name == set.Name) != null) { Exception error = new Exception($"RuleManagement: prediction set already exist"); throw error; } string fileName = name + ".json"; string json = JsonConvert.SerializeObject(rules, Formatting.Indented); string url = await _fileStorage.SaveFileUri(ruleShare, fileName, json); set.RuleUrl = url; _predictionSetData.SavePredictionDataSet(set); }
public static async Task <IActionResult> SavePrediction( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("SavePredictionSet: Starting"); try { string name = req.Query["name"]; if (string.IsNullOrEmpty(name)) { log.LogError("SaveDaSavePredictionSettaRule: error, prediction set name is missing"); return(new BadRequestObjectResult("Error missing prediction set name")); } string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); PredictionSet set = JsonConvert.DeserializeObject <PredictionSet>(requestBody); if (set == null || set.RuleSet == null) { log.LogError("SavePredictionSet: error missing prediction set"); return(new BadRequestObjectResult("Error missing prediction set")); } var headers = req.Headers; string storageAccount = headers.FirstOrDefault(x => x.Key == "azurestorageconnection").Value; if (string.IsNullOrEmpty(storageAccount)) { log.LogError("SavePredictionSet: error, missing azure storage account"); return(new BadRequestObjectResult("Missing azure storage account in http header")); } RuleManagement rules = new RuleManagement(storageAccount); await rules.SavePredictionSet(name, set); } catch (Exception ex) { log.LogError($"SavePredictionSet: Error saving prediction set: {ex}"); return(new BadRequestObjectResult($"Error saving prediction set: {ex}")); } return(new OkObjectResult("OK")); }
public void UpdatePredictionDataSet(PredictionSet predictionSet) { throw new NotImplementedException(); }
public void SavePredictionDataSet(PredictionSet predictionSet) { TableEntity entity = MapPredictionSetModelToTableEntity(predictionSet); _az.SaveRecord(container, entity); }
/// <summary> /// The predict. /// </summary> /// <param name="scenarioId"> /// The scenario id. /// </param> /// <param name="inputSetId"> /// The input set id. /// </param> /// <returns> /// The <see cref="PredictionSet"/>. /// </returns> public PredictionSet Predict(string scenarioId, string inputSetId) { var predictions = new PredictionSet { Predictions = new List <Prediction>() }; ScenarioTrainings trainings; if (!trainingByScenario.TryGetValue(scenarioId, out trainings)) { trainings = this.Train(scenarioId); } if (trainings == null) { return(predictions); } using (var dbContext = new OpenAIEntities1()) { List <Feature> features = dbContext.Features.Where(f => f.ScenarioId == scenarioId).OrderBy(f => f.Position).ToList(); Dictionary <string, Input> inputsById = dbContext.Inputs.Where(i => i.ScenarioId == scenarioId && i.InputSetId == inputSetId) .ToDictionary(i => i.FeatureId); var sortedInputs = new List <Input>(); foreach (Feature feature in features) { Input input; if (inputsById.TryGetValue(feature.FeatureId, out input)) { sortedInputs.Add(input); } else { sortedInputs.Add(new Input { FeatureId = feature.FeatureId }); } } List <string> unset = features.Select(f => f.FeatureId).Except(inputsById.Values.Select(i => i.FeatureId)).ToList(); foreach (string inputId in unset) { TrainerHelper training; if (!trainings.TrainingByFeatureId.TryGetValue(inputId, out training)) { continue; } var inputsMinusFeature = sortedInputs.Where(i => i.FeatureId != inputId).Select(i => i.Value).ToArray(); KeyValuePair <string, double> valueAndConfidence = trainer.Decide(training, inputsMinusFeature, inputId); var prediction = new Prediction { InputId = inputId, Confidence = valueAndConfidence.Value, Value = valueAndConfidence.Key }; predictions.Predictions.Add(prediction); } } return(predictions); }