public async Task <ContentResult> Get()
        {
            var result = await _hubService.SampleHubData("28851-396", 10);

            var formattedResult = DataConverter.Convert(result);
            var classification  = _classificationService.Classify(formattedResult);
            var output          = (Locations)classification;

            return(base.Content(output.ToString(), "text/html", Encoding.UTF8));
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            string json     = File.ReadAllText("importSettings.json");
            var    settings = JsonConvert.DeserializeObject <ImportSettings>(json);

            decimal total = 0;

            foreach (var file in settings.Files)
            {
                System.Console.WriteLine($"File {file}");
                System.Console.WriteLine("--------------------------------------------");
                using (var stream = File.OpenRead(file))
                {
                    IImportService importService = new ImportService();
                    var            result        = importService.Import(stream, "csv", "ANZ");

                    IClassificationService classificationService = new ClassificationService();
                    classificationService.Classify(result.Transactions, settings.Categories, settings.Tags);

                    decimal subtotal = 0;
                    foreach (var t in result.Transactions.Where(t => t.Category != null || t.Tags.Any()))
                    {
                        System.Console.WriteLine($"{t.Date.ToString("dd/MM/yyyy")}\t${t.Amount.ToString()}\t{t.Description}");
                        System.Console.WriteLine($"\tCategory: { t.Category?.Name ?? "No category" }");

                        if (t.Tags.Any())
                        {
                            System.Console.WriteLine($"\tTags: {t.Tags?.Select(x => x.Name).Aggregate((a, b) => $"{a}, {b}") ?? "No tags"}");
                        }
                        else
                        {
                            System.Console.WriteLine("\tTags: No tags");
                        }

                        subtotal += t.Amount;
                    }

                    total += subtotal;

                    System.Console.WriteLine("-------------------");
                    System.Console.WriteLine("Total: ${0}", subtotal);
                    System.Console.WriteLine();
                }
            }

            System.Console.WriteLine("Full total: ${0}", total);

            if (System.Diagnostics.Debugger.IsAttached)
            {
                System.Console.WriteLine("Press any key to continue...");
                System.Console.ReadLine();
            }
        }
        public void Test()
        {
            var transactions = new List <Transaction>();

            transactions.Add(new Transaction(new DateTime(2017, 4, 7), 7777.77m, "PAY/SALARY FROM SUPERIOR SOFTWAR FORTNIGHTLY SALARY"));
            transactions.Add(new Transaction(new DateTime(2017, 4, 5), -1000m, "ANZ M-BANKING PAYMENT TRANSFER 1234 TO LAND LORD"));
            transactions.Add(new Transaction(new DateTime(2017, 4, 1), -10m, "MISC thing"));

            List <TagDefinition> tagDefs = new List <TagDefinition>();

            tagDefs.Add(new TagDefinition("ssw", "SSW", new[] { "FROM SUPERIOR SOFTWAR" }, new string[0]));
            tagDefs.Add(new TagDefinition("salary", "Salary", new[] { "SALARY" }, new string[0]));
            tagDefs.Add(new TagDefinition("rent", "Rent", new[] { "LAND LORD" }, new string[0]));
            tagDefs.Add(new TagDefinition("land-lord", "Land lord", new[] { "LAND LORD" }, new string[0]));

            List <CategoryDefinition> categoryDefs = new List <CategoryDefinition>();

            categoryDefs.Add(new CategoryDefinition("salary", "Salary", new[] { "FROM SUPERIOR SOFTWAR" }, new string[0]));
            categoryDefs.Add(new CategoryDefinition("home", "Home and Utillities", new[] { "LAND LORD" }, new string[0]));

            var undefined = new Category("xyz", "XYZ");

            IClassificationService service = new ClassificationService();

            service.Classify(transactions, categoryDefs, tagDefs, undefined);

            Assert.IsTrue(transactions[0].Tags.Any(t => t.Id == "ssw"));
            Assert.IsTrue(transactions[0].Tags.Any(t => t.Id == "salary"));
            Assert.IsTrue(transactions[1].Tags.Any(t => t.Id == "rent"));
            Assert.IsNotNull(transactions[0].Category);
            Assert.IsNotNull(transactions[1].Category);
            Assert.IsNotNull(transactions[2].Category);
            Assert.AreEqual("salary", transactions[0].Category.Id);
            Assert.AreEqual("home", transactions[1].Category.Id);
            Assert.AreEqual("xyz", transactions[2].Category.Id);
        }