I am creating a website for my buddies and I to track all of our offensive softball stats. I am getting tired of maintaining a huge excel spreadsheet and emailing it out every week, so a website is the way to go.
I've created the DB a few times but I want to make sure I am making this thing right without duplicating data. Here is what I have for models:
public class Person
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string NickName { get; set; }
}
public class Player : Person
{
public int Id { get; set; }
public virtual ICollection<Team> Teams { get; set; }
}
public class Manager : Person
{
public int ID { get; set; }
public ICollection<Team> Teams { get; set; }
}
public class Game
{
public int ID { get; set; }
public int TeamID { get; set; }
public String Opponent { get; set }
public DateTime? GameDate { get; set; }
public string Score { get; set; }
public Results Result { get; set; }
public virtual Team Team { get; set; }
public virtual ICollection<Stat> Stats { get; set; }
}
public class League
{
public int ID { get; set; }
public string Name { get; set; }
public virtual ICollection<Team> Teams { get; set; }
}
public enum Results
{
W, L
}
public class Stat
{
public int ID { get; set; }
public int PlayerID { get; set; }
public int GameID { get; set; }
public virtual Player Player { get; set; }
public virtual Game Game { get; set; }
public int? BattingOrder { get; set; }
public int? PA { get; set; }
public int? Single { get; set; }
public int? Double { get; set; }
public int? Triple { get; set; }
public int? HR { get; set; }
public int? RBI { get; set; }
public int? BB { get; set; }
public int? SAC { get; set; }
public int? RBoE { get; set; }
public int? R { get; set; }
public int? H { get { return Single + Double + Triple + HR; } }
public int? AB { get { return PA - (BB + SAC + RBoE); } }
public double? BA { get { return Math.Round(((double)H / (double)AB), 3); } }
public int? TB { get { return Single + 2 * Double + 3 * Triple + 4 * HR; } }
public double? SLG { get { return Math.Round(((double)TB / (double)AB), 3); } }
public double? OBP { get { return Math.Round(((double)(H + BB) / (double)(AB + BB + SAC)), 3); } }
public double? TBP { get { return Math.Round(((double)(H + BB) / (double)(AB + BB)), 3); } }
public double? RC { get { return Math.Round(((double)OBP * (double)TB), 3); } }
}
public class Team
{
public int ID { get; set; }
public string Name { get; set; }
public WeekNights WeekNight { get; set; }
public int? Year { get; set; }
public int ManagerID { get; set; }
public virtual Manager Manager { get; set; }
public virtual League League { get; set; }
public virtual ICollection<Game> Games { get; set; }
}
public enum WeekNights
{
Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
}
The 1-1 relationships aren't an issue, it's relating players to a team and a game and linking the stats that's hanging me up. If anyone has any advice or better, a schema drawing, that would be awesome.
Also, is it better to have Angular calculate the 'calculated' stats on the front end instead of trying to save them in the database? I didn't know how much that would slow down the sight calculating the stats every time you click a new player or game.