示例#1
0
        public void ShowClickbaitDetails(List <string> cbResult)
        {
            TabStats.SelectTab(1);
            dataGridViewClickbait.Rows.Clear();
            zedGraphClickbaitDetails.GraphPane.CurveList.Clear();
            zedGraphClickbaitDetails.GraphPane.GraphObjList.Clear();

            List <double> featureVals    = new List <double>();
            double        clickbaitScore = 0;

            //this for loop is a mess. Had to remove the 3 features listed above because the numbers make the graph look weird
            int j = 0;

            for (int i = 0; i < cbResult.Count; ++i)
            {
                if (i == cbResult.Count - 1)
                {
                    TxtClickbait.Text = cbResult[i];
                    break;
                }

                if (i == 0)
                {
                    clickbaitScore = Convert.ToDouble(cbResult[i]);
                }
                else if (i == 1)
                {
                    continue;
                }
                else
                {
                    dataGridViewClickbait.Rows.Add(clickbaitFeatures[j], cbResult[i]);
                    ++j;
                    featureVals.Add(Convert.ToDouble(cbResult[i]));
                }
            }

            zedGraphClickbaitDetails.GraphPane.BarSettings.Base = BarBase.Y;

            zedGraphClickbaitDetails.GraphPane.YAxis.Scale.TextLabels = clickbaitFeatures;
            zedGraphClickbaitDetails.GraphPane.YAxis.Type             = AxisType.Text;
            zedGraphClickbaitDetails.GraphPane.Title.Text             = "Text on page (colored by clickbait level)";
            zedGraphClickbaitDetails.GraphPane.XAxis.Title            = new AxisLabel("Feature Score", "Consolas", 12, Color.Black, true, false, false);
            zedGraphClickbaitDetails.GraphPane.YAxis.Title            = new AxisLabel("Feature Name", "Consolas", 12, Color.Black, true, false, false);

            zedGraphClickbaitDetails.GraphPane.YAxis.Scale.FontSpec.Size  = 7.0f;
            zedGraphClickbaitDetails.GraphPane.YAxis.Scale.FontSpec.Angle = 90;

            Color clickbaitColor = GetClickbaitScoreColor(clickbaitScore);

            zedGraphClickbaitDetails.GraphPane.AddCurve("AVG. Clickbait Score", AVG_CLICKBAIT_SCORES, null, Color.Red);
            zedGraphClickbaitDetails.GraphPane.AddCurve("AVG. Not Clickbait Score", AVG_NOT_CLICKBAIT_SCORES, null, Color.Green);
            zedGraphClickbaitDetails.GraphPane.AddBar(TxtClickbait.Text, featureVals.ToArray(), null, clickbaitColor);
            zedGraphClickbaitDetails.AxisChange();
            zedGraphClickbaitDetails.Refresh();
        }
示例#2
0
        protected override bool RunInternal(Area ws, Versionr.Status status, IList <Versionr.Status.StatusEntry> targets, FileBaseCommandVerbOptions options)
        {
            BomTabOptions localOptions = options as BomTabOptions;

            try
            {
                List <Versionr.Status.StatusEntry> realTargets = new List <Status.StatusEntry>();
                foreach (var x in targets)
                {
                    if (x.VersionControlRecord != null && !x.IsDirectory && x.FilesystemEntry != null)
                    {
                        realTargets.Add(x);
                    }
                }
                Printer.PrintMessage("Found {0} files for processing...", realTargets.Count);
                TabStats    ts    = new TabStats();
                List <Task> tasks = new List <Task>();
                foreach (var x in realTargets)
                {
                    tasks.Add(GetTaskFactory(options).StartNew(() =>
                    {
                        var newFileType = Versionr.Utilities.FileClassifier.Classify(x.FilesystemEntry.Info);
                        if (newFileType == Versionr.Utilities.FileEncoding.Binary)
                        {
                            return;
                        }
                        ProcessFile(AddTabs, localOptions.Trim, localOptions.TabSize, x, ts);
                    }));
                    if (System.Diagnostics.Debugger.IsAttached)
                    {
                        tasks[tasks.Count - 1].Wait();
                    }
                }
                Task.WaitAll(tasks.ToArray());
                if (ts.Files > 0)
                {
                    if (AddTabs)
                    {
                        Printer.PrintMessage("Updated {0} files and inserted {1} tabs.", ts.Files, ts.Insertions);
                    }
                    else
                    {
                        Printer.PrintMessage("Updated {0} files and inserted {1} spaces.", ts.Files, ts.Insertions * localOptions.TabSize);
                    }
                }
            }
            finally
            {
            }
            return(true);
        }
示例#3
0
        public void ShowFalsificationDetails(List <string> falsResult, string textProcessed)
        {
            TabStats.SelectTab(3);
            dataGridViewFalsification.Rows.Clear();
            zedGraphFalsificationDetails.GraphPane.CurveList.Clear();
            zedGraphFalsificationDetails.GraphPane.GraphObjList.Clear();
            RtbFalsificationText.Text = textProcessed;

            List <double> featureVals        = new List <double>();
            double        FalsificationScore = 0;

            int j = 0;

            for (int i = 0; i < falsResult.Count; ++i)
            {
                if (i == 0)
                {
                    FalsificationScore = Convert.ToDouble(falsResult[i]);
                }
                else if (i == 1)
                {
                    continue;
                }
                else
                {
                    dataGridViewFalsification.Rows.Add(FalsificationFeatures[j], falsResult[i]);
                    ++j;
                    featureVals.Add(Convert.ToDouble(falsResult[i]));
                }
            }

            zedGraphFalsificationDetails.GraphPane.BarSettings.Base = BarBase.Y;

            zedGraphFalsificationDetails.GraphPane.YAxis.Scale.TextLabels = FalsificationFeatures;
            zedGraphFalsificationDetails.GraphPane.YAxis.Type             = AxisType.Text;
            zedGraphFalsificationDetails.GraphPane.Title.Text             = "Text on page (colored by Falsification level)";
            zedGraphFalsificationDetails.GraphPane.XAxis.Title            = new AxisLabel("Feature Score", "Consolas", 12, Color.Black, true, false, false);
            zedGraphFalsificationDetails.GraphPane.YAxis.Title            = new AxisLabel("Feature Name", "Consolas", 12, Color.Black, true, false, false);

            zedGraphFalsificationDetails.GraphPane.YAxis.Scale.FontSpec.Size  = 7.0f;
            zedGraphFalsificationDetails.GraphPane.YAxis.Scale.FontSpec.Angle = 90;

            Color FalsificationColor = GetClickbaitScoreColor(FalsificationScore); //fix me

            zedGraphFalsificationDetails.GraphPane.AddCurve("AVG. Falsification Score", AVG_FALSIFICATION_SCORES, null, Color.Red);
            zedGraphFalsificationDetails.GraphPane.AddCurve("AVG. Legitimate Score", AVG_LEGIT_SCORES, null, Color.Green);
            zedGraphFalsificationDetails.GraphPane.AddBar("Selected Text", featureVals.ToArray(), null, FalsificationColor);
            zedGraphFalsificationDetails.AxisChange();
            zedGraphFalsificationDetails.Refresh();
        }
示例#4
0
        public void ShowSatireDetails(List <string> satResult, string textProcessed)
        {
            TabStats.SelectTab(2);
            dataGridViewSatire.Rows.Clear();
            zedGraphSatireDetails.GraphPane.CurveList.Clear();
            zedGraphSatireDetails.GraphPane.GraphObjList.Clear();
            RtbSatireText.Text = textProcessed;

            List <double> featureVals = new List <double>();
            double        satireScore = 0;

            int j = 0;

            for (int i = 0; i < satResult.Count; ++i)
            {
                if (i == 0)
                {
                    satireScore = Convert.ToDouble(satResult[i]);
                }
                else if (i == 1 || i == 2 || i == 3)
                {
                    continue;
                }
                else
                {
                    dataGridViewSatire.Rows.Add(satireFeatures[j], satResult[i]);
                    ++j;
                    featureVals.Add(Convert.ToDouble(satResult[i]));
                }
            }

            zedGraphSatireDetails.GraphPane.BarSettings.Base = BarBase.Y;

            zedGraphSatireDetails.GraphPane.YAxis.Scale.TextLabels = satireFeatures;
            zedGraphSatireDetails.GraphPane.YAxis.Type             = AxisType.Text;
            zedGraphSatireDetails.GraphPane.Title.Text             = "Text on page (colored by satire level)";
            zedGraphSatireDetails.GraphPane.XAxis.Title            = new AxisLabel("Feature Score", "Consolas", 12, Color.Black, true, false, false);
            zedGraphSatireDetails.GraphPane.YAxis.Title            = new AxisLabel("Feature Name", "Consolas", 12, Color.Black, true, false, false);

            zedGraphSatireDetails.GraphPane.YAxis.Scale.FontSpec.Size  = 7.0f;
            zedGraphSatireDetails.GraphPane.YAxis.Scale.FontSpec.Angle = 90;

            Color satireColor = GetClickbaitScoreColor(satireScore); //fix me

            zedGraphSatireDetails.GraphPane.AddCurve("AVG. Satire Score", AVG_SATIRE_SCORES, null, Color.Red);
            zedGraphSatireDetails.GraphPane.AddCurve("AVG. Not Satire Score", AVG_NOT_SATIRE_SCORES, null, Color.Green);
            zedGraphSatireDetails.GraphPane.AddBar("Selected Text", featureVals.ToArray(), null, satireColor);
            zedGraphSatireDetails.AxisChange();
            zedGraphSatireDetails.Refresh();
        }
示例#5
0
 public void NewTab(string aSessionId, string aTabId, string aUserId, string aAppId)
 {
     var tabKey = Tuple.Create(aSessionId, aTabId);
     lock (iLock)
     {
         if (iIterating) Debugger.Break();
         iTabStats[tabKey] = new TabStats(aAppId, aUserId);
         Broadcast(
             new JsonObject {
                 {"type", "newtab"},
                 {"session", aSessionId},
                 {"tab", aTabId},
                 {"app", aAppId},
                 {"queue", 0},
                 {"reader", false},
                 {"user", aUserId},
                 {"lastread", DateTime.UtcNow.ToString()}
             }, null, null);
     }
 }
示例#6
0
        private void ProcessFile(bool addTabs, bool trim, int tabSize, Status.StatusEntry x, TabStats ts)
        {
            byte[] data = null;
            using (var fs = System.IO.File.OpenRead(x.FilesystemEntry.Info.FullName))
            {
                data = new byte[fs.Length];
                fs.Read(data, 0, data.Length);
            }
            System.IO.MemoryStream ms = new System.IO.MemoryStream(data.Length * 2);
            int  count   = 0;
            bool newline = false;
            bool trimmed = false;

            for (int i = 0; i < data.Length; i++)
            {
                if (data[i] == (byte)'\n')
                {
                    newline = true;
                    ms.WriteByte((byte)'\n');
                }
                else if (data[i] == (byte)'\r')
                {
                    newline = true;
                    ms.WriteByte((byte)'\r');
                }
                else if (data[i] == (byte)' ')
                {
                    if (trim && !newline)
                    {
                        int trimcount = 1;
                        for (int j = i + 1; j < data.Length; j++)
                        {
                            if (data[j] == (byte)'\n' || data[j] == (byte)'\r')
                            {
                                break;
                            }
                            if (data[j] != (byte)' ' && data[j] != (byte)'\t')
                            {
                                trimcount = 0;
                                break;
                            }
                            trimcount++;
                        }
                        if (trimcount != 0)
                        {
                            trimmed = true;
                            i      += trimcount - 1;
                            continue;
                        }
                        else
                        {
                            ms.WriteByte(data[i]);
                            newline = false;
                        }
                    }
                    else if (addTabs && newline)
                    {
                        int span = 1;
                        for (int j = i + 1; j < i + tabSize && j < data.Length; j++)
                        {
                            if (data[j] != (byte)' ')
                            {
                                break;
                            }
                            span++;
                        }
                        if (span == tabSize)
                        {
                            count++;
                            ms.WriteByte((byte)'\t');
                        }
                        else
                        {
                            for (int j = 0; j < span; j++)
                            {
                                ms.WriteByte((byte)' ');
                            }
                        }
                        i += span - 1;
                    }
                    else
                    {
                        ms.WriteByte((byte)' ');
                    }
                }
                else if (data[i] == (byte)'\t')
                {
                    if (trim && !newline)
                    {
                        int trimcount = 1;
                        for (int j = i + 1; j < data.Length; j++)
                        {
                            if (data[j] == (byte)'\n' || data[j] == (byte)'\r')
                            {
                                break;
                            }
                            if (data[j] != (byte)' ' && data[j] != (byte)'\t')
                            {
                                trimcount = 0;
                                break;
                            }
                            trimcount++;
                        }
                        if (trimcount != 0)
                        {
                            trimmed = true;
                            i      += trimcount - 1;
                            continue;
                        }
                        else
                        {
                            ms.WriteByte(data[i]);
                            newline = false;
                        }
                    }
                    else if (!addTabs && newline)
                    {
                        for (int j = 0; j < tabSize; j++)
                        {
                            ms.WriteByte((byte)' ');
                        }
                        count++;
                    }
                    else
                    {
                        ms.WriteByte((byte)'\t');
                    }
                }
                else
                {
                    ms.WriteByte(data[i]);
                    newline = false;
                }
            }
            if (count > 0 || trimmed)
            {
                using (var fs = System.IO.File.Create(x.FilesystemEntry.Info.FullName))
                {
                    data = ms.ToArray();
                    fs.Write(data, 0, data.Length);
                }

                string mods = "";
                if (count > 0)
                {
                    if (addTabs)
                    {
                        mods = string.Format("added #b#{0}## tabs", count);
                    }
                    else
                    {
                        mods = string.Format("added #b#{0}## spaces", count * tabSize);
                    }
                }
                if (trimmed)
                {
                    if (!string.IsNullOrEmpty(mods))
                    {
                        mods += ", ";
                    }
                    mods += "trimmed trailing whitespace";
                }

                Printer.PrintMessage("#s#{0}## - {1}.", x.CanonicalName, mods);

                lock (ts)
                {
                    ts.Files++;
                    ts.Insertions += count;
                }
            }
        }