Exemplo n.º 1
0
        public void Initialize(PhoneCollection phones, EntityBase entity)
        {
            this.phones = phones;
            this.entity = entity;

            grid.Columns[1].Visible = true;
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Merges Contact's Phones.
        /// </summary>
        /// <param name="custId"></param>
        /// <param name="contactId"></param>
        /// <param name="phones"></param>
        public void MergeContactPhones(int custId, int contactId, PhoneCollection <ContactPhone> phones)
        {
            ThrowIfNull(phones);
            ValidateAndThrow(phones, new ContactPhoneCollectionValidator());
            if (phones.Phones != null)
            {
                foreach (var p in phones.Phones)
                {
                    p.PhoneType = null;
                    p.ContactId = contactId;
                }
            }

            var existing = Context.ContactPhones.Where(cp => cp.ContactId == contactId);

            Context.Merge <ContactPhone>()
            .SetExisting(existing)
            .SetUpdates(phones.Phones)
            .MergeBy((e, u) => e.Phone == u.Phone && e.Extension == u.Extension)
            .MapUpdatesBy((e, u) =>
            {
                e.IsPrimary   = u.IsPrimary;
                e.PhoneTypeId = u.PhoneTypeId;
            })
            .Merge();
            Context.SaveChanges();
        }
 private static void Preprocessing(PhoneCollection collection)
 {
     //NOTE: Order is important
     collection.Phones = DataDuplication.RemoveDuplicates(collection);
     collection.Phones = DataValidity.FillGaps(collection);
     collection.Phones = DataValidity.RemoveSpaces(collection);
 }
Exemplo n.º 4
0
        /// <summary>
        ///     Merges CustomerPhones.
        /// </summary>
        /// <param name="customerId"></param>
        /// <param name="phones"></param>
        public void MergeCustomerPhones(int customerId, PhoneCollection <CustomerPhone> phones)
        {
            ThrowIfNull(phones);
            ValidateAndThrow(phones, new CustomerPhoneCollectionValidator()); //  validate phones that will persist

            if (phones.Phones != null)
            {
                foreach (var p in phones.Phones)
                {
                    p.PhoneType  = null;       // clean out PhoneType if present for adds
                    p.CustomerId = customerId; // in case it wasn't set...
                }
            }

            var existing = Context.CustomerPhones.Where(cp => cp.CustomerId == customerId);

            Context.Merge <CustomerPhone>()
            .SetExisting(existing)
            .SetUpdates(phones.Phones)
            .MergeBy((e, u) => e.Phone == u.Phone && e.Extension == u.Extension)
            .MapUpdatesBy((e, u) =>
            {
                e.IsPrimary   = u.IsPrimary;
                e.PhoneTypeId = u.PhoneTypeId;
            })
            .Merge();
            Context.SaveChanges();
        }
Exemplo n.º 5
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="VCard" /> class.
        /// </summary>
        public VCard()
        {
            // Per Microsoft best practices, string properties should
            // never return null.  String properties should always
            // return String.Empty.

            _additionalNames = string.Empty;
            _department      = string.Empty;
            _displayName     = string.Empty;
            _familyName      = string.Empty;
            _formattedName   = string.Empty;
            _givenName       = string.Empty;
            _mailer          = string.Empty;
            _namePrefix      = string.Empty;
            _nameSuffix      = string.Empty;
            _office          = string.Empty;
            _organization    = string.Empty;
            _productId       = string.Empty;
            _role            = string.Empty;
            _timeZone        = string.Empty;
            _title           = string.Empty;
            _uniqueId        = string.Empty;

            Categories        = new StringCollection();
            Certificates      = new CertificateCollection();
            DeliveryAddresses = new DeliveryAddressCollection();
            DeliveryLabels    = new DeliveryLabelCollection();
            EmailAddresses    = new EmailAddressCollection();
            _nicknames        = new StringCollection();
            _notes            = new NoteCollection();
            Phones            = new PhoneCollection();
            _photos           = new PhotoCollection();
            Sources           = new SourceCollection();
            Websites          = new WebsiteCollection();
        }
Exemplo n.º 6
0
 public static List <Phone> Calculate(PhoneCollection collection)
 {
     for (int index = 0; index < collection.Phones.Count(); index++)
     {
         collection.Phones[index].Trend = Calculate(index, collection);
     }
     return(collection.Phones);
 }
Exemplo n.º 7
0
 public IHttpActionResult PutContactPhones(int custId, int contactId, PhoneCollection <ContactPhone> phones)
 {
     return(ExecuteValidatedAction(() =>
     {
         _service.MergeContactPhones(custId, contactId, phones);
         return Ok();
     }));
 }
 public static List <Phone> Calculate(PhoneCollection collection, Timeframe timeframe = Timeframe.Quarterly)
 {
     for (int index = 0; index < collection.Phones.Count(); index++)
     {
         collection.Phones[index].Seasonality = Calculate(index, collection, timeframe);
     }
     return(collection.Phones);
 }
Exemplo n.º 9
0
 public IHttpActionResult PutPhones(int userId, [FromBody] PhoneCollection <UserPhone> phones)
 {
     return(ExecuteValidatedAction(() =>
     {
         _userService.MergePhones(userId, phones);
         return Ok();
     }));
 }
Exemplo n.º 10
0
        public static List <Phone> RemoveDuplicates(PhoneCollection collection)
        {
            // Finds the earliest date in the collection of phones
            var start = collection.Phones
                        .Min(i => i.Date);

            // Finds the latest date in the collection of phones
            var end = collection.Phones
                      .Max(i => i.Date);

            if (start == end)
            {
                throw new Exception("Pre-processing exception: Collection's start and end date are the same.");
            }
            if (start > end)
            {
                throw new Exception("Pre-processing exception: Collection's end date is earlier than the start date.");
            }

            // Checks if all phones in collection have the same brand and model.
            if (DataAuditing.HasConsistentBranding(collection.Phones))
            {
                // Loops - month by month - through all dates from the collection's beginning to the end.
                for (var date = start; date < end; date = date.AddMonths(1))
                {
                    if (collection.ContainsDate(date))
                    {
                        var occurancesOfItem = collection.Phones
                                               .Where(i => i.Date.Month == date.Month)
                                               .Where(i => i.Date.Year == date.Year);

                        if (occurancesOfItem.Count() > 1)
                        {
                            // Retrieves current date
                            DateTime currentDate = new DateTime(date.Year, date.Month, 1);

                            // Calculates the average price for items with the same month and year
                            var averagePrice = occurancesOfItem
                                               .Select(i => i.Price)
                                               .Average();

                            // Remove all phones
                            collection.Phones.RemoveAll(x => x.Date.Month == date.Month && x.Date.Year == date.Year);

                            collection.AddItem(collection.Phones[0].Brand,
                                               collection.Phones[0].Model,
                                               currentDate,
                                               averagePrice);
                        }
                    }
                }
            }

            collection.Phones.Sort((x, y) => DateTime.Compare(x.Date, y.Date));

            return(collection.Phones);
        }
Exemplo n.º 11
0
        public static List <Phone> RemoveSpaces(PhoneCollection collection)
        {
            foreach (Phone p in collection.Phones)
            {
                p.Model.Trim();
            }

            return(collection.Phones);
        }
Exemplo n.º 12
0
 private static void RunAlgorithm(PhoneCollection collection, Timeframe timeframe)
 {
     collection.Phones = MovingAverage.Calculate(collection, timeframe);
     collection.Phones = CenteredMovingAverage.Calculate(collection, timeframe);
     collection.Phones = SeasonalIrregularity.Calculate(collection);
     collection.Phones = Seasonality.Calculate(collection, timeframe);
     collection.Phones = Deseasonalize.Calculate(collection);
     collection.Phones = Trend.Calculate(collection);
     collection.Phones = Forecast.Calculate(collection);
 }
Exemplo n.º 13
0
 public static List <Phone> Calculate(PhoneCollection collection)
 {
     for (int index = 0; index < collection.Phones.Count(); index++)
     {
         if (collection.Phones[index].Seasonality != null)
         {
             collection.Phones[index].Deseasonalized = (collection.Phones[index].Price / collection.Phones[index].Seasonality);
         }
     }
     return(collection.Phones);
 }
        public static List <Phone> Calculate(PhoneCollection collection)
        {
            for (int index = 0; index < collection.Phones.Count(); index++)
            {
                if (collection.Phones[index].CenteredMovingAverage != null && collection.Phones[index].CenteredMovingAverage.GetValueOrDefault() != 0)
                {
                    collection.Phones[index].SeasonalIrregularity = (collection.Phones[index].Price / collection.Phones[index].CenteredMovingAverage);
                }
            }

            return(collection.Phones);
        }
Exemplo n.º 15
0
        public static List <Phone> Calculate(PhoneCollection collection, Timeframe timeframe = Timeframe.Quarterly)
        {
            for (int index = 0; index < collection.Phones.Count(); index++)
            {
                if (collection.Phones.ElementAtOrDefault(index).MovingAverage != null && collection.Phones.ElementAtOrDefault(index + 1).MovingAverage != null)
                {
                    collection.Phones[index].CenteredMovingAverage = (collection.Phones[index].MovingAverage + collection.Phones[index + 1].MovingAverage) / 2;
                }
            }

            return(collection.Phones);
        }
        public TimeSeriesPrediction(List <Item> items, Brand brand, string model, Timeframe timeframe = Timeframe.Monthly)
        {
            List <Phone> phones = new List <Phone>();

            foreach (Item item in items.Where(m => m.Brand == brand).Where(m => m.Model == model).ToList())
            {
                phones.Add(new Phone(item.Brand, item.Model, item.Date, item.Price));
            }

            PhoneCollection = new PhoneCollection(phones);
            Algorithm.Calculate(PhoneCollection, timeframe);
        }
        public TimeSeriesPrediction(List <Item> items, Timeframe timeframe = Timeframe.Monthly)
        {
            List <Phone> phones = new List <Phone>();

            foreach (Item item in items)
            {
                phones.Add(new Phone(item.Brand, item.Model, item.Date, item.Price));
            }

            // Create a PhoneCollection from passed items.
            PhoneCollection = new PhoneCollection(phones);
            Algorithm.Calculate(PhoneCollection, timeframe);
        }
Exemplo n.º 18
0
        private object ConvertPhoneCollectionFromString(object value)
        {
            string phoneString = (string)value;

            string[] phones = phoneString.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

            PhoneCollection phoneCollection = new PhoneCollection();
            for (int i = 0; i < phones.Length; i++)
            {
                string normalizedPhone = PhoneNumberUtils.ValidatePhoneNumber(phones[i]);
                phoneCollection.Add(normalizedPhone);
            }

            return phoneCollection;
        }
Exemplo n.º 19
0
        private object ConvertPhoneCollectionFromString(object value)
        {
            string phoneString = (string)value;

            string[] phones = phoneString.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

            PhoneCollection phoneCollection = new PhoneCollection();

            for (int i = 0; i < phones.Length; i++)
            {
                string normalizedPhone = PhoneNumberUtils.ValidatePhoneNumber(phones[i]);
                phoneCollection.Add(normalizedPhone);
            }

            return(phoneCollection);
        }
Exemplo n.º 20
0
        public static PhoneCollection GetAllPhones()
        {
            PhoneCollection ac = new PhoneCollection();

            using (SqlConnection conn = new SqlConnection(PhoneSQL.csPhone))
            {
                SqlCommand cmd = new SqlCommand(PhoneSQL.cGetAllPhones, conn);
                cmd.CommandType = CommandType.StoredProcedure;
                conn.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                FillPhoneList(ac, reader);
                reader.Close();
                conn.Close();

                return(ac);
            }
        }
Exemplo n.º 21
0
        public static List <Phone> FillGaps(PhoneCollection collection)
        {
            // Finds the earliest date in the collection of phones
            var start = collection.Phones
                        .Min(i => i.Date);

            // Finds the latest date in the collection of phones
            var end = collection.Phones
                      .Max(i => i.Date);

            if (start == end)
            {
                throw new Exception("Pre-processing exception: Collection's start and end date are the same.");
            }
            if (start > end)
            {
                throw new Exception("Pre-processing exception: Collection's end date is earlier than the start date.");
            }

            //collection.Phones.RemoveAll(x => x.Date.Month == 3);
            //collection.Phones.RemoveAll(x => x.Date.Month == 4);

            // Checks if all phones in collection have the same brand and model.
            if (DataAuditing.HasConsistentBranding(collection.Phones))
            {
                // Loops - month by month - through all dates from the collection's beginning to the end.
                for (var date = start; date < end; date = date.AddMonths(1))
                {
                    if (collection.ContainsDate(date) == false)
                    {
                        DateTime currentDate = new DateTime(date.Year, date.Month, 1);

                        collection.AddItem(collection.Phones[0].Brand,
                                           collection.Phones[0].Model,
                                           currentDate,
                                           GenerateSuggestedPrice(collection.Phones, currentDate));
                    }
                }
            }

            // Sort all phones in ascending order by Datetime
            collection.Phones.Sort((x, y) => DateTime.Compare(x.Date, y.Date));

            return(collection.Phones);
        }
Exemplo n.º 22
0
        public static PhoneCollection GetMyPhones(string edipi)
        {
            PhoneCollection ac = new PhoneCollection();

            using (SqlConnection conn = new SqlConnection(PhoneSQL.csPhone))
            {
                SqlCommand cmd = new SqlCommand(PhoneSQL.cGetMyPhones, conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@psEDIPI", edipi);
                conn.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                FillPhoneList(ac, reader);
                reader.Close();
                conn.Close();

                return(ac);
            }
        }
Exemplo n.º 23
0
        public static List <Phone> Calculate(PhoneCollection collection, Timeframe timeframe = Timeframe.Quarterly)
        {
            for (int index = 0; index < collection.Phones.Count(); index++)
            {
                if (collection.Phones.ElementAtOrDefault(index - 2) != null && collection.Phones.ElementAtOrDefault(index - 3 + (int)timeframe) != null)
                {
                    double sum = 0.0;

                    for (int i = (index - 2); i < (index - 2 + (int)timeframe); i++)
                    {
                        sum += collection.Phones[i].Price.Value;
                    }

                    collection.Phones[index].MovingAverage = sum / (int)timeframe;
                }
            }

            return(collection.Phones);
        }
Exemplo n.º 24
0
        private object ConvertPhoneCollectionToPhoneString(object value)
        {
            PhoneCollection phones  = (PhoneCollection)value;
            StringBuilder   builder = new StringBuilder();

            for (int i = 0; i < phones.Count; i++)
            {
                if (i == 0)
                {
                    builder.Append(phones[i]);
                }
                else
                {
                    builder.AppendFormat(";{0}", phones[i]);
                }
            }

            return(builder.ToString());
        }
Exemplo n.º 25
0
        public static double Calculate(int index, PhoneCollection collection)
        {
            int xValueCount = collection.Phones
                              .Where(x => x.Deseasonalized.HasValue)
                              .Count();

            int[] xValues = Enumerable
                            .Range(1, xValueCount)
                            .ToArray();
            double[] yValues = collection.Phones
                               .Where(x => x.Deseasonalized.HasValue)
                               .Select(x => x.Deseasonalized)
                               .Cast <double>()
                               .ToArray();

            LinearRegression.Calculate(xValues, yValues, out double rSquared, out double yIntercept, out double slope);

            return(CalculateTrend(index, yIntercept, slope));
        }
Exemplo n.º 26
0
 public Contact(XElement element)
 {
     ContactID = XElementHelper.ValueOrDefault<Guid>(element.Element("ContactID"));
     ContactStatus = XElementHelper.ValueOrDefault<string>(element.Element("ContactStatus"));
     Name = XElementHelper.ValueOrDefault<string>(element.Element("Name"));
     FirstName = XElementHelper.ValueOrDefault<string>(element.Element("FirstName"));
     LastName = XElementHelper.ValueOrDefault<string>(element.Element("LastName"));
     EmailAddress = XElementHelper.ValueOrDefault<string>(element.Element("EmailAddress"));
     BankAccountDetails = XElementHelper.ValueOrDefault<string>(element.Element("BankAccountDetails"));
     TaxNumber = XElementHelper.ValueOrDefault<string>(element.Element("TaxNumber"));
     AccountsReceivableTaxType = XElementHelper.ValueOrDefault<string>(element.Element("AccountsReceivableTaxType"));
     AccountsPayableTaxType = XElementHelper.ValueOrDefault<string>(element.Element("AccountsPayableTaxType"));
     Addresses = new AddressCollection(element.Element("Addresses"));
     Phones = new PhoneCollection(element.Element("Phones"));
     UpdatedDateUTC = XElementHelper.ValueOrDefault<DateTime>(element.Element("UpdatedDateUTC"));
     ContactGroups = XElementHelper.ValueOrDefault<string>(element.Element("ContactGroups"));
     IsSupplier = XElementHelper.ValueOrDefault<bool>(element.Element("IsSupplier"));
     IsCustomer = XElementHelper.ValueOrDefault<bool>(element.Element("IsCustomer"));
     DefaultCurrency = XElementHelper.ValueOrDefault<string>(element.Element("DefaultCurrency"));
 }
Exemplo n.º 27
0
        public static void FillPhoneList(PhoneCollection coll, SqlDataReader reader, int totalRows, int firstRow)
        {
            int  index    = 0;
            bool readMore = true;

            while (reader.Read())
            {
                if (index >= firstRow && readMore)
                {
                    if (coll.Count >= totalRows && totalRows > 0)
                    {
                        readMore = false;
                    }
                    else
                    {
                        Phone trx = Phone.GetPhone(reader);
                        coll.Add(trx);
                    }
                }
                index++;
            }
        }
Exemplo n.º 28
0
 public static void Calculate(PhoneCollection collection, Timeframe timeframe)
 {
     Preprocessing(collection);
     RunAlgorithm(collection, timeframe);
 }
Exemplo n.º 29
0
        public void Initialize(PhoneCollection phones)
        {
            this.phones = phones;

            grid.Columns[1].Visible = false;
        }
Exemplo n.º 30
0
 public static void FillPhoneList(PhoneCollection coll, SqlDataReader reader)
 {
     FillPhoneList(coll, reader, -1, 0);
 }
Exemplo n.º 31
0
 public static double Calculate(int index, PhoneCollection collection)
 {
     return(collection.Phones[index].Seasonality.GetValueOrDefault(0) * collection.Phones[index].Trend.GetValueOrDefault(0));
 }
        public static double?Calculate(int index, PhoneCollection items, Timeframe timeframe = Timeframe.Quarterly)
        {
            int month = items.Phones[index].Date.Month;

            if (timeframe == Timeframe.Quarterly)
            {
                switch (month)
                {
                // January, February, March: calculate Seasonal Irregularity average
                case 1:
                case 2:
                case 3:
                    return(items.Phones
                           .Where(x => (x.Date.Month == 1 || x.Date.Month == 2 || x.Date.Month == 3) && x.SeasonalIrregularity != null)
                           .Select(x => x.SeasonalIrregularity)
                           .Average());

                // April, May, June: calculate Seasonal Irregularity average
                case 4:
                case 5:
                case 6:
                    return(items.Phones
                           .Where(x => (x.Date.Month == 4 || x.Date.Month == 5 || x.Date.Month == 6) && x.SeasonalIrregularity != null)
                           .Select(x => x.SeasonalIrregularity)
                           .Average());

                // July, August, September: calculate Seasonal Irregularity average
                case 7:
                case 8:
                case 9:
                    return(items.Phones
                           .Where(x => (x.Date.Month == 7 || x.Date.Month == 8 || x.Date.Month == 9) && x.SeasonalIrregularity != null)
                           .Select(x => x.SeasonalIrregularity)
                           .Average());

                // October, November, December: calculate Seasonal Irregularity average
                case 10:
                case 11:
                case 12:
                    return(items.Phones
                           .Where(x => (x.Date.Month == 10 || x.Date.Month == 11 || x.Date.Month == 12) && x.SeasonalIrregularity != null)
                           .Select(x => x.SeasonalIrregularity)
                           .Average());

                default:
                    return(null);
                }
            }
            else if (timeframe == Timeframe.Monthly)
            {
                switch (month)
                {
                // January: calculate Seasonal Irregularity average
                case 1:
                    return(items.Phones
                           .Where(x => x.Date.Month == 1 && x.SeasonalIrregularity != null)
                           .Select(x => x.SeasonalIrregularity)
                           .Average());

                // February: calculate Seasonal Irregularity average
                case 2:
                    return(items.Phones
                           .Where(x => x.Date.Month == 2 && x.SeasonalIrregularity != null)
                           .Select(x => x.SeasonalIrregularity)
                           .Average());

                // March: calculate Seasonal Irregularity average
                case 3:
                    return(items.Phones
                           .Where(x => x.Date.Month == 3 && x.SeasonalIrregularity != null)
                           .Select(x => x.SeasonalIrregularity)
                           .Average());

                // April: calculate Seasonal Irregularity average
                case 4:
                    return(items.Phones
                           .Where(x => x.Date.Month == 4 && x.SeasonalIrregularity != null)
                           .Select(x => x.SeasonalIrregularity)
                           .Average());

                // May: calculate Seasonal Irregularity average
                case 5:
                    return(items.Phones
                           .Where(x => x.Date.Month == 5 && x.SeasonalIrregularity != null)
                           .Select(x => x.SeasonalIrregularity)
                           .Average());

                // June: calculate Seasonal Irregularity average
                case 6:
                    return(items.Phones
                           .Where(x => x.Date.Month == 6 && x.SeasonalIrregularity != null)
                           .Select(x => x.SeasonalIrregularity)
                           .Average());

                // July: calculate Seasonal Irregularity average
                case 7:
                    return(items.Phones
                           .Where(x => x.Date.Month == 7 && x.SeasonalIrregularity != null)
                           .Select(x => x.SeasonalIrregularity)
                           .Average());

                // August: calculate Seasonal Irregularity average
                case 8:
                    return(items.Phones
                           .Where(x => x.Date.Month == 8 && x.SeasonalIrregularity != null)
                           .Select(x => x.SeasonalIrregularity)
                           .Average());

                // September: calculate Seasonal Irregularity average
                case 9:
                    return(items.Phones
                           .Where(x => x.Date.Month == 9 && x.SeasonalIrregularity != null)
                           .Select(x => x.SeasonalIrregularity)
                           .Average());

                // October: calculate Seasonal Irregularity average
                case 10:
                    return(items.Phones
                           .Where(x => x.Date.Month == 10 && x.SeasonalIrregularity != null)
                           .Select(x => x.SeasonalIrregularity)
                           .Average());

                // November: calculate Seasonal Irregularity average
                case 11:
                    return(items.Phones
                           .Where(x => x.Date.Month == 11 && x.SeasonalIrregularity != null)
                           .Select(x => x.SeasonalIrregularity)
                           .Average());

                // December: calculate Seasonal Irregularity average
                case 12:
                    return(items.Phones
                           .Where(x => x.Date.Month == 12 && x.SeasonalIrregularity != null)
                           .Select(x => x.SeasonalIrregularity)
                           .Average());

                default:
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }