Esempio n. 1
0
 /// <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(MPAiSoundScoreBoard scoreboard)
 {
     if (scoreboard.IsEmpty())
     {
         return;
     }
     if (File.Exists(SoundScoreboardFileAddress(scoreboard.User)))
     {
         File.Delete(SoundScoreboardFileAddress(scoreboard.User));
     }
     using (FileStream fs = new FileStream(SoundScoreboardFileAddress(scoreboard.User), FileMode.Create))
     {
         using (StreamWriter sw = new StreamWriter(fs))
         {
             sw.WriteLine("<Scoreboard>");
             foreach (MPAiSoundScoreBoardSession session in scoreboard.Sessions)
             {
                 if (session.IsEmpty())
                 {
                     continue;
                 }
                 sw.WriteLine("<Session>");
                 sw.WriteLine("<Date>");
                 sw.WriteLine(session.DateAndTime);
                 sw.WriteLine("</Date>");
                 sw.WriteLine("<OverallCorrectnessPercentage>");
                 sw.WriteLine(session.OverallCorrectnessPercentage);
                 sw.WriteLine("</OverallCorrectnessPercentage>");
                 sw.WriteLine("<Content>");
                 foreach (MPAiSoundScoreBoardItem item in session.Content)
                 {
                     sw.WriteLine("<Vowel>");
                     sw.WriteLine(item.Vowel);
                     sw.WriteLine("</Vowel>");
                     sw.WriteLine("<CorrectnessPercentage>");
                     sw.WriteLine(item.CorrectnessPercentage);
                     sw.WriteLine("</CorrectnessPercentage>");
                 }
                 sw.WriteLine("</Content>");
                 sw.WriteLine("</Session>");
             }
             sw.WriteLine("</Scoreboard>");
         }
     }
     File.SetAttributes(SoundScoreboardFileAddress(scoreboard.User), File.GetAttributes(SoundScoreboardFileAddress(scoreboard.User)) | FileAttributes.Hidden);
 }
Esempio n. 2
0
        /// <summary>
        /// Generates an HTML score report based on an input MPAiSound scoreboard.
        /// </summary>
        /// <param name="scoreboard">The scoreboard to generate an HTML report of.</param>
        public static void GenerateMPAiSoundScoreHTML(MPAiSoundScoreBoard scoreboard)
        {
            if (scoreboard.IsEmpty())
            {
                return;
            }

            scoreboard.SaveScoreBoardToFile();

            if (!File.Exists(ScoreboardReportCSSAddress))
            {
                generateScoreboardCSS();
            }
            using (FileStream fs = new FileStream(MPAiSoundScoreReportHTMLAddress, 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 Sound Pronunciation Scoreboard");
                        htw.RenderEndTag();
                        htw.RenderEndTag();

                        foreach (MPAiSoundScoreBoardSession 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("Vowel");
                            htw.RenderEndTag();
                            htw.RenderBeginTag(HtmlTextWriterTag.Th);
                            htw.Write("Correctness Percentage");
                            htw.RenderEndTag();
                            htw.RenderEndTag();
                            // Table rows
                            foreach (MPAiSoundScoreBoardItem item in session.Content)
                            {
                                htw.RenderBeginTag(HtmlTextWriterTag.Tr);
                                htw.RenderBeginTag(HtmlTextWriterTag.Td);
                                htw.Write(item.Vowel);
                                htw.RenderEndTag();
                                htw.RenderBeginTag(HtmlTextWriterTag.Td);
                                htw.Write(item.CorrectnessPercentage);
                                htw.RenderEndTag();
                                htw.RenderEndTag();
                            }
                            // Correctness score
                            float correctness = session.OverallCorrectnessPercentage / 100;
                            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, "2");
                            htw.RenderBeginTag(HtmlTextWriterTag.Td);
                            htw.Write("Pronunciation is " + correctness.ToString("0.0%") + " Correct");
                            htw.RenderEndTag();
                            htw.RenderEndTag();
                            htw.RenderEndTag();
                        }
                        htw.RenderEndTag();
                        htw.RenderEndTag();
                    }
                }
            }
        }