public void Convert(Configuration configuration)
        {
            var filenames  = Directory.EnumerateFiles(configuration.GpxFolder);
            var folder     = new ActivityFolder("Activities");
            var subFolders = new Dictionary <string, ActivityFolder>();

            foreach (var filename in filenames.OrderBy(x => x))
            {
                if (filename.EndsWith(".gpx"))
                {
                    var activity = GpxReader.Read(filename);
                    if (activity != null)
                    {
                        var monthId = GetMonthId(activity);
                        if (monthId != null)
                        {
                            if (!subFolders.ContainsKey(monthId))
                            {
                                subFolders[monthId] = new ActivityFolder(monthId);
                            }
                            subFolders[monthId].AddItem(activity);
                        }
                    }
                }
            }
            foreach (var activityFolderName in subFolders.Keys.OrderBy(x => x))
            {
                folder.AddItem(subFolders[activityFolderName]);
            }
            KmlWriter.Write(configuration.KmlFilename, folder, configuration);
        }
        /// <summary>
        /// Model the management activities for each breed
        /// </summary>
        public IEnumerable <ActivityFolder> GetManageBreeds(ActivityFolder herd)
        {
            List <ActivityFolder> breeds = new List <ActivityFolder>();

            foreach (int id in RumIDs)
            {
                // Add a new folder for individual breed
                ActivityFolder breed = new ActivityFolder(herd)
                {
                    Name = "Manage " + RumSpecs.ColumnNames[id]
                };

                // Manage breed numbers
                RuminantActivityManage numbers = new RuminantActivityManage(breed)
                {
                    MaximumBreedersKept = RumSpecs.GetData <int>(2, id),
                    MinimumBreedersKept = RumSpecs.GetData <int>(38, id),
                    MaximumBreedingAge  = RumSpecs.GetData <int>(3, id),
                    MaximumBullAge      = RumSpecs.GetData <double>(25, id),
                    MaleSellingAge      = RumSpecs.GetData <double>(5, id),
                    MaleSellingWeight   = RumSpecs.GetData <double>(6, id)
                };

                numbers.Add(new ActivityTimerInterval(numbers)
                {
                    Name     = "NumbersTimer",
                    Interval = 12,
                    MonthDue = 12
                });
                breed.Add(numbers);

                // Manage breed weaning
                breed.Add(new RuminantActivityWean(breed)
                {
                    WeaningAge    = RumSpecs.GetData <double>(7, id),
                    WeaningWeight = RumSpecs.GetData <double>(8, id)
                });

                // Manage breed milking
                if (RumSpecs.GetData <double>(18, id) > 0)
                {
                    breed.Add(new RuminantActivityMilking(breed)
                    {
                        Name             = "Milk",
                        ResourceTypeName = "HumanFoodStore." + RumSpecs.ColumnNames[id] + "_Milk"
                    });
                }

                // Manage sale of dry breeders
                breed.Add(new RuminantActivitySellDryBreeders(breed)
                {
                    MonthsSinceBirth   = RumSpecs.GetData <double>(32, id),
                    ProportionToRemove = RumSpecs.GetData <double>(4, id) * 0.01
                });
                breeds.Add(breed);
            }

            return(breeds);
        }
Exemple #3
0
        public IEnumerable <ActivityFolder> GetManageBreeds(ActivityFolder folder)
        {
            List <ActivityFolder> folders = new List <ActivityFolder>();

            foreach (string breed in PresentBreeds)
            {
                string name  = breed.Replace(".", " ");
                int    index = Breeds.IndexOf(breed);

                ActivityFolder manage = new ActivityFolder(folder)
                {
                    Name = name
                };

                manage.Add(new RuminantActivityWean(manage)
                {
                    WeaningAge         = GetValue <double>(RumSpecs.Element("Weaning_age"), index),
                    WeaningWeight      = GetValue <double>(RumSpecs.Element("Weaning_weight"), index),
                    GrazeFoodStoreName = "NativePasture"
                });

                string homemilk = GetValue <string>(RumSpecs.Element("Home_milk"), index);
                if (homemilk != "0")
                {
                    manage.Add(new RuminantActivityMilking(manage)
                    {
                        ResourceTypeName = "HumanFoodStore." + name + "_Milk"
                    });
                }

                manage.Add(new RuminantActivityManage(manage)
                {
                    MaximumBreedersKept = GetValue <int>(RumSpecs.Element("Max_breeders"), index),
                    MaximumBreedingAge  = GetValue <int>(RumSpecs.Element("Max_breeder_age"), index),
                    MaximumBullAge      = GetValue <int>(RumSpecs.Element("Max_Bull_age"), index),
                    MaleSellingAge      = GetValue <int>(RumSpecs.Element("Anim_sell_age"), index),
                    MaleSellingWeight   = GetValue <int>(RumSpecs.Element("Anim_sell_wt"), index),
                    GrazeFoodStoreName  = "GrazeFoodStore.NativePasture"
                });

                manage.Add(new RuminantActivitySellDryBreeders(manage)
                {
                    MinimumConceptionBeforeSell = 1,
                    MonthsSinceBirth            = GetValue <int>(RumSpecs.Element("Joining_age"), index),
                    ProportionToRemove          = GetValue <double>(RumSpecs.Element("Dry_breeder_cull_rate"), index) * 0.01
                });

                folders.Add(manage);
            }

            return(folders);
        }
        /// <summary>
        /// Return the interest rate calculation model
        /// </summary>
        /// <param name="cashflow">The base model</param>
        public FinanceActivityCalculateInterest GetInterestRates(ActivityFolder cashflow)
        {
            // Find the interest amount
            int row = Overheads.RowNames.FindIndex(s => s == "Int_rate");

            // If the interest is 0, ignore the model
            if (Overheads.GetData <int>(row, 0) == 0)
            {
                return(null);
            }

            return(new FinanceActivityCalculateInterest(cashflow));
        }
Exemple #5
0
        public void Write(string filename, ActivityFolder folder, Configuration configuration)
        {
            var document = new XmlDocument();

            document.AddXmlDeclaration("1.0", "UTF-8", null);
            document
            .AddSubElement("kml", "http://www.opengis.net/kml/2.2")
            .WithXmlns("gx", "http://www.google.com/kml/ext/2.2")
            .WithXmlns("kml", "http://www.opengis.net/kml/2.2")
            .WithXmlns("atom", "http://www.w3.org/2005/Atom")
            .AppendChild(GetFolderNode(document, folder, configuration))
            ;
            document.Save(filename);
        }
Exemple #6
0
        /// <summary>
        /// Constructs the Native Pasture model
        /// </summary>
        public IEnumerable <CropActivityManageCrop> GetNativePasture(ActivityFolder forages)
        {
            List <CropActivityManageCrop> pastures = new List <CropActivityManageCrop>();

            // Check if there are native pasture feeds before proceeding
            var feed_type = RumSpecs.GetRowData <int>(28);
            var feeds     = from breed in feed_type
                            where RumIDs.Contains(feed_type.IndexOf(breed))
                            where breed > 1
                            select breed;

            if (feeds.Count() == 0)
            {
                return(null);
            }

            CropActivityManageCrop farm = new CropActivityManageCrop(forages)
            {
                LandItemNameToUse = "Land",
                UseAreaAvailable  = true,
                Name = "NativePastureFarm"
            };

            farm.Add(new CropActivityManageProduct(farm)
            {
                ModelNameFileCrop = "FileForage",
                CropName          = "Native_grass",
                StoreItemName     = "AnimalFoodStore.NativePasture",
                Name = "Cut and carry Native Pasture"
            });

            CropActivityManageCrop common = new CropActivityManageCrop(forages)
            {
                LandItemNameToUse = "Land",
                Name = "Native Pasture Common Land"
            };

            common.Add(new CropActivityManageProduct(common)
            {
                ModelNameFileCrop = "FileForage",
                CropName          = "Native_grass",
                StoreItemName     = "GrazeFoodStore.NativePasture",
                Name = "Grazed Common Land"
            });

            pastures.Add(farm);
            pastures.Add(common);
            return(pastures.AsEnumerable());
        }
Exemple #7
0
        public bool CreateBPMOnlineFolder(Guid id, string userName, string userPassword)
        {
            if (UserConnection.GetIsFeatureEnabled("EmailIntegrationV2"))
            {
                return(false);
            }
            var currentMailServer = new MailServer(UserConnection);

            if (!currentMailServer.FetchFromDB(id))
            {
                return(false);
            }
            var imapServerCredentials = new MailCredentials {
                Host         = currentMailServer.GetTypedColumnValue <string>("Address"),
                Port         = currentMailServer.GetTypedColumnValue <int>("Port"),
                UseSsl       = currentMailServer.GetTypedColumnValue <bool>("UseSSL"),
                StartTls     = currentMailServer.GetTypedColumnValue <bool>("IsStartTls"),
                UserName     = userName,
                UserPassword = userPassword
            };
            var imapClient = ClassFactory.Get <IImapClient>("OldEmailIntegration",
                                                            new ConstructorArgument("credentials", imapServerCredentials),
                                                            new ConstructorArgument("errorMessages", new Terrasoft.Mail.ImapErrorMessages()),
                                                            new ConstructorArgument("userConnection", UserConnection));

            imapClient.EnsureFolderExists("BPMonline");
            var mailboxFolderTypeId = new Guid("99c2351c-f0f8-e111-9dba-00155d051801");
            var emailFolderTypeId   = new Guid("b97a5836-1cd0-e111-90c6-00155d054c03");
            var mailboxFolder       = new ActivityFolder(UserConnection);

            if (mailboxFolder.FetchFromDB(
                    new Dictionary <string, object> {
                { "FolderType", mailboxFolderTypeId },
                { "Name", imapServerCredentials.UserName }
            }))
            {
                var activityFolderSchema = UserConnection.EntitySchemaManager.GetInstanceByName("ActivityFolder");
                var bpmonlineFolder      = activityFolderSchema.CreateEntity(UserConnection);
                var parentColumn         = activityFolderSchema.Columns.GetByName("Parent");
                var folderTypeColumn     = activityFolderSchema.Columns.GetByName("FolderType");
                bpmonlineFolder.SetDefColumnValues();
                bpmonlineFolder.SetColumnValue("Name", "BPMonline");
                bpmonlineFolder.SetColumnValue(parentColumn.ColumnValueName, mailboxFolder.PrimaryColumnValue);
                bpmonlineFolder.SetColumnValue(folderTypeColumn.ColumnValueName, emailFolderTypeId);
                bpmonlineFolder.Save();
                return(true);
            }
            return(false);
        }
Exemple #8
0
        public FinanceActivityCalculateInterest GetInterestRates(ActivityFolder cashflow)
        {
            // Find the interest amount
            string value = FindFirst(SingleParams, "Int_rate").Value;

            int.TryParse(value, out int rate);

            // If the interest is 0, don't add the element
            if (rate == 0)
            {
                return(null);
            }

            return(new FinanceActivityCalculateInterest(cashflow));
        }
Exemple #9
0
        private XmlNode GetFolderNode(XmlDocument document, ActivityFolder folder, Configuration configuration)
        {
            var folderNode = document.CreateElement("Folder");

            folderNode.AddSubElement("name").WithText(folder.Name);
            folderNode.AddSubElement("open").WithText("1");
            foreach (var activityFolderItem in folder.Items)
            {
                var node = GetFolderOrPlacemarkNode(document, activityFolderItem, configuration);
                if (node != null)
                {
                    folderNode.AppendChild(node);
                }
            }
            return(folderNode);
        }
Exemple #10
0
        public ActivityFolder GetAnnualExpenses(ActivityFolder cashflow)
        {
            ActivityFolder annual = new ActivityFolder(cashflow)
            {
                Name = "AnnualExpenses"
            };

            // Names of parameters to search for in the Element
            string[] items = new string[]
            {
                "Farm_maint",
                "Mach_maint",
                "Fuel",
                "Pests",
                "Contractors",
                "Admin",
                "Rates",
                "Insurance",
                "Electricity",
                "Water",
                "Other_costs"
            };

            foreach (string item in items)
            {
                string value = FindFirst(SingleParams, item).Value;
                int.TryParse(value, out int amount);

                // Only need to add the element if its a non-zero expenditure
                if (amount <= 0)
                {
                    continue;
                }

                FinanceActivityPayExpense expense = new FinanceActivityPayExpense(annual)
                {
                    Name        = item.Replace("_", ""),
                    Amount      = amount,
                    AccountName = "Finances.Bank",
                    IsOverhead  = false
                };
                annual.Add(expense);
            }

            return(annual);
        }
Exemple #11
0
        /// <summary>
        /// Constructs the Manage Forages model
        /// </summary>
        /// <param name="iat">The IAT file to access data from</param>
        public IEnumerable <CropActivityManageCrop> GetManageForages(ActivityFolder forages)
        {
            List <CropActivityManageCrop> manage = new List <CropActivityManageCrop>();

            int col = 0;
            // Check present forages
            var list = ForagesGrown.GetRowData <double>(0);

            foreach (var item in list)
            {
                if (item == 0)
                {
                    continue;
                }

                double area = ForagesGrown.GetData <double>(2, col);
                if (area > 0)
                {
                    int    num  = ForagesGrown.GetData <int>(1, col);
                    int    row  = ForagesGrown.GetData <int>(0, col);
                    string name = ForageSpecs.RowNames[row + 1];

                    CropActivityManageCrop crop = new CropActivityManageCrop(forages)
                    {
                        Name = "Manage " + name,
                        LandItemNameToUse = "Land." + LandSpecs.RowNames[num],
                        AreaRequested     = ForagesGrown.GetData <double>(2, col)
                    };

                    crop.Add(new CropActivityManageProduct(crop)
                    {
                        Name = "Cut and carry " + name,
                        ModelNameFileCrop = "FileForage",
                        CropName          = name,
                        StoreItemName     = "AnimalFoodStore"
                    });

                    manage.Add(crop);
                }
                col++;
            }

            return(manage.AsEnumerable());
        }
Exemple #12
0
        /// <summary>
        /// Return a collection of the annual expenses from the IAT data
        /// </summary>
        /// <param name="cashflow">The base model</param>
        public ActivityFolder GetAnnualExpenses(ActivityFolder cashflow)
        {
            var annual = new ActivityFolder(cashflow)
            {
                Name = "AnnualExpenses"
            };

            // Names of the expenses
            var rows = Overheads.RowNames;

            // Amounts of the expenses
            var amounts = Overheads.GetColData <double>(0);

            // Look at each row in the overheads table
            foreach (string row in rows)
            {
                // The overheads table contains more than just annual data,
                // so stop at the "Int_rate" row (table is ordered)
                if (row == "Int_rate")
                {
                    break;
                }

                // Find the upkeep amount
                int    index  = rows.FindIndex(s => s == row);
                double amount = amounts.ElementAt(index);

                // Only need to add the element if its a non-zero expenditure
                if (amount > 0)
                {
                    annual.Add(new FinanceActivityPayExpense(annual)
                    {
                        Name   = row.Replace("_", ""),
                        Amount = amount
                    });
                }
            }
            // If there are no annual expenses, ignore this folder
            if (annual.Children.Count == 0)
            {
                return(null);
            }
            return(annual);
        }
Exemple #13
0
        public ActivityFolder GetMonthlyExpenses(ActivityFolder cashflow)
        {
            ActivityFolder monthly = new ActivityFolder(cashflow)
            {
                Name = "MonthlyExpenses"
            };

            string value = FindFirst(SingleParams, "Living_cost").Value;

            double.TryParse(value, out double amount);

            monthly.Add(new FinanceActivityPayExpense(monthly)
            {
                Name        = "LivingCost",
                Amount      = amount,
                AccountName = "Finance.Bank"
            });

            return(monthly);
        }
Exemple #14
0
        /// <summary>
        /// Gets the monthly living expenses from the IAT data
        /// </summary>
        /// <param name="cashflow">The model to attach the data to</param>
        public ActivityFolder GetMonthlyExpenses(ActivityFolder cashflow)
        {
            var monthly = new ActivityFolder(cashflow)
            {
                Name = "MonthlyExpenses"
            };

            // Find the monthly living cost
            double amount = Overheads.GetData <double>(13, 0);

            // Only include if non-zero
            if (amount == 0)
            {
                return(null);
            }

            monthly.Add(new FinanceActivityPayExpense(monthly)
            {
                Name   = "LivingCost",
                Amount = amount
            });

            return(monthly);
        }
Exemple #15
0
        /// <summary>
        /// Finds all crops in the source IAT which require management
        /// </summary>
        public IEnumerable <CropActivityManageCrop> GetManageCrops(ActivityFolder manage)
        {
            List <CropActivityManageCrop> crops = new List <CropActivityManageCrop>();

            int[] ids = CropsGrown.GetRowData <int>(0).ToArray();

            // Find the name of the crop in the file
            Sheet         sheet  = SearchSheets("crop_inputs");
            WorksheetPart inputs = (WorksheetPart)Book.GetPartById(sheet.Id);

            // Find the name of the crop
            int rows = sheet.Elements <Row>().Count();

            foreach (int id in GrainIDs)
            {
                string name = "Unknown";
                int    row  = 1;

                while (row < rows)
                {
                    if (GetCellValue(inputs, row, 3) == id.ToString())
                    {
                        name = GetCellValue(inputs, row, 4);
                        break;
                    }
                    row++;
                }

                // Find which column holds the data for a given crop ID
                int col = Array.IndexOf(ids, id);

                // Find names
                int    land     = CropsGrown.GetData <int>(1, col);
                string cropname = CropSpecs.RowNames[id + 1];

                // Model the crop management
                CropActivityManageCrop crop = new CropActivityManageCrop(manage)
                {
                    Name = "Manage " + cropname,
                    LandItemNameToUse = LandSpecs.RowNames[land - 1],
                    AreaRequested     = CropsGrown.GetData <double>(2, col)
                };

                // Find the storage pool which the crop uses
                string pool = Pools.Values.ToList().Find(s => s.Contains(cropname));

                // Add the product management model
                crop.Add(new CropActivityManageProduct(crop)
                {
                    Name = "Manage grain",
                    ModelNameFileCrop = "FileCrop",
                    CropName          = name,
                    ProportionKept    = 1.0 - CropsGrown.GetData <double>(5, col) / 100.0,
                    StoreItemName     = "HumanFoodStore." + pool
                });

                // Add the residue management
                crop.Add(new CropActivityManageProduct(crop)
                {
                    Name = "Manage residue",
                    ModelNameFileCrop = "FileCropResidue",
                    CropName          = name,
                    ProportionKept    = CropsGrown.GetData <double>(4, col) / 100.0,
                    StoreItemName     = "AnimalFoodStore." + pool
                });

                crops.Add(crop);
            }
            return(crops);
        }
Exemple #16
0
 public IEnumerable <CropActivityManageCrop> GetManageCrops(ActivityFolder folder)
 {
     return(null);
 }
Exemple #17
0
 public IEnumerable <CropActivityManageCrop> GetNativePasture(ActivityFolder forages)
 {
     return(null);
 }