public static void UpdateGrade(Zlaggable zlaggable) { // get amount of ascents // var totalAscents = Ascents. // get average of grades var source = zlaggable is Route ? routeGrades : boulderGrades; if (source.ContainsKey(zlaggable.Id.Value)) { var grades = source[zlaggable.Id.Value]; // calculate average index var gradeCount = grades.Count; var gradeIndexSum = grades.Sum(); var avg = (int)Math.Round((decimal)gradeIndexSum / gradeCount, 0, MidpointRounding.AwayFromZero); var grade = GetGradigSystemByIndex(avg, zlaggable is Route); if (grade == null) { Console.WriteLine("no grade found for zlaggable id: " + zlaggable.Id + "(" + zlaggable.Slug + ")"); return; } if (zlaggable.Grade != grade.VLGrade) { Console.WriteLine("updating zlaggable id " + zlaggable.Id + "-" + (zlaggable is Route).ToString() + " grade from '" + zlaggable.Difficulty + "/" + zlaggable.Grade + "' to '" + grade.Grade + "/" + grade.VLGrade + "'"); zlaggable.Difficulty = grade.Grade; zlaggable.Grade = grade.VLGrade; } } }
public static Zlaggable GetThingie(int sectorId, string name, int category) { Zlaggable thingie = null; var key = string.Join("-", new object[] { sectorId, name.Trim().ToLower() }); var coll = category == 0 ? Routes : Boulders; if (coll.ContainsKey(key)) { thingie = coll[key]; } return(thingie); }
private Api.Common.DataEntities.Ascent HandleScore(Score score) { currentScoreId = Convert.ToInt32(score.Id); ind++; if (ind % 10000 == 0) { Console.Write(". " + (++logTimes * 10000).ToString("#,##0")); Console.WriteLine("crags: {0}, sectors: {1}, b: {2}, r: {3}, a: {4}", new object[] { SeedStore.CragCount, SeedStore.SectorCount, SeedStore.BoulderCount, SeedStore.RouteCount, SeedStore.AscentCount }); } else if (ind % 10000 == 0) { Console.Write("."); } // todo: unicode crag name, look for &234 without ; and remove spaces // todo: only do the unicode check if we create a new one // todo: find out does old 8a get routes difficulty from the first ascent in score DB? Crag crag = null; Sector sector = null; Zlaggable thingie = null; var scoreHasCountry = false; var scoreHasRouteOrBoulderName = false; var scoreHasCragName = false; var scoreHasSectorName = false; var cragName = getValue(score.Crag, "Unknown Crag", out scoreHasCragName); var sectorName = getValue(score.CragSector, "Unknown Sector", out scoreHasSectorName); var routeName = getValue(score.Name, "Unknown ", out scoreHasRouteOrBoulderName); if (!scoreHasRouteOrBoulderName) { var ending = score.What == 0 ? "route" : "boulder"; routeName += ending; } var verticalCategory = score.What == 0 ? SeedStore.CATEGORY_SPORTSCLIMBING : SeedStore.CATEGORY_BOULDERING; var verticalAscentCategory = score.What == 0 ? SeedStore.ASCENT_CATEGORY_ROUTE : SeedStore.ASCENT_CATEGORY_BOULDER; var scoreHasCrag = false; var scoreHasSector = false; var scoreHasRouteOrBoulder = false; var countryId = -1; // get user var user = SeedStore.GetUser(Convert.ToInt32(score.UserId)); if (user == null) { Console.WriteLine("score id: " + score.Id.ToString() + " USER DatabaseId: " + score.UserId.ToString() + " NOT FOUND!"); return(null); } // // get country - default to users country // var countryISO3 = score.Country; try { if (!string.IsNullOrEmpty(countryISO3)) { countryId = SeedStore.GetCountryId(score.Country); scoreHasCountry = true; } else { // if scores country is null, get users country // this will be used if we create new crag countryId = user.CountryId; } } catch { Console.WriteLine("trouble getting country for score id: " + score.Id + " - countryISO3: " + countryISO3); countryId = user.CountryId; } if (scoreHasCragName) { // get crag by name only crag = SeedStore.GetCragOnlyByName(score.Crag, verticalCategory); } else { crag = SeedStore.GetCrag(cragName, verticalCategory, countryId); } /* * // get existing crag * if (scoreHasCountry && scoreHasCragName) * { * // look for crag first by country * crag = SeedStore.GetCrag(score.Crag, verticalCategory, countryId); * * scoreHasCrag |= crag != null; * * // todo: * // optional: get existing crag with different category * } * else if (scoreHasCragName) * { * // score has no country defined .. so we just look for the crag name * crag = SeedStore.GetCragOnlyByName(score.Crag, verticalCategory); * } */ // im here with my performance tests: // return null; // create crag if we still don't have one if (crag == null) { var cragId = ++SeedStore.MaxCragId; var now = DateTime.Now; crag = new Crag { Id = cragId, Slug = cragName.ToSlug(postString: cragId.ToString()), Category = verticalCategory, Name = cragName, CountryId = countryId, DateCreated = now, DateModified = now, Published = true }; SeedStore.AddCrag(crag); } // get existing sector if score happens to have a crag //if (scoreHasCrag) //{ sector = SeedStore.GetSector(crag.Id.Value, sectorName); scoreHasSector |= sector != null; //} // create sector if nothing found if (sector == null) { var now = DateTime.Now; // create new sector var sectorId = ++SeedStore.MaxSectorId; sector = new Sector { Id = sectorId, Slug = "", CragId = crag.Id.Value, Name = sectorName, Category = verticalCategory, DateCreated = now, DateModified = now }; SeedStore.AddSector(sector); } // only try to get existing "climbablethingie" if there is already a sector //if (scoreHasSector) //{ thingie = SeedStore.GetThingie(sector.Id.Value, routeName, score.What); scoreHasRouteOrBoulder |= thingie != null; //} // get grading system to be used for using with route/boulder and ascent var gradingSystem = getGradingSystem(score.Grade, score.What); // no thingie (route or boulder) so we make new one if (thingie == null) { var now = DateTime.Now; if (score.What == 0) // could check for category but let's speed things up { //if (!scoreHasRouteOrBoulderName) //{ // routeName += "route"; //} var routeId = ++SeedStore.MaxRouteId; thingie = new Route { Id = routeId, Name = routeName, Slug = "", SectorId = sector.Id.Value }; SeedStore.AddRoute(thingie); } else { //if (!scoreHasRouteOrBoulderName) //{ // routeName += "boulder"; //} var boulderId = ++SeedStore.MaxBoulderId; thingie = new Boulder { Id = boulderId, Name = routeName, Slug = "", SectorId = sector.Id.Value }; SeedStore.AddBoulder(thingie); } thingie.DateCreated = now; thingie.DateModified = now; thingie.Difficulty = gradingSystem.Grade; // 6a+ thingie.Grade = gradingSystem.VLGrade; // vl-1-39 thingie.GradingSystem = gradingSystem.Type; // french } SeedStore.AddGrade(thingie.Id.Value, gradingSystem, score.What == 0 ? ZlaggableCategoryEnum.Sportclimbing : ZlaggableCategoryEnum.Bouldering); var objectClassLength = score.ObjectClass.Length; // comparing lenghts so it's a bit faster // lengths // 14 = CLS_UserAscent // 22 = CLS_UserAscent_Project // 18 = CLS_UserAscent_Try var type = ""; if (objectClassLength != 18) { type = getVerticalAscentType(score.How); } else { type = "go"; } var isProject = objectClassLength == 22; // create ascent var ascent = new Ascent { Id = ++SeedStore.MaxAscentId, UserId = user.Id.Value, Date = ParseScoreDate(score.Date), // climbed that shit date Difficulty = gradingSystem.Grade, // eg. 8a+ ZlaggableId = thingie.Id, // ID of route or boulder ZlaggableType = verticalAscentCategory, // route / boulder Comment = score.Comment, // user comment Score = score.TotalScore, Type = type, // f, os, tr, rp, go Rating = score.Rate, Repeat = score.Repeat == 1 ? true : false, Project = isProject, Chipped = score.Chipped == 1, ExcludeFromRanking = score.ExcludeFromRanking == 1, Note = Convert.ToInt32(score.Fa), DateCreated = score.RecDate, DateModified = score.RecDate, Recommended = score.UserRecommended == 1, LegacyId = (int)score.Id // todo: userRecommended to Route "likes" // todo: what to do with projectAscentDate? // todo: what to do with YellowId // variations -> not used // steepness -> not used // altgrade -> not used }; //SeedStore.Ascents.Add(ascent); return(ascent); }
public static void AddThingie(Zlaggable thingie, Dictionary <string, Zlaggable> coll) { var key = string.Join("-", new object[] { thingie.SectorId, thingie.Name.Trim().ToLower() }); coll.Add(key, thingie); }
public static void AddBoulder(Zlaggable thingie) { BoulderCount++; AddThingie(thingie, Boulders); }
public static void AddRoute(Zlaggable thingie) { RouteCount++; AddThingie(thingie, Routes); }