Exemple #1
0
        public DatePoint FindBlackPoint(Image <Gray, byte> image)
        {
            DatePoint result = new DatePoint();

            try
            {
                result._x = -1;

                for (int i = 0; i < image.Height; i++)
                {
                    for (int j = 0; j < image.Width; j++)
                    {
                        if (image.Data[i, j, 0] != 255)
                        {
                            result._x     = j;
                            result._y     = i;
                            result._z     = j;
                            result._value = 0;
                            break;
                        }
                    }
                    if (result._x != -1)
                    {
                        break;
                    }
                }

                return(result);
            }
            catch (Exception)
            {
                result._x = -1;
                return(result);
            }
        }
        public CompetitorTemplate(string filePath,
                                  CompetitorPoint competitor1,
                                  CompetitorPoint competitor2,
                                  CompetitorPoint competitor1Webcam,
                                  CompetitorPoint competitor2Webcam,
                                  ScorePoint score1, ScorePoint score2,
                                  RoundPoint round,
                                  TournamentPoint tournamentNameRound,
                                  DatePoint datePoint)
            : base(filePath)
        {
            if (competitor1 == null)
            {
                throw new Exception("Competitor Template: Competitor 1 must have a point on template");
            }
            if (competitor2 == null)
            {
                throw new Exception("Competitor Template: Competitor 2 must have a point on template");
            }
            if (competitor1Webcam == null)
            {
                throw new Exception("Competitor Template: Competitor 1's Webcam must have a point on template");
            }
            if (competitor2Webcam == null)
            {
                throw new Exception("Competitor Template: Competitor 2's Webcam must have a point on template");
            }
            if (score1 == null)
            {
                throw new Exception("Competitor Template: Score 1 must have a point on template");
            }
            if (score2 == null)
            {
                throw new Exception("Competitor Template: Score 2 must have a point on template");
            }
            if (round == null)
            {
                throw new Exception("Competitor Template: Round must have a point on template");
            }
            if (tournamentNameRound == null)
            {
                throw new Exception("Competitor Template: Tournament Name must have a point on template");
            }
            if (datePoint == null)
            {
                throw new Exception("Competitor Template: Date must have a point on template");
            }

            this.competitor1Point         = competitor1;
            this.competitor2Point         = competitor2;
            this.competitor1WebcamPoint   = competitor1Webcam;
            this.competitor2WebcamPoint   = competitor2Webcam;
            this.score1Point              = score1;
            this.score2Point              = score2;
            this.roundPoint               = round;
            this.tournamentNameRoundPoint = tournamentNameRound;
            this.datePoint = datePoint;
        }
        /// <summary>
        /// Evaluates the two indicators as passed
        /// </summary>
        /// <param name="indicatorLibraryAdapter">The indicatorLibraryAdapter to use for the indicator evaluation.</param>
        /// <returns>A boolean value of the evaluation.</returns>
        public override bool Eval(TestData testData)
        {
            double?indicator1 = testData.GetIndicator(this.IndicatorName1);
            double?indicator2 = testData.GetIndicator(this.IndicatorName2);

            if (lasttime != null)
            {
                if (lasttime.PointDateTime.Date.CompareTo(testData.GetStockPoint().PointDateTime.Date) != 0)
                {
                    PrevDifference = 0;
                }
            }
            lasttime = testData.GetStockPoint();
            if (indicator1 == null || indicator2 == null)
            {
                return(false);
            }
            double currentDifference = Math.Abs((double)indicator1 - (double)indicator2);

            if (PrevDifference == 0)
            {
                PrevDifference = Math.Abs((double)indicator1 - (double)indicator2);
                return(false);
            }

            switch (this.CompareType)
            {
            case IndicatorCompareType.positiveDiverge:
                if (currentDifference > PrevDifference)
                {
                    PrevDifference = currentDifference;
                    return(true);
                }
                else
                {
                    PrevDifference = currentDifference;
                    return(false);
                }

            case IndicatorCompareType.negativeDiverge:
                if (currentDifference < PrevDifference)
                {
                    PrevDifference = currentDifference;
                    return(true);
                }
                else
                {
                    PrevDifference = currentDifference;
                    return(false);
                }

            default:
                throw new Exception("Compare Type not defined");
            }
        }
Exemple #4
0
        public static CompetitorTemplate GetCompTemplate(string fileName)
        {
            string qry =
                "SELECT * FROM tbl_CompetitorTemplates WHERE FileName = '" + fileName + "';";
            SQLiteCommand cmd = new SQLiteCommand(qry, conn);

            try
            {
                DBOpen();
                SQLiteDataReader cur = cmd.ExecuteReader();
                while (cur.Read())
                {
                    string name  = cur.GetString(0);
                    int    tpx   = cur.GetInt32(1);
                    int    tpy   = cur.GetInt32(2);
                    int    rpx   = cur.GetInt32(3);
                    int    rpy   = cur.GetInt32(4);
                    int    p1px  = cur.GetInt32(5);
                    int    p1py  = cur.GetInt32(6);
                    int    p2px  = cur.GetInt32(7);
                    int    p2py  = cur.GetInt32(8);
                    int    p1cpx = cur.GetInt32(9);
                    int    p1cpy = cur.GetInt32(10);
                    int    p2cpx = cur.GetInt32(11);
                    int    p2cpy = cur.GetInt32(12);
                    int    p1spx = cur.GetInt32(13);
                    int    p1spy = cur.GetInt32(14);
                    int    p2spx = cur.GetInt32(15);
                    int    p2spy = cur.GetInt32(16);
                    int    dpx   = cur.GetInt32(17);
                    int    dpy   = cur.GetInt32(18);
                    string opt   = cur.GetString(19).Replace("\n", "");

                    CompetitorPoint player1pt    = new CompetitorPoint(p1px, p1py);
                    CompetitorPoint player2pt    = new CompetitorPoint(p2px, p2py);
                    CompetitorPoint player1CamPt = new CompetitorPoint(p1cpx, p1cpy);
                    CompetitorPoint player2CamPt = new CompetitorPoint(p2cpx, p2cpy);
                    ScorePoint      score1pt     = new ScorePoint(p1spx, p1spy);
                    ScorePoint      score2pt     = new ScorePoint(p2spx, p2spy);
                    RoundPoint      roundpt      = new RoundPoint(rpx, rpy);
                    TournamentPoint tourneypt    = new TournamentPoint(tpx, tpy);
                    DatePoint       datePoint    = new DatePoint(dpx, dpy);

                    DBClose();
                    return(new CompetitorTemplate(name, player1pt, player2pt, player1CamPt, player2CamPt, score1pt, score2pt, roundpt, tourneypt, datePoint, opt));
                }
                return(null);
            }
            catch (Exception ex)
            {
                DBClose();
                return(null);
            }
        }
Exemple #5
0
        private List <Place> ReseachImage()
        {
            List <Place> ls         = new List <Place>();
            DatePoint    BlackPoint = ImageWorks.FindBlackPoint(GrayImagePKKwithBorder);

            while (BlackPoint._x != -1)
            {
                var location    = MyMapView.ScreenToLocation(new Point(BlackPoint._x, BlackPoint._y));
                var coord       = CoordinateFormatter.ToLatitudeLongitude(location, LatitudeLongitudeFormat.DecimalDegrees, 6);
                var _placeCoord = GetPlaceProp.GetPlaceCoordMethod(coord.Substring(0, 9), coord.Substring(12, 9));
                int cnt         = _placeCoord.Features[0].Attrs.Cn.Count(c => c == ':');
                if (_placeCoord.Features[0].Attrs.Address != null)
                {
                    var place1 = GetPlaceProp.Get_Place(_placeCoord.Features[0].Attrs.Id);
                    ls.Add(place1);
                }
                LineFill(BlackPoint._x, BlackPoint._y);
                BlackPoint = ImageWorks.FindBlackPoint(GrayImagePKKwithBorder);
            }
            ls = ls.GroupBy(s => s.Feature.Attrs.Cn).Select(g => g.First()).ToList();
            return(ls);
        }
        /// <summary>
        /// Evaluates the two indicators as passed
        /// </summary>
        /// <param name="indicatorLibraryAdapter">The indicatorLibraryAdapter to use for the indicator evaluation.</param>
        /// lasttime makes sure program is circulating through different indicators of the same date/time
        /// prevTime is used to find the difference between the previous date/time
        /// <returns>A boolean value of the evaluation.</returns>
        public override bool Eval(Dictionary <DateTime, Dictionary <string, double> > indicatorLibraryAdapter, DatePoint point)
        {
            double?indicator1 = indicatorLibraryAdapter[point.PointDateTime][this.IndicatorName1];
            double?indicator2 = indicatorLibraryAdapter[point.PointDateTime][this.IndicatorName2];

            if (lasttime != null)
            {
                if (lasttime.PointDateTime.CompareTo(point.PointDateTime) != 0)
                {
                    prevPoint = lasttime;
                }
                if (prevPoint.Date.CompareTo(point.PointDateTime.Date) != 0)
                {
                    prevPoint = point;
                    lasttime  = point;
                    return(false);
                }
            }

            if (indicator1 == 0 || indicator2 == 0)
            {
                return(false);
            }
            double currentDifference = Math.Abs((double)indicator1 - (double)indicator2);

            point.PointDateTime.AddMinutes(-5);
            double?indicator1a = indicatorLibraryAdapter[point.PointDateTime][this.IndicatorName1];
            double?indicator2b = indicatorLibraryAdapter[point.PointDateTime][this.IndicatorName2];

            point.PointDateTime.AddMinutes(5);
            double prevDifference = Math.Abs((double)indicator1a - (double)indicator2b);

            switch (this.CompareType)
            {
            case IndicatorCompareType.positiveDiverge:
                if (currentDifference > PrevDifference)
                {
                    PrevDifference = currentDifference;
                    return(true);
                }
                else
                {
                    PrevDifference = currentDifference;
                    return(false);
                }

            case IndicatorCompareType.negativeDiverge:
                if (currentDifference < PrevDifference)
                {
                    PrevDifference = currentDifference;
                    return(true);
                }
                else
                {
                    PrevDifference = currentDifference;
                    return(false);
                }

            default:
                throw new Exception("Compare Type not defined");
            }
        }
Exemple #7
0
 public void Add(DatePoint data)
 {
     Data.Add(data);
 }
        public Bitmap drawTextOnImage(SmashOverlayGenerator form, bool swap, bool camSwap)
        {
            string cam1 = GenFcns.removeWinLoseTags(form.Competitor1);
            string cam2 = GenFcns.removeWinLoseTags(form.Competitor2);

            setFontSizes(form.ResourceType, form.Competitor1, form.Competitor2);

            Bitmap   image = base.getImage();
            Graphics g     = Graphics.FromImage(image);

            if (!swap)
            {
                g.DrawString(form.Competitor1, Name1Font, Brushes.White, Competitor1Point.getPoint(), Player1Format);
                g.DrawString(form.Competitor2, Name2Font, Brushes.White, Competitor2Point.getPoint(), Player2Format);
                g.DrawString(form.Score1, ScoreFont, Brushes.White, Score1Point.getPoint(), ScoreFormat);
                g.DrawString(form.Score2, ScoreFont, Brushes.White, Score2Point.getPoint(), ScoreFormat);
            }
            else
            {
                g.DrawString(form.Competitor1, Name1Font, Brushes.White, Competitor2Point.getPoint(), Player2Format);
                g.DrawString(form.Competitor2, Name2Font, Brushes.White, Competitor1Point.getPoint(), Player1Format);
                g.DrawString(form.Score1, ScoreFont, Brushes.White, Score2Point.getPoint(), ScoreFormat);
                g.DrawString(form.Score2, ScoreFont, Brushes.White, Score1Point.getPoint(), ScoreFormat);
            }

            if (!camSwap)
            {
                g.DrawString(cam1, Name1Font, Brushes.White, Competitor1WebcamPoint.getPoint(), NameFormat);
                g.DrawString(cam2, Name2Font, Brushes.White, Competitor2WebcamPoint.getPoint(), NameFormat);
            }
            else
            {
                g.DrawString(cam2, Name1Font, Brushes.White, Competitor1WebcamPoint.getPoint(), NameFormat);
                g.DrawString(cam1, Name2Font, Brushes.White, Competitor2WebcamPoint.getPoint(), NameFormat);
            }

            if (RoundPoint == null)
            {
                g.DrawString(form.TournamentName + " | " + form.TournamentRound,
                             TournamentFont, Brushes.White, TournamentNameRoundPoint.getPoint(), NameFormat);
            }
            else
            {
                g.DrawString(form.TournamentName, TournamentFont, Brushes.White, TournamentNameRoundPoint.getPoint(), TourneyFormat);

                RoundFont = new Font(FontFamily.GenericSerif, 25, FontStyle.Bold);
                g.DrawString(form.TournamentRound, RoundFont, Brushes.White, RoundPoint.getPoint(), NameFormat);
            }

            if (DatePoint != null)
            {
                g.DrawString(form.CurrentDateTime.ToString("MMMM dd, yyyy"), TournamentFont, Brushes.White, DatePoint.getPoint(), DateFormat);
            }

            return(image);
        }
Exemple #9
0
        /// <summary>
        /// Evaluates the two indicators as passed
        /// </summary>
        /// <param name="indicatorLibraryAdapter">The indicatorLibraryAdapter to use for the indicator evaluation.</param>
        /// <returns>A boolean value of the evaluation.</returns>
        public override bool Eval(Dictionary <DateTime, Dictionary <string, double> > indicatorLibraryAdapter, DatePoint point)
        {
            double?indicator1 = indicatorLibraryAdapter[point.PointDateTime][this.IndicatorName1];
            double?indicator2 = indicatorLibraryAdapter[point.PointDateTime][this.IndicatorName2];

            if (indicator1 == null || indicator2 == null)
            {
                return(false);
            }

            switch (this.CompareType)
            {
            case IndicatorCompareType.GT:
                return(indicator1 > indicator2);

            case IndicatorCompareType.LT:
                return(indicator1 < indicator2);

            default:
                throw new Exception("Compare Type not defined");
            }
        }
Exemple #10
0
 public void Add(DatePoint data)
 {
     Data.Add(data);
 }
Exemple #11
0
        /// <summary>
        /// Evaluates the two indicators as passed
        /// </summary>
        /// <param name="indicatorLibraryAdapter">The indicatorLibraryAdapter to use for the indicator evaluation.</param>
        /// <returns>A boolean value of the evaluation.</returns>
        public override bool Eval(Dictionary <DateTime, Dictionary <string, double> > indicatorLibraryAdapter, DatePoint point)
        {
            //double? indicator1 = (double)indicatorLibraryAdapter[point][this.IndicatorName1];
            //double? indicator2 = (double)indicatorLibraryAdapter[point][this.IndicatorName2];
            DateTime test = new DateTime();

            if (lasttime != null)
            {
                if (lasttime.Date.CompareTo(point.PointDateTime.Date) != 0)
                {
                    indicator1a = 0;
                    indicator2a = 0;
                    prevTime    = lasttime;
                }
                else
                {
                    indicator1 = (double)indicatorLibraryAdapter[point.PointDateTime][this.IndicatorName1];
                    indicator2 = (double)indicatorLibraryAdapter[point.PointDateTime][this.IndicatorName2];
                    if (lasttime.CompareTo(point.PointDateTime) == 0)
                    {
                        if (prevTime == test)
                        {
                            prevTime = lasttime;
                        }
                        else
                        {
                            indicator1a = indicatorLibraryAdapter[prevTime][this.IndicatorName1];
                            indicator2a = indicatorLibraryAdapter[prevTime][this.IndicatorName1];
                        }
                    }
                    else
                    {
                        indicator1a = indicatorLibraryAdapter[lasttime][this.IndicatorName1];
                        indicator2a = indicatorLibraryAdapter[lasttime][this.IndicatorName1];
                        prevTime    = lasttime;
                    }
                }
            }

            lasttime = point.PointDateTime;
            if (indicator1 == 0 || indicator2 == 0)
            {
                return(false);
            }
            if (indicator1a == 0 || indicator2a == 0)
            {
                return(false);
            }
            switch (this.CompareType)
            {
            case IndicatorCompareType.crossesAbove:
                if (indicator1a < indicator2 && indicator1 > indicator2)
                {
                    indicator1a = indicator1;
                    indicator2a = indicator2;
                    return(true);
                }
                else
                {
                    indicator1a = indicator1;
                    indicator2a = indicator2;
                    return(false);
                }

            case IndicatorCompareType.crossesBelow:
                if (indicator1a > indicator2 && indicator1 < indicator2)
                {
                    indicator1a = indicator1;
                    indicator2a = indicator2;
                    return(true);
                }
                else
                {
                    indicator1a = indicator1;
                    indicator2a = indicator2;
                    return(false);
                }

            default:
                throw new Exception("Compare Type not defined");
            }
        }
        /// <summary>
        /// Evaluates the trade rule for the current indicatorLibraryAdapter line.
        /// </summary>
        /// <param name="indicatorLibraryAdapter">The data source to evaluate.</param>
        /// <returns>A boolean value for the conditionon this line.</returns>
        public bool Eval(TestData indicatorLibraryAdapter)
        {
            if (this.TradeRules.Count == 0)
            {
                throw new TradeRuleException("Trade rules not defined.");
            }
            DatePoint newPoint = indicatorLibraryAdapter.GetStockPoint();

            TradeRule[] traderule1 = new TradeRule[TradeRules.Count];

            bool evalValue = false;

            if (TradeRules.Count >= 2)
            {
                bool[] tradeeval = new bool[TradeRules.Count];
                for (int i = 0; i < TradeRules.Count; i++)
                {
                    string    indicator1 = TradeRules[i].IndicatorName1;
                    string    indicator2 = TradeRules[i].IndicatorName2;
                    TradeRule nT         = TradeRuleFactory.GenerateTradeRule(indicator1, TradeRules[i].CompareType, indicator2);
                    traderule1[i] = nT;
                }
                for (int i = 0; i < TradeRules.Count; i++)
                {
                    tradeeval[i] = traderule1[i].Eval(indicatorLibraryAdapter);
                }
                for (int i = 0; i < RuleJoinTypes.Count; i++)
                {
                    if (i != 0 && RuleJoinTypes[i - 1] == RuleJoinType.and)
                    {
                    }
                    else
                    {
                        while (RuleJoinTypes[i] == RuleJoinType.and)
                        {
                            if (tradeeval[i] && tradeeval[i + 1])
                            {
                                evalValue = true;
                            }
                            else
                            {
                                evalValue = false;
                                break;
                            }
                            i++;
                            if (i >= RuleJoinTypes.Count)
                            {
                                i--;
                                break;
                            }
                        }
                    }
                    if (evalValue == true)
                    {
                        break;
                    }
                    if (RuleJoinTypes[i] == RuleJoinType.or)
                    {
                        if (i >= RuleJoinTypes.Count)
                        {
                        }
                        else if (RuleJoinTypes[i + 1] == RuleJoinType.and)
                        {
                            while (RuleJoinTypes[i] == RuleJoinType.and)
                            {
                                if (tradeeval[i] && tradeeval[i + 1])
                                {
                                    evalValue = true;
                                }
                                else
                                {
                                    evalValue = false;
                                }
                                i++;
                            }
                            if (evalValue == true)
                            {
                                break;
                            }
                        }
                        else
                        {
                            if (tradeeval[i])
                            {
                                evalValue = true;
                                break;
                            }
                        }
                    }
                }
            }
            else
            {
                string indicator1 = TradeRules[0].IndicatorName1;
                string indicator2 = TradeRules[0].IndicatorName2;
                traderule1[0] = TradeRuleFactory.GenerateTradeRule(indicator1, TradeRules[0].CompareType, indicator2);
                evalValue     = traderule1[0].Eval(indicatorLibraryAdapter);
            }



            return(evalValue);
        }
        /// <summary>
        /// Evaluates the trade rule for the current indicatorLibraryAdapter line.
        /// </summary>
        /// <param name="indicatorLibraryAdapter">The data source to evaluate.</param>
        /// <returns>A boolean value for the conditionon this line.</returns>
        public bool Eval(Dictionary <DateTime, Dictionary <string, double> > indicatorLibraryAdapter, DatePoint point)
        {
            if (this.TradeRules.Count == 0)
            {
                throw new TradeRuleException("Trade rules not defined.");
            }
            DatePoint newPoint = point;

            TradeRule[] traderule1 = new TradeRule[TradeRules.Count];

            bool evalValue = false;

            if (TradeRules.Count >= 2)
            {
                bool[] tradeeval      = new bool[TradeRules.Count];
                int    tradeevalcount = 0;
                for (int i = 0; i < TradeRules.Count; i++)
                {
                    string    indicator1 = TradeRules[i].IndicatorName1;
                    string    indicator2 = TradeRules[i].IndicatorName2;
                    TradeRule nT         = TradeRuleFactory.GenerateTradeRule(indicator1, TradeRules[i].CompareType, indicator2);
                    traderule1[i] = nT;
                }
                for (int i = 0; i < TradeRules.Count; i++)
                {
                    tradeeval[i] = traderule1[i].Eval(indicatorLibraryAdapter, point);
                }
                for (int i = 0; i < RuleJoinTypes.Count; i++)
                {
                    #region and jointype
                    if (RuleJoinTypes[i] == RuleJoinType.and)
                    {
                        int andCount = 0;
                        int j        = 0;
                        while (RuleJoinTypes[i] == RuleJoinType.and)
                        {
                            for (int k = 0; k < 2; k++)
                            {
                                if (tradeevalcount >= tradeeval.Count())
                                {
                                    break;
                                }
                                if (tradeeval[tradeevalcount++])
                                {
                                    andCount++;
                                    j++;
                                }
                                else
                                {
                                    j++;
                                }
                            }
                            if (i >= RuleJoinTypes.Count - 1)
                            {
                                //i--;
                                break;
                            }
                            if (RuleJoinTypes[i + 1] == RuleJoinType.and)
                            {
                                tradeevalcount--;
                            }

                            i++;
                        }
                        if (j == andCount)
                        {
                            return(true);
                        }
                    }
                    #endregion
                    #region or jointype
                    if (RuleJoinTypes[i] == RuleJoinType.or)
                    {
                        /*if (i == 0)
                         * {
                         *  if (tradeeval[tradeevalcount++])
                         *  {
                         *      return true;
                         *  }
                         * }
                         * else if (RuleJoinTypes[i - 1] == RuleJoinType.or && RuleJoinTypes[i+1] != RuleJoinType.and)
                         * {
                         *  if (tradeeval[tradeevalcount++])
                         *  {
                         *      return true;
                         *  }
                         * }
                         * else */if (i >= RuleJoinTypes.Count - 1)
                        {
                            if (tradeeval[tradeevalcount++])
                            {
                                return(true);
                            }
                        }
                        else if (RuleJoinTypes[i + 1] == RuleJoinType.and)
                        {
                            int andCount = 0;
                            int j        = 0;
                            while (RuleJoinTypes[i + 1] == RuleJoinType.and)
                            {
                                for (int k = 0; k < 2; k++)
                                {
                                    if (tradeevalcount >= tradeeval.Count())
                                    {
                                        break;
                                    }
                                    if (tradeeval[tradeevalcount++])
                                    {
                                        andCount++;
                                        j++;
                                    }
                                    else
                                    {
                                        j++;
                                    }
                                }
                                if (RuleJoinTypes[i + 1] == RuleJoinType.and)
                                {
                                    tradeevalcount--;
                                }
                                i++;
                                if (i >= RuleJoinTypes.Count - 1)
                                {
                                    //i--;
                                    break;
                                }
                            }
                            if (andCount == j)
                            {
                                return(true);
                            }
                        }
                        else
                        {
                            if (tradeevalcount >= tradeeval.Count())
                            {
                                break;
                            }
                            if (tradeeval[tradeevalcount++])
                            {
                                return(true);
                            }
                        }
                    }
                }
                #endregion
            }
            else
            {
                string indicator1 = TradeRules[0].IndicatorName1;
                string indicator2 = TradeRules[0].IndicatorName2;
                traderule1[0] = TradeRuleFactory.GenerateTradeRule(indicator1, TradeRules[0].CompareType, indicator2);
                evalValue     = traderule1[0].Eval(indicatorLibraryAdapter, point);
            }



            return(evalValue);
        }
Exemple #14
0
 /// <summary>
 /// Evaluates the two indicators as passed
 /// </summary>
 /// <param name="indicatorLibraryAdapter">The indicatorLibraryAdapter to use for the indicator evaluation.</param>
 /// <returns>A boolean value of the evaluation.</returns>
 public abstract bool Eval(Dictionary <DateTime, Dictionary <string, double> > indicatorLibraryAdapter, DatePoint point);