public string PredictSingle(InputData input)
        {
            var        signClassificationResult    = signClassification.Predict(input);
            var        signClassificationResultStr = signClassLabels[Array.IndexOf(signClassificationResult.Score, signClassificationResult.Score.Max())];
            string     signResult = "";
            OutPutData predResult = new OutPutData();

            if (signClassificationResultStr.Equals("num"))
            {
                predResult = numberPrediciton.Predict(input);
                signResult = numberLabels[Array.IndexOf(predResult.Score, predResult.Score.Max())];
            }
            else if (signClassificationResultStr.Equals("char"))
            {
                predResult = alphabetPredicion.Predict(input);
                signResult = alphabetLabels[Array.IndexOf(predResult.Score, predResult.Score.Max())];
            }
            else if (signClassificationResultStr.Equals("greet"))
            {
                predResult = commonSignPrediciton.Predict(input);
                signResult = commonSignLabels[Array.IndexOf(predResult.Score, predResult.Score.Max())];
            }

            var confidence = predResult.Score.Max() * signClassificationResult.Score.Max();

            if (confidence > 0.5)
            {
                return(signResult);
            }
            else
            {
                return(null);
            }
        }
        public string Predict(InputData input)
        {
            var        signClassificationResult    = signClassification.Predict(input);
            var        signClassificationResultStr = signClassLabels[Array.IndexOf(signClassificationResult.Score, signClassificationResult.Score.Max())];
            OutPutData predResult = new OutPutData();
            string     signResult = "";

            if (signClassificationResultStr.Equals("num"))
            {
                predResult = numberPrediciton.Predict(input);
                signResult = numberLabels[Array.IndexOf(predResult.Score, predResult.Score.Max())];
            }
            else if (signClassificationResultStr.Equals("char"))
            {
                predResult = alphabetPredicion.Predict(input);
                signResult = alphabetLabels[Array.IndexOf(predResult.Score, predResult.Score.Max())];
            }
            else if (signClassificationResultStr.Equals("greet"))
            {
                predResult = commonSignPrediciton.Predict(input);
                signResult = commonSignLabels[Array.IndexOf(predResult.Score, predResult.Score.Max())];
            }

            var confidence = predResult.Score.Max() * signClassificationResult.Score.Max();

            if (confidence > 0.6)
            {
                return("Predicted : " + signResult +
                       Environment.NewLine + "Confidence : " + confidence.ToString());
            }
            else
            {
                return(null);
            }
        }
Esempio n. 3
0
        public override void OnActionExecuting(HttpActionContext filterContext)
        {
            string mes = "";

            if (!filterContext.ModelState.IsValid)
            {
                StringBuilder errinfo = new StringBuilder();
                foreach (var s in filterContext.ModelState.Values)
                {
                    foreach (var p in s.Errors)
                    {
                        errinfo.AppendFormat("{0},", p.ErrorMessage);
                    }
                }
                mes = errinfo.ToString().TrimEnd(',');
                filterContext.Response = filterContext.Request.CreateResponse(OutPutData.NewOutPutData(mes, false));
            }
            base.OnActionExecuting(filterContext);
        }
Esempio n. 4
0
        public override void OnActionExecuting(HttpActionContext filterContext)
        {
            string token   = "";
            var    request = ((HttpContextBase)filterContext.Request.Properties["MS_HttpContext"]).Request;

            token = request.Headers["token"];
            if (string.IsNullOrEmpty(token))
            {
                token = request.Params["token"];
            }
            if (string.IsNullOrEmpty(token))
            {
                filterContext.Response = filterContext.Request.CreateResponse(OutPutData.NewOutPutData("请授权", false));
                return;
            }
            var JwtDictionary = JwtHelper.ValidateJwtToken(token);

            if (JwtDictionary == null)
            {
                filterContext.Response = filterContext.Request.CreateResponse(OutPutData.NewOutPutData("非法授权", false));
                return;
            }
            if (string.IsNullOrEmpty(JwtDictionary["UserName"]) || string.IsNullOrEmpty(JwtDictionary["RandomNum"]))
            {
                filterContext.Response = filterContext.Request.CreateResponse(OutPutData.NewOutPutData("非法授权", false));
                return;
            }
            if (!redisHelper.Exist(ConstData.UserLoginJwt + JwtDictionary["UserName"]))
            {
                filterContext.Response = filterContext.Request.CreateResponse(OutPutData.NewOutPutData("请重新登陆", false));
                return;
            }
            var RedisJwtDictionary = JwtHelper.ValidateJwtToken(redisHelper.Get(ConstData.UserLoginJwt + JwtDictionary["UserName"]));

            if (RedisJwtDictionary["RandomNum"] != JwtDictionary["RandomNum"])
            {
                filterContext.Response = filterContext.Request.CreateResponse(OutPutData.NewOutPutData("您的账号已在其他地方登陆", false));
                return;
            }
            base.OnActionExecuting(filterContext);
        }
Esempio n. 5
0
        /// <summary>
        /// 有返回类型的POS接口调用
        /// </summary>
        /// <param name="inputdata"></param>
        /// <returns></returns>
        private static ServiceResult <POSReturn> BankTrans(InputData inputdata)
        {
            int output = -1;

            byte[] inputDataBytes  = null;
            byte[] outputDataBytes = new byte[1000];
            try
            {
                //序列化入参
                inputDataBytes = InputData.Serlize(inputdata);

                //调用POS机接口
                outputDataBytes = new byte[1000];
                output          = BankTrans(inputDataBytes, outputDataBytes);

                //反序列化出参
                OutPutData outputData = new OutPutData();
                OutPutData.Deserlize(outputDataBytes, ref outputData);

#if DEBUGPOS
                output = 0;
                outputData.resp_code       = "00";
                outputData.bank_code       = "0308";
                outputData.card_no         = "111111111111111111111";
                outputData.expr            = "";
                outputData.amount          = inputdata.amount;
                outputData.trace           = DateTime.Now.ToString("HHmmss");
                outputData.refer           = DateTime.Now.ToString("yyyyMMddHHmmss");
                outputData.auth            = "";
                outputData.batch           = "";
                outputData.date            = DateTime.Now.ToString("yyyyMMddHHmmss");
                outputData.userno          = "";
                outputData.terno           = "00000815";
                outputData.old_terno       = "";
                outputData.szOrderTrace    = DateTime.Now.ToString("HHmmssyyyyMMdd");
                outputData.resp_chin       = "";
                outputData.CredentialsType = "";
                outputData.CredentialsNum  = "";
                outputData.Name            = "";
                outputData.birthDay        = "";
                outputData.age             = "";
                outputData.Address         = "";
                outputData.PhoneNum        = "";
                outputData.Nation          = "";
                outputData.szExtend1       = "";
                outputData.szExtend2       = "";
                outputData.szExtend3       = "";
                outputData.szExtend4       = "";
                outputData.szExtend5       = "";
                outputData.OrderNo         = DateTime.Now.ToString("HHmmssyyyyMMdd");
#endif

                if (output == 0 && outputData.resp_code == BankTransSuccessCode)
                {
                    //正常交易后记录日志
                    log.Info(logFormat,
                             POSTranslateCode.GetDisplayString(inputdata.trans),
                             output,
                             Encode.GetString(inputDataBytes),
                             Encode.GetString(outputDataBytes));
                    return(new ServiceResult <POSReturn>(new POSReturn(outputData)));
                }
                else
                {
                    throw new Exception(outputData.resp_chin.ToString());
                }
            }
            catch (POSSerlizeException ex)
            {
                log.Error(logFormat,
                          ex,
                          POSTranslateCode.GetDisplayString(inputdata.trans),
                          output,
                          string.Empty,
                          string.Empty);
                return(new ServiceResult <POSReturn>(false, InnerError, ex.Message));
            }
            catch (POSDerlizeException ex)
            {
                log.Error(logFormat,
                          ex,
                          POSTranslateCode.GetDisplayString(inputdata.trans),
                          output,
                          Encode.GetString(inputDataBytes),
                          string.Empty);
                return(new ServiceResult <POSReturn>(false, InnerError, ex.Message));
            }
            catch (Exception ex)
            {
                log.Error(logFormat,
                          ex,
                          POSTranslateCode.GetDisplayString(inputdata.trans),
                          output,
                          Encode.GetString(inputDataBytes),
                          Encode.GetString(outputDataBytes));
                return(new ServiceResult <POSReturn>(false, InnerError, ex.Message));
            }
        }
Esempio n. 6
0
 public bool IsEqual(OutPutData rhs)
 {
     return(this.Call == rhs.Call && this.Put == rhs.Put);
 }
Esempio n. 7
0
 /// <summary>
 /// 返回成功结果
 /// </summary>
 /// <param name="message"></param>
 /// <param name="data"></param>
 /// <returns></returns>
 public OutPutData Success(string message = "成功", object data = null)
 {
     return(OutPutData.NewOutPutData(message, true, data));
 }
Esempio n. 8
0
 /// <summary>
 /// 返回失败结果
 /// </summary>
 /// <param name="message"></param>
 /// <param name="data"></param>
 /// <returns></returns>
 public OutPutData Fail(string message = "失败", object data = null)
 {
     return(OutPutData.NewOutPutData(message, false, data));
 }