private static RowCollection MakeRowCollectionForFromTrendVariable([NotNull] MultiyearTrend trend, [NotNull] string variable)
        {
            string shortendName = variable;

            if (shortendName.Length > 30)
            {
                shortendName = shortendName.Substring(0, 30);
            }

            RowCollection rc = new RowCollection(shortendName, variable);
            //scenarios
            var scenarios = trend.Dict.Keys.Select(x => x.DstScenario.FriendlyName).Distinct().ToList();

            //values
            var years = trend.Dict.Keys.Select(x => x.DstYear).Distinct().OrderBy(x => x).ToList();

            foreach (var year in years)
            {
                if (year == 2017)
                {
                    var rb  = RowBuilder.Start("Year", 2017);
                    var val = trend.Dict[Constants.PresentSlice].GetSliceValueByName(variable);
                    foreach (var scenario in scenarios)
                    {
                        if (scenario == Scenario.Present().FriendlyName)
                        {
                            continue;
                        }

                        rb.Add(scenario, val);
                    }

                    rc.Add(rb);
                }
                else
                {
                    var rb = RowBuilder.Start("Year", year);
                    foreach (var scenario in scenarios)
                    {
                        if (scenario == Scenario.Present().FriendlyName)
                        {
                            continue;
                        }

                        var    slicevalues = trend.Dict.Values.FirstOrDefault(x => x.Slice.DstYear == year && x.Slice.DstScenario.FriendlyName == scenario);
                        object o           = null;
                        if (slicevalues != null)
                        {
                            o = slicevalues.GetSliceValueByName(variable);
                        }

                        rb.Add(scenario, o);
                    }

                    rc.Add(rb);
                }
            }

            return(rc);
        }
        public static void DumpMultiyearTrendToExcel([NotNull] string fullFileName, [NotNull] MultiyearTrend trend)
        {
            if (trend.Dict.Count == 0)
            {
                throw new FlaException("No values");
            }

            if (!trend.Dict.ContainsKey(Constants.PresentSlice))
            {
                throw new FlaException("Missing present");
            }

            var allVariables = trend.Dict.Values.SelectMany(x => x.Values.Select(y => y.VariableName)).Distinct().ToList();
            var p            = PrepareExcelPackage(fullFileName);


            foreach (var variable in allVariables)
            {
                var rc = MakeRowCollectionForFromTrendVariable(trend, variable);
                var ws = p.Workbook.Worksheets.Add(rc.SheetName);
                FillExcelSheet(rc, ws, false);
                int       columns  = trend.Dict.Keys.Select(x => x.DstScenario).Distinct().Count() - 1;
                int       rows     = trend.Dict.Keys.Select(x => x.DstYear).Distinct().Count() + 1;
                const int chartrow = 4;
                MakeSingleXyChart(ws, chartrow, columns + 1, columns, 2, rows, variable);
            }

            p.Save();
            p.Dispose();
        }
Ejemplo n.º 3
0
        public void RunMultiyearTestSingleColumn()
        {
            PrepareUnitTest();
            string fn = WorkingDirectory.Combine("trend3.xlsx");

            Config.LimitToScenarios.Clear();
            Config.InitializeSlices(Logger);
            MultiyearTrend trend = new MultiyearTrend();
            Random         rnd   = new Random();

            if (Config.Slices == null)
            {
                throw new FlaException("No slices");
            }
            trend[Constants.PresentSlice].AddValue("MyValue", 50, DisplayUnit.Stk);
            foreach (var slice in Config.Slices)
            {
                if (slice.DstScenario != Scenario.FromEnum(ScenarioEnum.Nep))
                {
                    continue;
                }

                trend[slice].AddValue("MyValue", rnd.Next(100), DisplayUnit.Stk);
            }

            XlsxDumper.DumpMultiyearTrendToExcel(fn, trend);
            Info("Wrote to " + fn);
            Process.Start(fn);
        }