public void Initialize(PhoneCollection phones, EntityBase entity) { this.phones = phones; this.entity = entity; grid.Columns[1].Visible = true; }
/// <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); }
/// <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(); }
/// <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(); }
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); }
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); }
public IHttpActionResult PutPhones(int userId, [FromBody] PhoneCollection <UserPhone> phones) { return(ExecuteValidatedAction(() => { _userService.MergePhones(userId, phones); return Ok(); })); }
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); }
public static List <Phone> RemoveSpaces(PhoneCollection collection) { foreach (Phone p in collection.Phones) { p.Model.Trim(); } return(collection.Phones); }
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); }
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); }
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); }
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; }
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); }
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); } }
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); }
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); } }
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); }
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()); }
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)); }
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")); }
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++; } }
public static void Calculate(PhoneCollection collection, Timeframe timeframe) { Preprocessing(collection); RunAlgorithm(collection, timeframe); }
public void Initialize(PhoneCollection phones) { this.phones = phones; grid.Columns[1].Visible = false; }
public static void FillPhoneList(PhoneCollection coll, SqlDataReader reader) { FillPhoneList(coll, reader, -1, 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); } }