コード例 #1
0
ファイル: CCRecordSetTests.cs プロジェクト: natesternberg/C3
        public void TestRecordSetFromBank()
        {
            var    recordReader = new CsvRecordReader("USBank");
            Stream s            = TestUtils.RetrieveResource(testResource1);
            var    oldRecords   = recordReader.ReadFromStream(s, this.config);

            CCRecordSet recordSet   = new CCRecordSet(oldRecords, config);
            int         creditCount = oldRecords.Count(x => x.Amount < 0);

            Assert.AreEqual(creditCount, 1);
            try
            {
                recordSet.SerializeToFile(serializationOutput);
                Assert.IsTrue(File.Exists(serializationOutput));
                CCRecordSet newRecordSet = CCRecordSet.FromFile(serializationOutput, config);
                CollectionAssert.AreEquivalent(recordSet.ToList(), newRecordSet.ToList());
            }
            finally
            {
                if (File.Exists(serializationOutput))
                {
                    File.Delete(serializationOutput);
                }
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            config = C3Configuration.LoadFromConfigurationManager();
            var options = new Options();

            if (CommandLine.Parser.Default.ParseArguments(args, options))
            {
                if (options.Command == CommandType.IMPORT)
                {
                    IRecordReader bankRecordReader = null;
                    try
                    {
                        bankRecordReader = new CsvRecordReader(options.BankType);
                    }
                    catch (ApplicationException e)
                    {
                        Console.WriteLine($"Unable to create '{options.BankType}' record reader:\n{e.Message}");
                        Environment.Exit(-1);
                    }
                    if (!File.Exists(options.BaseFile))
                    {
                        Console.WriteLine("Base file {0} does not exist.", options.BaseFile);
                    }
                    else if (!File.Exists(options.InputFile))
                    {
                        Console.WriteLine("Input file {0} does not exist.", options.BaseFile);
                    }
                    else
                    {
                        try
                        {
                            Updater.ClassifyAndUpdate(options.BaseFile, options.InputFile, bankRecordReader, config);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Update failed: {0}", e.Message);
                        }
                    }
                }
                if (options.Command == CommandType.VIEW)
                {
                    if (options.BaseFile == null)
                    {
                        Console.WriteLine("Base file must be specified.");
                        return;
                    }
                    if (!File.Exists(options.BaseFile))
                    {
                        Console.WriteLine($"Failed to open specified base file {options.BaseFile}");
                        return;
                    }
                    CCRecordSet records = CCRecordSet.FromFile(options.BaseFile, config);
                    new Application().Run(new C3Window(records, options.BaseFile, config));
                }
            }
        }
コード例 #3
0
        public void WeirdColumnTest()
        {
            Stream      weirdStream = TestUtils.RetrieveResource(weirdColumnResource);
            var         weirdConfig = GetWeirdConfig();
            CCRecordSet recordSet   = CCRecordSet.FromStream(weirdStream, weirdConfig);
            var         nbc         = ClassifierFactory.GetClassifierByName <string>("NaiveBayesClassifier");

            nbc.Train(recordSet.Select(rec => new KeyValuePair <string, string>(rec.Description, rec.PredictedValues["Fish"])).ToList());
            Assert.AreEqual(nbc.Categorize("Seattle Lounge").Category, "Trout");
        }
コード例 #4
0
ファイル: CCRecordSetTests.cs プロジェクト: natesternberg/C3
        public void TestRecordSetFromCsv()
        {
            Stream      s         = TestUtils.RetrieveResource(fullChargeList);
            CCRecordSet recordSet = CCRecordSet.FromStream(s, config);

            recordSet.SerializeToFile(serializationOutput);
            Assert.IsTrue(File.Exists(serializationOutput));
            CCRecordSet newRecordSet = CCRecordSet.FromFile(serializationOutput, config);

            CollectionAssert.AreEquivalent(recordSet.ToList(), newRecordSet.ToList());
        }
コード例 #5
0
        public C3Window(CCRecordSet ccRecordSet, string recordSetFileName, C3Configuration config)
            : this()
        {
            this.ccRecordSet          = ccRecordSet;
            this.recordSetFileName    = recordSetFileName;
            this.config               = config;
            this.editDateTimeRange    = Selectors.timeFilters[Consts.TIMEEXPR_LASTMONTH];
            this.summaryDateTimeRange = Selectors.timeFilters[Consts.TIMEEXPR_LASTMONTH];

            this.requiredHeaderNames = new HashSet <string>(this.ccRecordSet.RequiredHeaderNames);
            currentDataTable         = ccRecordSet.ToDataTable();

            UpdateEditDataGrid();

            foreach (var header in this.ccRecordSet.RequiredHeaderNames)
            {
                var col = new DataGridTextColumn
                {
                    Header  = header,
                    Binding = new Binding(header)
                    {
                        StringFormat = columnFormats[header]
                    },
                    IsReadOnly = true
                };
                EditTabDatagrid.Columns.Add(col);
            }
            foreach (var header in config.columns)
            {
                var col = new DataGridComboBoxColumn
                {
                    Header               = header.columnName,
                    ItemsSource          = header.validValues,
                    SelectedValueBinding = new Binding(header.columnName)
                };
                EditTabDatagrid.Columns.Add(col);
            }

            EditTimeFilterComboBox.ItemsSource  = Selectors.timeFilters.Keys;
            EditTimeFilterComboBox.SelectedItem = Selectors.timeFilters.Keys.FirstOrDefault();

            SummaryTimeFilterComboBox.ItemsSource  = Selectors.timeFilters.Keys;
            SummaryTimeFilterComboBox.SelectedItem = Selectors.timeFilters.Keys.FirstOrDefault();
            SummaryAggregateComboBox.ItemsSource   = this.ccRecordSet.PredictedHeaderNames;
            SummaryAggregateComboBox.SelectedItem  = this.ccRecordSet.PredictedHeaderNames.FirstOrDefault();

            ReportGroupByComboBox.ItemsSource      = this.ccRecordSet.PredictedHeaderNames;
            ReportGroupByComboBox.SelectedIndex    = 0;
            ReportPeriodComboBox.ItemsSource       = Selectors.periodSpecifiers.Keys;
            ReportPeriodComboBox.SelectedItem      = Consts.PERIOD_SPECIFIER_MONTH;
            ReportAggregationComboBox.ItemsSource  = Selectors.aggreations.Keys;
            ReportAggregationComboBox.SelectedItem = Consts.AGGREGATION_SUM;
        }
コード例 #6
0
 private void btnSave_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         CCRecordSet.FromDataTable(this.currentDataTable, config)
         .SerializeToFile(this.recordSetFileName);
     }
     catch (IOException ex)
     {
         MessageBox.Show($"Couldn't save file: {ex.Message}");
     }
 }
コード例 #7
0
        public void DuplicateDetectionTest()
        {
            var         recordReader    = new CsvRecordReader("USBank");
            Stream      stream          = TestUtils.RetrieveResource(fullChargeList);
            CCRecordSet recordSet       = CCRecordSet.FromStream(stream, config);
            var         duplicateRecord = new List <CCRecord>()
            {
                recordSet.ToArray()[0]
            };

            Updater.ClassifyAndUpdate(recordSet, duplicateRecord, recordReader, config);
        }
コード例 #8
0
ファイル: TransformTests.cs プロジェクト: natesternberg/C3
        public void TestGrouping()
        {
            Stream      s                = TestUtils.RetrieveResource(fullChargeList);
            CCRecordSet recordSet        = CCRecordSet.FromStream(s, config);
            var         periodSpec       = Selectors.periodSpecifiers[Consts.PERIOD_SPECIFIER_MONTH];
            var         aggregation      = Selectors.aggreations[Consts.AGGREGATION_AVG];
            var         predictedColumns = TestUtils.GetMockC3PredictedColumns();
            var         report           = Transforms.GetPeriodSummary(recordSet.ToDataTable(), periodSpec, predictedColumns[0], aggregation);

            var expectedHeaders = new DateTime[] { DateTime.Parse("1/1/2004 12:00:00 AM"), DateTime.Parse("2/1/2004 12:00:00 AM"), DateTime.Parse("3/1/2004 12:00:00 AM"), DateTime.Parse("4/1/2004 12:00:00 AM") };
            var actualHeaders   = report.AsEnumerable().Select(row => row["Period start"]).Cast <DateTime>().ToArray();

            CollectionAssert.AreEqual(expectedHeaders, actualHeaders);
            TestUtils.AssertApproximatelyEqual((decimal)report.Rows[0][1], 65.73384615m);
            TestUtils.AssertApproximatelyEqual((decimal)report.Rows[1][2], 44.94272727m);
            TestUtils.AssertApproximatelyEqual((decimal)report.Rows[2][3], 32.17625m);
            TestUtils.AssertApproximatelyEqual((decimal)report.Rows[3][4], 111.4819697m);
        }
コード例 #9
0
        public void NaiveBayesClassificationIntegrationTest()
        {
            Stream      oldRecordsStream = TestUtils.RetrieveResource(fullChargeList);
            CCRecordSet records          = CCRecordSet.FromStream(oldRecordsStream, config);
            var         nbc          = ClassifierFactory.GetClassifierByName <string>("NaiveBayesClassifier");
            var         trainingData = records
                                       .Select(rec => new KeyValuePair <string, string>(rec.Description, rec.PredictedValues["Category"]))
                                       .ToList();

            nbc.Train(trainingData);
            Assert.AreEqual(nbc.Categorize("Trader Joe's").Category, "GROC");
            Assert.AreEqual(nbc.Categorize("Shell Oil 27440482209 Seattle Wa").Category, "TRANS");

            trainingData = records
                           .Select(rec => new KeyValuePair <string, string>(rec.Description, rec.PredictedValues["Owner"]))
                           .ToList();
            nbc = ClassifierFactory.GetClassifierByName <string>("NaiveBayesClassifier");
            nbc.Train(trainingData);
            Assert.AreEqual(nbc.Categorize("Radio Shack 00133652 Knoxville").Category, "Bob");
        }
コード例 #10
0
ファイル: CCRecordSetTests.cs プロジェクト: natesternberg/C3
 public void TestRecordSetWithInvalidValues()
 {
     Stream      s         = TestUtils.RetrieveResource(invalidValueResource);
     CCRecordSet recordSet = CCRecordSet.FromStream(s, config);
 }