Paralelismo realizado por ponto de medição em vez de dias a serem processados.
This commit is contained in:
parent
920904fe11
commit
9b13701441
53
Program.cs
53
Program.cs
@ -76,11 +76,8 @@ internal class Plat_integ
|
|||||||
|
|
||||||
var errosPersistentes = new ConcurrentBag<string>();
|
var errosPersistentes = new ConcurrentBag<string>();
|
||||||
|
|
||||||
//using var conn = new NpgsqlConnection(PG_CONN_STRING_PROD);
|
|
||||||
//await conn.OpenAsync();
|
|
||||||
await using var dataSource = NpgsqlDataSource.Create(PG_CONN_STRING_PROD);
|
await using var dataSource = NpgsqlDataSource.Create(PG_CONN_STRING_PROD);
|
||||||
|
|
||||||
//client.DefaultRequestHeaders.Clear();
|
|
||||||
client.DefaultRequestHeaders.Add("SOAPAction", "listarMedidaCincoMinutos");
|
client.DefaultRequestHeaders.Add("SOAPAction", "listarMedidaCincoMinutos");
|
||||||
var endpoint = new Uri("https://servicos.ccee.org.br/ws/v2/MedidaCincoMinutosBSv2");
|
var endpoint = new Uri("https://servicos.ccee.org.br/ws/v2/MedidaCincoMinutosBSv2");
|
||||||
|
|
||||||
@ -88,8 +85,49 @@ internal class Plat_integ
|
|||||||
|
|
||||||
await Parallel.ForEachAsync(perfis, async (perfil, ct) =>
|
await Parallel.ForEachAsync(perfis, async (perfil, ct) =>
|
||||||
{
|
{
|
||||||
foreach (var item in perfis)
|
try
|
||||||
{
|
{
|
||||||
|
Console.WriteLine($"{DateTime.Now}: Iniciado ponto {perfil._Codigo_SCDE}");
|
||||||
|
if (perfil._Cod_5min == "0" || perfil._Cod_5min == string.Empty)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Pular {perfil._Codigo_SCDE} - (cod 5 min pendente)");
|
||||||
|
errosPersistentes.Add($"{perfil._Cod_5min};{perfil._Codigo_SCDE}; cod_5min pendente");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
string sqlSelect = @"
|
||||||
|
SELECT ponto, dia_num, minuto, origem,
|
||||||
|
ativa_consumo, ativa_geracao, reativa_consumo, reativa_geracao
|
||||||
|
FROM med_5min
|
||||||
|
WHERE ponto = @ponto AND dia_num >= @data_ini AND dia_num < @data_fim;
|
||||||
|
";
|
||||||
|
|
||||||
|
var existentes = new Dictionary<(string, double, int), dynamic>();
|
||||||
|
|
||||||
|
await using (var command = dataSource.CreateCommand(sqlSelect))
|
||||||
|
{
|
||||||
|
|
||||||
|
command.Parameters.AddWithValue("ponto", perfil._Codigo_SCDE + "P");
|
||||||
|
command.Parameters.AddWithValue("data_ini", dataIni.ToOADate());
|
||||||
|
command.Parameters.AddWithValue("data_fim", dataFim.ToOADate());
|
||||||
|
|
||||||
|
await using (var reader = await command.ExecuteReaderAsync(ct))
|
||||||
|
{
|
||||||
|
while (await reader.ReadAsync())
|
||||||
|
{
|
||||||
|
existentes[(reader.GetString(0), reader.GetDouble(1), reader.GetInt32(2))] = new
|
||||||
|
{
|
||||||
|
Origem = reader.GetString(3),
|
||||||
|
AtivaC = reader.GetDouble(4),
|
||||||
|
AtivaG = reader.GetDouble(5),
|
||||||
|
ReatC = reader.GetDouble(6),
|
||||||
|
ReatG = reader.GetDouble(7)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (DateTime dia in datas)
|
||||||
|
{
|
||||||
int tentativas = 0;
|
int tentativas = 0;
|
||||||
bool sucesso = false;
|
bool sucesso = false;
|
||||||
|
|
||||||
@ -135,6 +173,13 @@ internal class Plat_integ
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Console.WriteLine($"{DateTime.Now}: Finalizado ponto {perfil._Codigo_SCDE}");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (errosPersistentes.Count > 0)
|
if (errosPersistentes.Count > 0)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user