internal static string GetSupplyAnalysisExcelData(Dictionary <string, string> parameters, FutureTrendDataType dataType,
                                                          int scenarioId, int siteGroup, int fleetGroup, DataType timeZone, bool weeklyGrouping)
        {
            var toDate = timeZone == DataType.FrozenZone
                             ? FutureTrendDataAccess.SetFrozenZoneToDateLimit(DateTime.Parse(parameters[ParameterNames.ToDate]))
                             : parameters[ParameterNames.ToDate];


            var newParameters = new Dictionary <string, string>
            {
                { ParameterNames.Country, parameters[ParameterNames.Country] },
                { ParameterNames.ToDate, toDate },
                { ParameterNames.FromDate, parameters[ParameterNames.FromDate] }
            };


            if (timeZone == DataType.DailyChanging)
            {
                //return new FutureTrendRepository().GetSupplyAnalysisCsvData(newParameters, scenarioId, siteGroup, fleetGroup
                //       , dataType, weeklyGrouping);
                using (var dataContext = new MarsDBDataContext(MarsConnection.ConnectionString))
                {
                    var joinedData = timeZone == DataType.DailyChanging
                                             ? GenericSizingDataAccess.GetFutureTrendRawData(dataContext, parameters,
                                                                                             scenarioId)
                                             : FutureTrendDataAccess.GetRawFrozenZoneFutureTrendData(dataContext, newParameters,
                                                                                                     (byte)scenarioId);



                    return(GenerateExcelDataFromRaw(dataContext, joinedData, siteGroup, fleetGroup, dataType, weeklyGrouping));
                }
            }
            else
            {
                using (var dataContext = new MarsDBDataContext(MarsConnection.ConnectionString))
                {
                    var joinedData = FutureTrendDataAccess.GetRawFrozenZoneFutureTrendData(dataContext,
                                                                                           newParameters,
                                                                                           (byte)scenarioId);
                    return(GenerateExcelDataFromRaw(dataContext, joinedData, siteGroup, fleetGroup, dataType,
                                                    weeklyGrouping));
                }
            }

            return(null);
        }
        internal static List <GraphSeries> GetSupplyAnalysisData(Dictionary <string, string> parameters, FutureTrendDataType dataType, int scenarioId, DataType timeZone)
        {
            using (var dataContext = new MarsDBDataContext(MarsConnection.ConnectionString))
            {
                if (timeZone == DataType.FrozenZone)
                {
                    parameters[ParameterNames.ToDate] = FutureTrendDataAccess.SetFrozenZoneToDateLimit(DateTime.Parse(parameters[ParameterNames.ToDate]));
                }

                IQueryable <FutureTrendOrSupplyAnalysisRawDataHolder> groupedData;
                if (timeZone == DataType.DailyChanging)
                {
                    //groupedData = new FutureTrendRepository().GetData(parameters, scenarioId);
                    groupedData = GenericSizingDataAccess.GetFutureTrendGroupyByDayData(dataContext, parameters, scenarioId);
                }
                else
                {
                    var joinedData = FutureTrendDataAccess.GetRawFrozenZoneFutureTrendData(dataContext, parameters, (byte)scenarioId);
                    groupedData = from fc in joinedData
                                  group fc by new { fc.ReportDate }
                    into g
                    orderby g.Key.ReportDate ascending
                        select new FutureTrendOrSupplyAnalysisRawDataHolder {
                        ReportDate             = g.Key.ReportDate,
                        Constrained            = g.Sum(c => c.Constrained),
                        Unconstrained          = g.Sum(c => c.Unconstrained),
                        Booked                 = g.Sum(c => c.Booked),
                        NessesaryConstrained   = g.Sum(c => c.NessesaryConstrained),
                        NessesaryUnconstrained = g.Sum(c => c.NessesaryUnconstrained),
                        NessesaryBooked        = g.Sum(c => c.NessesaryBooked),
                        Expected               = g.Sum(c => c.Expected)
                    };
                }



                IQueryable <SupplyAnalysisGraphDataHolder> data;
                switch (dataType)
                {
                case FutureTrendDataType.Constrained:
                    data = from gd in groupedData
                           select new SupplyAnalysisGraphDataHolder
                    {
                        ReportDate = gd.ReportDate,
                        Expected   = gd.Expected - gd.NessesaryConstrained,
                    };
                    break;

                case FutureTrendDataType.Unconstrained:
                    data = from gd in groupedData
                           select new SupplyAnalysisGraphDataHolder
                    {
                        ReportDate = gd.ReportDate,
                        Expected   = gd.Expected - gd.NessesaryUnconstrained,
                    };
                    break;

                case FutureTrendDataType.AlreadyBooked:
                    data = from gd in groupedData
                           select new SupplyAnalysisGraphDataHolder
                    {
                        ReportDate = gd.ReportDate,
                        Expected   = gd.Expected - gd.NessesaryBooked,
                    };
                    break;

                default:
                    throw new ArgumentException("Invalid Future Trend Datatype selected");
                }
                var sw = new Stopwatch();
                sw.Start();
                var finalGraphingData = data.ToList();
                sw.Stop();
                var ell       = sw.Elapsed;
                var graphData = GetSupplyAnalysisSeriesData(finalGraphingData);



                graphData.Add(GetSupplyAnalysisWeeklyData(finalGraphingData));

                return(graphData);
            }
        }