From 08b2ca1007478f7e0ac2371cac021cdba8176f96 Mon Sep 17 00:00:00 2001 From: James Friel Date: Tue, 29 Oct 2024 12:48:45 +0000 Subject: [PATCH] move items around --- .../Curation/Data/Overview/OverviewModel.cs | 65 +++--- .../ViewCatalogueOverviewUI.Designer.cs | 208 +++++++++--------- Rdmp.UI/Overview/ViewCatalogueOverviewUI.cs | 13 +- 3 files changed, 143 insertions(+), 143 deletions(-) diff --git a/Rdmp.Core/Curation/Data/Overview/OverviewModel.cs b/Rdmp.Core/Curation/Data/Overview/OverviewModel.cs index 8506854fa2..9770ff2dd8 100644 --- a/Rdmp.Core/Curation/Data/Overview/OverviewModel.cs +++ b/Rdmp.Core/Curation/Data/Overview/OverviewModel.cs @@ -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; @@ -39,21 +35,32 @@ 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); @@ -61,34 +68,28 @@ public int GetNumberOfRecords() 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 GetStartEndDates(ColumnInfo dateColumn) + public Tuple 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 = $@" @@ -96,7 +97,7 @@ select min({dateColumn.GetRuntimeName()}) as min, max({dateColumn.GetRuntimeName 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 "; @@ -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(); diff --git a/Rdmp.UI/Overview/ViewCatalogueOverviewUI.Designer.cs b/Rdmp.UI/Overview/ViewCatalogueOverviewUI.Designer.cs index 6ba625fb25..ab918cbfd3 100644 --- a/Rdmp.UI/Overview/ViewCatalogueOverviewUI.Designer.cs +++ b/Rdmp.UI/Overview/ViewCatalogueOverviewUI.Designer.cs @@ -34,6 +34,11 @@ private void InitializeComponent() System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ViewCatalogueOverviewUI)); panel1 = new System.Windows.Forms.Panel(); splitContainer1 = new System.Windows.Forms.SplitContainer(); + panel3 = new System.Windows.Forms.Panel(); + lblLatestExtraction = new System.Windows.Forms.Label(); + label2 = new System.Windows.Forms.Label(); + label1 = new System.Windows.Forms.Label(); + lblLastDataLoad = new System.Windows.Forms.Label(); btnSettings = new System.Windows.Forms.Button(); lblDescription = new System.Windows.Forms.Label(); lblName = new System.Windows.Forms.Label(); @@ -42,6 +47,7 @@ private void InitializeComponent() tbMainWhere = new System.Windows.Forms.TextBox(); cbTimeColumns = new System.Windows.Forms.ComboBox(); panel2 = new System.Windows.Forms.Panel(); + button1 = new System.Windows.Forms.Button(); panel7 = new System.Windows.Forms.Panel(); label6 = new System.Windows.Forms.Label(); lblPeople = new System.Windows.Forms.Label(); @@ -53,24 +59,16 @@ private void InitializeComponent() panel5 = new System.Windows.Forms.Panel(); label3 = new System.Windows.Forms.Label(); lblRecords = new System.Windows.Forms.Label(); - panel4 = new System.Windows.Forms.Panel(); - label2 = new System.Windows.Forms.Label(); - lblLatestExtraction = new System.Windows.Forms.Label(); - panel3 = new System.Windows.Forms.Panel(); - label1 = new System.Windows.Forms.Label(); - lblLastDataLoad = new System.Windows.Forms.Label(); - button1 = new System.Windows.Forms.Button(); areaChart1 = new CatalogueSummary.DataQualityReporting.AreaChartUI(OnTabChange); panel1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit(); splitContainer1.Panel1.SuspendLayout(); splitContainer1.SuspendLayout(); + panel3.SuspendLayout(); panel2.SuspendLayout(); panel7.SuspendLayout(); panel6.SuspendLayout(); panel5.SuspendLayout(); - panel4.SuspendLayout(); - panel3.SuspendLayout(); SuspendLayout(); // // panel1 @@ -89,6 +87,7 @@ private void InitializeComponent() // // splitContainer1.Panel1 // + splitContainer1.Panel1.Controls.Add(panel3); splitContainer1.Panel1.Controls.Add(btnSettings); splitContainer1.Panel1.Controls.Add(lblDescription); splitContainer1.Panel1.Controls.Add(lblName); @@ -96,16 +95,6 @@ private void InitializeComponent() splitContainer1.SplitterDistance = 259; splitContainer1.TabIndex = 0; // - // btnSettings - // - btnSettings.Image = (System.Drawing.Image)resources.GetObject("btnSettings.Image"); - btnSettings.Location = new System.Drawing.Point(230, 3); - btnSettings.Name = "btnSettings"; - btnSettings.Size = new System.Drawing.Size(26, 23); - btnSettings.TabIndex = 4; - btnSettings.UseVisualStyleBackColor = false; - btnSettings.Click += btnSettings_Click; - // // splitContainer1.Panel2 // splitContainer1.Panel2.Controls.Add(areaChart1); @@ -119,6 +108,73 @@ private void InitializeComponent() areaChart1.TabIndex = 0; areaChart1.Load += areaChart1_Load; // + // panel3 + // + panel3.BackColor = System.Drawing.SystemColors.ControlDark; + panel3.Controls.Add(lblLatestExtraction); + panel3.Controls.Add(label2); + panel3.Controls.Add(label1); + panel3.Controls.Add(lblLastDataLoad); + panel3.Location = new System.Drawing.Point(16, 245); + panel3.Name = "panel3"; + panel3.Size = new System.Drawing.Size(190, 148); + panel3.TabIndex = 4; + // + // lblLatestExtraction + // + lblLatestExtraction.BackColor = System.Drawing.SystemColors.ControlDark; + lblLatestExtraction.Font = new System.Drawing.Font("Segoe UI", 12F); + lblLatestExtraction.Location = new System.Drawing.Point(13, 116); + lblLatestExtraction.Name = "lblLatestExtraction"; + lblLatestExtraction.Size = new System.Drawing.Size(166, 23); + lblLatestExtraction.TabIndex = 3; + lblLatestExtraction.Text = "label2"; + lblLatestExtraction.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + lblLatestExtraction.Click += lblLatestExtraction_Click; + // + // label2 + // + label2.AutoSize = true; + label2.Font = new System.Drawing.Font("Segoe UI", 16F); + label2.Location = new System.Drawing.Point(13, 77); + label2.Name = "label2"; + label2.Size = new System.Drawing.Size(169, 30); + label2.TabIndex = 2; + label2.Text = "Latest Extraction"; + label2.Click += label2_Click; + // + // label1 + // + label1.AutoSize = true; + label1.Font = new System.Drawing.Font("Segoe UI", 16F); + label1.Location = new System.Drawing.Point(3, 1); + label1.Name = "label1"; + label1.Size = new System.Drawing.Size(181, 30); + label1.TabIndex = 0; + label1.Text = "Lastest Data Load"; + // + // lblLastDataLoad + // + lblLastDataLoad.BackColor = System.Drawing.SystemColors.ControlDark; + lblLastDataLoad.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0); + lblLastDataLoad.Location = new System.Drawing.Point(13, 42); + lblLastDataLoad.Name = "lblLastDataLoad"; + lblLastDataLoad.Size = new System.Drawing.Size(166, 25); + lblLastDataLoad.TabIndex = 1; + lblLastDataLoad.Text = "label2"; + lblLastDataLoad.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + lblLastDataLoad.Click += lblLastDataLoad_Click; + // + // btnSettings + // + btnSettings.Image = (System.Drawing.Image)resources.GetObject("btnSettings.Image"); + btnSettings.Location = new System.Drawing.Point(230, 3); + btnSettings.Name = "btnSettings"; + btnSettings.Size = new System.Drawing.Size(26, 23); + btnSettings.TabIndex = 4; + btnSettings.UseVisualStyleBackColor = false; + btnSettings.Click += btnSettings_Click; + // // lblDescription // lblDescription.Location = new System.Drawing.Point(16, 108); @@ -184,20 +240,29 @@ private void InitializeComponent() panel2.Controls.Add(lblWhere); panel2.Controls.Add(lblTime); panel2.Controls.Add(cbTimeColumns); - panel2.Controls.Add(panel4); - panel2.Controls.Add(panel3); panel2.Location = new System.Drawing.Point(0, 424); panel2.Name = "panel2"; panel2.Size = new System.Drawing.Size(1342, 246); panel2.TabIndex = 1; // + // button1 + // + button1.Image = (System.Drawing.Image)resources.GetObject("button1.Image"); + button1.Location = new System.Drawing.Point(723, 6); + button1.Name = "button1"; + button1.Size = new System.Drawing.Size(26, 23); + button1.TabIndex = 5; + button1.UseVisualStyleBackColor = false; + button1.Click += button1_Click; + // // panel7 // + panel7.BackColor = System.Drawing.SystemColors.ControlDark; panel7.Controls.Add(label6); panel7.Controls.Add(lblPeople); - panel7.Location = new System.Drawing.Point(585, 36); + panel7.Location = new System.Drawing.Point(615, 35); panel7.Name = "panel7"; - panel7.Size = new System.Drawing.Size(182, 200); + panel7.Size = new System.Drawing.Size(182, 108); panel7.TabIndex = 7; // // label6 @@ -212,9 +277,10 @@ private void InitializeComponent() // // lblPeople // + lblPeople.Font = new System.Drawing.Font("Segoe UI", 12F); lblPeople.Location = new System.Drawing.Point(3, 63); lblPeople.Name = "lblPeople"; - lblPeople.Size = new System.Drawing.Size(166, 23); + lblPeople.Size = new System.Drawing.Size(176, 23); lblPeople.TabIndex = 3; lblPeople.Text = "label2"; lblPeople.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; @@ -240,40 +306,45 @@ private void InitializeComponent() // panel6 // panel6.AutoSize = true; + panel6.BackColor = System.Drawing.SystemColors.ControlDark; panel6.Controls.Add(label4); panel6.Controls.Add(lblDateRange); - panel6.Location = new System.Drawing.Point(778, 35); + panel6.Location = new System.Drawing.Point(831, 35); panel6.Name = "panel6"; - panel6.Size = new System.Drawing.Size(202, 200); + panel6.Size = new System.Drawing.Size(202, 108); panel6.TabIndex = 7; // // label4 // label4.AutoSize = true; + label4.Dock = System.Windows.Forms.DockStyle.Fill; label4.Font = new System.Drawing.Font("Segoe UI", 16F); - label4.Location = new System.Drawing.Point(3, 4); + label4.Location = new System.Drawing.Point(0, 0); label4.Name = "label4"; label4.Size = new System.Drawing.Size(125, 30); label4.TabIndex = 2; label4.Text = "Date Range"; + label4.Click += label4_Click; // // lblDateRange // lblDateRange.AutoSize = true; + lblDateRange.Font = new System.Drawing.Font("Segoe UI", 12F); lblDateRange.Location = new System.Drawing.Point(16, 63); lblDateRange.Name = "lblDateRange"; - lblDateRange.Size = new System.Drawing.Size(38, 15); + lblDateRange.Size = new System.Drawing.Size(52, 21); lblDateRange.TabIndex = 3; lblDateRange.Text = "label2"; lblDateRange.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // panel5 // + panel5.BackColor = System.Drawing.SystemColors.ControlDark; panel5.Controls.Add(label3); panel5.Controls.Add(lblRecords); panel5.Location = new System.Drawing.Point(397, 35); panel5.Name = "panel5"; - panel5.Size = new System.Drawing.Size(182, 200); + panel5.Size = new System.Drawing.Size(182, 108); panel5.TabIndex = 6; // // label3 @@ -288,82 +359,14 @@ private void InitializeComponent() // // lblRecords // + lblRecords.Font = new System.Drawing.Font("Segoe UI", 12F); lblRecords.Location = new System.Drawing.Point(3, 63); lblRecords.Name = "lblRecords"; - lblRecords.Size = new System.Drawing.Size(166, 23); + lblRecords.Size = new System.Drawing.Size(176, 23); lblRecords.TabIndex = 3; lblRecords.Text = "label2"; lblRecords.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // - // panel4 - // - panel4.Controls.Add(label2); - panel4.Controls.Add(lblLatestExtraction); - panel4.Location = new System.Drawing.Point(209, 35); - panel4.Name = "panel4"; - panel4.Size = new System.Drawing.Size(182, 200); - panel4.TabIndex = 5; - // - // label2 - // - label2.AutoSize = true; - label2.Font = new System.Drawing.Font("Segoe UI", 16F); - label2.Location = new System.Drawing.Point(10, 4); - label2.Name = "label2"; - label2.Size = new System.Drawing.Size(169, 30); - label2.TabIndex = 2; - label2.Text = "Latest Extraction"; - label2.Click += label2_Click; - // - // lblLatestExtraction - // - lblLatestExtraction.Location = new System.Drawing.Point(3, 63); - lblLatestExtraction.Name = "lblLatestExtraction"; - lblLatestExtraction.Size = new System.Drawing.Size(166, 23); - lblLatestExtraction.TabIndex = 3; - lblLatestExtraction.Text = "label2"; - lblLatestExtraction.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - lblLatestExtraction.Click += lblLatestExtraction_Click; - // - // panel3 - // - panel3.Controls.Add(label1); - panel3.Controls.Add(lblLastDataLoad); - panel3.Location = new System.Drawing.Point(13, 35); - panel3.Name = "panel3"; - panel3.Size = new System.Drawing.Size(190, 201); - panel3.TabIndex = 4; - // - // label1 - // - label1.AutoSize = true; - label1.Font = new System.Drawing.Font("Segoe UI", 16F); - label1.Location = new System.Drawing.Point(3, 1); - label1.Name = "label1"; - label1.Size = new System.Drawing.Size(181, 30); - label1.TabIndex = 0; - label1.Text = "Lastest Data Load"; - // - // lblLastDataLoad - // - lblLastDataLoad.Location = new System.Drawing.Point(3, 63); - lblLastDataLoad.Name = "lblLastDataLoad"; - lblLastDataLoad.Size = new System.Drawing.Size(179, 25); - lblLastDataLoad.TabIndex = 1; - lblLastDataLoad.Text = "label2"; - lblLastDataLoad.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - lblLastDataLoad.Click += lblLastDataLoad_Click; - // - // button1 - // - button1.Image = (System.Drawing.Image)resources.GetObject("button1.Image"); - button1.Location = new System.Drawing.Point(723, 6); - button1.Name = "button1"; - button1.Size = new System.Drawing.Size(26, 23); - button1.TabIndex = 5; - button1.UseVisualStyleBackColor = false; - button1.Click += button1_Click; - // // ViewCatalogueOverviewUI // AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); @@ -378,6 +381,8 @@ private void InitializeComponent() splitContainer1.Panel1.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)splitContainer1).EndInit(); splitContainer1.ResumeLayout(false); + panel3.ResumeLayout(false); + panel3.PerformLayout(); panel2.ResumeLayout(false); panel2.PerformLayout(); panel7.ResumeLayout(false); @@ -386,10 +391,6 @@ private void InitializeComponent() panel6.PerformLayout(); panel5.ResumeLayout(false); panel5.PerformLayout(); - panel4.ResumeLayout(false); - panel4.PerformLayout(); - panel3.ResumeLayout(false); - panel3.PerformLayout(); ResumeLayout(false); } @@ -407,7 +408,6 @@ private void InitializeComponent() private CatalogueSummary.DataQualityReporting.AreaChartUI areaChart1; private System.Windows.Forms.ComboBox cbTimeColumns; private System.Windows.Forms.Panel panel3; - private System.Windows.Forms.Panel panel4; private System.Windows.Forms.Label lblTime; private System.Windows.Forms.Label lblWhere; private System.Windows.Forms.TextBox tbMainWhere; diff --git a/Rdmp.UI/Overview/ViewCatalogueOverviewUI.cs b/Rdmp.UI/Overview/ViewCatalogueOverviewUI.cs index 8fb7b75ec4..25743e90df 100644 --- a/Rdmp.UI/Overview/ViewCatalogueOverviewUI.cs +++ b/Rdmp.UI/Overview/ViewCatalogueOverviewUI.cs @@ -97,7 +97,7 @@ private void UpdateCatalogueData() cbTimeColumns.SelectedIndex = 0; } lblRecords.Text = _overview.GetNumberOfRecords().ToString(); - var dates = _overview.GetStartEndDates(_dateColumns[cbTimeColumns.SelectedIndex].ColumnInfo); + var dates = _overview.GetStartEndDates(_dateColumns[cbTimeColumns.SelectedIndex].ColumnInfo, tbMainWhere.Text); lblDateRange.Text = $"{dates.Item1} - {dates.Item2}"; lblPeople.Text = $"{_overview.GetNumberOfPeople()}"; @@ -187,9 +187,20 @@ private void btnSettings_Click(object sender, EventArgs e) private void button1_Click(object sender, EventArgs e) { + _overview.Regen(tbMainWhere.Text); + lblRecords.Text = _overview.GetNumberOfRecords().ToString(); + lblPeople.Text = _overview.GetNumberOfPeople().ToString(); + var dates = _overview.GetStartEndDates(_dateColumns[cbTimeColumns.SelectedIndex].ColumnInfo, tbMainWhere.Text); + lblDateRange.Text = $"{dates.Item1} - {dates.Item2}"; + lblPeople.Text = $"{_overview.GetNumberOfPeople()}"; var dt = _overview.GetCountsByDatePeriod(_dateColumns[cbTimeColumns.SelectedIndex].ColumnInfo, cbFrequency.SelectedItem.ToString(), tbMainWhere.Text); areaChart1.GenerateChart(dt, $"Records per {cbFrequency.SelectedItem.ToString()}"); } + + private void label4_Click(object sender, EventArgs e) + { + + } } [TypeDescriptionProvider(typeof(AbstractControlDescriptionProvider))] public abstract class ViewCatalogueOverviewUI_Design : RDMPSingleDatabaseObjectControl