public bool ValidateSetup(CohortAnalysisSetup cohortAnalysisSetup)
        {
            if (cohortAnalysisSetup == null)
            {
                throw new Exception("Setup data was not provided");
            }

            if (string.IsNullOrEmpty(cohortAnalysisSetup.CustomerFilePath))
            {
                throw new Exception("Customer file path was not provided");
            }

            if (!File.Exists(cohortAnalysisSetup.CustomerFilePath))
            {
                throw new Exception(
                          $"Customer file path: {cohortAnalysisSetup.CustomerFilePath} " +
                          "does not exist");
            }

            if (string.IsNullOrEmpty(cohortAnalysisSetup.OrderFilePath))
            {
                throw new Exception("Order file path was not provided");
            }

            if (!File.Exists(cohortAnalysisSetup.OrderFilePath))
            {
                throw new Exception(
                          $"Order file path: {cohortAnalysisSetup.OrderFilePath} " +
                          "does not exist");
            }

            if (string.IsNullOrEmpty(cohortAnalysisSetup.TimeZone))
            {
                throw new Exception("Timezone was not provided");
            }

            try
            {
                TimeZoneInfo.FindSystemTimeZoneById(cohortAnalysisSetup.TimeZone);
            }
            catch (TimeZoneNotFoundException)
            {
                throw new Exception("Timezone is not valid " +
                                    $"{cohortAnalysisSetup.TimeZone}");
            }

            return(true);
        }
        public void Run()
        {
            string orderFileName    = null;
            string customerFileName = null;
            string outputFileName   = null;
            string timezone         = null;

            Console.WriteLine("Invitae.CohortAnalysis Initiated...");

            customerFileName = this.RetrieveCustomerFileNameFromUser();

            orderFileName = this.RetrieveOrderFileNameFromUser();

            timezone = this.RetrieveTimeZoneFromUser();

            var cohortAnalysisSetup = new CohortAnalysisSetup
            {
                CustomerFilePath = $"{_settings.DataFilesFolderPath}/{customerFileName}",
                OrderFilePath    = $"{_settings.DataFilesFolderPath}/{orderFileName}",
                TimeZone         = timezone,
            };

            _cohortAnalysisService.ValidateSetup(cohortAnalysisSetup);

            Console.WriteLine("Running Cohort Analysis....");

            IEnumerable <CohortGroup> cohortAnalysisData = _cohortAnalysisService.RunAnalysis(cohortAnalysisSetup);

            Console.WriteLine("Cohort Analysis Completed...");

            outputFileName = this.RetrieveOutputFileNameFromUser();

            bool didAnalysisSave = _cohortAnalysisService
                                   .SaveAnalysisIntoCsvFile(
                $"{_settings.OutputResultsFolderPath}/{outputFileName}",
                cohortAnalysisData);

            if (didAnalysisSave)
            {
                Console.WriteLine("Cohort Analysis Completed...");
            }
            else
            {
                Console.WriteLine("Could not save file to given folder path");
            }
        }
        public IEnumerable <CohortGroup> RunAnalysis(CohortAnalysisSetup cohortAnalysisSetup)
        {
            if (cohortAnalysisSetup == null)
            {
                throw new Exception("Can not run analysis without a setting up.");
            }

            this.ValidateSetup(cohortAnalysisSetup);

            this.LoadData(
                cohortAnalysisSetup.CustomerFilePath,
                cohortAnalysisSetup.OrderFilePath
                );

            this.ConvertDataDatesWithTimeZone(cohortAnalysisSetup.TimeZone);

            IEnumerable <CohortMember> cohortMembers = _cohortCalculationLogic
                                                       .GenerateCohortMembersBasedOnCustomerSignup(_orderData, _customerData);

            return(_cohortCalculationLogic
                   .MapCohortGroups(cohortMembers)
                   .ToList());
        }