public ActionResult <ReturnObject> GetWalletReport([FromBody] HistoryReport walletReport) { try { // var _history = _walletBusiness.GetHistory(walletSearch.wallet, 1, 3, new string[] { nameof(BlockchainTransaction.CreatedAt) }); var userModel = (User)RouteData.Values[ParseDataKeyApi.KEY_PASS_DATA_USER_MODEL]; // CommonHelper.GetUnixTimestamp DateTime dateForButton = DateTime.Now.AddDays(-1 * walletReport.DayTime); var _searchTime = UnixTimestamp.ToUnixTimestamp(dateForButton); int numberData; var history = _walletBusiness.GetHistory(out numberData, userModel.Id, walletReport.NetworkName, -1, -1, null, null, _searchTime); if (walletReport.Email != null) { string fileName = userModel.Id + UnixTimestamp.ToUnixTimestamp(DateTime.Now) + ".csv"; using (StreamWriter sw = new StreamWriter(System.IO.File.Open(AppSettingHelper.GetReportStoreUrl() + fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite))) { var csv = new CsvWriter(sw); csv.WriteRecords(history); } EmailQueue email = new EmailQueue() { ToEmail = walletReport.Email, NetworkName = walletReport.NetworkName, // Amount = addedBalance, Template = EmailTemplate.Report, Subject = EmailConfig.SUBJECT_REPORT, SendFileList = fileName // Content = networkName + "+" + addedBlance }; _sendMailBusiness.CreateEmailQueueAsync(email); } // Console.WriteLine("csv " + csv); return(new ReturnObject() { Status = Status.STATUS_SUCCESS, Data = JsonHelper.SerializeObject(history), Message = numberData.ToString() }); } catch (Exception e) { return(new ReturnObject() { Status = Status.STATUS_ERROR, Message = e.Message }); } // return null; }
public static HistoryReport GetProjectHistory(this UnitOfWork unit, int id, ModelFactory factory) { decimal? monthlyRate = unit.Projects.Get(id).Amount; HistoryReport report = new HistoryReport(); List <HistoryReportEmployees> ReportEmployees = new List <HistoryReportEmployees>(); var project = unit.Projects.Get(id); List <int> years = new List <int> { 2015, 2016, 2017, 2018 }; var employees = unit.Projects.Get().Where(x => x.Id == id) .Select(y => y.Team) .SelectMany(z => z.Engagements) .Select(y => y.Employee) .ToList(); foreach (var employee in employees) { HistoryReportEmployees empToAdd = new HistoryReportEmployees(); empToAdd.Id = employee.Id; empToAdd.Name = employee.FirstName + " " + employee.LastName; var totalHours = unit.Days.Get().Where(x => x.Employee.Id == employee.Id) .SelectMany(y => y.Tasks) .Where(x => x.Project.Id == id) .Select(x => x.Hours) .DefaultIfEmpty(0) .Sum(); empToAdd.TotalHours = totalHours; foreach (var year in years) { HistoryReportTotal empvar = new HistoryReportTotal() { Year = year, Sum = unit.Days.Get().Where(x => x.Employee.Id == employee.Id && x.Date.Year == year) .SelectMany(y => y.Tasks) .Where(x => x.Project.Id == id) .Select(x => x.Hours) .DefaultIfEmpty(0).Sum() }; empToAdd.SumList.Add(empvar); } ReportEmployees.Add(empToAdd); } report.Employees = ReportEmployees; var projectTotalHours = unit.Days.Get().SelectMany(y => y.Tasks) .Where(x => x.Project.Id == id) .Select(x => x.Hours) .DefaultIfEmpty(0) .Sum(); report.TotalHours = projectTotalHours; return(report); }
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); } }
public HistoryReport Analyze(IEnumerable <TestHistoryEntry> currentRun) { var report = new HistoryReport(_colorScheme); var data = _testHistoryDatabaseProvider.Database.Entries; var testsByName = data.GroupBy(x => x.FullName); var dataCopy = data.ToList(); dataCopy.AddRange(currentRun); var testsByNameWithCurrent = dataCopy.GroupBy(x => x.FullName); var total = 0; var passed = 0; var failed = 0; report.TotalDataPoints = data.GroupBy(x => x.CommanderRunId).Count(); // look for unstable tests. Those are defined as tests which have a high ratio of pass/fail var ratio = string.Empty; var percentage = 0.0; foreach (var testgroup in testsByNameWithCurrent) { // CommanderRunId gives us a better indication of individual runs, rather than by test name total = testgroup.GroupBy(x => x.CommanderRunId).Count(); // if there isn't enough data, skip the check if (total < _configuration.HistoryAnalysisConfiguration.MinTestHistoryToAnalyze) { continue; } var test = testgroup.Key; var tests = testgroup.ToList(); var gcd = (double)MathExtensions.GCD(passed, failed); passed = tests.Count(x => x.IsPass); failed = tests.Count() - passed; // express ratio as a percentage if (gcd > 0) { ratio = $"{(failed / gcd)}:{(passed / gcd)}"; } else { ratio = $"{failed}:{passed}"; } percentage = (double)failed / tests.Count(); if (percentage > _configuration.HistoryAnalysisConfiguration.MinTestReliabilityThreshold) { // only report test if it's contained in this run. That way deleted and renamed tests will be filtered out. if (currentRun.Any(x => x.FullName == test)) { report.UnstableTests.Add(new TestPoint(test, passed, failed, tests.Count(), percentage, ratio)); } } } // look for duration changes foreach (var testgroup in testsByName) { // CommanderRunId gives us a better indication of individual runs, rather than by test name total = testgroup.GroupBy(x => x.CommanderRunId).Count(); // if there isn't enough data, skip the check if (total < _configuration.HistoryAnalysisConfiguration.MinTestHistoryToAnalyze) { continue; } var test = testgroup.Key; var tests = testgroup.ToList(); var medianDuration = (long)tests.Median(x => x.Duration.Ticks); // var avgDuration = (long)tests.Average(x => x.Duration.Ticks); var threshold = _configuration.HistoryAnalysisConfiguration.MaxTestDurationChange; var differenceThreshold = medianDuration * threshold; // look for tests with duration changes var currentRunChanges = currentRun .Where(x => x.FullName == test && x.Duration.TotalMilliseconds >= _configuration.HistoryAnalysisConfiguration.MinTestMillisecondsForDurationAnalysis && Math.Abs(x.Duration.Ticks - medianDuration) >= differenceThreshold) .GroupBy(x => x.FullName) .ToList(); if (currentRunChanges.Any()) { var currentEntry = currentRun .Where(x => x.FullName == test) .OrderByDescending(x => x.Duration) .First(); var durationChange = TimeSpan.FromTicks(currentEntry.Duration.Ticks - medianDuration); var anomaly = new TestPoint(test, durationChange, currentEntry.Duration, TimeSpan.FromTicks(medianDuration)); // only report test if it's contained in this run. That way deleted and renamed tests will be filtered out. if (currentRun.Any(x => x.FullName == test) && durationChange.TotalMilliseconds >= _configuration.HistoryAnalysisConfiguration.MinTestMillisecondsForDurationAnalysis) { report.DurationAnomalyTests.Add(anomaly); } } } return(report); }