/// <summary> /// Write the MeSH Heading report /// </summary> /// <param name="writer">Writer to send the report to</param> public void MeSHHeadingReport(StreamWriter writer, ReportStatus StatusCallback, ReportMessage MessageCallback) { // Write the header writer.WriteLine("setnb,year,heading,count"); // The MeSH Heading report has one row per person per year per heading People people = new People(DB, PeopleTable); int Total = people.PersonList.Count; int Count = 0; foreach (Person person in people.PersonList) { // Report status Count++; StatusCallback(Count, Total, person, false); // Catch any errors, report them, and continue try { // Find the minimum and maximum year for the person int MinYear = 0; int MaxYear = 0; Publications pubs = new Publications(DB, person, PeoplePublicationsTable, false); Hashtable years = new Hashtable(); if (pubs.PublicationList != null) { foreach (Publication pub in pubs.PublicationList) { if (MinYear == 0 || MinYear > pub.Year) { MinYear = pub.Year; } if (MaxYear == 0 || MaxYear < pub.Year) { MaxYear = pub.Year; } // Go through each of the MeSH headings and count how many // occurrences of each heading are in each year. Store each // count in a hashtable keyed by heading, which in turn is // stored in a hashtable keyed by year. if (!years.ContainsKey(pub.Year)) { years[pub.Year] = new Hashtable(); } Hashtable yearHeadings = (Hashtable)years[pub.Year]; if (pub.MeSHHeadings != null) { foreach (string Heading in pub.MeSHHeadings) { if (!yearHeadings.ContainsKey(Heading)) { yearHeadings[Heading] = 0; } yearHeadings[Heading] = ((int)yearHeadings[Heading]) + 1; } } } } // Write the heading rows for each year for (int Year = MinYear; Year <= MaxYear; Year++) { // Write the rows for that person's year to the writer if (years.ContainsKey(Year)) { Hashtable yearHeadings = (Hashtable)years[Year]; if (yearHeadings != null) { foreach (string Heading in yearHeadings.Keys) { StringWriter swriter = new StringWriter(); swriter.Write(person.Setnb); // setnb Reports.WriteCSV(Year.ToString(), swriter); // year Reports.WriteCSV(Heading, swriter); // heading Reports.WriteCSV(yearHeadings[Heading].ToString(), swriter); // count writer.WriteLine(swriter.ToString()); } } } } } catch (Exception ex) { MessageCallback(ex.Message); } } }
/// <summary> /// Add rows to the People report /// </summary> /// <param name="writer">Writer to write the CSV rows to</param> public void PeopleReport(ArrayList SetnbsToSkip, StreamWriter writer, ReportStatus StatusCallback, ReportMessage MessageCallback) { // Write the header row -- this must be generated dynamically // based on the values in PeopleReportSections // write the keys writer.Write("setnb,year"); // write a set of column names for each element in PeopleReportSections for (int i = 0; i < PeopleReportSections.Length; i++) { string values = PeopleReportSections[i].ToLower().Trim(); string[] BaseColumnNames = { "pubcount", "wghtd_pubcount", "pubcount_pos1", "wghtd_pubcount_pos1", "pubcount_posN", "wghtd_pubcount_posN", "pubcount_posM", "wghtd_pubcount_posM", "pubcount_posNTL", "wghtd_pubcount_posNTL", "pubcount_pos2", "wghtd_pubcount_pos2" }; if (values == "all") { // all bins -- use the base column names as-is writer.Write("," + String.Join(",", BaseColumnNames)); } else { // string any +'s from the value type, so "1+2+3" turns into "123" values = values.Replace("+", ""); // replace pubcount_posM with 123pubcount_posM // replace wghtd_pubcount_pos1 with wghtd_123pubcount_pos1 for (int j = 0; j < BaseColumnNames.Length; j++) { string Column; if (BaseColumnNames[j].Contains("wghtd_")) { Column = BaseColumnNames[j].Replace("wghtd_", "wghtd_" + values); } else { Column = values + BaseColumnNames[j]; } writer.Write("," + Column); } } } writer.WriteLine(); // Write the row for each person People people = new People(DB, PeopleTable); int Total = people.PersonList.Count; int Number = 0; foreach (Person person in people.PersonList) { Number++; StatusCallback(Number, Total, person, false); // Skip the person if the Setnb is in SetnbsToSkip if ((SetnbsToSkip == null) || (!SetnbsToSkip.Contains(person.Setnb))) { // Get the person's publications. If there are no publications for // the person, this will throw an error. Publications pubs; try { pubs = new Publications(DB, person, PeoplePublicationsTable, false); } catch (Exception ex) { MessageCallback(ex.Message); pubs = null; } // Sort the list of publications if (pubs != null) { PublicationComparer Comparer = new PublicationComparer(); Comparer.DB = DB; Comparer.person = person; Comparer.publicationTypes = PubTypes; Array.Sort(pubs.PublicationList, Comparer); // Find the minimum and maximum years int YearMinimum = pubs.PublicationList[0].Year; int YearMaximum = pubs.PublicationList[0].Year; if (pubs.PublicationList != null) { foreach (Publication pub in pubs.PublicationList) { if (pub.Year < YearMinimum) { YearMinimum = pub.Year; } if (pub.Year > YearMaximum) { YearMaximum = pub.Year; } } } // Write each row for (int Year = YearMinimum; Year <= YearMaximum; Year++) { StatusCallback(Year - YearMinimum, YearMaximum - YearMinimum, person, true); writer.WriteLine(ReportRow(person, pubs, Year)); } } } else { MessageCallback("Skipping " + person.Last + " (" + person.Setnb + ")"); } } }