Skip to content

Commit

Permalink
improve ui with frequency
Browse files Browse the repository at this point in the history
  • Loading branch information
JFriel committed Oct 28, 2024
1 parent b0f3388 commit cb41028
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 140 deletions.
26 changes: 21 additions & 5 deletions Rdmp.Core/Curation/Data/Overview/OverviewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,37 @@ where occurs >1
}


public DataTable GetCountsByMonth(ColumnInfo dateColumn, string optionalWhere = "")
public DataTable GetCountsByDatePeriod(ColumnInfo dateColumn, string datePeriod, string optionalWhere = "")
{
DataTable dt = new();

if (!(new[] { "Day", "Month", "Year" }).Contains(datePeriod))
{
throw new Exception("Invalid Date period");
}
var discoveredColumn = dateColumn.Discover(DataAccessContext.InternalDataProcessing);
var server = discoveredColumn.Table.Database.Server;
using var con = server.GetConnection();
con.Open();
//TODO make this work on non-sql
var dateString = "yyyy-MM";
switch (datePeriod)
{
case "Day":
dateString = "yyyy-MM-dd";
break;
case "Month":
dateString = "yyyy-MM";
break;
case "Year":
dateString = "yyyy";
break;
}
var sql = @$"
SELECT format({dateColumn.GetRuntimeName()}, 'yyyy-MM') as YearMonth, count(*) as '# Records'
SELECT format({dateColumn.GetRuntimeName()}, '{dateString}') as YearMonth, count(*) as '# Records'
FROM {discoveredColumn.Table.GetRuntimeName()}
WHERE {dateColumn.GetRuntimeName()} IS NOT NULL
{(optionalWhere != "" ? "AND" : "")} {optionalWhere}
GROUP BY format({dateColumn.GetRuntimeName()}, 'yyyy-MM')
{(optionalWhere != "" ? "AND" : "")} {optionalWhere.Replace('"', '\'')}
GROUP BY format({dateColumn.GetRuntimeName()}, '{dateString}')
ORDER BY 1
";

Expand Down
8 changes: 7 additions & 1 deletion Rdmp.UI/ChartLookAndFeelSetter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ public static void PopulateYearMonthChart(Chart chart, DataTable dt, string yAxi
/// <returns></returns>
private static int GetOffset(string yearMonth)
{
var matchYearDigit = Regex.Match(yearMonth, @"^\d+$");
if(matchYearDigit.Success)
{
return 0;
}

var matchMonthName = Regex.Match(yearMonth, @"\d+-([A-Za-z]+)");

if (matchMonthName.Success)
Expand All @@ -125,7 +131,7 @@ private static int GetOffset(string yearMonth)
return DateTime.ParseExact(monthName, "MMMM", CultureInfo.CurrentCulture).Month;
}

var matchMonthDigit = Regex.Match(yearMonth, @"\d+-(\d+)");
var matchMonthDigit = Regex.Match(yearMonth, @"\d+-(\d+)(-(\d\d))?");

return !matchMonthDigit.Success
? throw new Exception("Regex did not match expected YYYY-MM!")
Expand Down
193 changes: 104 additions & 89 deletions Rdmp.UI/Overview/ViewCatalogueOverviewUI.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit cb41028

Please sign in to comment.