Пример #1
0
        private void fillListViewStatistics()
        {
            tabControl1.SelectedIndex = 0;

            // Edits
            listViewStatistics.Items[0].SubItems.Add(revisions.Count.ToString());

            statistics.nrOfMinorEdits     = 0;
            statistics.nrOfAnonymousEdits = 0;
            foreach (Revision rev in revisions)
            {
                if (rev.minor)
                {
                    statistics.nrOfMinorEdits++;
                }
                if (rev.anon)
                {
                    statistics.nrOfAnonymousEdits++;
                }
            }
            // Minor Edits
            listViewStatistics.Items[1].SubItems.Add(statistics.nrOfMinorEdits.ToString());
            listViewStatistics.Items[1].SubItems.Add(((int)Math.Round(100 * (double)statistics.nrOfMinorEdits / revisions.Count)).ToString() + " %");

            // Anonymous Edits
            listViewStatistics.Items[2].SubItems.Add(statistics.nrOfAnonymousEdits.ToString());
            listViewStatistics.Items[2].SubItems.Add(((int)Math.Round(100 * (double)statistics.nrOfAnonymousEdits / revisions.Count)).ToString() + " %");

            // Different Users
            listViewStatistics.Items[4].SubItems.Add(users.Count.ToString());

            // Anonymous Users
            listViewStatistics.Items[5].SubItems.Add(statistics.nrOfAnonymousUsers.ToString());
            listViewStatistics.Items[5].SubItems.Add(((int)Math.Round(100 * (double)statistics.nrOfAnonymousUsers / users.Count)).ToString() + " %");

            // Edits per User
            listViewStatistics.Items[6].SubItems.Add(((double)revisions.Count / users.Count).ToString("0.00"));

            statistics.firstEdit = revisions[0].timestamp;
            statistics.lastEdit  = statistics.firstEdit;
            foreach (Revision rev in revisions)
            {
                if (statistics.firstEdit > rev.timestamp)
                {
                    statistics.firstEdit = rev.timestamp;
                }
                if (statistics.lastEdit < rev.timestamp)
                {
                    statistics.lastEdit = rev.timestamp;
                }
            }

            // First Edit
            listViewStatistics.Items[8].SubItems.Add(DateTimeHelpFunctions.DateTimeToString(statistics.firstEdit));
            listViewStatistics.Items[8].SubItems.Add(DateTimeHelpFunctions.DaysAgo(statistics.firstEdit));

            // Last Edit
            listViewStatistics.Items[9].SubItems.Add(DateTimeHelpFunctions.DateTimeToString(statistics.lastEdit));
            listViewStatistics.Items[9].SubItems.Add(DateTimeHelpFunctions.DaysAgo(statistics.lastEdit));
        }
Пример #2
0
        private void prepareListViewUsers()
        {
            if (users == null)
            {
                return;
            }
            List <ListViewItem> items = new List <ListViewItem>();

            foreach (User user in users)
            {
                ListViewItem lvi = new ListViewItem(user.name);
                lvi.UseItemStyleForSubItems = false;
                if (user.anon)
                {
                    lvi.SubItems[0].ForeColor = Color.Blue;
                }

                ListViewItem.ListViewSubItem lvsi = new ListViewItem.ListViewSubItem(lvi, user.nrOfEdits.ToString());
                lvi.SubItems.Add(lvsi);

                lvsi = new ListViewItem.ListViewSubItem(lvi, user.nrOfMinorEdits.ToString());
                lvi.SubItems.Add(lvsi);

                lvsi = new ListViewItem.ListViewSubItem(lvi, ((int)Math.Floor(((double)user.nrOfMinorEdits / user.nrOfEdits) * 100)).ToString() + " %");
                lvi.SubItems.Add(lvsi);

                lvsi = new ListViewItem.ListViewSubItem(lvi, DateTimeHelpFunctions.DateTimeToString(user.firstEdit));
                lvi.SubItems.Add(lvsi);

                lvsi = new ListViewItem.ListViewSubItem(lvi, DateTimeHelpFunctions.DateTimeToString(user.lastEdit));
                if (user.nrOfEdits == 1)
                {
                    lvsi.ForeColor = Color.DarkGray;
                }
                lvi.SubItems.Add(lvsi);

                if (user.percentageOfContentAdded < 0)
                {
                    lvsi           = new ListViewItem.ListViewSubItem(lvi, "?");
                    lvsi.ForeColor = Color.DarkGray;
                }
                else
                {
                    lvsi = new ListViewItem.ListViewSubItem(lvi, ((int)(Math.Round(100 * user.percentageOfContentAdded))).ToString() + " %");
                }
                lvi.SubItems.Add(lvsi);

                if (bwLoadHistory.CancellationPending)
                {
                    return;
                }
                items.Add(lvi);
            }
            this.Invoke(new FillListViewUsersDelegate(fillListViewUsers), new object[] { items });
        }
Пример #3
0
        private void cMenuListViewEditsCopy_Click(object sender, EventArgs e)
        {
            string copy = "";

            foreach (ListViewItem lvi in listViewEdits.SelectedItems)
            {
                Revision rev     = (Revision)lvi.Tag;
                string   newLine = " ";

                newLine += DateTimeHelpFunctions.DateTimeToString(rev.timestamp) + "  ";
                newLine += rev.user;
                for (int i = 0; i < 30 - rev.user.Length; i++)
                {
                    newLine += " ";
                }
                newLine += rev.comment;

                copy += newLine + Environment.NewLine;
            }


            Clipboard.SetText(copy);
        }
Пример #4
0
        private void bwAuthors_DoWork(object sender, DoWorkEventArgs e)
        {
            Revision rev = revisions[revisionNumber];

            if (!rev.fullTextLoaded)
            {
                this.Invoke(new ShowProgressDelegate(showProgress), new object[] { "Загрузка текущего текста статьи (" + DateTimeHelpFunctions.DateTimeToString(rev.timestamp) + ")", -1 });
                rev.LoadFullText();
            }
            thisArticleText = new ArticleText(rev.fullText);
            int revtow = 0, totalsize = 0, ls = 0, f2size = 0;

            if (revisionNumber >= 10)
            {
                // now check every revision
                totalsize = 0; ls = 0;
                for (int i = 0; i < revisionNumber; i++)
                {
                    totalsize += Math.Abs((revisions[i].size) - ls);
                    ls         = revisions[i].size;
                }
                revtow = revisionNumber / 10;
                if (revtow > 10)
                {
                    revtow = 10;
                }
                if (revtow < 4)
                {
                    revtow = 4;
                }
                //MessageBox.Show(revtow+"");
                for (int i = 0; i < revtow; i++)
                {
                    f2size += Math.Abs((revisions[i].size) - ls);
                    ls      = revisions[i].size;
                }
                //f2size = revisions[0].size + Math.Abs(revisions[1].size - revisions[0].size) + Math.Abs(revisions[2].size - revisions[1].size) + Math.Abs(revisions[3].size - revisions[2].size);
            }
            else
            {
                revtow = -1;
            }
            int wss = 0;

            // Selecting ids

            //Loading them
            String rvstartid = "";
            int    rvl       = 75;

            int already = 0;

againss:

            WebClient client1 = new WebClient();
            XmlDocument xmlDoc = new XmlDocument();

            SendProgressMessage2("Загрузка версий .. " + already + "/" + revisionNumber, already / revisionNumber);

            if (already + rvl > revisionNumber)
            {
                rvl = revisionNumber - already + 1;
            }
            String rvlimit = "" + rvl;

            already += rvl;
            String url = Projects.currentProjectBaseUrl + "api.php?format=xml&action=query&prop=revisions&rvlimit=" + rvlimit + "&rvdir=newer&titles=" + Uri.EscapeDataString(Revision.currentTitle) + "&rvprop=content|ids&" + rvstartid;

            if (bwAuthors.CancellationPending)
            {
                this.Invoke(new ShowProgressDelegate(showProgress), new object[] { "Analyzing authors canceled", -1 });
                return;
            }
            while (bwAuthors.Paused)
            {
                Thread.Sleep(100);
            }

            // String url = "http://toolserver.org/~haffman/wikihistory/grv.php?rvlist="+ldrv;
            client1.Encoding = Encoding.UTF8;
            client1.Headers.Add("User-Agent", "WikiHistory (http://de.wikipedia.org/wiki/Benutzer:APPER/WikiHistory) [he]");
            client1.Headers["Accept-Encoding"] = "gzip";

            //MessageBox.Show(client1.DownloadString(url));
tryg:
            try
            {
                System.IO.StreamReader webReader;
                webReader = new System.IO.StreamReader(client1.OpenRead(url));
                string sResponseHeader = client1.ResponseHeaders["Content-Encoding"];
                String data            = "";
                if (!string.IsNullOrEmpty(sResponseHeader))
                {
                    if (sResponseHeader.ToLower().Contains("gzip"))
                    {
                        byte[] b = DecompressGzip(webReader.BaseStream);

                        data = System.Text.Encoding.GetEncoding(client1.Encoding.CodePage).GetString(b);
                    }

                    else if (sResponseHeader.ToLower().Contains("deflate"))
                    {
                        byte[] b = DecompressDeflate(webReader.BaseStream);

                        data = System.Text.Encoding.GetEncoding(client1.Encoding.CodePage).GetString(b);
                    }
                    else
                    {
                        data = webReader.ReadToEnd();
                    }
                }
                else
                {
                    data = webReader.ReadToEnd();
                }
                //MessageBox.Show(data);

                //MessageBox.Show(sResponseHeader);
                // byte[] ba = client1.DownloadData(url);
                //MessageBox.Show(ba.Length + "/" + Cache.Decompress2(ba).Length);
                xmlDoc.LoadXml(data /*Cache.Decompress(*//*client1.DownloadString(url)*//*)*/);
            }
            catch (Exception es) { MessageBox.Show(es.Message); SendProgressMessage("Сбой при загрузке версий.. Очередная попытка ..."); Thread.Sleep(1000); goto tryg; }
            //MessageBox.Show("A");
            XmlNode xmlRevisions = xmlDoc.DocumentElement;
            XmlNode currentNode;

            rvstartid = "";
            XmlNode currentNode2 = xmlRevisions.SelectSingleNode("query-continue");

            if (currentNode2 != null)
            {
                currentNode2 = currentNode2.SelectSingleNode("revisions");
                long cntid = 0;
                try { cntid = Convert.ToInt64(currentNode2.Attributes.GetNamedItem("rvstartid").Value); }
                catch { }
                if (cntid > 0)
                {
                    rvstartid = "" + cntid;
                }
            }


            currentNode = xmlRevisions.SelectSingleNode("query");
            if (currentNode == null)
            {
                return;
            }
            currentNode = currentNode.SelectSingleNode("pages");
            if (currentNode == null)
            {
                return;
            }
            currentNode = currentNode.SelectSingleNode("page");
            if (currentNode == null)
            {
                return;
            }
            if (currentNode.Attributes.GetNamedItem("missing") != null)
            {
                return;
            }
            currentNode = currentNode.SelectSingleNode("revisions");
            if (currentNode == null)
            {
                return;
            }

            foreach (XmlNode xrev in currentNode.SelectNodes("rev"))
            {
                XmlNode attribute;
                long    nowid = 0;
                attribute = xrev.Attributes.GetNamedItem("revid");
                if (attribute == null)
                {
                    continue;
                }
                try { nowid = Convert.ToInt64(attribute.Value); }
                catch { continue; }
                // MessageBox.Show(xrev.InnerText);
                for (int i = 0; i <= revisionNumber; i++)
                {
                    if (revisions[i].id == nowid)
                    {
                        revisions[i].SetFullText(xrev.InnerText);
                        // MessageBox.Show("EBF");
                        break;
                    }
                }
            }
            if (already > revisionNumber)
            {
            }
            else if (rvstartid != "")
            {
                rvstartid = "rvstartid=" + rvstartid; goto againss;
            }

            DateTime tf = DateTime.Now;
            DateTime t1 = DateTime.Now;

            //Loaded

            for (int i = 0; i <= revisionNumber; i++) // < revisions.Count
            {
                if (bwAuthors.CancellationPending)
                {
                    this.Invoke(new ShowProgressDelegate(showProgress), new object[] { "Analyzing authors canceled", -1 });
                    return;
                }
                while (bwAuthors.Paused)
                {
                    Thread.Sleep(100);
                }


                // if the next version is from the same author, this version could be skipped
                if ((i < revisionNumber) && (revisions[i].user == revisions[i + 1].user))
                {
                    continue;
                }


                // get revision full text
                rev = revisions[i];
                int sleepms = 3000;
                int trying  = 1;
again:
                if (!rev.fullTextLoaded)
                {
                    this.Invoke(new ShowProgressDelegate(showProgress), new object[] { (trying > 1 ? "(попытка " + trying : "") + "Загрузка текста для версии " + rev.id.ToString() + " (" + DateTimeHelpFunctions.DateTimeToString(rev.timestamp) + ") .... " + (100 * i / revisionNumber) + "%", (double)i / revisionNumber });
                    rev.LoadFullText();
                }
                if (rev.Deleted)
                {
                    continue;
                }
                if (!rev.fullTextLoaded)
                {
                    Thread.Sleep(sleepms);
                    sleepms *= 2;
                    trying++;
                    goto again;
                }
                if (rev.fullText.Length == 0)
                {
                    continue;
                }                                          //vandal 99.999999%
                //DateTime t3 = DateTime.Now;
                this.Invoke(new ShowProgressDelegate(showProgress), new object[] { "Анализ версии " + rev.id.ToString() + " (" + DateTimeHelpFunctions.DateTimeToString(rev.timestamp) + "; " + rev.size + " байт; " + (i > 0 ? "" + (rev.size - revisions[i - 1].size) + " байт" : "") + ")  .... " + (100 * i / revisionNumber) + "%", (double)i / revisionNumber });
                thisArticleText.MarkNewSections(rev, bwAuthors);
                //DateTime t4 = DateTime.Now;
                //TimeSpan t7 = t4 - t3;
                //MessageBox.Show(i + ": " + (t7.Hours * 3600000 + t7.Minutes * 60000 + t7.Seconds * 1000.0 + t7.Milliseconds));

                var ws = (DateTime.Now - tf).TotalMilliseconds;
                if (ws == 0)
                {
                    continue;
                }

                f2size = 0; ls = 0;
                for (int iq = 0; iq < i; iq++)
                {
                    f2size += Math.Abs((revisions[iq].size) - ls);
                    ls      = revisions[iq].size;
                }
                double ps = f2size / ws;//байт в миллисекунду
                we = DateTime.Now.AddSeconds((totalsize - f2size) * ps / 1000);
                if (i == 0)
                {
                    tf = DateTime.Now.AddSeconds(5); continue;
                }
                //MessageBox.Show(we.Year + "." + we.Month + "." + we.Day + " " + we.Hour + ":" + we.Minute + ":" + we.Second+" (ws="+ws+" ps="+ps+" f2size="+f2size+" totalsize="+totalsize);
                if (i > 2 && wss == 0 && ((totalsize - f2size) * ps / 1000) > 15)
                {
                    new Thread(TimeThread).Start(); wss = 1;
                }
            }
            stopped = 1;
            thisArticleText.ready = true;

            this.Invoke(new ShowProgressDelegate(showProgress), new object[] { "Статья полностью проанализирована...", 1 });

            // prepare user data
            int totalLength = 0;

            foreach (ArticleText.Section s in thisArticleText.sections)
            {
                if (s.revKnown)
                {
                    totalLength += s.Length;
                }
            }
            foreach (User u in users)
            {
                u.lengthOfContentAdded = 0;
                foreach (ArticleText.Section s in thisArticleText.sections)
                {
                    if ((s.revKnown) && (s.rev.user == u.name))
                    {
                        u.lengthOfContentAdded += s.Length;
                    }
                }
                if (thisArticleText.text.Length > 0)
                {
                    u.percentageOfContentAdded = (double)u.lengthOfContentAdded / totalLength;
                }
            }
            prepareListViewUsers();

            List <User> topUsers = new List <User>();
            User        maxUser;

            for (int i = 0; i < 5; i++)
            {
                maxUser = null;
                foreach (User u in users)
                {
                    if ((!topUsers.Contains(u)) && (u.lengthOfContentAdded > 0) && ((maxUser == null) || (u.lengthOfContentAdded > maxUser.lengthOfContentAdded)))
                    {
                        maxUser = u;
                    }
                }
                topUsers.Add(maxUser);
            }

            //this.Invoke(new ShowProgressDelegate(showProgress), new object[] { "", -1 });


            DateTime t2 = DateTime.Now;
            TimeSpan t  = t2 - t1;//(t.Hours*3600000 + t.Minutes*60000 + t.Seconds * 1000.0 + t.Milliseconds)

            this.Invoke(new ShowProgressDelegate(showProgress), new object[] { "Обработка заняла " + t.Hours + " ч " + (t.Minutes % 60) + " мин " + (t.Seconds % 60) + " с " + (t.Milliseconds % 1000) + " мс", -1 });
            this.Invoke(new analyzingEndedDelegate(analyzingEnded));
            this.Invoke(new AuthorsPrepareColoredComboBoxesDelegate(authorsPrepareColoredComboBoxes), new object[] { topUsers });
        }
Пример #5
0
        private void prepareListViewEdits(string user)
        {
            if (revisions == null)
            {
                return;
            }
            List <ListViewItem> items = new List <ListViewItem>();

            foreach (Revision rev in revisions)
            {
                ListViewItem lvi = new ListViewItem(rev.id.ToString());
                lvi.UseItemStyleForSubItems = false;
                lvi.BackColor = rev.displayColor;

                ListViewItem.ListViewSubItem lvsi = new ListViewItem.ListViewSubItem(lvi, rev.user);
                if (rev.anon)
                {
                    lvsi.ForeColor = Color.Blue;
                }
                lvi.SubItems.Add(lvsi);

                if (rev.minor)
                {
                    lvsi = new ListViewItem.ListViewSubItem(lvi, "X");
                }
                else
                {
                    lvsi = new ListViewItem.ListViewSubItem(lvi, "");
                }
                lvi.SubItems.Add(lvsi);

                lvsi = new ListViewItem.ListViewSubItem(lvi, DateTimeHelpFunctions.DateTimeToString(rev.timestamp));
                lvi.SubItems.Add(lvsi);

                if (rev.size >= 0)
                {
                    lvsi = new ListViewItem.ListViewSubItem(lvi, rev.size.ToString());
                    lvi.SubItems.Add(lvsi);
                }
                else
                {
                    lvsi           = new ListViewItem.ListViewSubItem(lvi, "0");
                    lvsi.ForeColor = Color.DarkGray;
                    lvi.SubItems.Add(lvsi);
                }

                lvsi = new ListViewItem.ListViewSubItem(lvi, rev.comment);
                lvi.SubItems.Add(lvsi);

                lvi.Tag = rev;

                if (bwLoadHistory.CancellationPending)
                {
                    return;
                }
                if ((user == "") || (user == rev.user))
                {
                    items.Add(lvi);
                }
                if ((items.Count % 100 == 0) || (items.Count == revisions.Count))
                {
                    this.Invoke(new ShowProgressDelegate(showProgress), new object[] { "Filling List (" + items.Count.ToString() + " revisions)", (double)items.Count / revisions.Count });
                }
            }
            this.Invoke(new FillListViewEditsDelegate(fillListViewEdits), new object[] { items });
            this.Invoke(new ShowProgressDelegate(showProgress), new object[] { "Edit list filled", -1 });
        }
Пример #6
0
        private void bwFindRevision_DoWork(object sender, DoWorkEventArgs e)
        {
            string searchText         = (string)e.Argument;
            bool   caseInsensitive    = checkBoxFindRevisionCaseInsensitive.Checked;
            bool   found              = false;
            int    nrOfRevisionsFound = 0;

            if (caseInsensitive)
            {
                searchText = searchText.ToLowerInvariant();
            }

            Regex        r;
            RegexOptions rOptions = RegexOptions.None;

            if (caseInsensitive)
            {
                rOptions |= RegexOptions.IgnoreCase;
            }
            if (checkBoxFindRevisionRegEx.Checked)
            {
                r = new Regex(searchText, rOptions);
            }
            else
            {
                r = new Regex(Regex.Escape(searchText), rOptions);
            }

            this.Invoke(new ShowProgressDelegate(showProgress), new object[] { "Поиск...", -1 });

            for (int i = 0; i < revisions.Count; i++)
            {
                if (!revisions[i].selected)
                {
                    continue;
                }

                if (bwFindRevision.CancellationPending)
                {
                    this.Invoke(new ShowProgressDelegate(showProgress), new object[] { "Поиск отменен", -1 });
                    return;
                }

                if (!revisions[i].fullTextLoaded)
                {
                    this.Invoke(new ShowProgressDelegate(showProgress), new object[] { "Loading text for revision " + revisions[i].id.ToString() + " (" + DateTimeHelpFunctions.DateTimeToString(revisions[i].timestamp) + ")", (double)i / revisions.Count });
                    revisions[i].LoadFullText();
                }

                found = r.IsMatch(revisions[i].fullText);
                if (found)
                {
                    nrOfRevisionsFound++;
                }
                this.Invoke(new ShowRevisionStateDelegate(showRevisionState), new object[] { revisions[i], found });

                if ((found) && (checkBoxFindRevisionOnlyOldest.Checked))
                {
                    // found!
                    this.Invoke(new FindRevisionSuccessDelegate(findRevisionSuccess), new object[] { revisions[i] });
                    this.Invoke(new ShowProgressDelegate(showProgress), new object[] { "Текст найден", -1 });
                    MessageBox.Show("Первое совпадение в версии " + revisions[i].id.ToString() + ".");
                    this.Invoke(new ShowProgressDelegate(showProgress), new object[] { "", -1 });
                    return;
                }
            }

            if (nrOfRevisionsFound > 0)
            {
                this.Invoke(new ShowProgressDelegate(showProgress), new object[] { "Text found", -1 });
                MessageBox.Show("The searched text was found in " + nrOfRevisionsFound.ToString() + " revisions.");
                this.Invoke(new ShowProgressDelegate(showProgress), new object[] { "", -1 });
                this.Invoke(new FindRevisionEndedDelegate(findRevisionEnded));
            }
            else
            {
                this.Invoke(new ShowProgressDelegate(showProgress), new object[] { "Text not found", -1 });
                MessageBox.Show("The searched text wasn't found in any revision.");
                this.Invoke(new ShowProgressDelegate(showProgress), new object[] { "", -1 });
                this.Invoke(new FindRevisionEndedDelegate(findRevisionEnded));
            }
        }