private static void WriteData(int day, ReportData data)
        {
            string reportsPath      = System.Reflection.Assembly.GetAssembly(typeof(ExportDailyReports_OptionsMenuScreen_OnPrefabInit)).Location;
            string reportsFile      = Path.Combine(Path.GetDirectoryName(SaveLoader.GetActiveSaveFilePath()), Path.GetFileNameWithoutExtension(SaveLoader.GetActiveSaveFilePath()) + "_" + day + "_General" + ".csv");
            string reportsPowerFile = Path.Combine(Path.GetDirectoryName(SaveLoader.GetActiveSaveFilePath()), Path.GetFileNameWithoutExtension(SaveLoader.GetActiveSaveFilePath()) + "_" + day + "_Power" + ".csv");

            try
            {
                WriteCSV(reportsFile, data.dataGeneral, data.headersGeneral);

                WriteCSV(reportsPowerFile, data.dataPower, data.headersPower);

                InfoDialogScreen infoDialogScreen = (InfoDialogScreen)GameScreenManager.Instance.StartScreen(ScreenPrefabs.Instance.InfoDialogScreen.gameObject, GameScreenManager.Instance.ssOverlayCanvas.gameObject);
                infoDialogScreen.SetHeader("Export Daily Reports").AddPlainText("Daily reports exported.");
                infoDialogScreen.Show();
            }
            catch (Exception e)
            {
                Debug.LogError(e);
                InfoDialogScreen infoDialogScreen = (InfoDialogScreen)GameScreenManager.Instance.StartScreen(ScreenPrefabs.Instance.InfoDialogScreen.gameObject, GameScreenManager.Instance.ssOverlayCanvas.gameObject);
                infoDialogScreen.SetHeader("Export Daily Reports").AddPlainText("Error exporting daily reports:\n" + e.ToString());
                infoDialogScreen.Show();
            }
        }
        private static void OnExportDailyReports()
        {
            bool error = false;

            if (ReportManager.Instance == null)
            {
                return;
            }
            List <DailyReport> dailyReports = ReportManager.Instance.reports;

            if (dailyReports == null)
            {
                return;
            }

            ReportData data = new ReportData();

            foreach (var report in dailyReports)
            {
                try
                {
                    //Debug.Log(report.day);

                    AddValueCycle("Cycle", report.day, data.dataGeneral, data.headersGeneral);
                    AddValueCycle("Cycle", report.day, data.dataPower, data.headersPower);


                    foreach (KeyValuePair <ReportManager.ReportType, ReportManager.ReportGroup> reportGroup in ReportManager.Instance.ReportGroups)
                    {
                        ReportManager.ReportEntry entry = report.GetEntry(reportGroup.Key);

                        bool showLine = true;
                        if (entry.accumulate == 0f)
                        {
                            showLine = reportGroup.Value.reportIfZero;
                        }

                        if (reportGroup.Value.isHeader)
                        {
                            //CreateHeader(reportGroup.Value);
                        }
                        else if (showLine)
                        {
                            CreateOrUpdateLine(entry, reportGroup.Value, report.day, data);
                        }
                        else
                        {
                            string columnName = (entry.context == null ? reportGroup.Value.stringKey : entry.context);
                            //Debug.Log("Hidden data: "+ columnName);
                        }
                    }
                }
                catch (Exception e)
                {
                    error = true;
                    Debug.LogError(e);
                    InfoDialogScreen infoDialogScreen = (InfoDialogScreen)GameScreenManager.Instance.StartScreen(ScreenPrefabs.Instance.InfoDialogScreen.gameObject, GameScreenManager.Instance.ssOverlayCanvas.gameObject);
                    infoDialogScreen.SetHeader("Export Daily Reports").AddPlainText("Error exporting daily reports:\n" + e.ToString());
                    infoDialogScreen.Show();
                    break;
                }
            }

            if (!error)
            {
                data.headersPower.Sort((f1, f2) =>
                {
                    if (f1.Equals("Cycle"))
                    {
                        return(-1);                                                     // Cycle is the first column
                    }
                    return(f1.CompareTo(f2));
                }
                                       );

                WriteData(dailyReports.Count, data);
            }

            data.dataGeneral.Clear();
            data.dataPower.Clear();

            data.headersGeneral.Clear();
            data.headersPower.Clear();
        }