Conversione su MongoDb corretta, da verificare rilettura e filtraggio
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using SteamWare;
|
||||
using MapoDb;
|
||||
using SteamWare;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
@@ -24,7 +25,9 @@ namespace MP_SITE
|
||||
protected void lbtConvertData_Click(object sender, EventArgs e)
|
||||
{
|
||||
// effettuo lettura dati FluxLog
|
||||
|
||||
DateTime dataRif = DateTime.Now;
|
||||
DateTime.TryParse(txtData.Text, out dataRif);
|
||||
FluxArchive.man.trasferData(dataRif);
|
||||
// converto
|
||||
|
||||
// salvo su mongoDB!
|
||||
|
||||
+25
-12
@@ -39,42 +39,45 @@ namespace MapoDb
|
||||
List<tsData> valori = new List<tsData>();
|
||||
tsData campione = null;
|
||||
DateTime tStamp;
|
||||
int ora = 0;
|
||||
string filtro = "";
|
||||
string sort = "codFlux ASC";
|
||||
string sort = "idxMacchina ASC, codFlux ASC";
|
||||
string currFlux = "";
|
||||
string currMacc = "";
|
||||
// leggo da DB i records...
|
||||
var tabDati = DataLayer.obj.taFL.getFilt("*", data2transfer, data2transfer.AddHours(3), true);
|
||||
var tabDati = DataLayer.obj.taFL.getFilt("", data2transfer, data2transfer.AddDays(7), true);
|
||||
// ora converto...
|
||||
// faccio ciclo su 24 h...
|
||||
for (int i = 0; i < 24; i++)
|
||||
{
|
||||
valori = new List<tsData>();
|
||||
tStamp = data2transfer.AddHours(ora);
|
||||
filtro = $"dtEvento >= #{tStamp}# AND dtEvento <= #{tStamp.AddHours(1)}#";
|
||||
tStamp = data2transfer.AddHours(i);
|
||||
filtro = $"dtEvento >= #{tStamp:yyyy-MM-dd HH:mm:00}# AND dtEvento <= #{tStamp.AddHours(1):yyyy-MM-dd HH:mm:00}#";
|
||||
var tabOraria = (DS_applicazione.FluxLogRow[])tabDati.Select(filtro, sort);
|
||||
foreach (var item in tabOraria)
|
||||
{
|
||||
// controllo flusso x nuovo record...
|
||||
if (item.CodFlux != currFlux)
|
||||
if (item.CodFlux != currFlux || item.IdxMacchina != currMacc)
|
||||
{
|
||||
// salvo il VECCHIO record...
|
||||
if(currRecord!=null)
|
||||
if (currRecord != null)
|
||||
{
|
||||
currRecord.samples = valori;
|
||||
listaRecords.Add(currRecord);
|
||||
}
|
||||
// nuovo record...
|
||||
// nuovi record...
|
||||
currFlux = item.CodFlux;
|
||||
currMacc = item.IdxMacchina;
|
||||
valori = new List<tsData>();
|
||||
currRecord = new tsGrouped()
|
||||
{
|
||||
vcMachine = currMacc,
|
||||
vcName = currFlux,
|
||||
timeStamp = tStamp,
|
||||
period = timeWindow.hour,
|
||||
samples=valori
|
||||
period = timeWindow.hour
|
||||
};
|
||||
}
|
||||
campione = new tsData()
|
||||
{
|
||||
vcMachine = item.IdxMacchina,
|
||||
vcName = item.CodFlux,
|
||||
timeStamp = item.dtEvento,
|
||||
strValue = item.Valore
|
||||
@@ -82,7 +85,7 @@ namespace MapoDb
|
||||
// salvo ULTIMO sample i record prec...
|
||||
if (campione != null && currRecord != null)
|
||||
{
|
||||
currRecord.samples.Add(campione);
|
||||
valori.Add(campione);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -95,6 +98,16 @@ namespace MapoDb
|
||||
var collection = database.GetCollection<tsGrouped>("FluxLog");
|
||||
// salvo in blocco
|
||||
collection.InsertMany(listaRecords);
|
||||
|
||||
// test rilettura: https://stackoverflow.com/questions/2943222/find-objects-between-two-dates-mongodb
|
||||
// https://studio3t.com/knowledge-base/articles/mongodb-find-method/
|
||||
// https://github.com/mongodb/mongo-csharp-driver
|
||||
// http://www.binaryheap.com/tech/time-series-data-in-mongodb/
|
||||
// https://www.codeproject.com/Tips/760099/Resampling-and-merging-time-series-data-using-LINQ
|
||||
// https://docs.microsoft.com/it-it/aspnet/core/tutorials/first-mongo-app?view=aspnetcore-3.0&tabs=visual-studio
|
||||
// https://www.codementor.io/pmbanugo/working-with-mongodb-in-net-1-basics-g4frivcvz
|
||||
// https://www.codementor.io/pmbanugo/working-with-mongodb-in-net-2-retrieving-mrlbeanm5
|
||||
// https://www.codementor.io/pmbanugo/working-with-mongodb-in-net-part-3-skip-sort-limit-and-projections-oqfwncyka
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,6 +222,10 @@ namespace MapoSDK
|
||||
/// </summary>
|
||||
public class tsData
|
||||
{
|
||||
/// <summary>
|
||||
/// Nome Macchina
|
||||
/// </summary>
|
||||
public string vcMachine { get; set; } = "";
|
||||
/// <summary>
|
||||
/// Nome della Var Casuale
|
||||
/// </summary>
|
||||
@@ -287,6 +291,10 @@ namespace MapoSDK
|
||||
/// </summary>
|
||||
public class tsGrouped
|
||||
{
|
||||
/// <summary>
|
||||
/// Nome Macchina
|
||||
/// </summary>
|
||||
public string vcMachine { get; set; } = "";
|
||||
/// <summary>
|
||||
/// Nome della Var Casuale
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user