public EvaluationOutput Evaluate(EvaluationRequest request) { IEnumerable <TemplateField> templateFields = null; if (!string.IsNullOrEmpty(request.TemplateName)) { var template = repository.GetLatestTemplate(request.TemplateName); if (template != null) { templateFields = OpenXmlWordProcessing.FindTemplateFields(template.Buffer); } } if (templateFields == null) { templateFields = request.Expressions.Select(e => new TemplateField() { Name = e.Name, Parent = e.Parent, IsCollection = e.IsCollection, Content = e.Content }); } var processor = new MappingExpressionEvaluator(); var input = new EvaluationInput() { Fields = templateFields, Expressions = request.Expressions, Sources = request.Sources }; var response = processor.Evaluate(input); return(response); }
private async Task <REvaluationResult> EvaluateAsyncWorker(string expression, REvaluationKind kind, CancellationToken cancellationToken) { await TaskUtilities.SwitchToBackgroundThread(); var request = await EvaluationRequest.SendAsync(this, expression, kind, cancellationToken); return(await request.Task); }
private EvaluationRequest getEvaluationRequest(string cdsInput, string scopingEntityId, string businessId, string version) { EvaluationRequest evaluationRequest = new EvaluationRequest(); evaluationRequest.clientLanguage = ""; evaluationRequest.clientTimeZoneOffset = ""; evaluationRequest.kmEvaluationRequest = new KMEvaluationRequest[] { getKMEvaluationRequest(scopingEntityId, businessId, version) }; evaluationRequest.dataRequirementItemData = new DataRequirementItemData[] { getDataRequirementItemData(cdsInput, businessId) }; return(evaluationRequest); }
static void Main1(string[] args) { try { // 必要步骤: // 实例化一个认证对象,入参需要传入腾讯云账户密钥对secretId,secretKey。 // 这里采用的是从环境变量读取的方式,需要在环境变量中先设置这两个值。 // 你也可以直接在代码中写死密钥对,但是小心不要将代码复制、上传或者分享给他人, // 以免泄露密钥对危及你的财产安全。 Credential cred = new Credential { SecretId = Environment.GetEnvironmentVariable("TENCENTCLOUD_SECRET_ID"), SecretKey = Environment.GetEnvironmentVariable("TENCENTCLOUD_SECRET_KEY") }; // 实例化一个client选项,可选的,没有特殊需求可以跳过 ClientProfile clientProfile = new ClientProfile(); // 非必要步骤 // 实例化一个客户端配置对象,可以指定超时时间等配置 HttpProfile httpProfile = new HttpProfile(); // 代理服务器,当你的环境下有代理服务器时设定 httpProfile.WebProxy = Environment.GetEnvironmentVariable("HTTPS_PROXY"); clientProfile.HttpProfile = httpProfile; // 实例化要请求产品(以cvm为例)的client对象 // 第二个参数是地域信息,可以直接填写字符串ap-guangzhou,或者引用预设的常量,clientProfile是可选的 HcmClient client = new HcmClient(cred, "ap-guangzhou", clientProfile); // 实例化一个请求对象,根据调用的接口和实际情况,可以进一步设置请求参数 // 你可以直接查询SDK源码确定DescribeZonesRequest有哪些属性可以设置, // 属性可能是基本类型,也可能引用了另一个数据结构。 // 推荐使用IDE进行开发,可以方便的跳转查阅各个接口和数据结构的文档说明。 EvaluationRequest req = new EvaluationRequest(); req.SessionId = "123456"; req.Image = "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"; req.HcmAppId = ""; req.Url = ""; // 通过client对象调用DescribeInstances方法发起请求。注意请求方法名与请求对象是对应的 // 返回的resp是一个DescribeInstancesResponse类的实例,与请求对象对应 EvaluationResponse resp = client.Evaluation(req). ConfigureAwait(false).GetAwaiter().GetResult(); // 输出json格式的字符串回包 Console.WriteLine(AbstractModel.ToJsonString(resp)); } catch (Exception e) { Console.WriteLine(e.ToString()); } Console.Read(); }
public Evaluation SubmitNewEvaluation(EvaluationRequest request) { return(PolicyService.ExecuteRetryAndCapture400Errors( "PersonalizerService.SubmitNewEvaluation", ApiKeys.PersonalizerRetryInSeconds, () => { var result = Repository.SubmitNewEvaluation(request); return result; }, null)); }
private async Task <REvaluationResult> EvaluateAsyncBackground(string expression, REvaluationKind kind, CancellationToken ct) { await TaskUtilities.SwitchToBackgroundThread(); JArray message; var request = new EvaluationRequest(this, expression, kind, out message); _evalRequests[request.Id] = request; await SendAsync(message, ct); return(await request.CompletionSource.Task); }
public static TaskProperties CreateTaskProperties(EvaluationRequest request) { var taskPropertiesDictionary = new Dictionary <string, string>(); taskPropertiesDictionary.Add(TaskProperties.ProjectIdKey, request.ProjectId.ToString()); taskPropertiesDictionary.Add(TaskProperties.AuthTokenKey, request.AuthToken); taskPropertiesDictionary.Add(TaskProperties.HubNameKey, request.HubName); taskPropertiesDictionary.Add(TaskProperties.PlanUrlKey, request.HostUrl.ToString()); taskPropertiesDictionary.Add(TaskProperties.JobIdKey, request.JobId.ToString()); taskPropertiesDictionary.Add(TaskProperties.PlanIdKey, request.PlanId.ToString()); taskPropertiesDictionary.Add(TaskProperties.TimelineIdKey, request.TimelineId.ToString()); return(new TaskProperties(taskPropertiesDictionary)); }
public IEvaluationResult EvaluatePrediction(IPredictionResult predicted, double[][] observed) { var request = new EvaluationRequest(); request.PredictionParameters = new PredictionRequest(); request.PredictionToEvaluate = new PredictionResult(); request.EstimatorType = ErrorEstimatorType.Value; request.PredictionParameters.Tolerance = PREDICTION_LIKELIHOOD_TOLERANCE; request.PredictionParameters.TestSet = observed; request.PredictionToEvaluate.Predicted = predicted.Predicted; var predictor = new LikelihoodBasedPredictor(); return(predictor.Evaluate(request)); }
/// <summary> /// Evaluation接口的同步版本,速算题目批改接口,根据用户上传的图片或图片的URL识别图片中的数学算式,进而给出算式的正确性评估。 /// </summary> /// <param name="req">参考<see cref="EvaluationRequest"/></param> /// <returns>参考<see cref="EvaluationResponse"/>实例</returns> public EvaluationResponse EvaluationSync(EvaluationRequest req) { JsonResponseModel <EvaluationResponse> rsp = null; try { var strResp = this.InternalRequestSync(req, "Evaluation"); rsp = JsonConvert.DeserializeObject <JsonResponseModel <EvaluationResponse> >(strResp); } catch (JsonSerializationException e) { throw new TencentCloudSDKException(e.Message); } return(rsp.Response); }
public void Evaluate_NullTemplateName_OK() { var request = new EvaluationRequest() { Expressions = new List <MappingExpression>() { new MappingExpression() { Name = "E1", Expression = "1+1" } } }; var output = processor.Evaluate(request); Assert.Equal("2", output.Results.First().Text); }
public void Evaluate_ReturnsCell() { var request = new EvaluationRequest() { Expressions = new List <MappingExpression>() { new MappingExpression() { Name = "E1", Cell = "A1", Expression = "1+1" } } }; var output = processor.Evaluate(request); Assert.Equal("A1", output.Results.First().Cell); }
public async Task <REvaluationResult> EvaluateAsync(string expression, REvaluationKind kind, CancellationToken cancellationToken) { if (_runTask == null) { throw new InvalidOperationException("Host was not started"); } using (CancellationTokenUtilities.Link(ref cancellationToken, _cts.Token)) { try { await TaskUtilities.SwitchToBackgroundThread(); var request = await EvaluationRequest.SendAsync(this, expression, kind, cancellationToken); return(await request.Task); } catch (OperationCanceledException ex) when(_cts.IsCancellationRequested) { throw new RHostDisconnectedException(Resources.Error_RHostIsStopped, ex); } } }
public IEvaluationResult EvaluatePrediction(IPredictionResult results, double[][] observations) { var model = (HiddenMarkovModelMultivariateGaussianDistribution)HiddenMarkovModelFactory.GetModel(new ModelCreationParameters <IMultivariateDistribution> { Pi = _pi, TransitionProbabilityMatrix = _transitionProbabilityMatrix, Emissions = _emission }); //new HiddenMarkovModelState<IMultivariateDistribution>(_pi, _transitionProbabilityMatrix, _emission); model.Normalized = Normalized; var request = new EvaluationRequest(); request.PredictionParameters = new PredictionRequest(); request.PredictionToEvaluate = new PredictionResult(); request.EstimatorType = ErrorEstimatorType.Value; request.PredictionParameters.Tolerance = PREDICTION_LIKELIHOOD_TOLERANCE; request.PredictionParameters.TestSet = observations; request.PredictionToEvaluate.Predicted = results.Predicted; var predictor = new LikelihoodBasedPredictor(); return(predictor.Evaluate(request)); }
public static async Task <EvaluationRequest> SendAsync(RHost host, string expression, REvaluationKind kind, CancellationToken cancellationToken) { var nameBuilder = new StringBuilder("?="); if (kind.HasFlag(REvaluationKind.Reentrant)) { nameBuilder.Append('@'); } if (kind.HasFlag(REvaluationKind.Cancelable)) { nameBuilder.Append('/'); } if (kind.HasFlag(REvaluationKind.BaseEnv)) { nameBuilder.Append('B'); } if (kind.HasFlag(REvaluationKind.EmptyEnv)) { nameBuilder.Append('E'); } if (kind.HasFlag(REvaluationKind.NoResult)) { nameBuilder.Append('0'); } if (kind.HasFlag(REvaluationKind.RawResult)) { nameBuilder.Append('r'); } string messageName = nameBuilder.ToString(); expression = expression.Replace("\r\n", "\n"); var message = host.CreateMessage(messageName, ulong.MaxValue, new JArray { expression }); var request = new EvaluationRequest(host, message, kind, cancellationToken); await host.SendAsync(message, cancellationToken); return(request); }
public void Evaluate_HMMMultivariateAndFTSESeriesLength20_ErrorEstimatorCalculated() { var util = new TestDataUtils(); var series = util.GetSvcData(util.FTSEFilePath, new DateTime(2010, 12, 18), new DateTime(2011, 12, 18)); var test = util.GetSvcData(util.FTSEFilePath, new DateTime(2011, 12, 18), new DateTime(2012, 01, 18)); var model = (HiddenMarkovModelMultivariateGaussianDistribution)HiddenMarkovModelFactory.GetModel(new ModelCreationParameters <IMultivariateDistribution>() { NumberOfStates = _NumberOfStates }); model.Normalized = true; model.Train(series, _NumberOfIterations, _LikelihoodTolerance); var pred = new ViterbiBasedPredictor(); var request = new PredictionRequest { TrainingSet = series, NumberOfDays = 20, TestSet = test }; pred.NumberOfIterations = _NumberOfIterations; pred.LikelihoodTolerance = _LikelihoodTolerance; var predictions = pred.Predict(model, request); var errorRequest = new EvaluationRequest { EstimatorType = ErrorEstimatorType.Value, PredictionParameters = request, PredictionToEvaluate = predictions }; var errorEstimation = pred.Evaluate(errorRequest); for (int i = 0; i < series[0].Length; i++) { Assert.IsTrue(errorEstimation.CumulativeForecastError[i] > 0); Assert.IsTrue(errorEstimation.MeanAbsoluteDeviation[i] > 0); Assert.IsTrue(errorEstimation.MeanAbsolutePercentError[i] > 0); Assert.IsTrue(errorEstimation.MeanError[i] > 0); Assert.IsTrue(errorEstimation.MeanSquaredError[i] > 0); Assert.IsTrue(errorEstimation.RootMeanSquaredError[i] > 0); } }
private async Task <EvaluationResponse> GetFlag(EvaluationRequest request) { const string url = "http://localhost:18000/api"; var response = await url .ConfigureRequest(settings => { var jsonSettings = new JsonSerializerSettings { NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, ContractResolver = new CamelCasePropertyNamesContractResolver(), ObjectCreationHandling = ObjectCreationHandling.Replace }; settings.JsonSerializer = new NewtonsoftJsonSerializer(jsonSettings); }) .AppendPathSegment("v1") .AppendPathSegment("evaluation") .AllowAnyHttpStatus() .PostJsonAsync(request) .ReceiveJson <EvaluationResponse>() .ConfigureAwait(false); return(response); }
public void CreateTaskPropertiesShouldCreateCorrectObject() { EvaluationRequest request = new EvaluationRequest { ProjectId = Guid.NewGuid(), PlanId = Guid.NewGuid(), HostUrl = "hostUrl1", JobId = Guid.NewGuid(), HubName = "Build", TimelineId = Guid.NewGuid(), AuthToken = "authToken1" }; var taskProperties = CommonUtilities.CreateTaskProperties(request); Assert.AreEqual(request.ProjectId, taskProperties.ProjectId, "Project id should match"); Assert.AreEqual(request.PlanId, taskProperties.PlanId, "Plan id should match"); Assert.AreEqual(request.JobId, taskProperties.JobId, "Job id should match"); Assert.AreEqual(request.HubName, taskProperties.HubName, "Hub name should match"); Assert.AreEqual(request.AuthToken, taskProperties.AuthToken, "Auth token should match"); Assert.AreEqual(request.HostUrl, taskProperties.PlanUrl, "Plan url should match"); Assert.AreEqual(request.TimelineId, taskProperties.TimelineId, "Timeline id should match"); }
public string evaluate(string cdsInputString, string scopingEntityId, string businessId, string version) { string METHODNAME = "evaluate "; if (true) { Console.WriteLine(METHODNAME + "calling evaluate with businessId '" + businessId + "; scopingEntityId " + scopingEntityId + "; version " + version + "' @ " + endPoint + " with requestTimeout:" + requestTimeout + " and connectTimeout:" + connectTimeout); } evaluateResponse response = null; string result = null; InteractionIdentifier interactionIdentifier = getInteractionIdentifier(); EvaluationRequest evaluationRequest = getEvaluationRequest(encodeTo64(cdsInputString), scopingEntityId, businessId, version); evaluate e = new evaluate(); e.interactionId = interactionIdentifier; e.evaluationRequest = evaluationRequest; response = service.evaluate(e); if (response == null) { throw new Exception("response is null!"); } EvaluationResponse er = response.evaluationResponse; FinalKMEvaluationResponse[] finalKMEvaluationResponse = er.finalKMEvaluationResponse; if (finalKMEvaluationResponse == null) { throw new Exception("finalKMEvaluationResponse is null!"); } if (finalKMEvaluationResponse.Length != 1) { throw new Exception("finalKMEvaluationResponse size wrong: " + finalKMEvaluationResponse.Length); } FinalKMEvaluationResponse kmEvaluationResponse = finalKMEvaluationResponse[0]; KMEvaluationResultData[] kmEvaluationResultData = kmEvaluationResponse.kmEvaluationResultData; if (kmEvaluationResultData == null) { throw new Exception("kmEvaluationResultData is null!"); } if (kmEvaluationResultData.Length != 1) { throw new Exception("kmEvaluationResultData size wrong: " + kmEvaluationResultData.Length); } KMEvaluationResultData resultData = kmEvaluationResultData[0]; if (resultData == null) { throw new Exception("resultData is null!"); } SemanticPayload data = resultData.data; if (data == null) { throw new Exception("data is null!"); } result = decodeFrom64(data.base64EncodedPayload); if (result == null) { throw new Exception("result is null!"); } return(result); }
public string Save(string year, string jurisdiction, string returnType, Guid?locatorId, EfileSchemaType schemaType, EvaluationRequest evaluationRequest, string status, string DiagnosticInfo = null, string Id = null) { //_context.StartEventLog("Save start"); _logger.Info("RuleExecutionLogService Save method start"); try { RuleExecutionLog LogInformation = null; if (string.IsNullOrEmpty(Id)) { LogInformation = new RuleExecutionLog(); LogInformation.Locator = new Locator(); LogInformation.Locator.Id = (Guid)locatorId; LogInformation.Id = Guid.NewGuid(); LogInformation.StartTime = DateTime.Now; LogInformation.Status = status; LogInformation.SchemaType = schemaType; LogInformation.EvaluationRequest = evaluationRequest; LogInformation.Endtime = DateTime.Now; // LogInformation.Jurisdiction = jurisdiction; _repository.Insert <RuleExecutionLog>(LogInformation); } else { LogInformation = _repository.Get <RuleExecutionLog>(new Guid(Id)); if (LogInformation != null) { LogInformation.Endtime = DateTime.Now; LogInformation.DiagnosticInfo = DiagnosticInfo; LogInformation.Status = status; LogInformation.EvaluationRequest = evaluationRequest; _repository.Merge <RuleExecutionLog>(LogInformation); } } Id = (LogInformation != null) ? LogInformation.Id.ToString() : null; } catch (Exception ex) { _logger.Error("Error in RuleExecutionLogService Save Method ", ex); } _logger.Info("RuleExecutionLogService Save method End"); //_context.EndEventLog(); return(Id); }
private EvaluationRequest getEvaluationRequest(string cdsInput, string scopingEntityId, string businessId, string version) { EvaluationRequest evaluationRequest = new EvaluationRequest(); evaluationRequest.clientLanguage = ""; evaluationRequest.clientTimeZoneOffset = ""; evaluationRequest.kmEvaluationRequest = new KMEvaluationRequest[] { getKMEvaluationRequest(scopingEntityId, businessId, version) }; evaluationRequest.dataRequirementItemData = new DataRequirementItemData[] { getDataRequirementItemData(cdsInput, businessId) }; return evaluationRequest; }
public IEnumerable <FailedExecutionInfo> ExecuteRules(RuleEvaluationRequest nextRequest, Processor processor) { EvaluationRequest evaluationRequest = new EvaluationRequest(); evaluationRequest.Id = nextRequest.Id; //_context.StartEventLog("ExecuteRules start"); _logger.Info("ExecuteRules start"); IList <FailedExecutionInfo> failedRules = new List <FailedExecutionInfo>(); Guid? LocatorId = null; EfileSchemaType efileSchemaType = null; string logId = ""; string diagnosticLog = string.Empty; CurrentSelection currentSelection = new CurrentSelection(nextRequest.Jurisdiction, nextRequest.Year, nextRequest.ReturnType); try { LocatorId = _logService.GetOrSaveLocator(nextRequest.Year, nextRequest.Jurisdiction, nextRequest.ReturnType, nextRequest.Locator).Id; efileSchemaType = _schemaTypeService.GetSchemaType(nextRequest.SchemaType); logId = _logService.Save(nextRequest.Year, nextRequest.Jurisdiction, nextRequest.ReturnType, LocatorId, efileSchemaType, evaluationRequest, RequestStatusConstants.IN_PROCESS); var xmlDocumentToEvaluate = CreateXmlDocument(nextRequest.DocumentToEvaluate); var defaultNamespace = ExtractDefaultNamespaceUri(xmlDocumentToEvaluate); var ruleExecutionElements = _ruleQueryExecuter.ExecuteRuleQuery(nextRequest.Year, nextRequest.ReturnType, nextRequest.Jurisdiction, nextRequest.SchemaType, defaultNamespace, processor).ToList(); Stopwatch sw = Stopwatch.StartNew(); DocumentBuilder documentBuilder = processor.NewDocumentBuilder(); documentBuilder.IsLineNumbering = true; documentBuilder.WhitespacePolicy = WhitespacePolicy.PreserveAll; XdmNode _XdmNode = documentBuilder.Build(xmlDocumentToEvaluate); sw.Stop(); _logger.Info(String.Format("End SaxonApi DocumentBuilder {0} - Time {1:0.00}s", evaluationRequest.Id, sw.ElapsedMilliseconds / 1000)); sw.Restart(); _logger.Info(String.Format("Start loop rule execution elements RequestId: {0}", evaluationRequest.Id)); Parallel.ForEach(ruleExecutionElements, (element) => //foreach (var element in ruleExecutionElements) { try { EFileDocument documentToEvaluate = new EFileDocument(xmlDocumentToEvaluate, true); if (documentToEvaluate.IsDiagnosable) { documentToEvaluate.BeginDiagnostic(); } var success = element.Evaluate(documentToEvaluate, element.useAtLeast, element.XQuery, currentSelection, string.IsNullOrEmpty(element.AlternateText) ? element.RuleText : element.AlternateText, processor, _XdmNode, element.Fields, element.CompiledXQueryExecutable); if (element.useAtLeast > 0) { if (documentToEvaluate.NumberOfNoDiagnostics <= element.useAtLeast - 1) { FailedExecutionInfo failRule = GetFailRule(documentToEvaluate, element); lock (failedRules) { failedRules.Add(failRule); } } } else { if (documentToEvaluate.NumberOfDiagnostics > 0) { FailedExecutionInfo failRule = GetFailRule(documentToEvaluate, element); lock (failedRules) { failedRules.Add(failRule); } } } } catch (Exception e) { string message = string.Empty; if (e is ArgumentException) { message = "The fields from the rule cannot be used together."; _logger.Error( String.Format( "The fields from the rule cannot be used together RequestId: {0}, RuleId: {1}, RuleNumber: {2}", evaluationRequest.Id, element.RuleId, element.RuleNumber), e); } else { message = "Error while evaluating rule: " + e.Message; _logger.Error( String.Format( "Error while evaluating rule RequestId: {0}, RuleId: {1}, RuleNumber: {2}", evaluationRequest.Id, element.RuleId, element.RuleNumber), e); } lock (failedRules) { failedRules.Add(CreateFailRule(element.RuleId, element.RuleNumber, message, element.Categories, element.TaxProfileArea, element.LinkedQuery, 0)); } _logger.Info( String.Format( "Catch loop rule execution elements end add rule RequestId: {0}, RuleId: {1}, RuleNumber: {2}", evaluationRequest.Id, element.RuleId, element.RuleNumber)); } //} }); sw.Stop(); _logger.Info(String.Format("End loop rule execution elements RequestId: {0}, Time: {1:0.00}s ", evaluationRequest.Id, sw.ElapsedMilliseconds / 1000)); diagnosticLog = string.Empty; if (failedRules.Count > 0) { diagnosticLog = JsonConvert.SerializeObject(failedRules); } _logger.Info(String.Format("End Rule Execution Loop {0}", evaluationRequest.Id)); _logService.Save(nextRequest.Year, nextRequest.Jurisdiction, nextRequest.ReturnType, LocatorId, efileSchemaType, evaluationRequest, RequestStatusConstants.SUCCESS, diagnosticLog, logId); _logger.Info(String.Format("Rule execution elements end save rule RequestId: {0}", evaluationRequest.Id)); } catch (Exception ex) { _logger.Error("Error in ExecuteRules method", ex); _logService.Save(nextRequest.Year, nextRequest.Jurisdiction, nextRequest.ReturnType, LocatorId, efileSchemaType, evaluationRequest, RequestStatusConstants.FAILED, diagnosticLog, logId); throw new Exception("Error in ExecuteRules method", ex); } _logger.Info("Execute Rules Service Method end"); //_context.EndEventLog(); return(failedRules); }
public Evaluation SubmitNewEvaluation(EvaluationRequest request) { var response = RepositoryClient.SendJsonPost(ApiKeys.Personalizer, $"{ApiKeys.PersonalizerEndpoint}evaluations", JsonConvert.SerializeObject(request)); return(JsonConvert.DeserializeObject <Evaluation>(response)); }
public IActionResult TestEvaluations([FromBody] EvaluationRequest request) { var response = processor.Evaluate(request); return(Ok(response)); }