Ejemplo n.º 1
0
        public void AddUser(Users user)
        {
            SqliteCommand addUser = db.CreateCommand();
            addUser.CommandText = "INSERT INTO User VALUES(\""
                + user.Name + "\", "
                + user.MailingListMessages + ", "
                + user.BugsClosed
                + ")";
            addUser.ExecuteNonQuery();

            int id = GetID("User", "UserName=\"" + user.Name + "\"");
            foreach (Projects project in user.projects)
            {
                AddProject(project, id);
            }
            foreach (string email in user.email)
            {
                AddEmail(email, id);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sorts users by number of commits.
        /// </summary>
        /// <returns>
        /// Sorted array of Users <see cref="User[]"/>
        /// </returns>
        internal Users[] UserRanks()
        {
            int STOP = users.Count - 1;
            Users[] ranks = new Users[users.Count];

            for (int i = 0; i <= STOP; i++)
            {
                int score = 0;
                Users highRanking = null;
                foreach (Users user in users)
                {
                    if (user.Score() >= score)
                    {
                        score = user.Score();
                        highRanking = user;
                    }
                }
                ranks[i] = highRanking;
                users.Remove(highRanking);
            }
            return ranks;
        }
Ejemplo n.º 3
0
Archivo: HtmlOut.cs Proyecto: mono/rank
 private static string ReplaceKeywords(string html, Users user, int rank)
 {
     Gravatar img = new Gravatar(user.email[0], Gravatar.IconSets.identicon, Gravatar.Ratings.g, 50);
     string gravatar = img.GravatarURL();
     return html.Replace("<!-- rank -->", rank.ToString())
         .Replace("<!-- name -->", user.Name)
         .Replace("<!-- code -->", user.CodeAdded().ToString())
         .Replace("<!-- email -->", user.email[0])
         .Replace("<!-- Gravatar -->", gravatar)
         .Replace("<!-- Image -->", ReplaceImageName(user))
         .Replace("<!-- score -->", user.Score().ToString())
         .Replace("<!-- commits -->", user.CommitCount().ToString());
 }
Ejemplo n.º 4
0
Archivo: HtmlOut.cs Proyecto: mono/rank
        private static string ReplaceImageName(Users user)
        {
            int GROVE = 50000;
            int TREE = 5000;
            int CRATE = 500;
            int BUNCHES = 50;
            int BUNCH = 0;
            int PEEL = 0;

            if (user.Score() > GROVE)
            {
                return "grove.png";
            }
            else if (user.Score() > TREE)
            {
                return "banana_tree.png";
            }
            else if (user.Score() > CRATE)
            {
                return "crate.png";
            }
            else if (user.Score() > BUNCHES)
            {
                return "banana_bunches.png";
            }
            else if (user.Score() > BUNCH)
            {
                return "3_bananas.png";
            }
            else if (user.Score() == PEEL)
            {
                return "peel.png";
            }

            return "";
        }
Ejemplo n.º 5
0
Archivo: HtmlOut.cs Proyecto: mono/rank
        /// <summary>
        /// Creates an html instance of a user.
        /// </summary>
        /// <param name="name">
        /// User's name <see cref="System.String"/>
        /// </param>
        /// <param name="email">
        /// User's e-mail address <see cref="System.String"/>
        /// </param>
        /// <param name="rank">
        /// User's rank <see cref="System.Int32"/>
        /// </param>
        /// <param name="code">
        /// User's contributed lines of code <see cref="System.Int32"/>
        /// </param>
        /// <returns>
        /// The html string representing the user <see cref="System.String"/>
        /// </returns>
        internal static string UserRank(Users user, int rank)
        {
            string data = ReplaceKeywords(userHeader, user, rank);
            foreach (Projects proj in user.projects)
            {
                data += ReplaceKeywords(projData, user, rank)
                    .Replace("<!-- Project -->", proj.name)
                    .Replace("<!-- projCode -->", "+" + proj.CodeAdded.ToString() + " -" + proj.CodeRemoved.ToString())
                    .Replace("<!-- BluePercent -->", proj.BluePercent().ToString());
            }

            for (int i = 0; i < (4 - user.projects.Count); i++)
            {
                data += "<td></td>";
            }

            data += ReplaceKeywords(userFooter, user, rank);
            return data;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Parses the messages from bugzilla and inserts the data into the user list.
        /// </summary>
        /// <param name="start_date">
        /// The date to begin using data<see cref="DateTime"/>
        /// </param>
        private void GetBugzillaData(DateTime start_date)
        {
            string listLocation = homePath + "/mail/.inboxes/bugzilla";
            StreamReader read = File.OpenText(listLocation);

            List<Users> users = new List<Users>();
            Users user = new Users();
            users.Add(user);
            while (!read.EndOfStream)
            {
                string line = read.ReadLine();
                if (line.Contains("_______________________________________________"))
                {
                    user = new Users();
                    users.Add(user);
                }
                else if (line.Contains("From ") && line.Contains("@lists.ximian.com"))
                {
                    string date = line.Substring(line.IndexOf(' ', 5)).Trim();
                    string[] splitDate = date.Split(' ');
                    date = splitDate[1] + " " + splitDate[2] + " " + splitDate[4];
                    try
                    {
                        if (DateTime.Parse(date) < start_date)
                        {
                            users.Remove(user);
                        }
                    }
                    catch(Exception e){Console.WriteLine(e.Message);}
                }
                else if (line.Contains("https://bugzilla.novell.com/show_bug.cgi?id="))
                {
                    string bugID = line.Replace("https://bugzilla.novell.com/show_bug.cgi?id=", "");
                    string[] bugIDParse = bugID.Split('#');
                    user.BugsWorked(bugIDParse[0]);
                }
                else if (line.Contains("Status|"))
                {
                    string status = line.Split('|')[2];
                    if (status == "RESOLVED")
                    {
                        user.BugsClosed++;
                    }
                }
                else if (line.Contains(" changed:"))
                {
                    try
                    {
                        string name = line.Substring(0, line.IndexOf('<'));
                        user.Name = name;
                        string email = line.Split('<')[1];
                        email = email.Substring(0, email.IndexOf('>'));
                        user.email.Add(email);
                    }
                    catch(Exception e){Console.WriteLine(e.Message);}
                }
                else if (line.Contains("--- Comment #"))
                {
                    try
                    {
                        string name = line.Remove(0, line.IndexOf("from") + 5);
                        name = name.Substring(0, name.IndexOf('<')).Trim();
                        user.Name = name;
                        string email = line.Split('<')[1];
                        email = email.Substring(0, email.IndexOf('>'));
                        user.email.Add(email);
                    }
                    catch(Exception e){Console.WriteLine(e.Message);}
                }
            }
            read.Close();

            StreamWriter empty = new StreamWriter(listLocation);
            empty.Write("");
            empty.Close();

            foreach (Users user2 in users)
            {
                if (user2.email.Count != 0)
                {
                    if (UserExists(user2.email[0], user2.Name))
                    {
                        user = GetUser(user2.email[0]);
                        user.BugsClosed += user2.BugsClosed;
                        foreach (string bug in user2.BugsWorked())
                        {
                            user.BugsWorked(bug);
                        }
                    }
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Encapsulates git data in an object.
        /// </summary>
        /// <param name="data">
        /// git data<see cref="System.String"/>
        /// </param>
        private void ParseGitData(string data, string project)
        {
            //user[0] is the commit #, user[1] is the name, and user[2] is email.
            char[] chars = new char[2];
            chars[0] = '\r';
            chars[1] = '\n';
            string[] sdata = data.Split(chars);
            Users previousUser = new Users();
            bool newcommit = false;

            foreach (string line in sdata)
            {
                if (line.Contains("files changed"))
                {
                    if (newcommit)
                    {
                        string[] changes = line.Split(',');
                        int added = int.Parse(changes[1].Trim().Split(' ')[0]);
                        int removed = int.Parse(changes[2].Trim().Split(' ')[0]);
                        previousUser.CodeAdded(added, project);
                        previousUser.CodeRemoved(removed, project);
                        if (added > removed)
                        {
                            previousUser.CodeCurved(added - removed, project);
                        }
                        else if (removed > added)
                        {
                            previousUser.CodeCurved(removed - added, project);
                        }
                    }
                }
                else if (line.Trim() != "")
                {
                    string[] user = line.Split(';');
                    if (UserExists(user[2], user[1]))
                    {
                        previousUser = GetUser(user[2]);
                        newcommit = previousUser.AddCommit(user[0], project);
                    }
                    else
                    {
                        Users aUser = new Users(user[2], user[1]);
                        users.Add(aUser);
                        newcommit = aUser.AddCommit(user[0], project);
                        previousUser = aUser;
                    }
                }
            }
        }
Ejemplo n.º 8
0
        private void MergeUsers(Users first, Users second)
        {
            if (second.Name.Split(' ').Length > 1)
            {
                first.Name = second.Name;
            }

            first.BugsClosed += second.BugsClosed;
            first.MailingListMessages += second.MailingListMessages;

            foreach (Projects secondproject in second.projects)
            {
                bool found = false;
                foreach (Projects firstproject in first.projects)
                {
                    if (firstproject.name == secondproject.name)
                    {
                        found = true;
                        firstproject.CodeAdded += secondproject.CodeAdded;
                        firstproject.CodeCurved += secondproject.CodeCurved;
                        firstproject.CodeRemoved += secondproject.CodeRemoved;
                        foreach (string commit in secondproject.commits)
                        {
                            firstproject.commits.Add(commit);
                        }
                    }
                }
                if (!found)
                {
                    Projects project = new Projects(secondproject.name);
                    first.projects.Add(project);
                    project.CodeAdded = secondproject.CodeAdded;
                    project.CodeCurved = secondproject.CodeCurved;
                    project.CodeRemoved = secondproject.CodeRemoved;
                    foreach (string commit in secondproject.commits)
                    {
                        project.commits.Add(commit);
                    }
                }
            }
            users.Remove(second);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Retreives contribution data from the mailing lists.
        /// </summary>
        private void GetMailingListData(DateTime start_date)
        {
            string listLocation = homePath + "/mail/.inboxes/monolists";
            StreamReader read = File.OpenText(listLocation);

            DateTime dtDate = new DateTime();

            while (!read.EndOfStream)
            {
                string line = read.ReadLine();
                if (line.Contains("Date: "))
                {
                    try
                    {
                        string date = line.Replace("Date: ", "").Substring(5, 11);
                        dtDate = DateTime.Parse(date);
                    }
                    catch(Exception e){Console.WriteLine(e.Message);}
                }
                else if (line.Contains("From: "))
                {
                    try
                    {
                        if (dtDate > start_date)
                        {
                            string nameEmailLine = line.Replace("From: ", "");
                            string name = nameEmailLine.Substring(0, nameEmailLine.IndexOf('<') - 1).Replace("\"", "").Trim();
                            string email = nameEmailLine.Trim().Substring(name.Length, nameEmailLine.Length - name.Length).Replace("<", "").Replace(">", "").Trim();

                            if (name.ToLower().Contains("utf-8"))
                            {
                                name = email.Substring(0, email.IndexOf('@'));
                            }

                            name.Replace(".", " ");

                            if (name.Contains(","))
                            {
                                string[] names = name.Split(',');
                                name = names[1] + " " + names[0];
                                name = name.Trim();
                            }

                            Users user;
                            name = UserName(email, name);
                            if (!UserExists(email, name))
                            {
                                user = new Users(email, name);
                                users.Add(user);
                            }
                            else
                            {
                                user = GetUser(email);
                            }
                            user.MailingListMessages++;
                        }
                    }
                    catch(Exception e){Console.WriteLine(e.Message);}
                }
            }
            read.Close();
            StreamWriter empty = new StreamWriter(listLocation);
            empty.Write("");
            empty.Close();
        }
Ejemplo n.º 10
0
        public List<Users> RetrieveUsers()
        {
            List<Users> users = new List<Users>();
            Users user;

            SqliteCommand retrieveUsers = db.CreateCommand();
            retrieveUsers.CommandText = "SELECT rowid, UserName, MailingListMessage, ResolvedBugs FROM User";
            SqliteDataReader reader = retrieveUsers.ExecuteReader();
            while(reader.Read())
            {
                user = new Users();
                users.Add(user);
                SqliteCommand retrieveEmails = db.CreateCommand();
                retrieveEmails.CommandText = "SELECT Email, UserID FROM Address WHERE UserID=" + reader["rowid"].ToString();
                SqliteDataReader addressReader = retrieveEmails.ExecuteReader();
                while(addressReader.Read())
                {
                    user.email.Add(addressReader["Email"].ToString());
                }
                user.Name = reader["UserName"].ToString();
                user.MailingListMessages = int.Parse(reader["MailingListMessage"].ToString());
                user.BugsClosed = int.Parse(reader["ResolvedBugs"].ToString());

                SqliteCommand retrieveProjects = db.CreateCommand();
                retrieveProjects.CommandText = "SELECT rowid, ProjName, CodeCurved, CodeAdded, CodeRemoved, UserID FROM Project WHERE UserID=" + reader["rowid"].ToString();
                SqliteDataReader projectReader = retrieveProjects.ExecuteReader();
                while(projectReader.Read())
                {
                    Projects project = new Projects(projectReader["ProjName"].ToString());
                    user.projects.Add(project);
                    project.CodeCurved = int.Parse(projectReader["CodeCurved"].ToString());
                    project.CodeAdded = int.Parse(projectReader["CodeAdded"].ToString());
                    project.CodeRemoved = int.Parse(projectReader["CodeRemoved"].ToString());

                    SqliteCommand retrieveData = db.CreateCommand();
                    retrieveData.CommandText = "SELECT * FROM Data WHERE ProjID=" + projectReader["rowid"].ToString();
                    SqliteDataReader dataReader = retrieveData.ExecuteReader();
                    while(dataReader.Read())
                    {
                        project.commits.Add(dataReader["CommitID"].ToString());
                    }
                }
            }

            return users;
        }