예제 #1
0
        private string ToShowUpText(PageTimePriceResult LastResult)
        {
            string prefix = string.Format("本机时间:{0:HH:mm:ss}。\n解析的内容是:", DateTime.Now);

            if (LastResult.status != 0)
            {
                return(string.Format("{0}ERROR: {1}", prefix, LastResult.status));
            }

            PagePrice pp = LastResult.data;

            return(string.Format("{0}{1:HH:mm:ss}.\n{2} - {3}.", prefix, pp.pageTime, pp.low, pp.high));
        }
예제 #2
0
 private void ProcessErrorDetect(PageTimePriceResult ret)
 {
     if (ret.status == -1)
     {
         actionManager.FindAndSetCoordOfCurrentTime();
     }
     else if (ret.status == -2)
     {
         actionManager.FindAndSetCoordOfPriceSection();
     }
     else if (ret.status == -11)
     {
         actionManager.FindAndSetCoordOfCurrentTime();
     }
     else if (ret.status == -12)
     {
         actionManager.FindAndSetCoordOfPriceSection();
     }
 }
예제 #3
0
        private void LoopDetectPriceAndTimeInScreen()
        {
            logger.InfoFormat("begin loopDetectPriceAndTimeInScreen");
            int i = 0;

            PageTimePriceResult lastResultx = null;

            while (isCollectingWork)
            {
                long ss = KK.CurrentMills();

                try
                {
                    long s1 = KK.CurrentMills();
                    PageTimePriceResult lastResult = actionManager.DetectPriceAndTimeInScreen(lastResultx);

                    // 重复检测
                    if (lastResult.status == 300)
                    {
                        continue;
                    }

                    SetShowUpText(ToShowUpText(lastResult));

                    // 处理异常情况
                    if (lastResult.status != 0)
                    {
                        ProcessErrorDetect(lastResult);

                        // TODO: 这里也需要处理 可能需要的提交,因为远程会下发一个可能的当前秒数
                        // 目的是防止出现卡秒现象

                        continue;
                    }

                    lastResultx = lastResult;

                    PagePrice pp = lastResult.data;

                    logger.DebugFormat("detectPriceAndTimeInScreen elapsed {0}ms", KK.CurrentMills() - s1);

                    if (pp != null)
                    {
                        if (pp.pageTime.Minute == 28)
                        {
                            if (IsOneRoundStarted)
                            {
                                ResetContext();
                                IsOneRoundStarted = false;
                            }
                        }
                        else if (pp.pageTime.Minute == 29)
                        {
                            if (!IsOneRoundStarted)
                            {
                                IsOneRoundStarted = true;
                            }
                        }

                        s1 = KK.CurrentMills();
                        AfterSuccessDetectInner(pp);
                        logger.DebugFormat("afterDetect elapsed {0}ms", KK.CurrentMills() - s1);
                    }
                    else
                    {
                        // TODO:
                    }
                }
                catch (Exception e)
                {
                    logger.Error("detect price and time error", e);
                }
                finally
                {
                    // TODO: 这里可能不需要每次重置dict
                    // actionManager.ResetDictIndex();

                    KK.Sleep(12);
                }

                logger.DebugFormat("round {0} loopDetectPriceAndTimeInScreen elapsed {1}ms", i++, KK.CurrentMills() - ss);
            }

            logger.InfoFormat("END loopDetectPriceAndTimeInScreen ");
        }
예제 #4
0
        public PageTimePriceResult DetectPriceAndTimeInScreen(PageTimePriceResult LastResult)
        {
            long   t1   = KK.CurrentMills();
            string uuid = KK.uuid();

            if (this.coordOfCurrentTime == null || coordOfCurrentTime.x <= 0 || coordOfCurrentTime.y <= 0)
            {
                return(PageTimePriceResult.ErrorCoordTime());
            }

            var p = this.coordOfCurrentTime;

            // 11:29:57
            int x1 = p.x + 20, y1 = p.y, x2 = p.x + 20 + 150, y2 = p.y + 18;

            long s1 = KK.CurrentMills();

            robot.UseDict(DictIndex.INDEX_NUMBER);
            string ret1 = robot.Ocr(x1, y1, x2, y2, "ff0000-000000", 0.8);

            // string ret1 = robot.Ocr(x1, y1, x2, y2, "0066cc-101010", 0.8);
            logger.DebugFormat("目前时间 - OCR内容 {0}, {1}, {2}, {3}. elapsed {4}ms, {5}, {6}", x1, y1, x2, y2, KK.CurrentMills() - s1, ret1, uuid);


            if (ret1 == null || ret1.Length == 0 || ret1.Length < 6)
            {
                return(PageTimePriceResult.ErrorTime());
            }

            DateTime no = DateTime.Now;

            string td = KK.ExtractDigits(ret1);

            if (td == null || td.Length != 6)
            {
                return(PageTimePriceResult.ErrorTime());
            }

            logger.DebugFormat("Parsed time is {0}.", td);

            DateTime dt = new DateTime(no.Year, no.Month, no.Day, int.Parse(td.Substring(0, 2)), int.Parse(td.Substring(2, 2)), int.Parse(td.Substring(4, 2)));

            // 检测是否已经拿到过该秒的数据,则可以忽略不检测价格了
            if (LastResult?.data != null && dt == LastResult.data.pageTime)
            {
                return(PageTimePriceResult.RepeatedTime());
            }

            // 找到坐标 of 价格区间
            if (this.coordOfPriceSection == null || coordOfPriceSection.x <= 0 || coordOfPriceSection.y <= 0)
            {
                return(PageTimePriceResult.ErrorCoordPrice());
            }

            var p2 = this.coordOfPriceSection;

            logger.DebugFormat("价格区间 - 坐标是 - {0}. {1}", p2.ToString(), KK.CurrentMills() - t1);

            // 11:29:57
            int x21 = p2.x + 20, y21 = p2.y, x22 = p2.x + 20 + 250, y22 = p2.y + 18;

            // ff0000-101010
            s1 = KK.CurrentMills();
            robot.UseDict(DictIndex.INDEX_NUMBER);
            string ret2 = robot.Ocr(x21, y21, x22, y22, "ff0000-000000", 0.8);

            if (dt.Minute > 26)
            {
                logger.InfoFormat("价格区间 - OCR内容, {0} @ {1}, elapsed {2}ms", ret2, dt, KK.CurrentMills() - s1);
            }
            else
            {
                logger.DebugFormat("价格区间 - OCR内容, {0} @ {1}, elapsed {2}ms", ret2, dt, KK.CurrentMills() - s1);
            }


            if (ret2 == null || ret2.Length == 0 || ret2.Length < 10)
            {
                return(PageTimePriceResult.ErrorPrice());
            }

            string numberStr = KK.ExtractDigits(ret2);

            if (numberStr.Length < 10)
            {
                logger.WarnFormat("识别到 错误的 价格 - {0}. 数字的位数不对.", numberStr);
                return(PageTimePriceResult.ErrorPrice());
            }

            int[] arr2      = ParsePrice(numberStr);
            int   priceLow  = arr2[0];
            int   priceHigh = arr2[1];

            if (priceHigh < 70000 || priceHigh < 70000 || priceHigh > 200000 || priceLow > 200000)
            {
                logger.WarnFormat("识别到 错误的 价格 - {0}, {1}.", priceLow, priceHigh);
                return(PageTimePriceResult.ErrorPrice());
            }

            int basePrice = (priceLow + priceHigh) / 2;

            if (dt.Minute > 25)
            {
                logger.InfoFormat("parsed price - base#{0}, low#{1}, high#{2}", basePrice, priceLow, priceHigh);
            }
            else
            {
                logger.DebugFormat("parsed price - base#{0}, low#{1}, high#{2}", basePrice, priceLow, priceHigh);
            }

            var pp = new PagePrice(dt, basePrice);

            pp.low  = priceLow;
            pp.high = priceHigh;

            return(PageTimePriceResult.Ok(pp));
        }