static String[] getOrderedItems(Dictionary <string, int> L)
        {
            Console.WriteLine("--------Ordered Itemset----------");

            String[] _temp = new string[Transactions.Count()];
            foreach (KeyValuePair <string, int> Item in L)
            {
                for (int i = 0; i < Transactions.Count(); i++)
                {
                    if (ExistItem(Item.Key, Transactions[i]))
                    {
                        if (_temp[i] == "" || _temp[i] == null)
                        {
                            _temp[i] = Item.Key;
                        }
                        else
                        {
                            _temp[i] += "," + Item.Key;
                        }
                    }
                }
            }

            return(_temp);
        }
        static void Apriori()
        {
            if (Transactions.Count() == 0)
            {
                Console.WriteLine("Empty file..!");
                return;
            }
            //GET C1
            Dictionary <string, int> C1 = getC1(Transactions);

            Console.WriteLine("Support Count Average = " + getAverage(C1));
            Console.Write("Enter a minimum support = ");
            min_sup = int.Parse(Console.ReadLine());
            Dictionary <string, int> L1 = getLN(C1);

            Console.WriteLine("--------L1----------");
            foreach (KeyValuePair <string, int> i in L1)
            {
                Console.WriteLine("{ " + i.Key + " } | " + i.Value);
            }
            Dictionary <string, int> OLD_C = C1;
            Dictionary <string, int> OLD_L = L1;
            // OLD_Ls.Add(1, L1);

            Dictionary <string, int> NEW_C;
            Dictionary <string, int> NEW_L;
            int cpt  = 2;
            int cptL = 1;

            while (true)
            {
                NEW_C = getCN(OLD_L, cpt);
                NEW_L = getLN(NEW_C);
                Console.WriteLine("--------L" + cpt + "----------");
                foreach (KeyValuePair <string, int> i in NEW_L)
                {
                    Console.WriteLine("{ " + i.Key + " } | " + i.Value);
                }
                if (NEW_L.Count() == 0)
                {
                    Console.Write("Enter Confidence (e.g. 0,7)= ");
                    confidence = float.Parse(Console.ReadLine());
                    //confidence /= 10;
                    GeneratingRules(OLD_L);
                    break;
                }
                else
                {
                    OLD_C = NEW_C;
                    OLD_L = NEW_L;


                    cptL++;
                    cpt++;
                }
            }
        }
Ejemplo n.º 3
0
        public override string ToString()
        {
            var numCredit = Transactions != null?Transactions.Count(t => t.IsCredit) : 0;

            var numDebit = Transactions != null?Transactions.Count(t => !t.IsCredit) : 0;

            var firstTran = Transactions != null && Transactions.Any() ? Transactions[0].ToString() : "";

            return(string.Format("Name: {0} From: {1} To: {2} {3} {4} # Transactions: {5} #credit: {7} #debit: {8}\n First Transaction: {6}",
                                 Name, DateFrom, DateTo, Balance.HasValue ? "Balance: " : "", Balance.HasValue ? Balance.Value.ToString(CultureInfo.InvariantCulture) : "",
                                 NumOfTransactions, firstTran, numCredit, numDebit));
        }
        static void FP_Growth()
        {
            if (Transactions.Count() == 0)
            {
                Console.WriteLine("Empty file..!");
                return;
            }
            //GET C1
            Dictionary <string, int> C1 = getC1(Transactions);

            Console.WriteLine("Support Count Average = " + getAverage(C1));
            Console.Write("Enter a minimum support = ");
            min_sup = int.Parse(Console.ReadLine());
            Dictionary <string, int> L1 = getLN(C1);

            // Order By Descendent
            L1 = L1.OrderByDescending(Item => Item.Value).ToDictionary(Item => Item.Key, Item => Item.Value);
            Console.WriteLine("--------L1----------");
            foreach (KeyValuePair <string, int> i in L1)
            {
                Console.WriteLine("{ " + i.Key + " } | " + i.Value);
            }
            // Return if nothing > than the min_sup criteria
            if (L1.Count == 0)
            {
                Console.WriteLine("All Transactions have been eliminated"); return;
            }
            // Get ordered list
            String[] OrderedItemSet = getOrderedItems(L1);
            // Dump the OrderedList
            dumpOrderedList(OrderedItemSet);
            //Creating Tree and Items Routers
            Node root = new Node();
            Dictionary <String, Node> ItemsRouters = new Dictionary <string, Node>();

            InitRouters(ItemsRouters, L1);
            // Construct Tree
            TreeConstruction(ItemsRouters, root, OrderedItemSet);
            // Order By Ascendent
            L1 = L1.OrderBy(Item => Item.Value).ToDictionary(Item => Item.Key, Item => Item.Value);

            // Conditional Pattern Base
            String[] ConPatternBase = new string[L1.Count];
            getCondPatternBase(L1, ConPatternBase, ItemsRouters);
            String[] ConFPTree = new string[L1.Count];
            getConFPTree(ConPatternBase, ConFPTree, L1);
            Console.Write("Enter Confidence (e.g. 0,7)= ");
            confTree = double.Parse(Console.ReadLine());
            //confTree /= 10;

            FrequentPatternGeneration(ConFPTree, L1);
        }
        public void RemoveTransactions(int index)
        {
            if (Transactions.Count == 0)
            {
                return;
            }
            DatabaseHandler db = new DatabaseHandler(MainWindow);

            db.Open();
            while (Transactions.Count() > index)
            {
                Size += (Transactions[index].IsRemoval ? 1 : -1) * Transactions[index].NumberTransacted;
                db.DeleteTransaction(Transactions[index]);
                Transactions.RemoveAt(index);
            }
            db.Close();
            HasTransactions    = false;
            GetLastTransaction = null;
        }
Ejemplo n.º 6
0
        private void HandleAgregatedTransaction(TransactionViewModel transaction)
        {
            if (Transactions.Count(t => t.SupplierId == transaction.SupplierId) == 1)
            {
                var child = Transactions.First(t => t.SupplierId == transaction.SupplierId);

                var newParent = new AgregatedTransaction
                {
                    EventDate        = transaction.Date,
                    AccountId        = transaction.AccountId,
                    SupplierId       = transaction.SupplierId.ToString(),
                    EventDescription = transaction.Description,
                    EventAmount      = child.IsActive ? child.Amount : 0,
                    Type             = TransactionType.Expense
                };

                if (child.ParentId > 0)
                {
                    newParent.EventId = child.ParentId;
                }

                var newParentVm = new TransactionViewModel(newParent);
                Transactions.Add(newParentVm);

                child.ParentId       = newParentVm.Id;
                newParentVm.IsActive = child.IsActive || transaction.IsActive;
            }

            var parent = Transactions.FirstOrDefault(t => t.SupplierId == transaction.SupplierId && t.ParentId == 0);

            if (parent != null)
            {
                transaction.ParentId = parent.Id;
                parent.IsActive      = parent.IsActive || transaction.IsActive;

                if (transaction.IsActive)
                {
                    parent.Amount += transaction.Amount;
                }
            }
        }
Ejemplo n.º 7
0
        public Transaction CreateReceive(decimal amount, string sourceName, string sourceIBAN, string description)
        {
            if (string.IsNullOrEmpty(sourceName) && string.IsNullOrEmpty(sourceIBAN))
            {
                throw new Exception("");
            }

            if (amount <= 0)
            {
                throw new Exception("");
            }

            Transactions.Count();
            var transaction = Transaction.Create(amount, Id, sourceName, sourceIBAN, description);

            AddTransaction(transaction);

            Balance += amount;

            return(transaction);
        }
        //---------------------- Apriori END ----------------

        //---------------------- FP GROWTH BEGING -----------
        static void Preprocessing()
        {
            String[] _tempTransaction = new String[Transactions.Count()];
            for (int i = 0; i < _tempTransaction.Count(); i++)
            {
                int Attr = 1;
                foreach (String Attribute in Transactions[i].Split(' '))
                {
                    if (String.IsNullOrEmpty(_tempTransaction[i]))
                    {
                        _tempTransaction[i] = "C" + Attr + "_" + Attribute;
                    }
                    else
                    {
                        _tempTransaction[i] += " " + "C" + Attr + "_" + Attribute;
                    }
                    Attr++;
                }
            }


            Transactions = _tempTransaction;
        }
Ejemplo n.º 9
0
 public override string ToString()
 {
     return($"Index={Index}, Transactions={Transactions.Count()}, Proof={Proof}, PrevHash={PrevHash}");
 }
Ejemplo n.º 10
0
 public int SellCount(IEnumerable <IOhlcv> candles) => Transactions.Count(t => t.OhlcvList.Equals(candles) && t.Type == TransactionType.Sell);
Ejemplo n.º 11
0
 public int BuyCount(IEnumerable <IOhlcv> candles) => Transactions.Count(t => t.IOhlcvDatas.Equals(candles) && t.Type == TransactionType.Buy);
Ejemplo n.º 12
0
 private void AddTransaction(Transaction transaction)
 {
     Transactions.Count();
     transactions.Add(transaction);
     LastTransactionDate = DateTime.UtcNow;
 }
Ejemplo n.º 13
0
 public int SellCount(IList <Candle> candles) => Transactions.Count(t => t.Candles.Equals(candles) && t.Type == TransactionType.Sell);
Ejemplo n.º 14
0
        public decimal YTDinterestEarned()
        {
            decimal dailyInterest   = (decimal)InterestRate / (decimal)365;
            decimal principleAmount = 0;
            Dictionary <DateTime, decimal> DailyTransaction = new Dictionary <DateTime, decimal>();

            if (Transactions == null || Transactions.Count() == 0)
            {
                return(0);
            }
            for (int i = 0; i < Transactions.Count(); i++)
            {
                if (Transactions[i].transactionDate < DateTime.Today)
                {
                    if (DailyTransaction != null && DailyTransaction.Keys.Contains(Transactions[i].transactionDate))
                    {
                        DailyTransaction[Transactions[i].transactionDate] = DailyTransaction[Transactions[i].transactionDate] + Transactions[i].transactionAmount;
                    }
                    else
                    {
                        DailyTransaction[Transactions[i].transactionDate] = Transactions[i].transactionAmount;
                    }
                }
            }
            decimal interestAccrued = DailyTransaction.Values.Sum();

            DailyTransaction.Add(DateTime.Today.Date, 0);
            var myList = DailyTransaction.ToList();

            myList.Sort((pair1, pair2) => pair1.Key.CompareTo(pair2.Key));

            // DailyTransaction.Values.ToList().Sort();
            int     numberofDays        = 0;
            decimal accumulatedInterest = 0;

            int month = myList[0].Key.Month;

            for (int i = 0; i < myList.Count(); i++)
            {
                if (i > 0)
                {
                    if (month == myList[i].Key.Month)
                    {
                        numberofDays = myList[i].Key.DayOfYear - myList[i - 1].Key.DayOfYear;
                    }
                    else
                    {
                        numberofDays = (DateTime.DaysInMonth(myList[i - 1].Key.Year, myList[i - 1].Key.Month) - myList[i - 1].Key.Date.Day) + 1;
                    }
                }

                if (month != myList[i].Key.Month)
                {
                    accumulatedInterest = accumulatedInterest + principleAmount * (dailyInterest / 100) * (numberofDays);
                }
                if (month != myList[i].Key.Month && i != myList.Count() - 1)
                {
                    principleAmount     = principleAmount + accumulatedInterest;
                    accumulatedInterest = (principleAmount * ((dailyInterest) / 100) * (myList[i].Key.Day - 1));
                }

                principleAmount = principleAmount + myList[i].Value;
                month           = myList[i].Key.Month;
            }
            decimal total = principleAmount + accumulatedInterest;

            return(decimal.Round(total - interestAccrued, 2));
        }
Ejemplo n.º 15
0
 public int BuyCount(IEnumerable <Candle> candles) => Transactions.Count(t => t.Candles.Equals(candles) && t.Type == TransactionType.Buy);