A Dictionary<string, QuestionAnswers> that associates fields with their answers.
public Dictionary<string, QuestionAnswers> QuestionsAnswers { get; set; }
Dictionary<string, QuestionAnswers> object
The key in this dictionary is a string that identifies a field. This string should be unique and mapped to a field. To generate a unique string the formatted string contains the page number, the field name and the OmrCollection name, where PageNumber specifies the form page where the OMR field exists. OmrFieldName
is the name for the OMR field. OmrCollectionName
is the name of the OMR collection of interest inside the OMR field.
using Leadtools;
using Leadtools.Barcode;
using Leadtools.Codecs;
using Leadtools.Forms.Processing.Omr;
using Leadtools.Ocr;
private static void GenerateStatistics(List<IRecognitionForm> recognitionForms, IRecognitionForm answers)
{
OmrAnalysisEngine omrAnalysisEngine = new OmrAnalysisEngine(recognitionForms, answers);
omrAnalysisEngine.GradeForms();
// Table generation helpers
const string columnSeparator = " ";
List<List<string>> lines = new List<List<string>>();
List<int> widths = new List<int>();
void AddLine(List<string> line)
{
while (widths.Count < line.Count)
widths.Add(0);
for (int i = 0; i < line.Count; i++)
widths[i] = Math.Max(widths[i], line[i].Length);
lines.Add(line);
}
// Generate the table
foreach (KeyValuePair<string, QuestionAnswers> kvp in omrAnalysisEngine.QuestionsAnswers)
{
List<string> line = new List<string>() { kvp.Key, kvp.Value.Answer };
foreach (KeyValuePair<string, int> stat in kvp.Value.AnswersCount)
line.Add($"{stat.Key}: {stat.Value}");
AddLine(line);
}
// Display the header
if (widths.Count < 2)
Console.WriteLine($"Field{columnSeparator}Answer{columnSeparator}Breakdown");
else
{
widths[0] = Math.Max(widths[0], "Field".Length);
widths[1] = Math.Max(widths[1], "Answer".Length);
Console.WriteLine($"{"Field".PadRight(widths[0])}{columnSeparator}{"Answer".PadRight(widths[1])}{columnSeparator}Breakdown");
}
// Display the results
foreach (List<string> line in lines)
{
for (int i = 0; i < line.Count; i++)
{
if (i > 0)
Console.Write(columnSeparator);
Console.Write($"{line[i].PadRight(widths[i])}");
}
Console.WriteLine();
}
}