From 3a46ad74d3cf53604e60c27cbb1c34379e608b3d Mon Sep 17 00:00:00 2001 From: Giuliano Paschoalino Date: Thu, 2 Oct 2025 16:57:07 -0300 Subject: [PATCH] =?UTF-8?q?chore:=20-refatorei=20informa=C3=A7=C3=B5es=20d?= =?UTF-8?q?e=20data=20feat:=20-novas=20estiliza=C3=A7=C3=B5es=20para=20con?= =?UTF-8?q?sultas=20de=20meses=20anteriores?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Program.cs | 70 ++++++++++++++++++++++++++---------------------------- 1 file changed, 34 insertions(+), 36 deletions(-) diff --git a/Program.cs b/Program.cs index 42b5705..caf3028 100644 --- a/Program.cs +++ b/Program.cs @@ -1,4 +1,6 @@ -using System.Data.Common; +using System; +using System.ComponentModel.Design; +using System.Data.Common; using System.Globalization; using System.Numerics; using Npgsql; @@ -10,7 +12,8 @@ class Program static bool _stop = false; static bool _isAuthenticated = false; static readonly string _connectionString = "Server=192.168.10.248;Port=5432;Database=pipefy_move_cards;User Id=postgres;Password=gds21;"; - static DateTime date = DateTime.Now; + static readonly DateTime dateToday = DateTime.Today; + static DateTime date = dateToday; static DateTime firstDayOfMonth = new(date.Year, date.Month, 1); static DateTime lastDayOfMonth = firstDayOfMonth.AddMonths(1).AddSeconds(-1); static string firstDayOfMonthStr = firstDayOfMonth.ToString("yyyy-MM-dd HH\\:mm\\:sszz", new System.Globalization.CultureInfo("pt-BR")); @@ -84,22 +87,14 @@ class Program { if (System.Text.RegularExpressions.Regex.IsMatch(monthString, @"^\d{4}$")) { - if (DateTime.TryParseExact(monthString[2..] + "/" + monthString[..2], - "MM/yy", - CultureInfo.InvariantCulture, - DateTimeStyles.None, - out date)) + if (!DateTime.TryParseExact(monthString[2..] + "/" + monthString[..2], "MM/yy", CultureInfo.InvariantCulture, DateTimeStyles.None, out date)) { - //valid date - } - else - { - date = DateTime.Now; + date = dateToday; } } else { - date = DateTime.Now; + date = dateToday; } firstDayOfMonth = new DateTime(date.Year, date.Month, 1); lastDayOfMonth = firstDayOfMonth.AddMonths(1).AddSeconds(-1); @@ -119,7 +114,7 @@ class Program var userRecords = ObterRegistrosUsuario(userId, nome); var (count, countA, countR, countC) = ContarRegistros(userRecords); - var format = ObterFormatoCor(count); + var format = ObterFormatoCor(count, userRecords.Select(x => x.MovedAt.Date).Distinct().Count()); tableContLigacoes.AddRow(nome, userId.ToString(), $"{format} {count} [/]"); tableContReunioes.AddRow(nome, userId.ToString(), $"[yellow] {countA:#;-#;} [/]", $"[green] {countR:#;-#;} [/]", $"[red] {countC:#;-#;} [/]"); @@ -167,7 +162,7 @@ class Program var table = new Table().Border(TableBorder.Rounded).Alignment(Justify.Center); table.AddColumn(new TableColumn("[green]Nome[/]").Centered()); table.AddColumn(new TableColumn("[green]UserID[/]").Centered()); - table.AddColumn(new TableColumn("[green]Registros Hoje[/]").Centered()); + table.AddColumn(new TableColumn("[green]Registros " + (date != dateToday ? "no mês" : "Hoje") + "[/]").Centered()); return table; } static Table CriarTabelaReunioes() @@ -246,30 +241,37 @@ class Program } static (int count, int countA, int countR, int countC) ContarRegistros(List userRecords) { - int count = userRecords.Count(x => x.MovedAt > DateTime.Today && x.FieldID is not null); + DateTime dateCheckStart = date; + DateTime dateCheckEnd = date.AddDays(1).AddSeconds(-1); + + if (dateCheckStart != dateToday) + { + dateCheckStart = new DateTime(date.Year, date.Month, 1); + dateCheckEnd = dateCheckStart.AddMonths(1).AddSeconds(-1); + } + + int count = userRecords.Count(x => x.MovedAt > dateCheckStart && x.MovedAt <= dateCheckEnd && x.FieldID is not null); int countR = userRecords.Count(x => (x.Acao ?? "").StartsWith("Realizou")); int countA = userRecords.Count(x => (x.Acao ?? "").StartsWith("Agendou")); int countC = userRecords.Count(x => (x.Acao ?? "").EndsWith("cancelada")); return (count, countA, countR, countC); } - static string ObterFormatoCor(int count) + static string ObterFormatoCor(int count, int days) { - var format = ""; - switch (count) + days = days == 0 ? 1 : days; // Evita divisão por zero + string? format = count switch { - case int n when (n < 20): - format = "[red]"; - break; - case int n when (n >= 20 && n < 40): - format = "[yellow]"; - break; - case int n when (n >= 40 && n < 60): - format = "[blue]"; - break; - case int n when (n >= 60): - format = "[white on green bold]"; - break; - } + int n when n < 20 && date == dateToday => "[red]", + int n when n >= 20 && n < 40 && date == dateToday => "[yellow]", + int n when n >= 40 && n < 60 && date == dateToday => "[blue]", + int n when n >= 60 && date == dateToday => "[white on green bold]", + int n when n / days < 20 && date != dateToday => "[red]Média em " + days + " dias: " + n / days + " | Total: ", + int n when n / days >= 20 && n / days < 40 && date != dateToday => "[yellow]Média em " + days + " dias: " + n / days + " | Total: ", + int n when n / days >= 40 && n / days < 60 && date != dateToday => "[blue]Média em " + days + " dias: " + n / days + " | Total: ", + int n when n / days >= 60 && date != dateToday => "[white on green bold]Média em " + days + " dias: " + n / days + " | Total: ", + _ => "[white]", + }; + return format; } static void AguardarEntrada() @@ -290,16 +292,12 @@ class Program { // Quando chegar a zero, exibe a mensagem de atualização automática AnsiConsole.MarkupLine("\r[red]Atualização automática agora![/]"); - Thread.Sleep(1000); break; } // Monta o texto de “Próxima atualização em MM:SS” AnsiConsole.Markup($"\r[blue]Próxima atualização em {remaining.Minutes:00}:{remaining.Seconds:00}[/]"); - // Pequena pausa de 1 segundo - Thread.Sleep(1000); - // Se o usuário apertar qualquer tecla… if (Console.KeyAvailable) {