<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Jira.SDK.Domain
{
    public class Epic : Issue
    {
        private List<Issue> _issues;
        public List<Issue> Issues
        {
            get
            {
                if (_issues == null)
                {
                    throw new ArgumentException("The issues aren't loaded yet");
                }
                return _issues;
            }
            private set
            {
                _issues = value;
            }
        }

        public List<Sprint> Sprints { private get; set; }

        public String EpicStatus
        {
            get
            {
                return (GetCustomFieldValue("Epic Status") != null ? GetCustomFieldValue("Epic Status") : "");
            }
        }

        public double TimeSpentInSeconds { get; private set; }
        public double EstimateInSeconds { get; private set; }
        public double RemainingEstimateInSeconds { get; private set; }

        public Double GetCost(Double costPerSecond)
        {
            return Math.Round(TimeSpentInSeconds * costPerSecond, 2);
        }

        public Double GetEstimatedCost(Double costPerSecond)
        {
            return Math.Round(EstimateInSeconds * costPerSecond, 2);
        }


        public Double GetRemainingCost(Double costPerSecond)
        {
            return Math.Round(RemainingEstimateInSeconds * costPerSecond, 2);
        }

        public void LoadIssues(List<Sprint> sprints)
        {
            List<Issue> issues = GetJira().Client.GetIssuesWithEpicLink(this.Key);
            issues.ForEach(issue => issue.SetJira(GetJira()));

            foreach (Issue issue in issues)
            {
                issue.Sprint = sprints.Where(sprint => sprint.ID == issue.SprintID).FirstOrDefault();
            }

            LoadIssues(issues);
        }

        public void LoadIssues()
        {
            LoadIssues(GetJira().Client.GetIssuesWithEpicLink(this.Key));
        }

        public void LoadIssues(List<Issue> issues)
        {
            Double timeSpent = issues.Sum(issue => issue.TimeTracking.TimeSpentSeconds);
            LoadIssues(issues, timeSpent);
        }

        public void LoadIssues(List<Issue> issues, DateTime worklogStartdate, DateTime worklogEnddate)
        {            
            //Get all worklogs within the reach of the start- and enddate provided in the method.
            List<Worklog> worklogs = issues.SelectMany(issue => issue.GetWorklogs()).ToList();
            worklogs = worklogs.Where(worklog => worklog.Started.CompareTo(worklogStartdate) >= 0 && worklog.Started.CompareTo(worklogEnddate) <= 0).ToList();
            Double timeSpent = worklogs.Sum(worklog => worklog.TimeSpentSeconds);

            LoadIssues(issues, timeSpent);
        }

        private void LoadIssues(List<Issue> issues, double timeSpentInSeconds)
        {
            Issues = issues;
<commit_msg>Fixed a bug where the issues of an epic didn't have a link to Jira.<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Jira.SDK.Domain
{
    public class Epic : Issue
    {
        private List<Issue> _issues;
        public List<Issue> Issues
        {
            get
            {
                if (_issues == null)
                {
                    throw new ArgumentException("The issues aren't loaded yet");
                }
                return _issues;
            }
            private set
            {
                _issues = value;
            }
        }

        public List<Sprint> Sprints { private get; set; }

        public String EpicStatus
        {
            get
            {
                return (GetCustomFieldValue("Epic Status") != null ? GetCustomFieldValue("Epic Status") : "");
            }
        }

        public double TimeSpentInSeconds { get; private set; }
        public double EstimateInSeconds { get; private set; }
        public double RemainingEstimateInSeconds { get; private set; }

        public Double GetCost(Double costPerSecond)
        {
            return Math.Round(TimeSpentInSeconds * costPerSecond, 2);
        }

        public Double GetEstimatedCost(Double costPerSecond)
        {
            return Math.Round(EstimateInSeconds * costPerSecond, 2);
        }


        public Double GetRemainingCost(Double costPerSecond)
        {
            return Math.Round(RemainingEstimateInSeconds * costPerSecond, 2);
        }

        public void LoadIssues(List<Sprint> sprints)
        {
            List<Issue> issues = GetJira().Client.GetIssuesWithEpicLink(this.Key);
            issues.ForEach(issue => issue.SetJira(GetJira()));

            foreach (Issue issue in issues)
            {
                issue.Sprint = sprints.Where(sprint => sprint.ID == issue.SprintID).FirstOrDefault();
            }

            LoadIssues(issues);
        }

        public void LoadIssues()
        {
            LoadIssues(GetJira().Client.GetIssuesWithEpicLink(this.Key));
            Issues.ForEach(issue => issue.SetJira(this.GetJira()));
        }

        public void LoadIssues(List<Issue> issues)
        {
            Double timeSpent = issues.Sum(issue => issue.TimeTracking.TimeSpentSeconds);
            LoadIssues(issues, timeSpent);
        }

        public void LoadIssues(List<Issue> issues, DateTime worklogStartdate, DateTime worklogEnddate)
        {            
            //Get all worklogs within the reach of the start- and enddate provided in the method.
            List<Worklog> worklogs = issues.SelectMany(issue => issue.GetWorklogs()).ToList();
            worklogs = worklogs.Where(worklog => worklog.Started.CompareTo(worklogStartdate) >= 0 && worklog.Started.CompareTo(worklogEnddate) <= 0).ToList();
            Double timeSpent = worklogs.Sum(worklog => worklog.TimeSpentSeconds);

            LoadIssues(issues, timeSpent);
        }

        private void LoadIssues(List<Issue> issues, double timeSpentInSeconds)
        {
            Issues = issues;

{'fraction_non_alphanumeric': 0.08934930398187116, 'fraction_numerical': 0.0016186468112657818, 'mean_word_length': 1.898217636022514, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4475859', 'n_tokens_mistral': 1688, 'n_tokens_neox': 1616, 'n_words': 370}