private static List <PredictionEntityModel> Build(IQueryable <PredictionEntity> records) { var list = new List <PredictionEntityModel>(); foreach (var r in records) { var model = PredictionEntityModel.New(); model.Id = r.Id; model.SynAppsDeviceId = r.SynAppsDeviceId; model.LuisExampleId = r.LuisExampleId; model.EntityName = r.EntityName; model.EntityValue = r.EntityValue; model.CreatedAt = r.CreatedAt; model.UpdatedAt = r.UpdatedAt; list.Add(model); } return(list); }
public ApiResult RefreshPredictions() { var apiResult = new ApiResult { StatusCode = StatusCode.Success }; var intentList = new List <PredictionIntentModel>(); var entityList = new List <PredictionEntityModel>(); var list = new List <PreviewLabeledExampleDto>(); var r = GetPreviewLabeledExamples(); list.AddRange(r); while (r.Count >= 500) { r = GetPreviewLabeledExamples(list.Count); list.AddRange(r); } foreach (var l in list) { var intentModel = PredictionIntentModel.New(); intentModel.SynAppsDeviceId = this.DeviceId; intentModel.LuisExampleId = l.Id; intentModel.Intent = l.IntentLabel; intentList.Add(intentModel); foreach (var e in l.EntityLabels) { var entityModel = PredictionEntityModel.New(); entityModel.SynAppsDeviceId = this.DeviceId; entityModel.LuisExampleId = l.Id; entityModel.EntityName = e.EntityName; entityModel.EntityValue = e.EntityValue; entityList.Add(entityModel); } } var intentResult = PredictionIntentModel.Refresh(this.DeviceId, intentList); if (intentResult.StatusCode == StatusCode.Success) { var entityResult = PredictionEntityModel.Refresh(this.DeviceId, entityList); if (entityResult.StatusCode == StatusCode.Success) { var status = SynAppsSyncStatusModel.FindBySynAppsDeviceId(this.DeviceId); status.LastTrainingDateTime = DateTime.UtcNow; status.Save(); } else { apiResult.StatusCode = StatusCode.Error; apiResult.Message = entityResult.Message; } } else { apiResult.StatusCode = StatusCode.Error; apiResult.Message = intentResult.Message; } return(apiResult); }