Skip to content

Commit

Permalink
fix up
Browse files Browse the repository at this point in the history
  • Loading branch information
JFriel committed Jan 10, 2025
1 parent ed64315 commit 3e249c9
Showing 1 changed file with 19 additions and 25 deletions.
44 changes: 19 additions & 25 deletions Rdmp.Core/Curation/Data/Overview/OverviewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace Rdmp.Core.Curation.Data.Overview;
/// </summary>
public class OverviewModel
{

private readonly ICatalogue _catalogue;
private readonly IBasicActivateItems _activator;
private Evaluation _evaluation;
Expand Down Expand Up @@ -51,7 +52,7 @@ public DataTable GetTableData()
{
var extractableDataSets = _activator.RepositoryLocator.DataExportRepository.GetAllObjectsWhere<ExtractableDataSet>("Catalogue_ID", _catalogue.ID);
DateTime? maxDateOfExtraction = null;
foreach(var eds in extractableDataSets)
foreach (var eds in extractableDataSets)
{
var results = _activator.RepositoryLocator.DataExportRepository.GetAllObjectsWhere<CumulativeExtractionResults>("ExtractableDataSet_ID", eds.ID);
if (results.Length != 0)
Expand All @@ -70,18 +71,21 @@ public DataTable GetTableData()
{
if (_evaluation is null) return null;
int dataLoadID = _evaluation.RowStates.Max(rs => rs.DataLoadRunID);
if (dataLoadID > 0) {
if (dataLoadID > 0)
{
var loggingDB = _catalogue.CatalogueRepository.GetAllObjectsWhere<ExternalDatabaseServer>("CreatedByAssembly", "Rdmp.Core/Databases.LoggingDatabase").FirstOrDefault();
if (loggingDB != null) {
if (loggingDB != null)
{
var discoveredDB = loggingDB.Discover(DataAccessContext.InternalDataProcessing);
var discoveredTable = discoveredDB.ExpectTable("TableLoadRun");
if (discoveredTable != null) {
if (discoveredTable != null)
{
var conn = discoveredDB.Server.GetConnection();
conn.Open();
var cmd = discoveredTable.GetCommand($"SELECT startTime FROM {discoveredTable.GetFullyQualifiedName()} WHERE dataLoadRunID = {dataLoadID}", conn);
var result = cmd.ExecuteScalar();
conn.Close();
if(result != null)
if (result != null)
{
return DateTime.Parse(result.ToString());
}
Expand All @@ -97,7 +101,6 @@ public int GetNumberOfRecords()
return _dqeTable.AsEnumerable()
.Sum(x => int.Parse(x["# Records"].ToString()));
}
}

public string GetLatestExtraction()
{
Expand All @@ -106,15 +109,15 @@ public string GetLatestExtraction()

public string GetLatestDataLoad()
{
return _dataLoadDate!= null ? ((DateTime)_dataLoadDate).ToString("dd/MM/yyyy") : null;
return _dataLoadDate != null ? ((DateTime)_dataLoadDate).ToString("dd/MM/yyyy") : null;
}

public Tuple<DateTime?, DateTime?> GetStartEndDates()
{
if(_dqeTable.Rows.Count ==0) return new Tuple<DateTime?, DateTime?>(null,null);
if (_dqeTable.Rows.Count == 0) return new Tuple<DateTime?, DateTime?>(null, null);
var start = DateTime.Parse(_dqeTable.AsEnumerable().First()["YearMonth"].ToString());
var end= DateTime.Parse(_dqeTable.AsEnumerable().Last()["YearMonth"].ToString());
return new Tuple<DateTime?, DateTime?>(start,end);
var end = DateTime.Parse(_dqeTable.AsEnumerable().Last()["YearMonth"].ToString());
return new Tuple<DateTime?, DateTime?>(start, end);
}

private DataTable GetCountsByDatePeriod()
Expand All @@ -125,24 +128,16 @@ private DataTable GetCountsByDatePeriod()
{
var repo = new DQERepository(_catalogue.CatalogueRepository);
_evaluation = repo.GetAllObjectsWhere<Evaluation>("CatalogueID", _catalogue.ID).LastOrDefault();
}catch(Exception) {
}
catch (Exception)
{
return dt;
}
if (_evaluation != null)
{
var logCollection = new ViewLogsCollection(loggingServer, new LogViewerFilter(LoggingTables.DataLoadRun));
var dataLoadRunSql = $"{logCollection.GetSql()} WHERE ID={maxDataLoadId}";
var logServer = loggingServer.Discover(DataAccessContext.InternalDataProcessing).Server;
using var loggingCon = logServer.GetConnection();
loggingCon.Open();
using var loggingCmd = logServer.GetCommand(dataLoadRunSql, loggingCon);
loggingCmd.CommandTimeout = 30000;
using var loggingDa = server.GetDataAdapter(loggingCmd);
dt.BeginLoadData();
loggingDa.Fill(dt);
dt.EndLoadData();
loggingCon.Dispose();
if (dt.Rows.Count > 0)
dt = PeriodicityState.GetPeriodicityForDataTableForEvaluation(_evaluation, "ALL", true);
dt.Columns.Add("# Records");
foreach (DataRow row in dt.Rows)
{
row["# Records"] = int.Parse(row["Correct"].ToString()) + int.Parse(row["Wrong"].ToString()) + int.Parse(row["Missing"].ToString()) + int.Parse(row["InvalidatesRow"].ToString());
}
Expand All @@ -153,7 +148,6 @@ private DataTable GetCountsByDatePeriod()
dt.Columns.Remove("Missing");
dt.Columns.Remove("InvalidatesRow");
}

return dt;
}

Expand Down

0 comments on commit 3e249c9

Please sign in to comment.