Beispiel #1
0
        protected override void ValidateOrThrow(IEnumerable <Line> lines)
        {
            List <string> lineTexts = lines.Select((line, index) => line.Text).ToList();
            bool          valid     = Validate(lineTexts);

            if (!valid)
            {
                InvalidPortfolioStateException ex = new InvalidPortfolioStateException("Invalid portfolio state attempting to parse orders");
                Log.Warning(ex, "Invalid portfolio state attempting to parse orders. Extracted text: {@Text}", lineTexts);
                throw ex;
            }
        }
Beispiel #2
0
        public override async Task <bool> HaveOrdersChanged(bool?groundTruthChanged)
        {
            if (await HasHeaderChanged())
            {
                InvalidPortfolioStateException ex = new InvalidPortfolioStateException("Header has changed");
                Log.Information(ex, "Portfolio header has changed!");
                throw ex;
            }
            string filepath = GetNextTopOrderFilepath();

            await TakeTopOrderScreenshot(filepath);

            bool changed = OrderConsistencyClient.UpdateImageAndCheckHasChanged(filepath, 0.99, groundTruthChanged);

            if (!changed)
            {
                File.Delete(filepath);
            }
            return(changed);
        }
        protected override void ValidateOrThrow(IEnumerable <Line> lines)
        {
            List <string> lineTexts = lines.Select((line, index) => line.Text).ToList();

            int indexOfSymbol = lineTexts
                                .Select((text, index) => new { Text = text, Index = index })
                                .Where(obj => obj.Text == "Symbol")
                                .Select(obj => obj.Index)
                                .FirstOrDefault(); // Default is 0

            // We are looking for the 4 column headers in this order: "Symbol", "Quantity", "Last", and "Average"
            // However, "Quantity" may be interpreted as "A Quantity" due to the arrow to the left of the text "Quantity".
            // "Average" may be cut off.
            List <string> subList      = lineTexts.GetRange(indexOfSymbol, 4);
            string        joined       = string.Join(" ", subList);
            Regex         headersRegex = new Regex("^Symbol (. )?Quantity Last Aver");

            if (!headersRegex.IsMatch(joined))
            {
                InvalidPortfolioStateException ex = new InvalidPortfolioStateException("Invalid portfolio state when attempting to parse positions");
                Log.Warning(ex, "Invalid portfolio state attempting to parse positions. Extracted text: {@Text}", lineTexts);
                throw ex;
            }
        }