/* G E N R E P O R T B Y S I T E */ /*---------------------------------------------------------------------------- %%Function: GenReportBySite %%Qualified: ArbWeb.SlotAggr.GenReportBySite %%Contact: rlittle ----------------------------------------------------------------------------*/ public void GenReportBySite(string sReport, bool fFuzzyTimes, bool fDatePivot, string[] rgsSportFilter, string[] rgsSportLevelFilter) { SlotAggr os = SlotAggr.Gen(m_plgm, m_dttmStart, m_dttmEnd, rgsSportFilter, rgsSportLevelFilter, true); StreamWriter sw = new StreamWriter(sReport, false, System.Text.Encoding.Default); List<string> plsUse; SortedList<string, int> mpFilter = null; HtmlTableReport htr = new HtmlTableReport(); Dictionary<string, int> mpSiteCount = new Dictionary<string, int>(); int cTotalTotal = 0; htr.Axis1Title = "Date"; htr.Axis2Title = "Site"; plsUse = new List<string>(); foreach (string sSite in os.m_plsSites) { if (mpFilter != null && !mpFilter.ContainsKey(sSite)) continue; plsUse.Add(sSite); } // now, put out the actual values... for (int isc = 0, iscMac = os.m_mpSlotSc.Keys.Count; isc < iscMac; isc++) { SlotCount sc = os.m_mpSlotSc[os.m_mpSlotSc.Keys[isc]]; // merge adject SlotCounts for fuzzytime if (fFuzzyTimes) { while (isc + 1 < iscMac) { SlotCount scNext = os.m_mpSlotSc[os.m_mpSlotSc.Keys[isc + 1]]; if (!scNext.FMatchFuzzyTime(sc)) break; sc = sc.Merge(scNext); isc++; } } int cTotal = 0; string sWrite; string sKey; string sFormat = "{0}\r{1}"; if (fFuzzyTimes) { string sTime; string sTimeKey; if (sc.Dttm.Hour < 12) { sTime = "Morning"; sTimeKey = "0"; } else if (sc.Dttm.Hour >= 16) { sTime = "Evening"; sTimeKey = "2"; } else { sTime = "Afternoon"; sTimeKey = "1"; } sWrite = String.Format(sFormat, sc.Dttm.ToString("ddd M/d"), sTime); sKey = String.Format(sFormat, sc.Dttm.ToString("MN/dd ddd"), sTimeKey); } else { sWrite = String.Format(sFormat, sc.Dttm.ToString("M/d ddd"), sc.Dttm.ToString("h:mm tt")); sKey = String.Format(sFormat, sc.Dttm.ToString("MM/dd ddd"), sc.Dttm.ToString("HH:mm")); } // match all the items we have that begin with sCatT foreach (string sSite in plsUse) { int c = sc.OpenCount(sSite); if (!mpSiteCount.ContainsKey(sSite)) mpSiteCount.Add(sSite, 0); mpSiteCount[sSite] += c; if (c > 0) htr.AddValue(sWrite, sKey, sSite, sSite, String.Format("{0} umps", c)); cTotal += sc.OpenCount(sSite); } if (cTotal > 0) { htr.AddValue(sWrite, sKey, "Total", "zzzTotal", String.Format("{0} umps", cTotal)); cTotalTotal += cTotal; } } foreach (string sSite in mpSiteCount.Keys) { htr.AddValue("\rTotal", "zzz\rzzzTotal", sSite, sSite, String.Format("{0} umps", mpSiteCount[sSite])); } htr.AddValue("\rTotal", "zzz\rzzzTotal", "Total", "zzzTotal", String.Format("{0} umps", cTotalTotal)); htr.GenReport(sw, fDatePivot); sw.Close(); }
static ErrorCode Main_Internal(string[] args) { try { if ((args.Length == 0) || Parser.IsOption(args[0], _helpOptions) || _helpActions.ContainsIgnoreCase(args[0])) { // Print help PrintUsage(); return((int)ErrorCode.Success); } if ((args.Length == 1) && args[0].StartsWith("@")) { args = System.IO.File.ReadLines(args[0].Substring(1)).ToArray(); } // Parse first 'action' argument string actionArg = args[0]; ActionCommand action = 0; { bool isValidActionArg = false; foreach (ActionCommand actionCommand in Enum.GetValues(typeof(ActionCommand))) { if (actionArg.Equals(actionCommand.ToString(), StringComparison.OrdinalIgnoreCase)) { action = actionCommand; isValidActionArg = true; break; } } if (!isValidActionArg) { ReportError($"Error: unrecognized action '{actionArg}' - command line argument #1"); return(ErrorCode.InvalidCommand); } } Parser optionsParser = new Parser( args.Skip(1).ToArray(), PrintUsage); switch (action) { case ActionCommand.cache: { if (!optionsParser.Parse( new Option[] { _configOption, _prefixOption }, new Option[] { _authenticationTokenOption, _commentsPrefixOption })) { return(ErrorCode.InvalidCommand); } IEnumerable <string> configFiles = _configOption.GetValues(optionsParser); string filePrefix = _prefixOption.GetValue(optionsParser); // Optional args string authenticationToken = _authenticationTokenOption.GetValue(optionsParser); string commentsFilePrefix = _commentsPrefixOption.GetValue(optionsParser); return(CacheGitHubIssues(configFiles, filePrefix, commentsFilePrefix, authenticationToken)); } case ActionCommand.cacheRange: { if (!optionsParser.Parse( new Option[] { _configOption, _prefixOption, _startIndexOption, _endIndexOption }, new Option[] { _authenticationTokenOption, _commentsPrefixOption })) { return(ErrorCode.InvalidCommand); } IEnumerable <string> configFiles = _configOption.GetValues(optionsParser); string filePrefix = _prefixOption.GetValue(optionsParser); int startIndex = Int32.Parse(_startIndexOption.GetValue(optionsParser)); int endIndex = Int32.Parse(_endIndexOption.GetValue(optionsParser)); // Optional args string authenticationToken = _authenticationTokenOption.GetValue(optionsParser); if (startIndex <= 0) { optionsParser.ReportError($"Option /startIndex has to be positive number."); return(ErrorCode.InvalidCommand); } if (endIndex < startIndex) { optionsParser.ReportError($"Option /endIndex has to larger than /startIndex."); return(ErrorCode.InvalidCommand); } return(CacheGitHubIssuesRange( configFiles, filePrefix, startIndex, endIndex, authenticationToken)); } case ActionCommand.query: { if (!optionsParser.Parse( new Option[] { _configOption, _endOption, _outputOption }, new Option[] { _beginOption, _outputJsonOption })) { return(ErrorCode.InvalidCommand); } IEnumerable <string> configFiles = _configOption.GetValues(optionsParser); IEnumerable <string> beginFiles = _beginOption.GetValues(optionsParser); IEnumerable <string> endFiles = _endOption.GetValues(optionsParser); string outputJsonFile = _outputJsonOption.GetValue(optionsParser); string outputFile = _outputOption.GetValue(optionsParser); Config config = new Config(configFiles); QueryReport report = new QueryReport(config, beginFiles, endFiles); report.Write(outputFile, outputJsonFile); return(ErrorCode.Success); } case ActionCommand.report: { if (!optionsParser.Parse( new Option[] { _configOption, _endOption }, new Option[] { _beginOption, _middleOption, _outputOption, _outputCsvOption, _nameOption })) { return(ErrorCode.InvalidCommand); } IEnumerable <string> configFiles = _configOption.GetValues(optionsParser); IEnumerable <string> beginFiles = _beginOption.GetValues(optionsParser); IEnumerable <string> middleFiles = _middleOption.GetValues(optionsParser); IEnumerable <string> endFiles = _endOption.GetValues(optionsParser); string outputFile = _outputOption.GetValue(optionsParser); string csvFileNamePrefix = _outputCsvOption.GetValue(optionsParser); string reportName = _nameOption.GetValue(optionsParser); if ((outputFile == null) && (csvFileNamePrefix == null)) { optionsParser.ReportError("Required at least one option: '/out' or '/out_csv'."); return(ErrorCode.InvalidCommand); } if ((csvFileNamePrefix != null) && csvFileNamePrefix.EndsWith(".csv", StringComparison.OrdinalIgnoreCase)) { optionsParser.ReportError($"Option '/out_csv' takes file name prefix, not file name {csvFileNamePrefix}."); return(ErrorCode.InvalidCommand); } TableReport report = new TableReport(configFiles, beginFiles, middleFiles, endFiles); if (outputFile != null) { HtmlTableReport.Write(report, outputFile, reportName); } // Note we can have both options if (csvFileNamePrefix != null) { CsvTableReport.Write(report, csvFileNamePrefix, reportName); } return(ErrorCode.Success); } case ActionCommand.contributions: { if (!optionsParser.Parse( new Option[] { _configOption, _inputOption }, new Option[] { _outputOption, _outputCsvOption })) { return(ErrorCode.InvalidCommand); } IEnumerable <string> configFiles = _configOption.GetValues(optionsParser); IEnumerable <string> inputFiles = _inputOption.GetValues(optionsParser); string outputFileHtml = _outputOption.GetValue(optionsParser); string outputFileCsv = _outputCsvOption.GetValue(optionsParser); if ((outputFileHtml == null) && (outputFileCsv == null)) { optionsParser.ReportError("Required at least one option: '/out' or '/out_csv'."); return(ErrorCode.InvalidCommand); } ContributionsReport report = new ContributionsReport(configFiles, inputFiles); if (outputFileHtml != null) { HtmlContributionsReport.Write(report, outputFileHtml); } // Note we can have both options if (outputFileCsv != null) { //CsvContributionsReport.Write(report, outputFileCsv); } return(ErrorCode.Success); } case ActionCommand.alerts: { if (!optionsParser.Parse( new Option[] { _configOption, _beginOption, _endOption, _templateOption }, new Option[] { _filterOption, _skipEmailOption, _outputOption })) { return(ErrorCode.InvalidCommand); } IEnumerable <string> configFiles = _configOption.GetValues(optionsParser); IEnumerable <string> beginFiles = _beginOption.GetValues(optionsParser); IEnumerable <string> endFiles = _endOption.GetValues(optionsParser); string templateFile = _templateOption.GetValue(optionsParser); // Optional args IEnumerable <string> alertFilters = _filterOption.GetValues(optionsParser); bool skipEmail = _skipEmailOption.IsDefined(optionsParser); string outputFile = _outputOption.GetValue(optionsParser); Config config = new Config(configFiles); IEnumerable <DataModelIssue> beginIssues = IssueCollection.LoadIssues( beginFiles, config, IssueKindFlags.Issue | IssueKindFlags.PullRequest) .DistinctFirst_ByIssueNumber() .ToArray(); IEnumerable <DataModelIssue> endIssues = IssueCollection.LoadIssues( endFiles, config, IssueKindFlags.Issue | IssueKindFlags.PullRequest) .DistinctLast_ByIssueNumber() .ToArray(); if (AlertReport_Diff.DetectLargeChanges(beginIssues, endIssues, config)) { return(ErrorCode.EmailSendFailure); } return(GetSendEmailErrorCode(AlertReport_Diff.SendEmails( config, templateFile, skipEmail, outputFile, alertFilters, beginIssues, endIssues))); } case ActionCommand.history: { if (!optionsParser.Parse( new Option[] { _inputOption, _outputOption }, Option.EmptyList)) { return(ErrorCode.InvalidCommand); } IEnumerable <string> inputFiles = _inputOption.GetValues(optionsParser); string outputFile = _outputOption.GetValue(optionsParser); HistoryReport.Create(inputFiles, outputFile); return(ErrorCode.Success); } case ActionCommand.untriaged: { if (!optionsParser.Parse( new Option[] { _configOption, _inputOption, _templateOption }, new Option[] { _filterOption, _skipEmailOption, _outputOption })) { return(ErrorCode.InvalidCommand); } IEnumerable <string> configFiles = _configOption.GetValues(optionsParser); IEnumerable <string> inputFiles = _inputOption.GetValues(optionsParser); string templateFile = _templateOption.GetValue(optionsParser); // Optional args IEnumerable <string> alertFilters = _filterOption.GetValues(optionsParser); bool skipEmail = _skipEmailOption.IsDefined(optionsParser); string outputFile = _outputOption.GetValue(optionsParser); Config config = new Config(configFiles); return(GetSendEmailErrorCode(AlertReport_Untriaged.SendEmails( config, templateFile, skipEmail, outputFile, alertFilters, inputFiles))); } case ActionCommand.needsResponse: { if (!optionsParser.Parse( new Option[] { _configOption, _inputOption, _commentsOption, _templateOption }, new Option[] { _filterOption, _skipEmailOption, _outputOption })) { return(ErrorCode.InvalidCommand); } IEnumerable <string> configFiles = _configOption.GetValues(optionsParser); IEnumerable <string> inputFiles = _inputOption.GetValues(optionsParser); IEnumerable <string> commentsFiles = _commentsOption.GetValues(optionsParser); string templateFile = _templateOption.GetValue(optionsParser); // Optional args IEnumerable <string> alertFilters = _filterOption.GetValues(optionsParser); bool skipEmail = _skipEmailOption.IsDefined(optionsParser); string outputFile = _outputOption.GetValue(optionsParser); Config config = new Config(configFiles); IEnumerable <DataModelIssue> issues = IssueCollection.LoadIssues( inputFiles, config, IssueKindFlags.Issue); IEnumerable <DataModelIssue> comments = IssueCollection.LoadIssues( commentsFiles, config, IssueKindFlags.Comment); return(GetSendEmailErrorCode(AlertReport_NeedsResponse.SendEmails( config, templateFile, skipEmail, outputFile, alertFilters, issues, comments))); } default: Debug.Assert(false); return(ErrorCode.CatastrophicFailure); } } catch (Exception ex) { Console.Error.WriteLine(); Console.Error.WriteLine(); Console.Error.WriteLine(); Console.Error.WriteLine("Catastrophic failure:"); Console.Error.WriteLine(ex); return(ErrorCode.CatastrophicFailure); } }