Skip to main content
added 9 characters in body
Source Link

Good question! The years of experience calculation is pretty basicnot especially clever - it just looks at the experience entries in your Dev Story and adds up their lengths, while accounting for overlaps and gaps. (If you had two jobs concurrently in 2016, that should still count for only one year of experience. Likewise, if you took a career break that shouldn't count towards your years of experience.)

Good question! The years of experience calculation is pretty basic - it just looks at the experience entries in your Dev Story and adds up their lengths, while accounting for overlaps and gaps. (If you had two jobs concurrently in 2016, that should still count for only one year of experience. Likewise, if you took a career break that shouldn't count towards your years of experience.)

Good question! The years of experience calculation is not especially clever - it just looks at the experience entries in your Dev Story and adds up their lengths, while accounting for overlaps and gaps. (If you had two jobs concurrently in 2016, that should still count for only one year of experience. Likewise, if you took a career break that shouldn't count towards your years of experience.)

Highlight the code so it’s easier to read
Source Link
Jed Fox
  • 3k
  • 3
  • 21
  • 30
public static int CalculateYearsOfExperience(this CandidateSearchCv profile, DateTime utcNow)
{
    IEnumerable<DateRange> MergeOverlaps(IEnumerable<DateRange> dateRanges)
    {
        // The idea is to find contiguous clusters of overlapping date ranges and merge them into a single range.
        //
        // 2009  2010  2011  2012  2013  2014  2015  2016
        //  |-----------|     |-----------|     |-----|
        //        |-----------------|
        //                  |
        //                  |
        //                  V
        //  |-----------------------------|     |-----|
        //
        // This implementation is probably far from optimal but I don't expect dateRanges to ever be large:
        // even the most prolific Dev Story authors will only have a few dozen experience entries.


        var result = new List<DateRange>();

        foreach (var range in dateRanges)
        {
            var (overlapping, nonOverlapping) = result.Partition(range.Overlaps, (t, f) => (t.ToList(), f.ToList()));

            overlapping.Add(range);  // a range always overlaps itself
            nonOverlapping.Add(new DateRange(overlapping.Min(r => r.Start), overlapping.Max(r => r.End)));

            result = nonOverlapping;
        }

        return result;
    }

    var experienceDateRanges = profile
        .Experience
        .Where(e => e.ExperienceStartDate.HasValue)  // if they didn't give a start date, we can't reasonably figure out when that was
        .Select(e =>
        {
            var endDate = e.ExperienceEndDate ?? utcNow;  // if they didn't give an end date, assume they still work there
            var startDate = e.ExperienceStartDate.Value;

            // sometimes people have swapped date ranges in their dev story for some reason
            return new DateRange(DateExtensions.Min(startDate, endDate), DateExtensions.Max(endDate, startDate));
        });

    var actualExperienceTime = MergeOverlaps(experienceDateRanges).Select(r => r.Length).Sum();

    // I'd like to write TimeSpan.TotalYears, but it doesn't exist so I have to do this instead https://stackoverflow.com/a/4127396/1523776
    var zeroTime = new DateTime(1, 1, 1);
    return (zeroTime + actualExperienceTime).RoundToYear().Year - 1;
}
public static int CalculateYearsOfExperience(this CandidateSearchCv profile, DateTime utcNow)
{
    IEnumerable<DateRange> MergeOverlaps(IEnumerable<DateRange> dateRanges)
    {
        // The idea is to find contiguous clusters of overlapping date ranges and merge them into a single range.
        //
        // 2009  2010  2011  2012  2013  2014  2015  2016
        //  |-----------|     |-----------|     |-----|
        //        |-----------------|
        //                  |
        //                  |
        //                  V
        //  |-----------------------------|     |-----|
        //
        // This implementation is probably far from optimal but I don't expect dateRanges to ever be large:
        // even the most prolific Dev Story authors will only have a few dozen experience entries.


        var result = new List<DateRange>();

        foreach (var range in dateRanges)
        {
            var (overlapping, nonOverlapping) = result.Partition(range.Overlaps, (t, f) => (t.ToList(), f.ToList()));

            overlapping.Add(range);  // a range always overlaps itself
            nonOverlapping.Add(new DateRange(overlapping.Min(r => r.Start), overlapping.Max(r => r.End)));

            result = nonOverlapping;
        }

        return result;
    }

    var experienceDateRanges = profile
        .Experience
        .Where(e => e.ExperienceStartDate.HasValue)  // if they didn't give a start date, we can't reasonably figure out when that was
        .Select(e =>
        {
            var endDate = e.ExperienceEndDate ?? utcNow;  // if they didn't give an end date, assume they still work there
            var startDate = e.ExperienceStartDate.Value;

            // sometimes people have swapped date ranges in their dev story for some reason
            return new DateRange(DateExtensions.Min(startDate, endDate), DateExtensions.Max(endDate, startDate));
        });

    var actualExperienceTime = MergeOverlaps(experienceDateRanges).Select(r => r.Length).Sum();

    // I'd like to write TimeSpan.TotalYears, but it doesn't exist so I have to do this instead https://stackoverflow.com/a/4127396/1523776
    var zeroTime = new DateTime(1, 1, 1);
    return (zeroTime + actualExperienceTime).RoundToYear().Year - 1;
}
public static int CalculateYearsOfExperience(this CandidateSearchCv profile, DateTime utcNow)
{
    IEnumerable<DateRange> MergeOverlaps(IEnumerable<DateRange> dateRanges)
    {
        // The idea is to find contiguous clusters of overlapping date ranges and merge them into a single range.
        //
        // 2009  2010  2011  2012  2013  2014  2015  2016
        //  |-----------|     |-----------|     |-----|
        //        |-----------------|
        //                  |
        //                  |
        //                  V
        //  |-----------------------------|     |-----|
        //
        // This implementation is probably far from optimal but I don't expect dateRanges to ever be large:
        // even the most prolific Dev Story authors will only have a few dozen experience entries.


        var result = new List<DateRange>();

        foreach (var range in dateRanges)
        {
            var (overlapping, nonOverlapping) = result.Partition(range.Overlaps, (t, f) => (t.ToList(), f.ToList()));

            overlapping.Add(range);  // a range always overlaps itself
            nonOverlapping.Add(new DateRange(overlapping.Min(r => r.Start), overlapping.Max(r => r.End)));

            result = nonOverlapping;
        }

        return result;
    }

    var experienceDateRanges = profile
        .Experience
        .Where(e => e.ExperienceStartDate.HasValue)  // if they didn't give a start date, we can't reasonably figure out when that was
        .Select(e =>
        {
            var endDate = e.ExperienceEndDate ?? utcNow;  // if they didn't give an end date, assume they still work there
            var startDate = e.ExperienceStartDate.Value;

            // sometimes people have swapped date ranges in their dev story for some reason
            return new DateRange(DateExtensions.Min(startDate, endDate), DateExtensions.Max(endDate, startDate));
        });

    var actualExperienceTime = MergeOverlaps(experienceDateRanges).Select(r => r.Length).Sum();

    // I'd like to write TimeSpan.TotalYears, but it doesn't exist so I have to do this instead https://stackoverflow.com/a/4127396/1523776
    var zeroTime = new DateTime(1, 1, 1);
    return (zeroTime + actualExperienceTime).RoundToYear().Year - 1;
}
public static int CalculateYearsOfExperience(this CandidateSearchCv profile, DateTime utcNow)
{
    IEnumerable<DateRange> MergeOverlaps(IEnumerable<DateRange> dateRanges)
    {
        // The idea is to find contiguous clusters of overlapping date ranges and merge them into a single range.
        //
        // 2009  2010  2011  2012  2013  2014  2015  2016
        //  |-----------|     |-----------|     |-----|
        //        |-----------------|
        //                  |
        //                  |
        //                  V
        //  |-----------------------------|     |-----|
        //
        // This implementation is probably far from optimal but I don't expect dateRanges to ever be large:
        // even the most prolific Dev Story authors will only have a few dozen experience entries.


        var result = new List<DateRange>();

        foreach (var range in dateRanges)
        {
            var (overlapping, nonOverlapping) = result.Partition(range.Overlaps, (t, f) => (t.ToList(), f.ToList()));

            overlapping.Add(range);  // a range always overlaps itself
            nonOverlapping.Add(new DateRange(overlapping.Min(r => r.Start), overlapping.Max(r => r.End)));

            result = nonOverlapping;
        }

        return result;
    }

    var experienceDateRanges = profile
        .Experience
        .Where(e => e.ExperienceStartDate.HasValue)  // if they didn't give a start date, we can't reasonably figure out when that was
        .Select(e =>
        {
            var endDate = e.ExperienceEndDate ?? utcNow;  // if they didn't give an end date, assume they still work there
            var startDate = e.ExperienceStartDate.Value;

            // sometimes people have swapped date ranges in their dev story for some reason
            return new DateRange(DateExtensions.Min(startDate, endDate), DateExtensions.Max(endDate, startDate));
        });

    var actualExperienceTime = MergeOverlaps(experienceDateRanges).Select(r => r.Length).Sum();

    // I'd like to write TimeSpan.TotalYears, but it doesn't exist so I have to do this instead https://stackoverflow.com/a/4127396/1523776
    var zeroTime = new DateTime(1, 1, 1);
    return (zeroTime + actualExperienceTime).RoundToYear().Year - 1;
}
added 34 characters in body
Source Link

Good question! It'sThe years of experience calculation is pretty basic - it just looks at the experience entries in your Dev Story and adds up their lengths, while accounting for overlaps and gaps. (If you had two jobs concurrently in 2016, that should still count for only one year of experience. Likewise, if you took a career break that shouldn't count towards your years of experience.)

Good question! It's pretty basic - it just looks at the experience entries in your Dev Story and adds up their lengths, while accounting for overlaps and gaps. (If you had two jobs concurrently in 2016, that should still count for only one year of experience. Likewise, if you took a career break that shouldn't count towards your years of experience.)

Good question! The years of experience calculation is pretty basic - it just looks at the experience entries in your Dev Story and adds up their lengths, while accounting for overlaps and gaps. (If you had two jobs concurrently in 2016, that should still count for only one year of experience. Likewise, if you took a career break that shouldn't count towards your years of experience.)

added 12 characters in body
Source Link
Loading
Source Link
Loading