Skip to content

Commit

Permalink
move items around
Browse files Browse the repository at this point in the history
  • Loading branch information
JFriel committed Oct 29, 2024
1 parent 80518c4 commit 08b2ca1
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 143 deletions.
65 changes: 27 additions & 38 deletions Rdmp.Core/Curation/Data/Overview/OverviewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace Rdmp.Core.Curation.Data.Overview;

Expand All @@ -39,64 +35,69 @@ public class OverviewModel

private DataTable _dataLoads;

private int _numberOfPeople;
private int _numberOfRecords;

public OverviewModel(IBasicActivateItems activator, ICatalogue catalogue)
{
_activator = activator;
_catalogue = catalogue;
Regen("");
}

public int GetNumberOfRecords()
public void Regen(string whereClause)
{
DataTable dt = new();

var discoveredColumn = _catalogue.CatalogueItems.First().ColumnInfo.Discover(DataAccessContext.InternalDataProcessing);
bool hasExtractionIdentifier = true;
var column = _catalogue.CatalogueItems.Where(ci => ci.ExtractionInformation.IsExtractionIdentifier).FirstOrDefault();
if (column is null)
{
column = _catalogue.CatalogueItems.FirstOrDefault();
hasExtractionIdentifier = false;
}
var discoveredColumn = column.ColumnInfo.Discover(DataAccessContext.InternalDataProcessing);
var server = discoveredColumn.Table.Database.Server;
using var con = server.GetConnection();
con.Open();
var sql = $"select count(*) FROM {discoveredColumn.Table.GetRuntimeName()}";
string populatedWhere = !string.IsNullOrWhiteSpace(whereClause) ? $"WHERE {whereClause}" : "";
var sql = $"SELECT {column.ColumnInfo.GetRuntimeName()} FROM {discoveredColumn.Table.GetRuntimeName()} {populatedWhere}";
using var cmd = server.GetCommand(sql, con);
cmd.CommandTimeout = 30000;
using var da = server.GetDataAdapter(cmd);
dt.BeginLoadData();
da.Fill(dt);
dt.EndLoadData();
con.Dispose();
return int.Parse(dt.Rows[0].ItemArray[0].ToString());
_numberOfRecords = dt.Rows.Count;
_numberOfPeople = hasExtractionIdentifier ? dt.DefaultView.ToTable(true, column.ColumnInfo.GetRuntimeName()).Rows.Count : 0;
GetDataLoads();
}

public int GetNumberOfRecords()
{
return _numberOfRecords;
}

public int GetNumberOfPeople()
{
//extractionInformation isExtractionIdentifier
var discoveredColumns = _catalogue.CatalogueItems.Where(ci => ci.ExtractionInformation.IsExtractionIdentifier).Select(ci => ci.ColumnInfo.Discover(DataAccessContext.InternalDataProcessing));
if(discoveredColumns.Count() > 1)
{
//more than 1 extraction identifier...
}
var server = discoveredColumns.First().Table.Database.Server;
using var con = server.GetConnection();
con.Open();
var columnStrings = string.Join(" , ", discoveredColumns.Select(dc => dc.GetRuntimeName()));
var sql = $"SELECT COUNT(*) FROM (SELECT DISTINCT({columnStrings}) FROM {discoveredColumns.First().Table.GetRuntimeName()}) as x";
using var cmd = server.GetCommand(sql, con);
cmd.CommandTimeout = 30000;
var result = cmd.ExecuteScalar();
return (int)result;
return _numberOfPeople;
}

public Tuple<DateTime, DateTime> GetStartEndDates(ColumnInfo dateColumn)
public Tuple<DateTime, DateTime> GetStartEndDates(ColumnInfo dateColumn, string whereClause)
{
DataTable dt = new();

var discoveredColumn = _catalogue.CatalogueItems.First().ColumnInfo.Discover(DataAccessContext.InternalDataProcessing);
var server = discoveredColumn.Table.Database.Server;
var populatedWhereClause = !string.IsNullOrWhiteSpace(whereClause) ? $"WHERE {whereClause}" : "";
using var con = server.GetConnection();
con.Open();
var sql = $@"
select min({dateColumn.GetRuntimeName()}) as min, max({dateColumn.GetRuntimeName()}) as max
from
(select {dateColumn.GetRuntimeName()},
count(1) over (partition by year({dateColumn.GetRuntimeName()})) as occurs
from {discoveredColumn.Table.GetRuntimeName()}) as t
from {discoveredColumn.Table.GetRuntimeName()} {populatedWhereClause}) as t
where occurs >1
";

Expand Down Expand Up @@ -180,18 +181,6 @@ private void GetDataLoads()

}

public DataTable GetDataLoadDetails()
{
DataTable dt = new();
dt.Columns.Add("Data Load");
dt.Columns.Add("");
dt.Rows.Add("# Records inserted or updated in most recent data load", 1);
dt.Rows.Add("Average # Records inserted or updated in data loads", 1);
dt.Rows.Add("Data Load Frequency", "Weekly");

return dt;
}

public DataTable GetMostRecentDataLoad()
{
if (_dataLoads == null) GetDataLoads();
Expand Down
Loading

0 comments on commit 08b2ca1

Please sign in to comment.