Example #1
0
        /// <summary>
        /// Pop up the Harvesting Reports dialog box
        /// </summary>
        private void GenerateReports_Click(object sender, EventArgs e)
        {
            if (DSN.Text == "")
            {
                MessageBox.Show("Please specify a valid ODBC data source that points to a MySQL 5.5 server", "Unable to Initialize Database", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            ReportsDialog reportsDialog = new ReportsDialog();

            reportsDialog.DB       = new Database(DSN.Text);
            reportsDialog.MainForm = this;
            this.Enabled           = false;
            reportsDialog.ShowDialog(this);
            this.Enabled = true;
        }
        /// <summary>
        /// Generate the Star Colleagues report
        /// </summary>
        public static void Generate(TextWriter writer, Database DB, string JournalWeightsFilename, ArrayList SetnbsToSkip, ReportsDialog ParentForm, bool WriteHeaderRow)
        {
            Reports reports = new Reports(DB, JournalWeightsFilename);

            if (WriteHeaderRow)
            {
                WriteHeaderRowToReport(writer);
            }

            // Retrieve all of the star/colleague pairs from the StarColleagues table.
            // The report is generated colleague by colleague (so that it's sorted by
            // the first column -- for the fault tolerance).
            DataTable ColleagueStarPairs = DB.ExecuteQuery("SELECT Setnb, StarSetnb FROM StarColleagues ORDER BY Setnb, StarSetnb");

            if (ColleagueStarPairs.Rows.Count == 0)
            {
                if (ParentForm != null)
                {
                    ParentForm.AddLogEntry("Unable to generate StarColleagues report: No colleagues found!");
                }
                return;
            }

            // Go through the publications and collect the counts.
            Hashtable CountsPerYear  = new Hashtable();
            Hashtable WeightsPerYear = new Hashtable();

            // Create hashtables for the four global counts for each row
            Hashtable Nbcoauth1       = new Hashtable();
            Hashtable Wghtd_Nbcoauth1 = new Hashtable();
            Hashtable Nbcoauth2       = new Hashtable();
            Hashtable Wghtd_Nbcoauth2 = new Hashtable();

            // For each star/colleague pair, produce the report rows.
            // Note that report rows are only produced for years where there
            // are collaborations.
            int Pairs = ColleagueStarPairs.Rows.Count;

            for (int Row = 0; Row < Pairs; Row++)
            {
                string Setnb     = ColleagueStarPairs.Rows[Row]["Setnb"].ToString();
                string StarSetnb = ColleagueStarPairs.Rows[Row]["StarSetnb"].ToString();

                // If this is a continuation of a previous report, SetnbsToSkip will be
                // populated with colleague Setnb values from the rows that were already
                // in the file.
                if (!SetnbsToSkip.Contains(Setnb))
                {
                    // Generate the row for the colleague

                    /*
                     * This query retrieves all of the publications that a star and colleague
                     * have in common. It takes two parameters, the star setnb and the
                     * colleague setnb, and returns all of the data necessary to produce the
                     * Star Colleagues Report rows for that star/colleague pair. It's sorted
                     * by year so that it can be processed efficiently, and so that the first
                     * and last rows in the results can be used to find the years of first and
                     * last collaboration.
                     *
                     * SELECT p.Year, p.PMID, pp.PositionType AS StarPositionType,
                     *        cp.PositionType AS ColleaguePositionType, p.Journal
                     *   FROM Publications p, ColleaguePublications cp, PeoplePublications pp
                     *  WHERE pp.Setnb = ?
                     *    AND cp.Setnb = ?
                     *    AND p.PMID = pp.PMID
                     *    AND p.PMID = cp.PMID
                     *  ORDER BY p.Year ASC
                     *
                     */

                    ArrayList Parameters = new ArrayList();
                    Parameters.Add(Database.Parameter(StarSetnb));
                    Parameters.Add(Database.Parameter(Setnb));
                    using (DataTable PubData =
                               DB.ExecuteQuery(
                                   @"SELECT p.Year, p.PMID, pp.PositionType AS StarPositionType, 
                                 cp.PositionType AS ColleaguePositionType, p.Journal
                            FROM Publications p, ColleaguePublications cp, PeoplePublications pp
                           WHERE pp.Setnb = ?
                             AND cp.Setnb = ?
                             AND p.PMID = pp.PMID
                             AND p.PMID = cp.PMID
                           ORDER BY p.Year ASC", Parameters))
                    {
                        if (PubData.Rows.Count == 0)
                        {
                            if (ParentForm != null)
                            {
                                ParentForm.AddLogEntry("No publications found for colleague " + Setnb + ", star " + StarSetnb);
                            }
                        }
                        else
                        {
                            // Get the first and last years of collaboration
                            int FirstCollabYear = Convert.ToInt32(PubData.Rows[0]["Year"]);
                            int LastCollabYear  = Convert.ToInt32(PubData.Rows[PubData.Rows.Count - 1]["Year"]);

                            // Go through the publications and collect the counts.
                            CountsPerYear.Clear();
                            WeightsPerYear.Clear();

                            // Create hashtables for the four global counts for each row
                            Nbcoauth1.Clear();
                            Wghtd_Nbcoauth1.Clear();
                            Nbcoauth2.Clear();
                            Wghtd_Nbcoauth2.Clear();

                            for (int RowNum = 0; RowNum < PubData.Rows.Count; RowNum++)
                            {
                                // Get the information about the publication from the dataset
                                DataRow PubRow = PubData.Rows[RowNum];
                                UpdateCounts(reports, PubRow, CountsPerYear, WeightsPerYear,
                                             Nbcoauth1, Wghtd_Nbcoauth1, Nbcoauth2, Wghtd_Nbcoauth2);
                            }

                            // Write the rows to the report
                            int RowsWritten = WriteReportrows(Setnb, StarSetnb, FirstCollabYear, LastCollabYear,
                                                              Nbcoauth1, Wghtd_Nbcoauth1, Nbcoauth2, Wghtd_Nbcoauth2,
                                                              writer, CountsPerYear, WeightsPerYear);

                            //ParentForm.AddLogEntry("Wrote " + RowsWritten.ToString() + " rows for colleague " + Setnb + ", star " + StarSetnb + " (" + Row.ToString() + " of " + Pairs.ToString() + ")");
                            if (ParentForm != null)
                            {
                                ParentForm.SetProgressBar(0, Pairs, Row);
                            }
                        }
                    }
                }
            }
        }