using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
namespace Octokit
{
///
/// Returns the total commit counts for the owner and total commit counts in total in the last 52 weeks
///
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class Participation
{
public Participation() { }
public Participation(IEnumerable all, IEnumerable owner)
{
Ensure.ArgumentNotNull(all, nameof(all));
Ensure.ArgumentNotNull(owner, nameof(owner));
All = new ReadOnlyCollection(all.ToList());
Owner = new ReadOnlyCollection(owner.ToList());
}
///
/// Returns the commit counts made each week, for the last 52 weeks
///
public IReadOnlyList All { get; protected set; }
///
/// Returns the commit counts made by the owner each week, for the last 52 weeks
///
public IReadOnlyList Owner { get; protected set; }
///
/// The total number of commits made by the owner in the last 52 weeks.
///
///
public int TotalCommitsByOwner()
{
return Owner.Sum();
}
///
/// The total number of commits made by contributors in the last 52 weeks.
///
///
public int TotalCommitsByContributors()
{
return All.Sum() - Owner.Sum();
}
///
/// The total number of commits made in the last 52 weeks.
///
///
public int TotalCommits()
{
return All.Sum();
}
internal string DebuggerDisplay
{
get
{
return string.Format(CultureInfo.InvariantCulture,
"Owner: {0} Total: {1}", TotalCommitsByOwner(), TotalCommits());
}
}
}
}