/// <summary> /// This method saved the specified scoreboard to the appropriate user's scoreboard file. it writes the data of the scoreboard /// using a similar notation to html, where the different tags refer to different fields of the scoreboard hierarchy. Items /// are nested inside sessions, which are in turn nested inside a scoreboard. /// </summary> /// <param name="scoreboard"></param> public static void SaveScoreboard(MPAiSpeakScoreBoard scoreboard) { if (scoreboard.IsEmpty()) { return; } if (File.Exists(SpeakScoreboardFileAddress(scoreboard.User))) { File.Delete(SpeakScoreboardFileAddress(scoreboard.User)); } using (FileStream fs = new FileStream(SpeakScoreboardFileAddress(scoreboard.User), FileMode.Create)) { using (StreamWriter sw = new StreamWriter(fs)) { sw.WriteLine("<Scoreboard>"); foreach (MPAiSpeakScoreBoardSession session in scoreboard.Sessions) { if (session.IsEmpty()) { continue; } sw.WriteLine("<Session>"); sw.WriteLine("<Date>"); sw.WriteLine(session.DateAndTime); sw.WriteLine("</Date>"); sw.WriteLine("<Content>"); foreach (MPAiSpeakScoreBoardItem item in session.Content) { sw.WriteLine("<Expected>"); sw.WriteLine(item.ExpectedText); sw.WriteLine("</Expected>"); sw.WriteLine("<Recognised>"); sw.WriteLine(item.RecognisedText); sw.WriteLine("</Recognised>"); sw.WriteLine("<Analysis>"); sw.WriteLine(item.Analysis); sw.WriteLine("</Analysis>"); sw.WriteLine("<RecordingName>"); sw.WriteLine(item.RecordingName); sw.WriteLine("</RecordingName>"); } sw.WriteLine("</Content>"); sw.WriteLine("</Session>"); } sw.WriteLine("</Scoreboard>"); } } File.SetAttributes(SpeakScoreboardFileAddress(scoreboard.User), File.GetAttributes(SpeakScoreboardFileAddress(scoreboard.User)) | FileAttributes.Hidden); }
/// <summary> /// Generates an HTML score report based on an input MPAiSpeak scoreboard. /// </summary> /// <param name="scoreboard">The scoreboard to generate an HTML report of.</param> public static void GenerateMPAiSpeakScoreHTML(MPAiSpeakScoreBoard scoreboard) { if (scoreboard.IsEmpty()) { return; } scoreboard.SaveScoreBoardToFile(); if (!File.Exists(ScoreboardReportCSSAddress)) { generateScoreboardCSS(); } using (FileStream fs = new FileStream(MPAiSpeakScoreReportHTMLAddress, FileMode.Create)) { using (StreamWriter sw = new StreamWriter(fs)) { using (HtmlTextWriter htw = new HtmlTextWriter(sw)) { htw.RenderBeginTag(HtmlTextWriterTag.Html); // Table settings htw.RenderBeginTag(HtmlTextWriterTag.Head); htw.AddAttribute("charset", "UTF-8"); htw.RenderBeginTag(HtmlTextWriterTag.Meta); htw.AddAttribute(HtmlTextWriterAttribute.Rel, "stylesheet"); htw.AddAttribute(HtmlTextWriterAttribute.Type, "text/css"); htw.AddAttribute(HtmlTextWriterAttribute.Href, "Scoreboard.css"); htw.RenderBeginTag(HtmlTextWriterTag.Link); htw.RenderEndTag(); htw.RenderEndTag(); htw.RenderEndTag(); //Scoreboard Title htw.RenderBeginTag(HtmlTextWriterTag.Body); htw.AddAttribute(HtmlTextWriterAttribute.Class, "title"); htw.RenderBeginTag(HtmlTextWriterTag.Div); htw.RenderBeginTag(HtmlTextWriterTag.H3); htw.Write(scoreboard.User.GetCorrectlyCapitalisedName() + "'s MPAi Speak Pronunciation Scoreboard"); htw.RenderEndTag(); htw.RenderEndTag(); foreach (MPAiSpeakScoreBoardSession session in scoreboard.Sessions) { if (session.IsEmpty()) { continue; } //Table Title htw.AddAttribute(HtmlTextWriterAttribute.Class, "table-title"); htw.RenderBeginTag(HtmlTextWriterTag.Div); htw.RenderBeginTag(HtmlTextWriterTag.H3); htw.Write(session.DateAndTime.ToString("dd MMMM yyyy, h:mm tt")); htw.RenderEndTag(); htw.RenderEndTag(); // Header row of the table htw.AddAttribute(HtmlTextWriterAttribute.Class, "table-fill"); htw.RenderBeginTag(HtmlTextWriterTag.Table); htw.RenderBeginTag(HtmlTextWriterTag.Tr); htw.RenderBeginTag(HtmlTextWriterTag.Th); htw.Write("Expecting Word"); htw.RenderEndTag(); htw.RenderBeginTag(HtmlTextWriterTag.Th); htw.Write("Recognized Word"); htw.RenderEndTag(); htw.RenderBeginTag(HtmlTextWriterTag.Th); htw.Write("Similarity Score"); htw.RenderEndTag(); htw.RenderBeginTag(HtmlTextWriterTag.Th); htw.Write("Analysis Tips"); htw.RenderEndTag(); htw.RenderEndTag(); // Table rows foreach (MPAiSpeakScoreBoardItem item in session.Content) { htw.RenderBeginTag(HtmlTextWriterTag.Tr); htw.RenderBeginTag(HtmlTextWriterTag.Td); htw.Write(item.ExpectedText); htw.RenderEndTag(); htw.RenderBeginTag(HtmlTextWriterTag.Td); htw.Write(item.RecognisedText); htw.RenderEndTag(); htw.RenderBeginTag(HtmlTextWriterTag.Td); htw.Write(item.Similarity.ToString("0.0%")); htw.RenderEndTag(); htw.RenderBeginTag(HtmlTextWriterTag.Td); htw.Write(item.Analysis); htw.RenderEndTag(); htw.RenderEndTag(); } // Correctness score float correctness = session.OverallCorrectnessPercentage; if (correctness >= 0.8) { htw.AddAttribute(HtmlTextWriterAttribute.Class, "good-colour"); } else if (correctness >= 0.5) { htw.AddAttribute(HtmlTextWriterAttribute.Class, "medium-colour"); } else { htw.AddAttribute(HtmlTextWriterAttribute.Class, "bad-colour"); } htw.RenderBeginTag(HtmlTextWriterTag.Tr); htw.AddAttribute(HtmlTextWriterAttribute.Colspan, "4"); htw.RenderBeginTag(HtmlTextWriterTag.Td); htw.Write("Pronunciation is " + correctness.ToString("0.0%") + " Correct"); htw.RenderEndTag(); htw.RenderEndTag(); htw.RenderEndTag(); } htw.RenderEndTag(); htw.RenderEndTag(); } } } }