public void CanMatchSeasons() { HashSet <int> seasons = new HashSet <int>(); HashSet <int> eventTypes = new HashSet <int>(); PreOutfit po = new PreOutfit(); Combination c = new Combination(); c.GarmentA = new MasterGarment(); c.GarmentA.EventCode = 3; c.GarmentA.SeasonCode = 15; po.Accesory1 = new MasterGarment(); po.Accesory1.EventCode = 3; po.Accesory1.SeasonCode = 3; c.GarmentB = new MasterGarment(); c.GarmentB.EventCode = 1; c.GarmentB.SeasonCode = 3; po.Combination = c; OutfitValidationService.VerifyAndSetSeasonsAndEventTypes(seasons, eventTypes, po); Assert.IsTrue(seasons.Sum() == 3, seasons.Sum().ToString()); Assert.IsTrue(eventTypes.Sum() == 1, eventTypes.Sum().ToString()); }
public virtual void AddPreGarment(Garment garment) { int pos = OutfitValidationService.GetClosetOutfitPosition(garment); PropertyInfo pi = new PreCombination().GetType().GetProperty(string.Format("Garment{0}", pos + 1)); pi.SetValue(this, garment.PreGarment, null); }
public virtual IEnumerable <Garment> RetrieveCombinableComponents() { foreach (Garment g in this.Components) { if (!OutfitValidationService.IsAccessory(g)) { yield return(g); } } }
private bool ExecuteOutfitGenerator(IList <Garment> addedGarments, bool createRecords) { newGarments = null; flavorCombinations.Clear(); outfits.Clear(); this.createRecords = createRecords; if (addedGarments != null) { newGarments = new HashSet <Garment>(); foreach (Garment g in addedGarments) { newGarments.Add(g); } } lstGarments = (from cg in currentGarments where !OutfitValidationService.IsAccessory(cg) select cg).ToList <Garment>(); logger.DebugFormat("Found {0} garments.", lstGarments.Count); lstAccesories = (from cg in currentGarments where OutfitValidationService.IsAccessory(cg) select cg).ToList <Garment>(); logger.DebugFormat("Found {0} accesories.", lstAccesories.Count); if (lstGarments.Count == 0 || lstAccesories.Count == 0) { return(false); } if (createRecords) { closetRepository.DbContext.BeginTransaction(); this.Closet.StartProcessing(); closetRepository.SaveOrUpdate(this.Closet); closetRepository.DbContext.CommitTransaction(); } bool retVal = ExecuteSet(); if (createRecords) { closetRepository.DbContext.BeginTransaction(); this.Closet.MarkAsProcessed(); closetRepository.SaveOrUpdate(this.Closet); closetRepository.DbContext.CommitTransaction(); } return(retVal); }
public virtual void AddComponent(Garment garment, Garment hack) { int pos = OutfitValidationService.GetClosetOutfitPosition(garment); PropertyInfo pi = this.GetType().GetProperty(string.Format("Garment{0}", pos + 1)); pi.SetValue(this, garment, null); for (int i = 0; i <= 12; i++) { pi = this.GetType().GetProperty(string.Format("Garment{0}", i + 1)); if (pi.GetValue(this, null) == null) { pi.SetValue(this, hack, null); } } }
public void CanMatchColor() { Color c1 = new ColorRepository().Get(1); //Black Color c2 = new ColorRepository().Get(8); //Red Color c3 = new ColorRepository().Get(4); //Beige Color c4 = new ColorRepository().Get(24); //Dark Blue Green HashSet <Color> colors = new HashSet <Color>(); colors.Add(c1); colors.Add(c2); colors.Add(c3); colors.Add(c4); HashSet <ColorFamily> colorFamiliesHash = new HashSet <ColorFamily>(); colorFamiliesHash.Add(c1.Family); colorFamiliesHash.Add(c2.Family); colorFamiliesHash.Add(c3.Family); colorFamiliesHash.Add(c4.Family); HashSet <PatternType> pt = new HashSet <PatternType>(); pt.Add(new PatternRepository().Get(1).Type); HashSet <StructureType> st = new HashSet <StructureType>(); st.Add(StructureType.Structured); HashSet <ShapeType> sh = new HashSet <ShapeType>(); sh.Add(ShapeType.Fitted100); sh.Add(ShapeType.Fitted600Plus); StyleRule sr = new StyleRuleRepository().Get(8); Assert.IsFalse(OutfitValidationService.IsValidCombination( colorFamiliesHash, colors, pt, null, sr, null, false, false)); }
private bool ExecuteOutfitGenerator(IList <Garment> addedGarments, bool createRecords) { newGarments = null; flavorCombinations.Clear(); outfits.Clear(); logger.DebugFormat("Processing Closet {0}.", Closet.Id); this.createRecords = createRecords; if (addedGarments != null) { newGarments = new HashSet <Garment>(); foreach (Garment g in addedGarments) { newGarments.Add(g); } } lstGarments = (from cg in currentGarments where !OutfitValidationService.IsAccessory(cg) select cg).ToList(); logger.DebugFormat("Found {0} garments.", lstGarments.Count); lstAccesories = (from cg in currentGarments where OutfitValidationService.IsAccessory(cg) select cg).ToList(); logger.DebugFormat("Found {0} accesories.", lstAccesories.Count); if (lstGarments.Count == 0 || lstAccesories.Count == 0) { return(false); } bool retVal = ExecuteSet(); return(retVal); }
public override bool IsValid() { return(OutfitValidationService.IsValidCombination(this.Components)); }
/// <summary> /// Creates a new closet outfit in the system related with the current user. /// </summary> /// <param name="userId">User</param> /// <param name="garments">List of Garments</param> /// <param name="season">Season</param> /// <param name="visibility">Visibility</param> /// <exception cref="NotValidCombinationException">When a combination is not valid.</exception> public void CreateUserOutfit(int userId, IList <Garment> garments, Season season, ClosetOutfitVisibility visibility) { if (!OutfitValidationService.IsValidCombination(garments)) { throw new NotValidCombinationException(); } ClosetOutfit uo = new ClosetOutfit(); // HACK: We need the garments saved with 0 in the non filled fields to make sure we have no duplicates. Garment hack = garmentRepository.Get(0); foreach (Garment g in garments) { uo.AddComponent(g, hack); } uo.Rating.CalculateEditorRating(uo.Components); BasicUser bu = basicUserRepository.Get(userId); FashionFlavor ff = bu.GetPreferredFlavor(); uo.FashionFlavor = ff; uo.Closet = (bu as RegisteredUser).Closet; uo.SetSeason(season); uo.SetEventTypes(bu as RegisteredUser); uo.SetVisibility(visibility); //Agregar PreCombination PreCombination pc = preCombinationRepository.GetByGarments(uo.RetrieveCombinableComponents().ToList <Garment>(), ff); if (pc == null) { pc = new PreCombination(); pc.FashionFlavor = ff; for (int j = 0; j < garments.Count; j++) { Garment g = garments[j]; if (!OutfitValidationService.IsAccessory(g)) { pc.AddPreGarment(garments[j]); } } } uo.PreCombination = pc; uo.User = bu as RegisteredUser; if (!uo.IsValid()) { throw new NotValidCombinationException(); } closetOutfitRepository.DbContext.BeginTransaction(); // REVIEW: This may lead to orphaned records, given we cannot change the autonumeric for now because of the combination process. // TODO: Is better to check first if the Closet Outfit combination already exists and then proceed. preCombinationRepository.SaveOrUpdate(pc); try { closetOutfitRepository.SaveOrUpdate(uo); closetOutfitRepository.DbContext.BeginTransaction(); } catch { closetOutfitRepository.DbContext.RollbackTransaction(); throw new CombinationAlreadyExistsException(); } }
private IList <OutfitUpdaterByPreCombination> GetOutfitUpdatersByPreCombinations(IEnumerable <OutfitUpdater> outfitUpdaters, IEnumerable <PreCombination> lst) { IList <StyleRule> lstStyleRules = styleRuleRepository.GetAll(); IList <OutfitUpdaterByPreCombination> result = new List <OutfitUpdaterByPreCombination>(); // Exclude By Rules foreach (PreCombination pcb in lst) { var styleRule = from s in lstStyleRules where s.FashionFlavor.Id == pcb.FashionFlavor.Id select s; StyleRule sr = styleRule.First <StyleRule>(); logger.InfoFormat("Matching PrecombinationId : {0}", pcb.Id); foreach (OutfitUpdater outfitUpdater in outfitUpdaters) { HashSet <ColorFamily> colorFamiliesHash = new HashSet <ColorFamily>(); if (pcb.Garment1 != null && pcb.Garment1.Id != 0 && !OutfitValidationService.IsAccessory(pcb.Garment1)) { colorFamiliesHash.Add(pcb.Garment1.ColorFamily); } if (pcb.Garment2 != null && pcb.Garment2.Id != 0 && !OutfitValidationService.IsAccessory(pcb.Garment2)) { colorFamiliesHash.Add(pcb.Garment2.ColorFamily); } if (pcb.Garment3 != null && pcb.Garment3.Id != 0 && !OutfitValidationService.IsAccessory(pcb.Garment3)) { colorFamiliesHash.Add(pcb.Garment3.ColorFamily); } if (pcb.Garment4 != null && pcb.Garment4.Id != 0 && !OutfitValidationService.IsAccessory(pcb.Garment4)) { colorFamiliesHash.Add(pcb.Garment4.ColorFamily); } if (pcb.Garment5 != null && pcb.Garment5.Id != 0 && !OutfitValidationService.IsAccessory(pcb.Garment5)) { colorFamiliesHash.Add(pcb.Garment5.ColorFamily); } colorFamiliesHash.Add(outfitUpdater.ColorFamily); HashSet <PatternType> pt = new HashSet <PatternType>(); if (pcb.Garment1 != null && pcb.Garment1.Id != 0 && !OutfitValidationService.IsAccessory(pcb.Garment1)) { pt.Add(pcb.Garment1.PatternType); } if (pcb.Garment2 != null && pcb.Garment2.Id != 0 && !OutfitValidationService.IsAccessory(pcb.Garment2)) { pt.Add(pcb.Garment2.PatternType); } if (pcb.Garment3 != null && pcb.Garment3.Id != 0 && !OutfitValidationService.IsAccessory(pcb.Garment3)) { pt.Add(pcb.Garment3.PatternType); } if (pcb.Garment4 != null && pcb.Garment4.Id != 0 && !OutfitValidationService.IsAccessory(pcb.Garment4)) { pt.Add(pcb.Garment4.PatternType); } if (pcb.Garment5 != null && pcb.Garment5.Id != 0 && !OutfitValidationService.IsAccessory(pcb.Garment5)) { pt.Add(pcb.Garment5.PatternType); } pt.Add(outfitUpdater.Pattern.Type); HashSet <StructureType> st = new HashSet <StructureType>(); if (pcb.Garment1 != null && pcb.Garment1.Id != 0 && !OutfitValidationService.IsAccessory(pcb.Garment1)) { st.Add(pcb.Garment1.Silouhette.Structure.Type); } if (pcb.Garment2 != null && pcb.Garment2.Id != 0 && !OutfitValidationService.IsAccessory(pcb.Garment2)) { st.Add(pcb.Garment2.Silouhette.Structure.Type); } if (pcb.Garment3 != null && pcb.Garment3.Id != 0 && !OutfitValidationService.IsAccessory(pcb.Garment3)) { st.Add(pcb.Garment3.Silouhette.Structure.Type); } if (pcb.Garment4 != null && pcb.Garment4.Id != 0 && !OutfitValidationService.IsAccessory(pcb.Garment4)) { st.Add(pcb.Garment4.Silouhette.Structure.Type); } if (pcb.Garment5 != null && pcb.Garment5.Id != 0 && !OutfitValidationService.IsAccessory(pcb.Garment5)) { st.Add(pcb.Garment5.Silouhette.Structure.Type); } if (outfitUpdater.Silouhette.Structure != null) { st.Add(outfitUpdater.Silouhette.Structure.Type); } HashSet <ShapeType> sh = new HashSet <ShapeType>(); if (pcb.Garment1 != null && pcb.Garment1.Id != 0 && !OutfitValidationService.IsAccessory(pcb.Garment1)) { sh.Add(pcb.Garment1.Silouhette.Shape.Type); } if (pcb.Garment2 != null && pcb.Garment2.Id != 0 && !OutfitValidationService.IsAccessory(pcb.Garment2)) { sh.Add(pcb.Garment2.Silouhette.Shape.Type); } if (pcb.Garment3 != null && pcb.Garment3.Id != 0 && !OutfitValidationService.IsAccessory(pcb.Garment3)) { sh.Add(pcb.Garment3.Silouhette.Shape.Type); } if (pcb.Garment4 != null && pcb.Garment4.Id != 0 && !OutfitValidationService.IsAccessory(pcb.Garment4)) { sh.Add(pcb.Garment4.Silouhette.Shape.Type); } if (pcb.Garment5 != null && pcb.Garment5.Id != 0 && !OutfitValidationService.IsAccessory(pcb.Garment5)) { sh.Add(pcb.Garment5.Silouhette.Shape.Type); } if (outfitUpdater.Silouhette.Shape != null) { sh.Add(outfitUpdater.Silouhette.Shape.Type); } if (OutfitValidationService.IsValidCombination( colorFamiliesHash, null, pt, st, sr, sh, pcb.Garment1.Silouhette.Layers.Contains(LayerCode.Ai), OutfitValidationService.IsAccessory(outfitUpdater.Silouhette))) { result.Add(new OutfitUpdaterByPreCombination(outfitUpdater, pcb)); } } } return(result); }
public bool ExcludeCombinations(StyleRule sr, IEnumerable <Combination> lst) { foreach (Combination cb in lst) { if (!OutfitValidationService.IsValidCombination(cb, sr)) { continue; } var fabrics = new HashSet <Fabric>(); if (cb.GarmentA != null) { fabrics.Add(cb.GarmentA.Tags.Fabric); } if (cb.GarmentB != null) { fabrics.Add(cb.GarmentB.Tags.Fabric); } if (cb.GarmentC != null) { fabrics.Add(cb.GarmentC.Tags.Fabric); } if (cb.GarmentD != null) { fabrics.Add(cb.GarmentD.Tags.Fabric); } if (cb.GarmentE != null) { fabrics.Add(cb.GarmentE.Tags.Fabric); } var colors = new HashSet <Color>(); if (cb.GarmentA != null) { colors.Add(cb.GarmentA.Tags.Colors[0]); } if (cb.GarmentB != null) { colors.Add(cb.GarmentB.Tags.Colors[0]); } if (cb.GarmentC != null) { colors.Add(cb.GarmentC.Tags.Colors[0]); } if (cb.GarmentD != null) { colors.Add(cb.GarmentD.Tags.Colors[0]); } if (cb.GarmentE != null) { colors.Add(cb.GarmentE.Tags.Colors[0]); } var pt = new HashSet <PatternType>(); if (cb.GarmentA != null) { pt.Add(cb.GarmentA.Tags.Pattern.Type); } if (cb.GarmentB != null) { pt.Add(cb.GarmentB.Tags.Pattern.Type); } if (cb.GarmentC != null) { pt.Add(cb.GarmentC.Tags.Pattern.Type); } if (cb.GarmentD != null) { pt.Add(cb.GarmentD.Tags.Pattern.Type); } if (cb.GarmentE != null) { pt.Add(cb.GarmentE.Tags.Pattern.Type); } cb.EditorRating = EditorRatingCalculatorService.CalculateRating(colors, fabrics, pt); cb.FashionFlavor = sr.FashionFlavor; flavorCombinations.Add(cb); } if (flavorCombinations.Count > 0) { return(ProcessFoundCombinations(sr)); } return(false); }
private void IncludeAccesories(IEnumerable <Combination> currentCombinations, IEnumerable <Combination> accesories, int amount) { var seasons = new HashSet <int>(); var eventTypes = new HashSet <int>(); foreach (Combination comb in currentCombinations) { // Make sure there will be only 10 garments per outfit. int combinationAmount = 2; if (comb.GarmentC != null) { combinationAmount++; } if (comb.GarmentD != null) { combinationAmount++; } if (comb.GarmentE != null) { combinationAmount++; } if (combinationAmount + amount > 10) { continue; } int i = 0; foreach (Combination acc in accesories) { // Exclude combination if does not contains an added garment. if (newGarments != null) { if (!newGarments.Contains(comb.GarmentA) && !newGarments.Contains(comb.GarmentB) && !newGarments.Contains(comb.GarmentC) && !newGarments.Contains(comb.GarmentD) && !newGarments.Contains(comb.GarmentE) && !newGarments.Contains(acc.GarmentA) && !newGarments.Contains(acc.GarmentB) && !newGarments.Contains(acc.GarmentC) && !newGarments.Contains(acc.GarmentD) && !newGarments.Contains(acc.GarmentE) && !newGarments.Contains(acc.GarmentF) && !newGarments.Contains(acc.GarmentG) && !newGarments.Contains(acc.GarmentH) ) { continue; } } var outfit = new PreOutfit(); outfit.Combination = comb; outfit.Accesory1 = acc.GarmentA; outfit.Accesory2 = acc.GarmentB; outfit.Accesory3 = acc.GarmentC; outfit.Accesory4 = acc.GarmentD; outfit.Accesory5 = acc.GarmentE; outfit.Accesory6 = acc.GarmentF; outfit.Accesory7 = acc.GarmentG; outfit.Accesory8 = acc.GarmentH; if (!OutfitValidationService.IsValidOutfit(outfit, currentStyleRule, seasons, eventTypes)) { continue; } outfit.Seasons = seasons.Sum(); outfit.EventTypes = eventTypes.Sum(); outfits.Add(outfit); seasons.Clear(); eventTypes.Clear(); // Limit to 20 accesories per combination maximum. if (i >= MAX_ACCESORIES_PER_COMBINATION) { break; } i++; } } }
public void SaveToFile(IEnumerable <PreOutfit> currentOutfits) { int i = 0; var sb = new StringBuilder(lineSize * 200000, maxLineSize * maxRecords); foreach (PreOutfit po in currentOutfits) { Combination pc = po.Combination; var lb = new StringBuilder(lineSize, maxLineSize); // Add Closet & Flavor lb.Append(Closet.Id); lb.Append(","); lb.Append(pc.FashionFlavor.Id); int used = 2; // Let's setup in the correct order to avoid duplicates. var arrItems = new Garment[13]; foreach (Garment g in po.ToList()) { // Always use first silouhette to position int pos = OutfitValidationService.GetClosetOutfitPosition(g); arrItems[pos] = g; } foreach (Garment g in arrItems) { if (g != null) { lb.Append(","); lb.Append(g.Id); lb.Append(","); lb.Append(g.PreGarment.Id); used++; } else { lb.Append(","); lb.Append(@"0"); lb.Append(","); lb.Append(@"0"); } } lb.Append(","); lb.Append(po.Seasons.ToString()); lb.Append(","); lb.Append(po.EventTypes.ToString()); lb.Append(","); lb.Append(pc.EditorRating); sb.AppendLine(lb.ToString()); i++; if (i == 200000) { File.AppendAllText(Path.Combine(SharePath, fileName), sb.ToString()); sb = null; GC.Collect(); GC.WaitForPendingFinalizers(); sb = new StringBuilder(lineSize * maxRecords, maxLineSize * maxRecords); i = 0; } } if (i > 0) { File.AppendAllText(Path.Combine(SharePath, fileName), sb.ToString()); sb = null; GC.Collect(); GC.WaitForPendingFinalizers(); } }