/// <summary> /// Filters the item. /// </summary> /// <param name="item">The item.</param> /// <returns></returns> public bool FilterItem(BedData item) { bool result = BedStatusFilter.Any(x => x.IsChecked && x.BedStatus == item.BedStatus); if (item.BedStatus != BedStatus.Free) { result &= GenderFilter.Any(x => x.IsChecked && x.Gender == item.Patient.Gender); if (item.BedStatus != BedStatus.Assigned) { int days = (Today - item.Patient.AdmissionDate).Days; result &= days >= MinDays && days <= MaxDays; } if (SearchByName != null) { string searchByNameLower = _searchByName.ToLower(); result &= item.Patient.Name.ToLower().Contains(searchByNameLower); } } result &= (!HasVitalSignsMonitor || item.HasVitalSignsMonitor) && (!HasXRay || item.HasXRay); return(result); }
/// <summary> /// Generates a random <see cref="IName" />. /// </summary> /// <param name="filter">The <see cref="GenderFilter" />.</param> /// <returns> /// <see cref="IName" /> /// </returns> public IName GenerateName(GenderFilter filter) { IFirstNameData first; switch (filter) { case GenderFilter.Female: first = NameData.FirstNameData.GetRandom(x => x.Gender == Gender.Female); break; case GenderFilter.Male: first = NameData.FirstNameData.GetRandom(x => x.Gender == Gender.Male); break; case GenderFilter.Both: first = NameData.FirstNameData.GetRandom(); break; default: throw new ArgumentOutOfRangeException("filter"); } var middle = NameData.FirstNameData.GetRandom(x => x.Gender == first.Gender); var last = NameData.LastNameData.GetRandom(); return(new Name { First = first.Name, Middle = middle.Name, Last = last, Gender = first.Gender }); }
/// <summary> /// Gets the leaderboard of a segment. You can use various filters to filter the data. /// Some of the filters require a Strava Premium account! /// </summary> /// <param name="segmentId">The Strava segment Id.</param> /// <param name="weight">The weight class used to filter the leaderboard.</param> /// <param name="age">The age group used to filter the leaderboard.</param> /// <param name="time">The time used to filter the leaderboard.</param> /// <param name="gender">The gender used to filter the leaderboard.</param> /// <returns>The leaderboard filtered by gender.</returns> public async Task<Leaderboard> GetSegmentLeaderboardAsync(String segmentId, WeightFilter weight, AgeFilter age, TimeFilter time, GenderFilter gender) { int page = 1; //Create one dummy request to get the number of entries. Leaderboard request = await GetSegmentLeaderboardAsync(segmentId, weight, age, time, gender, 1, 1); int totalAthletes = request.EntryCount; Leaderboard leaderboard = new Leaderboard { EffortCount = request.EffortCount, EntryCount = request.EntryCount }; while ((page - 1) * 200 < totalAthletes) { Leaderboard l = await GetSegmentLeaderboardAsync(segmentId, weight, age, time, gender, page++, 200); foreach (LeaderboardEntry entry in l.Entries) { leaderboard.Entries.Add(entry); } } return leaderboard; }
public IGeneratorConfiguration IncludeName(GenderFilter filter) { NameIncluded = true; GenderFilter = filter; ExternalNameData = null; return(this); }
public IGeneratorConfiguration IncludeName(GenderFilter filter) { NameIncluded = true; GenderFilter = filter; ExternalNameData = null; return this; }
/// <summary> /// Converts the gender filter object to the appropriate string. /// </summary> /// <param name="gender">The gender filter.</param> /// <returns>The appropriate string for the specified filter.</returns> public static String GenderFilterToString(GenderFilter gender) { switch (gender) { case GenderFilter.Male: return "M"; case GenderFilter.Female: return "F"; default: return String.Empty; } }
public void Configure_IncludeName_Specify_GenderFilter(GenderFilter filter) { // Act var generator = Generator.Configure() .IncludeName(filter) .Build(); // Assert Assert.Equal(filter, generator.Genders); Assert.True(generator.IncludeName); Assert.True(((Generator)generator).NameData.FirstNameData.Any()); Assert.Equal(filter, ((Generator)generator).NameData.GenderFilter); Assert.True(((Generator)generator).NameData.LastNameData.Any()); }
public void GenerateName(GenderFilter filter) { // Arrange var list = new List <IName>(); // Act for (var i = 0; i < MAX_LOOP; i++) { list.Add(_generator.GenerateName(filter)); } // Assert Assert.Equal(MAX_LOOP, list.Distinct().Count()); }
public void GenerateName(GenderFilter filter) { // Arrange var list = new List<IName>(); // Act for (var i = 0; i < MAX_LOOP; i++) { list.Add(_generator.GenerateName(filter)); } // Assert Assert.Equal(MAX_LOOP, list.Distinct().Count()); }
/// <summary> /// Converts the gender filter object to the appropriate string. /// </summary> /// <param name="gender">The gender filter.</param> /// <returns>The appropriate string for the specified filter.</returns> public static String GenderFilterToString(GenderFilter gender) { switch (gender) { case GenderFilter.Male: return("M"); case GenderFilter.Female: return("F"); default: return(String.Empty); } }
public static IFilter GetFilter(eFilter i_Filter, string i_Text) { IFilter filter; if (i_Filter == eFilter.AGE) { filter = new AgeFilter(i_Text); } else { filter = new GenderFilter(i_Text); } return(filter); }
protected void chbxListGenders_SelectedIndexChanged(object sender, EventArgs e) { CheckBoxList list = (CheckBoxList)sender; GenderFilter filter = new GenderFilter(); _genderFilters = new List <GenderFilterItem>(); list.Items.Cast <ListItem>() .Where(li => li.Selected) .ToList() .ForEach(x => _genderFilters.Add((GenderFilterItem)filter.GetFilterItem(x.Value.ToString()))); Cache[GENDER_FILTER_CACHE_KEY] = _genderFilters; BindData(); }
public Leaderboard GetSegmentLeaderboard(string segmentId, bool following, WeightFilter weight, AgeFilter age, TimeFilter time, GenderFilter gender) { int num = 1; Leaderboard segmentLeaderboard = GetSegmentLeaderboard(segmentId, following, weight, age, time, gender, 1, 1); int entryCount = segmentLeaderboard.EntryCount; Leaderboard leaderboard = new Leaderboard { EffortCount = segmentLeaderboard.EffortCount, EntryCount = segmentLeaderboard.EntryCount }; while ((num - 1) * 200 < entryCount) { Leaderboard segmentLeaderboard2 = GetSegmentLeaderboard(segmentId, following, weight, age, time, gender, num++, 200); foreach (LeaderboardEntry entry in segmentLeaderboard2.Entries) { leaderboard.Entries.Add(entry); } } return(leaderboard); }
/// <summary> /// Gets the leaderboard of a segment. You can use various filters to filter the data. /// Some of the filters require a Strava Premium account! /// </summary> /// <param name="segmentId">The Strava segment Id.</param> /// <param name="weight">The weight class used to filter the leaderboard.</param> /// <param name="age">The age group used to filter the leaderboard.</param> /// <param name="time">The time used to filter the leaderboard.</param> /// <param name="gender">The gender used to filter the leaderboard.</param> /// <param name="page">The result page.</param> /// <param name="perPage">Efforts shown per page.</param> /// <returns>The leaderboard filtered by gender.</returns> public async Task<Leaderboard> GetSegmentLeaderboardAsync(String segmentId, WeightFilter weight, AgeFilter age, TimeFilter time, GenderFilter gender, int page, int perPage) { bool useGender = false; bool useTime = false; bool useAge = false; bool useWeight = false; String genderFilter = String.Empty; String timeFilter = String.Empty; String ageFilter = String.Empty; String weightFilter = String.Empty; if (!String.IsNullOrEmpty(StringConverter.GenderFilterToString(gender))) { genderFilter = String.Format("gender={0}", StringConverter.GenderFilterToString(gender)); useGender = true; } if (!String.IsNullOrEmpty(StringConverter.TimeFilterToString(time))) { timeFilter = String.Format("date_range={0}", StringConverter.TimeFilterToString(time)); useTime = true; } if (!String.IsNullOrEmpty(StringConverter.AgeFilterToString(age))) { ageFilter = String.Format("age_group={0}", StringConverter.AgeFilterToString(age)); useAge = true; } if (!String.IsNullOrEmpty(StringConverter.WeightFilterToString(weight))) { weightFilter = String.Format("weight_class={0}", StringConverter.WeightFilterToString(weight)); useWeight = true; } String getUrl = String.Format("{0}/{1}/leaderboard?{2}&{3}&{4}&{5}&page={6}&per_page={7}&access_token={8}", Endpoints.Leaderboard, segmentId, useGender ? genderFilter : String.Empty, useTime ? timeFilter : String.Empty, useAge ? ageFilter : String.Empty, useWeight ? weightFilter : String.Empty, page, perPage, Authentication.AccessToken ); String json = await WebRequest.SendGetAsync(new Uri(getUrl)); return Unmarshaller<Leaderboard>.Unmarshal(json); }
/// <summary> /// Gets the leaderboard of a segment. You can use various filters to filter the data. /// Some of the filters require a Strava Premium account! /// </summary> /// <param name="segmentId">The Strava segment Id.</param> /// <param name="weight">The weight class used to filter the leaderboard.</param> /// <param name="age">The age group used to filter the leaderboard.</param> /// <param name="time">The time used to filter the leaderboard.</param> /// <param name="gender">The gender used to filter the leaderboard.</param> /// <param name="page">The result page.</param> /// <param name="perPage">Efforts shown per page.</param> /// <returns>The leaderboard filtered by gender.</returns> public async Task <Leaderboard> GetSegmentLeaderboardAsync(string segmentId, WeightFilter weight, AgeFilter age, TimeFilter time, GenderFilter gender, int page, int perPage) { bool useGender = false; bool useTime = false; bool useAge = false; bool useWeight = false; string genderFilter = string.Empty; string timeFilter = string.Empty; string ageFilter = string.Empty; string weightFilter = string.Empty; if (!string.IsNullOrEmpty(StringConverter.GenderFilterToString(gender))) { genderFilter = string.Format("gender={0}", StringConverter.GenderFilterToString(gender)); useGender = true; } if (!string.IsNullOrEmpty(StringConverter.TimeFilterToString(time))) { timeFilter = string.Format("date_range={0}", StringConverter.TimeFilterToString(time)); useTime = true; } if (!string.IsNullOrEmpty(StringConverter.AgeFilterToString(age))) { ageFilter = string.Format("age_group={0}", StringConverter.AgeFilterToString(age)); useAge = true; } if (!string.IsNullOrEmpty(StringConverter.WeightFilterToString(weight))) { weightFilter = string.Format("weight_class={0}", StringConverter.WeightFilterToString(weight)); useWeight = true; } string getUrl = string.Format("{0}/{1}/leaderboard?{2}&{3}&{4}&{5}&page={6}&per_page={7}&access_token={8}", Endpoints.Leaderboard, segmentId, useGender ? genderFilter : string.Empty, useTime ? timeFilter : string.Empty, useAge ? ageFilter : string.Empty, useWeight ? weightFilter : string.Empty, page, perPage, AuthSettings.ScopeAccessToken ); string json = await StravaUWP.Helper.HttpHelper.GetRequestAsync(getUrl);; return(Unmarshaller <Leaderboard> .Unmarshal(json)); }
/// <summary> /// Gets the leaderboard of a segment. You can use various filters to filter the data. /// Some of the filters require a Strava Premium account! /// </summary> /// <param name="segmentId">The Strava segment Id.</param> /// <param name="following">The leaderboard only shows athletes you're following.</param> /// <param name="weight">The weight class used to filter the leaderboard.</param> /// <param name="age">The age group used to filter the leaderboard.</param> /// <param name="time">The time used to filter the leaderboard.</param> /// <param name="gender">The gender used to filter the leaderboard.</param> /// <returns>The leaderboard filtered by gender.</returns> public Leaderboard GetSegmentLeaderboard(string segmentId, bool following, WeightFilter weight, AgeFilter age, TimeFilter time, GenderFilter gender) { int page = 1; //Create one dummy request to get the number of entries. Leaderboard request = GetSegmentLeaderboard(segmentId, following, weight, age, time, gender, 1, 1); int totalAthletes = request.EntryCount; Leaderboard leaderboard = new Leaderboard { EffortCount = request.EffortCount, EntryCount = request.EntryCount }; while ((page - 1) * 200 < totalAthletes) { Leaderboard l = GetSegmentLeaderboard(segmentId, following, weight, age, time, gender, page++, 200); foreach (LeaderboardEntry entry in l.Entries) { leaderboard.Entries.Add(entry); } } return(leaderboard); }
private void buttonSeedGenerate_Click(object sender, EventArgs e) { if (!ParametersInputCheck()) { return; } #region Initialize if (comboBoxNature.Text == "Any") { MessageBox.Show("Please select a specific list of natures."); return; } List <uint> natures = (from t in comboBoxNature.CheckBoxItems where t.Checked select(uint) ((Nature)t.ComboBoxItem).Number). ToList(); var profile = (Profile)comboBoxProfiles.SelectedItem; uint mac_partial = (uint)profile.MAC_Address & 0xFFFFFF; uint minFrame = uint.Parse(maskedTextBoxCapMinOffset.Text); uint maxFrame = uint.Parse(maskedTextBoxCapMaxOffset.Text); uint groupSize = uint.Parse(maskedTextBoxGroupSize.Text); uint seedCGear = uint.Parse(textBoxSeed.Text, NumberStyles.HexNumber); int generateYear = int.Parse(maskedTextBoxYear.Text); if (generateYear < 2000 || generateYear > 2099) { MessageBox.Show("Year must be a value between 2000 and 2099, inclusive."); return; } uint frameCGear = uint.Parse(maskedTextBoxCGearFrame.Text); //generate the CGear Seed Times uint ab = seedCGear - mac_partial >> 24; uint cd = (seedCGear - mac_partial & 0x00FF0000) >> 16; uint efgh = seedCGear - mac_partial & 0x0000FFFF; // Get Delay uint delay = efgh + (uint)(2000 - generateYear); // Get Calibration uint calibration = uint.Parse(maskedTextBoxDelayCalibration.Text); // Store the Calibrated Delay and offset uint calibratedDelay = delay + calibration; long offset = -calibratedDelay / 60; // Get Hour var hour = (int)cd; // We need to check here, as a user could have entered a seed // that is not possible (invalid hour) to lets warn and exit // on it. if (hour > 23) { MessageBox.Show("This seed is invalid, please verify that you have entered it correctly and try again.", "Invalid Seed", MessageBoxButtons.OK); return; } maskedTextBoxDelay.Text = delay.ToString(CultureInfo.InvariantCulture); List <List <ButtonComboType> > keypresses = GetKeypresses(); iframes = new List <IFrameCapture>(); var generator = new FrameGenerator { InitialSeed = seedCGear, FrameType = FrameType.Method5CGear, InitialFrame = frameCGear, MaxResults = 1 }; GenderFilter genderFilter = checkBoxGenderless.Checked ? new GenderFilter("Genderless", 0xFF, GenderCriteria.DontCareGenderless) : new GenderFilter("Gendered", 0, GenderCriteria.DontCareGenderless); var possibleDates = new List <DateTime>(); // Loop through all months for (int month = 1; month <= 12; month++) { int daysInMonth = DateTime.DaysInMonth(generateYear, month); // Loop through all days for (int day = 1; day <= daysInMonth; day++) { // Loop through all minutes for (int minute = 0; minute <= 59; minute++) { // Loop through all seconds for (int second = 0; second <= 59; second++) { if (ab != ((month * day + minute + second) % 0x100)) { continue; } var dateTime = new DateTime(generateYear, month, day, hour, minute, second); // Standard seed time will be the C-Gear seed time, minus the delay // We'll skip seeds that cross over into the next day and cause unwanted advances // Added calibration to the delay to account for the fact that people aren't perfectly fast DateTime possibleDate = dateTime.AddSeconds(offset); if (dateTime.Day == possibleDate.Day) { possibleDates.Add(possibleDate); } } } } } // Generate the IVs for the corresponding C-Gear seed first var rngIVs = new uint[6]; frameCompare = new FrameCompare( 0, CompareType.None, 0, CompareType.None, 0, CompareType.None, 0, CompareType.None, 0, CompareType.None, 0, CompareType.None, null, -1, false, false, false, null, new NoGenderFilter()); List <Frame> IVs = generator.Generate(frameCompare, 0, 0); if (IVs.Count > 0) { rngIVs[0] = IVs[0].Hp; rngIVs[1] = IVs[0].Atk; rngIVs[2] = IVs[0].Def; rngIVs[3] = IVs[0].Spa; rngIVs[4] = IVs[0].Spd; rngIVs[5] = IVs[0].Spe; } // Now that each combo box item is a custom object containing the FrameType reference // We can simply retrieve the FrameType from the selected item generator.FrameType = FrameType.Method5Natures; generator.EncounterType = EncounterType.Entralink; generator.RNGIVs = rngIVs; generator.InitialFrame = minFrame; generator.MaxResults = maxFrame - minFrame + 1; frameCompare = new FrameCompare( 0, CompareType.None, 0, CompareType.None, 0, CompareType.None, 0, CompareType.None, 0, CompareType.None, 0, CompareType.None, null, -1, false, false, false, null, new NoGenderFilter()); frameCompare = new FrameCompare( 0, CompareType.None, 0, CompareType.None, 0, CompareType.None, 0, CompareType.None, 0, CompareType.None, 0, CompareType.None, natures, -1, false, false, false, null, genderFilter); #endregion waitHandle = new EventWaitHandle(true, EventResetMode.ManualReset); jobs = new Thread[cpus]; //divide the possible times into even groups int split = possibleDates.Count / cpus; for (int i = 0; i < cpus; ++i) { List <DateTime> dates = i < cpus - 1 ? possibleDates.GetRange(i * split, split) : possibleDates.GetRange(i * split, split + possibleDates.Count % cpus); //if the last i make sure we add the remainder as well // technically supposed to copy profile and send in a copy because now the threads are // using a reference to the same profile but that's fine because the profile isn't getting // mutated anyway jobs[i] = new Thread( () => Generate(generator.Clone(), dates, minFrame, maxFrame, profile, groupSize, calibratedDelay)); jobs[i].Start(); } listBindingCap = new BindingSource { DataSource = iframes }; dataGridViewCapValues.DataSource = listBindingCap; progressTotal = (ulong) (maxFrame - minFrame + 1) * (profile.Timer0Max - profile.Timer0Min + 1) * (ulong)keypresses.Count * (ulong)possibleDates.Count; var progressJob = new Thread(() => ManageProgress(listBindingCap, dataGridViewCapValues, generator.FrameType, 0)); progressJob.Start(); progressJob.Priority = ThreadPriority.Lowest; buttonSeedGenerate.Enabled = false; }
internal void LoadInternalNameData(GenderFilter genderFilter) { string line; var firstNames = new List <IFirstNameData>(); var lastNames = new List <string>(); using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("EfficientlyLazy.IdentityGenerator.DataFiles.NamesFirst.data")) { if (stream == null) { throw new InvalidOperationException("NamesFirst.data Embedded Resource Not Found"); } using (var cr = new GZipStream(stream, CompressionMode.Decompress)) { using (var sr = new StreamReader(cr)) { while ((line = sr.ReadLine()) != null) { var parts = line.Split('|'); switch (parts[1]) { case "M": // Male firstNames.Add(new FirstNameData { Gender = Gender.Male, Name = parts[0] }); break; case "F": // Female firstNames.Add(new FirstNameData { Gender = Gender.Female, Name = parts[0] }); break; case "B": // Male or Female firstNames.Add(new FirstNameData { Gender = Gender.Male, Name = parts[0] }); firstNames.Add(new FirstNameData { Gender = Gender.Female, Name = parts[0] }); break; default: throw new InvalidOperationException(string.Format("Invalid Line: '{0}'", line)); } } } } } using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("EfficientlyLazy.IdentityGenerator.DataFiles.NamesLast.data")) { if (stream == null) { throw new InvalidOperationException("NamesLast.txt Embedded Resource Not Found"); } using (var cr = new GZipStream(stream, CompressionMode.Decompress)) { using (var sr = new StreamReader(cr)) { while ((line = sr.ReadLine()) != null) { lastNames.Add(line); } } } } NameData = new NameData { FirstNameData = firstNames, GenderFilter = genderFilter, LastNameData = lastNames }; }
public async Task <Leaderboard> GetSegmentLeaderboardAsync(string segmentId, int clubId, WeightFilter weight, AgeFilter age, TimeFilter time, GenderFilter gender) { int page = 1; Leaderboard request = await GetSegmentLeaderboardAsync(segmentId, clubId, weight, age, time, gender, 1, 1); int totalAthletes = request.EntryCount; Leaderboard leaderboard = new Leaderboard { EffortCount = request.EffortCount, EntryCount = request.EntryCount }; while ((page - 1) * 200 < totalAthletes) { foreach (LeaderboardEntry entry in (await GetSegmentLeaderboardAsync(segmentId, clubId, weight, age, time, gender, page++, 200)).Entries) { leaderboard.Entries.Add(entry); } } return(leaderboard); }
public Leaderboard GetSegmentLeaderboard(string segmentId, bool following, WeightFilter weight, AgeFilter age, TimeFilter time, GenderFilter gender, int page, int perPage) { bool flag = false; bool flag2 = false; bool flag3 = false; bool flag4 = false; string text = string.Empty; string text2 = string.Empty; string text3 = string.Empty; string text4 = string.Empty; if (!string.IsNullOrEmpty(StringConverter.GenderFilterToString(gender))) { text = $"gender={StringConverter.GenderFilterToString(gender)}"; flag = true; } if (!string.IsNullOrEmpty(StringConverter.TimeFilterToString(time))) { text2 = $"date_range={StringConverter.TimeFilterToString(time)}"; flag2 = true; } if (!string.IsNullOrEmpty(StringConverter.AgeFilterToString(age))) { text3 = $"age_group={StringConverter.AgeFilterToString(age)}"; flag3 = true; } if (!string.IsNullOrEmpty(StringConverter.WeightFilterToString(weight))) { text4 = $"weight_class={StringConverter.WeightFilterToString(weight)}"; flag4 = true; } string uriString = string.Format("{0}/{1}/leaderboard?{2}&{3}&{4}&{5}&following={6}&page={7}&per_page={8}&access_token={9}", "https://www.strava.com/api/v3/segments", segmentId, flag ? text : string.Empty, flag2 ? text2 : string.Empty, flag3 ? text3 : string.Empty, flag4 ? text4 : string.Empty, following, page, perPage, Authentication.AccessToken); string json = WebRequest.SendGet(new Uri(uriString)); return(Unmarshaller <Leaderboard> .Unmarshal(json)); }
public async Task <Leaderboard> GetSegmentLeaderboardAsync(string segmentId, WeightFilter weight, AgeFilter age, TimeFilter time, GenderFilter gender, int page, int perPage) { bool useGender = false; bool useTime = false; bool useAge = false; bool useWeight = false; string genderFilter = string.Empty; string timeFilter = string.Empty; string ageFilter = string.Empty; string weightFilter = string.Empty; if (!string.IsNullOrEmpty(StringConverter.GenderFilterToString(gender))) { genderFilter = $"gender={StringConverter.GenderFilterToString(gender)}"; useGender = true; } if (!string.IsNullOrEmpty(StringConverter.TimeFilterToString(time))) { timeFilter = $"date_range={StringConverter.TimeFilterToString(time)}"; useTime = true; } if (!string.IsNullOrEmpty(StringConverter.AgeFilterToString(age))) { ageFilter = $"age_group={StringConverter.AgeFilterToString(age)}"; useAge = true; } if (!string.IsNullOrEmpty(StringConverter.WeightFilterToString(weight))) { weightFilter = $"weight_class={StringConverter.WeightFilterToString(weight)}"; useWeight = true; } string getUrl = string.Format("{0}/{1}/leaderboard?{2}&{3}&{4}&{5}&page={6}&per_page={7}&access_token={8}", "https://www.strava.com/api/v3/segments", segmentId, useGender ? genderFilter : string.Empty, useTime ? timeFilter : string.Empty, useAge ? ageFilter : string.Empty, useWeight ? weightFilter : string.Empty, page, perPage, Authentication.AccessToken); return(Unmarshaller <Leaderboard> .Unmarshal(await WebRequest.SendGetAsync(new Uri(getUrl)))); }
/// <summary> /// Gets the leaderboard of a segment. You can use various filters to filter the data. /// Some of the filters require a Strava Premium account! /// </summary> /// <param name="segmentId">The Strava segment Id.</param> /// <param name="following">The leaderboard only shows athletes you're following.</param> /// <param name="weight">The weight class used to filter the leaderboard.</param> /// <param name="age">The age group used to filter the leaderboard.</param> /// <param name="time">The time used to filter the leaderboard.</param> /// <param name="gender">The gender used to filter the leaderboard.</param> /// <param name="page">The result page.</param> /// <param name="perPage">Efforts shown per page.</param> /// <returns>The leaderboard filtered by gender.</returns> public Leaderboard GetSegmentLeaderboard(string segmentId, bool following, WeightFilter weight, AgeFilter age, TimeFilter time, GenderFilter gender, int page, int perPage) { bool useGender = false; bool useTime = false; bool useAge = false; bool useWeight = false; string genderFilter = string.Empty; string timeFilter = string.Empty; string ageFilter = string.Empty; string weightFilter = string.Empty; if (!string.IsNullOrEmpty(StringConverter.GenderFilterToString(gender))) { genderFilter = string.Format("gender={0}", StringConverter.GenderFilterToString(gender)); useGender = true; } if (!string.IsNullOrEmpty(StringConverter.TimeFilterToString(time))) { timeFilter = string.Format("date_range={0}", StringConverter.TimeFilterToString(time)); useTime = true; } if (!string.IsNullOrEmpty(StringConverter.AgeFilterToString(age))) { ageFilter = string.Format("age_group={0}", StringConverter.AgeFilterToString(age)); useAge = true; } if (!string.IsNullOrEmpty(StringConverter.WeightFilterToString(weight))) { weightFilter = string.Format("weight_class={0}", StringConverter.WeightFilterToString(weight)); useWeight = true; } string getUrl = string.Format("{0}/{1}/leaderboard?{2}&{3}&{4}&{5}&following={6}&page={7}&per_page={8}&access_token={9}", Endpoints.Leaderboard, segmentId, useGender ? genderFilter : string.Empty, useTime ? timeFilter : string.Empty, useAge ? ageFilter : string.Empty, useWeight ? weightFilter : string.Empty, following, page, perPage, Authentication.AccessToken ); string json = WebRequest.SendGet(new Uri(getUrl)); return(Unmarshaller <Leaderboard> .Unmarshal(json)); }
internal void LoadInternalNameData(GenderFilter genderFilter) { string line; var firstNames = new List<IFirstNameData>(); var lastNames = new List<string>(); using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("EfficientlyLazy.IdentityGenerator.DataFiles.NamesFirst.data")) { if (stream == null) { throw new InvalidOperationException("NamesFirst.data Embedded Resource Not Found"); } using (var cr = new GZipStream(stream, CompressionMode.Decompress)) { using (var sr = new StreamReader(cr)) { while ((line = sr.ReadLine()) != null) { var parts = line.Split('|'); switch (parts[1]) { case "M": // Male firstNames.Add(new FirstNameData { Gender = Gender.Male, Name = parts[0] }); break; case "F": // Female firstNames.Add(new FirstNameData { Gender = Gender.Female, Name = parts[0] }); break; case "B": // Male or Female firstNames.Add(new FirstNameData { Gender = Gender.Male, Name = parts[0] }); firstNames.Add(new FirstNameData { Gender = Gender.Female, Name = parts[0] }); break; default: throw new InvalidOperationException(string.Format("Invalid Line: '{0}'", line)); } } } } } using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("EfficientlyLazy.IdentityGenerator.DataFiles.NamesLast.data")) { if (stream == null) { throw new InvalidOperationException("NamesLast.txt Embedded Resource Not Found"); } using (var cr = new GZipStream(stream, CompressionMode.Decompress)) { using (var sr = new StreamReader(cr)) { while ((line = sr.ReadLine()) != null) { lastNames.Add(line); } } } } NameData = new NameData { FirstNameData = firstNames, GenderFilter = genderFilter, LastNameData = lastNames }; }
/// <summary> /// Generates a random <see cref="IName" />. /// </summary> /// <param name="filter">The <see cref="GenderFilter" />.</param> /// <returns> /// <see cref="IName" /> /// </returns> public IName GenerateName(GenderFilter filter) { IFirstNameData first; switch (filter) { case GenderFilter.Female: first = NameData.FirstNameData.GetRandom(x => x.Gender == Gender.Female); break; case GenderFilter.Male: first = NameData.FirstNameData.GetRandom(x => x.Gender == Gender.Male); break; case GenderFilter.Both: first = NameData.FirstNameData.GetRandom(); break; default: throw new ArgumentOutOfRangeException("filter"); } var middle = NameData.FirstNameData.GetRandom(x => x.Gender == first.Gender); var last = NameData.LastNameData.GetRandom(); return new Name { First = first.Name, Middle = middle.Name, Last = last, Gender = first.Gender }; }