Beispiel #1
0
        public static void GenerateStream(DbValidationResult validationData)
        {
            var text         = new StringBuilder();
            var correctTable = validationData.SolutionResult;
            var userTable    = validationData.UserResult.First();

            var i           = 0;
            var j           = 0;
            var correctRows = correctTable.Rows;
            var userRows    = userTable.Rows;

            var       maxUserDataLength    = GetMaxRowsDataLength(userRows);    //find max length of column data.
            var       maxCorrectDataLength = GetMaxRowsDataLength(correctRows); //find max length of column data.
            const int spaceBetweenTables   = 20;
            const int spaceBetweenColumns  = 5;

            while (i < userRows.Length || j < correctRows.Length)
            {
                var rowData = new StringBuilder();
                if (i < userRows.Length)
                {
                    var userRowCells = userRows[i].Cells;
                    for (var cell = 0; cell < userRowCells.Length; cell++)
                    {
                        var spacesToAdd = maxUserDataLength[cell] - userRowCells[cell].Value.Length + spaceBetweenColumns;
                        rowData.Append(userRowCells[cell].Value + GenerateWhiteSpaces(spacesToAdd));
                    }

                    i++;
                }

                if (j < correctRows.Length)
                {
                    if (rowData.Length == 0)
                    {
                        var spacesToAdd = maxUserDataLength.Sum(dict => dict.Value + spaceBetweenColumns);
                        rowData.Append(GenerateWhiteSpaces(spacesToAdd));
                    }

                    rowData.Append(GenerateWhiteSpaces(spaceBetweenTables)); //отступы до второй таблицы
                    var correctRowCells = correctRows[j].Cells;
                    for (var cell = 0; cell < correctRowCells.Length; cell++)
                    {
                        var spacesToAdd = maxCorrectDataLength[cell] - correctRowCells[cell].Value.Length + spaceBetweenColumns;
                        rowData.Append(correctRowCells[cell].Value + GenerateWhiteSpaces(spacesToAdd));
                    }

                    j++;
                }

                text.AppendLine(rowData.ToString());
            }

            var image = GenerateImageFromText(text.ToString());

            //var img2 = GenerateImageFromText2(text.ToString());
            image.Save("C:\\Users\\OlenPC\\Desktop\\Auca\\TelegramBot\\test.png", ImageFormat.Png);
            //img2.Save("C:\\Users\\OlenPC\\Desktop\\Auca\\TelegramBot\\test2.png", ImageFormat.Png);
        }
Beispiel #2
0
        public static void GenerateImageFromSolutionQuery(DbValidationResult validationData)
        {
            var textData     = new StringBuilder();
            var correctTable = validationData.SolutionResult;
            var userTable    = validationData.UserResult.First();


            var correctRows = correctTable.Rows;
            var userRows    = userTable.Rows;

            var       maxUserDataLength    = GetMaxRowsDataLength(userRows);    //find max length of column data.
            var       maxCorrectDataLength = GetMaxRowsDataLength(correctRows); //find max length of column data.
            const int spaceBetweenColumns  = 5;

            textData.AppendLine();
            textData.AppendLine("Result");
            textData.AppendLine();
            for (var i = 0; i < userRows.Length; i++)
            {
                var rowData      = new StringBuilder();
                var userRowCells = userRows[i].Cells;
                for (var cell = 0; cell < userRowCells.Length; cell++)
                {
                    var spacesToAdd = maxUserDataLength[cell] - userRowCells[cell].Value.Length + spaceBetweenColumns;
                    rowData.Append("  " + userRowCells[cell].Value + GenerateWhiteSpaces(spacesToAdd));
                }

                textData.AppendLine(rowData.ToString());
            }

            textData.AppendLine();
            textData.AppendLine();
            textData.AppendLine();
            textData.AppendLine("Correct Result");
            textData.AppendLine();
            for (var j = 0; j < correctRows.Length; j++)
            {
                var rowData         = new StringBuilder();
                var correctRowCells = correctRows[j].Cells;
                for (var cell = 0; cell < correctRowCells.Length; cell++)
                {
                    var spacesToAdd = maxCorrectDataLength[cell] - correctRowCells[cell].Value.Length + spaceBetweenColumns;
                    rowData.Append("  " + correctRowCells[cell].Value + GenerateWhiteSpaces(spacesToAdd));
                }

                textData.AppendLine(rowData.ToString());
            }



            var image = GenerateImageFromText(textData.ToString());

            //var img2 = GenerateImageFromText2(text.ToString());
            image.Save("C:\\Users\\OlenPC\\Desktop\\Auca\\TelegramBot\\test.png", ImageFormat.Png);
            //img2.Save("C:\\Users\\OlenPC\\Desktop\\Auca\\TelegramBot\\test2.png", ImageFormat.Png);
        }
        private PreparedMessageContent PrepareSubmissionStatus(DbValidationResult responseData, int problemId)
        {
            var sb = new StringBuilder();

            if (responseData.Result)
            {
                sb.AppendLine(Resources.QueryCorrect);
            }
            else
            {
                for (var i = 0; i < responseData.Description.Count; i++)
                {
                    if (responseData.Description[i].Contains("SUBMIS0004ER"))
                    {
                        var parsed = responseData.Description[i].Split(',');
                        sb.AppendLine($"The number of rows returned is different on database №-{i + 1}.\n quantity: {parsed[1]}. expected: {parsed[2]}"); //TODO: Ask Ermek
                    }
                    else if (responseData.Description[i].Contains("SUBMIS0003ER"))
                    {
                        var parsed = responseData.Description[i].Split(',');
                        sb.AppendLine($"The number of returned columns is different.\n quantity: {parsed[1]}. expected: {parsed[2]}");
                    }
                    else
                    {
                        sb.AppendLine(responseData.Description[0]);
                    }
                }
            }

            var buttons = new InlineKeyboardButton[1][];

            buttons[0]    = new InlineKeyboardButton[2];
            buttons[0][0] = InlineKeyboardButton.WithCallbackData(Resources.TableResultButton, $"{SectionEnums.TableResult}");
            buttons[0][1] = InlineKeyboardButton.WithCallbackData(Resources.SolveAgainButton, $"{SectionEnums.DbProblemSolve} {problemId}");
            return(new PreparedMessageContent
            {
                ResponseText = sb.ToString(),
                InlineKeyboardMarkup = new InlineKeyboardMarkup(buttons)
            });
        }