From 099c7946337d90c3adccfdfaf2daf2ad56582766 Mon Sep 17 00:00:00 2001 From: Jim Kerver Date: Tue, 11 Jun 2024 16:45:49 -0600 Subject: [PATCH] Add record number and distinct values to index listbox I have a feeling that the width of the whole screen might need to get wider. The listbox doesn't fit properly in the given width anymore (same goes for the 'tables' tab). --- Project/Sources/Classes/form_Explorer.4dm | 19 ++++++--- Project/Sources/Forms/Explorer_d/form.4DForm | 42 +++++++++++++++++-- Project/Sources/Methods/Compiler_Methods.4dm | 7 +++- .../Methods/Structure_GetFieldIndexRatio.4dm | 34 +++++++-------- 4 files changed, 73 insertions(+), 29 deletions(-) diff --git a/Project/Sources/Classes/form_Explorer.4dm b/Project/Sources/Classes/form_Explorer.4dm index 3933272..7933ed4 100644 --- a/Project/Sources/Classes/form_Explorer.4dm +++ b/Project/Sources/Classes/form_Explorer.4dm @@ -20,24 +20,31 @@ Function RefreshIndexedFieldInfo() Function PerformIndexAnalysis() - var $field_detail : Object - var $indexUsageRatio : Real + var $field_detail; $fieldStatistics : Object var $numberOfRecordsInTable : Integer For each ($field_detail; This:C1470._form.filteredIndexedFieldList) $numberOfRecordsInTable:=Records in table:C83(Table:C252($field_detail.tableNumber)->) If ($numberOfRecordsInTable=0) $field_detail.index_analysis_notes:="n/a - Table is empty" Else - $indexUsageRatio:=Structure_GetFieldIndexRatio($field_detail.tableNumber; $field_detail.fieldNumber)*100 + $fieldStatistics:={} + Structure_GetFieldIndexRatio($field_detail.tableNumber; $field_detail.fieldNumber; $fieldStatistics) + $fieldStatistics.indexUsageRatio:=$fieldStatistics.indexUsageRatio*100 + If ($fieldStatistics.numberOfRecords>0) + $field_detail.numberOfRecords:=$fieldStatistics.numberOfRecords + End if + If ($fieldStatistics.distinctValues>0) + $field_detail.distinctValues:=$fieldStatistics.distinctValues + End if Case of - : ($indexUsageRatio>=100) + : ($fieldStatistics.indexUsageRatio>=100) $field_detail.index_analysis_notes:="ALL values are unique" - : ($indexUsageRatio<1) + : ($fieldStatistics.indexUsageRatio<1) $field_detail.index_analysis_notes:="Less than 1% of the values are unique" Else - $field_detail.index_analysis_notes:=String:C10($indexUsageRatio; "#0.000")+"% of the values are unique" + $field_detail.index_analysis_notes:=String:C10($fieldStatistics.indexUsageRatio; "#0.000")+"% of the values are unique" End case End if End for each diff --git a/Project/Sources/Forms/Explorer_d/form.4DForm b/Project/Sources/Forms/Explorer_d/form.4DForm index fa28255..0a4ba20 100644 --- a/Project/Sources/Forms/Explorer_d/form.4DForm +++ b/Project/Sources/Forms/Explorer_d/form.4DForm @@ -1448,7 +1448,7 @@ "dataSource": "Form:C1466.filteredIndexedFieldList", "metaSource": "This:C1470.meta", "selectionMode": "none", - "scrollbarHorizontal": "hidden", + "scrollbarHorizontal": "automatic", "alternateFill": "#EEEEEE", "events": [ "onClick", @@ -1458,7 +1458,7 @@ { "name": "name1", "dataSource": "This:C1470.name", - "width": 320, + "width": 280, "minWidth": 10, "maxWidth": 32000, "resizable": false, @@ -1571,10 +1571,46 @@ "textAlign": "center", "alternateFill": "automaticAlternate" }, + { + "header": { + "name": "Header30", + "text": "Records", + "textAlign": "left", + "fontWeight": "bold" + }, + "name": "Column25", + "width": 100, + "dataSource": "This:C1470.numberOfRecords", + "dataSourceTypeHint": "number", + "textAlign": "left", + "numberFormat": "###,###,###,###,###,###,###", + "footer": { + "name": "Footer33" + }, + "alternateFill": "automaticAlternate" + }, + { + "header": { + "name": "Header31", + "text": "Distinct\\Values", + "textAlign": "left", + "fontWeight": "bold" + }, + "name": "Column26", + "numberFormat": "###,###,###,###,###,###,###", + "dataSourceTypeHint": "number", + "textAlign": "left", + "width": 75, + "footer": { + "name": "Footer34" + }, + "dataSource": "This:C1470.distinctValues", + "alternateFill": "automaticAlternate" + }, { "name": "Column24", "dataSource": "This:C1470.index_analysis_notes", - "width": 204, + "width": 200, "minWidth": 10, "maxWidth": 32000, "stroke": "automatic", diff --git a/Project/Sources/Methods/Compiler_Methods.4dm b/Project/Sources/Methods/Compiler_Methods.4dm index d40c9f9..a37f50a 100644 --- a/Project/Sources/Methods/Compiler_Methods.4dm +++ b/Project/Sources/Methods/Compiler_Methods.4dm @@ -906,9 +906,9 @@ C_LONGINT:C283(Structure_GetFieldIndexType; $1) C_LONGINT:C283(Structure_GetFieldIndexType; $2) //Structure_GetFieldIndexRatio -C_REAL:C285(Structure_GetFieldIndexRatio; $0) C_LONGINT:C283(Structure_GetFieldIndexRatio; $1) C_LONGINT:C283(Structure_GetFieldIndexRatio; $2) +C_OBJECT:C1216(Structure_GetFieldIndexRatio; $3) //Digest_GetForMethodText C_TEXT:C284(Digest_GetForMethodText; $0) @@ -1391,4 +1391,7 @@ C_BOOLEAN:C305(XML__XPathNewSyntax; $0) //UTL_lowerCamelCase C_TEXT:C284(UTL_lowerCamelCase; $0) -C_TEXT:C284(UTL_lowerCamelCase; $1) \ No newline at end of file +C_TEXT:C284(UTL_lowerCamelCase; $1) + +//Structure_GetFieldIndexRatio +C_OBJECT:C1216(Structure_GetFieldIndexRatio; $3) \ No newline at end of file diff --git a/Project/Sources/Methods/Structure_GetFieldIndexRatio.4dm b/Project/Sources/Methods/Structure_GetFieldIndexRatio.4dm index 19e6f30..c07f0d0 100644 --- a/Project/Sources/Methods/Structure_GetFieldIndexRatio.4dm +++ b/Project/Sources/Methods/Structure_GetFieldIndexRatio.4dm @@ -6,66 +6,64 @@ // Returns the uniqueness ratio for the specified field. // Value range between 1.00 (100% unique) to 0 (1 value for every record). // -#DECLARE($tableNo : Integer; $fieldNo : Integer)->$indexUsageRatio : Real +#DECLARE($tableNo : Integer; $fieldNo : Integer; $fieldStatistics : Object) // ---------------------------------------------------- -ASSERT:C1129(Count parameters:C259=2) -$indexUsageRatio:=1 // Default to fully unique +ASSERT:C1129(Count parameters:C259=3) +$fieldStatistics.indexUsageRatio:=1 // Default to fully unique OnErr_Install_Handler("OnErr_GENERIC") If (Is table number valid:C999($tableNo)) If (Is field number valid:C1000($tableNo; $fieldNo)) - C_LONGINT:C283($fieldtype; $fieldLength) - C_BOOLEAN:C305($indexed; $unique) + var $fieldtype; $fieldLength : Integer + var $indexed; $unique : Boolean GET FIELD PROPERTIES:C258($tableNo; $fieldNo; $fieldtype; $fieldLength; $indexed; $unique) If ($indexed) - C_LONGINT:C283($numberOfRecordsInTable; $numberOfRecordsHaveDistinctVals) - $numberOfRecordsInTable:=Records in table:C83(Table:C252($tableNo)->) + $fieldStatistics.numberOfRecords:=Records in table:C83(Table:C252($tableNo)->) ALL RECORDS:C47(Table:C252($tableNo)->) - If ($numberOfRecordsInTable>0) + If ($fieldStatistics.numberOfRecords>0) Case of : ($unique) - $numberOfRecordsHaveDistinctVals:=$numberOfRecordsInTable + $fieldStatistics.distinctValues:=$fieldStatistics.numberOfRecords : (($fieldtype=Is alpha field:K8:1) | ($fieldtype=Is text:K8:3)) ARRAY TEXT:C222($aText; 0) DISTINCT VALUES:C339(Field:C253($tableNo; $fieldNo)->; $aText) - $numberOfRecordsHaveDistinctVals:=Size of array:C274($aText) + $fieldStatistics.distinctValues:=Size of array:C274($aText) ARRAY TEXT:C222($aText; 0) : (($fieldtype=Is integer:K8:5) | ($fieldtype=Is longint:K8:6) | ($fieldtype=Is time:K8:8)) ARRAY LONGINT:C221($aiLongInt; 0) DISTINCT VALUES:C339(Field:C253($tableNo; $fieldNo)->; $aiLongInt) - $numberOfRecordsHaveDistinctVals:=Size of array:C274($aiLongInt) + $fieldStatistics.distinctValues:=Size of array:C274($aiLongInt) ARRAY LONGINT:C221($aiLongInt; 0) : (($fieldtype=Is real:K8:4) | ($fieldtype=_o_Is float:K8:26)) ARRAY REAL:C219($arReals; 0) DISTINCT VALUES:C339(Field:C253($tableNo; $fieldNo)->; $arReals) - $numberOfRecordsHaveDistinctVals:=Size of array:C274($arReals) + $fieldStatistics.distinctValues:=Size of array:C274($arReals) ARRAY REAL:C219($arReals; 0) : (($fieldtype=Is date:K8:7)) ARRAY DATE:C224($addates; 0) DISTINCT VALUES:C339(Field:C253($tableNo; $fieldNo)->; $addates) - $numberOfRecordsHaveDistinctVals:=Size of array:C274($addates) + $fieldStatistics.distinctValues:=Size of array:C274($addates) ARRAY DATE:C224($addates; 0) Else - $numberOfRecordsHaveDistinctVals:=$numberOfRecordsInTable + $fieldStatistics.distinctValues:=$fieldStatistics.numberOfRecords End case REDUCE SELECTION:C351(Table:C252($tableNo)->; 0) - $indexUsageRatio:=$numberOfRecordsHaveDistinctVals/$numberOfRecordsInTable + $fieldStatistics.indexUsageRatio:=$fieldStatistics.distinctValues/$fieldStatistics.numberOfRecords + $fieldStatistics.distinctValues:=$fieldStatistics.distinctValues End if - Else - $indexUsageRatio:=-1 // no index + $fieldStatistics.indexUsageRatio:=-1 End if - End if End if