From 8a78f5bba013c7c3ac5b145db5f98d1669449869 Mon Sep 17 00:00:00 2001 From: Per Inge Vaaje Date: Thu, 18 Feb 2021 13:00:06 +0100 Subject: [PATCH 1/3] Autopivot Table for best presentation --- PCAxis.Sql/Parser_23/PXSqlVariables.cs | 187 ++++++++++++++++++++++ PCAxis.Sql/Parser_24/PXSqlVariables.cs | 213 ++++++++++++++++++++++++- 2 files changed, 395 insertions(+), 5 deletions(-) diff --git a/PCAxis.Sql/Parser_23/PXSqlVariables.cs b/PCAxis.Sql/Parser_23/PXSqlVariables.cs index fd560a8..665275f 100644 --- a/PCAxis.Sql/Parser_23/PXSqlVariables.cs +++ b/PCAxis.Sql/Parser_23/PXSqlVariables.cs @@ -5,6 +5,7 @@ using PCAxis.Sql.QueryLib_23; using PCAxis.Paxiom; using PCAxis.Sql.Pxs; +using System.Configuration; using log4net; namespace PCAxis.Sql.Parser_23 @@ -21,6 +22,16 @@ public PXSqlVariables(PXSqlMeta_23 meta) } + internal enum DefaultPivot + { + alg1, + alg2, + alg3, + alg4, + alg5, + alg6 + } + /// /// True if one or more variable has applied grouping and the grouping requires a sum in the dataextraction, i.e. not all data are stored . /// @@ -72,10 +83,186 @@ internal void setStubHeadPxs() } } + string shouldPivot = ConfigurationManager.AppSettings["autopivot"]; + if (shouldPivot != null) { + if (shouldPivot.ToLower() == "yes") + { + setStubHeadOverridden(); + } + } + } + internal void setStubHeadOverridden() + { + int numberOfVariables = this.Count; + DefaultPivot pivotAlg; + int selectedClassCount = 0; + int selectedTimeValuesCount = 0; + int selectedContentsValuesCount = 0; + int selectedTimeContentsValuesCount = 0; + int lowestSelectedClassValues = Int32.MaxValue; + string VariableWithLowestSelected=""; + + //int stubIndex = 1;// eller 0 ?????? + foreach (PXSqlVariable tmpVar in this.Values) + { + if (tmpVar.isSelected) + { + if (tmpVar.IsTimevariable) + { + selectedTimeValuesCount = tmpVar.Values.Count; + } + else if (tmpVar.IsContentVariable) + { + selectedContentsValuesCount = tmpVar.Values.Count; + } + else + { + selectedClassCount += 1; + if (tmpVar.Values.Count < lowestSelectedClassValues) + { + lowestSelectedClassValues = tmpVar.Values.Count; + VariableWithLowestSelected = tmpVar.Name; + } + } + } + + } + selectedTimeContentsValuesCount = selectedTimeValuesCount * selectedContentsValuesCount; + pivotAlg = DefaultPivot.alg1; + if (selectedTimeContentsValuesCount <= 12 && selectedClassCount > 0){ + pivotAlg = DefaultPivot.alg1; + } + if (selectedTimeContentsValuesCount > 12 && selectedTimeValuesCount <= 24) { + pivotAlg = DefaultPivot.alg2; + } + if(selectedTimeValuesCount > 24){ + pivotAlg = DefaultPivot.alg3; + } + if(selectedTimeContentsValuesCount <= 12 && selectedClassCount == 0){ + pivotAlg = DefaultPivot.alg4; + } + if ((selectedTimeContentsValuesCount == 1 && selectedClassCount > 1) && (lowestSelectedClassValues <= 24) ){ + pivotAlg = DefaultPivot.alg5; + } + switch(pivotAlg) + { + case DefaultPivot.alg1: + break; + case DefaultPivot.alg2: + foreach (PXSqlVariable tmpVar in this.Values) + { + if (tmpVar.isSelected) + { + if (tmpVar.IsTimevariable) + { + tmpVar.IsHeading = true; + tmpVar.IsStub = false; + tmpVar.Index = -2; + } + else if (tmpVar.IsContentVariable) + { + tmpVar.IsStub = true; + tmpVar.IsHeading = false; + tmpVar.Index = -2; + } + else + { + tmpVar.IsStub = true; + tmpVar.IsHeading = false; + } + } + } + break; + case DefaultPivot.alg3: + foreach (PXSqlVariable tmpVar in this.Values) + { + if (tmpVar.isSelected) + { + if (tmpVar.IsTimevariable) + { + tmpVar.IsStub = true; + tmpVar.IsHeading = false; + tmpVar.Index = 100; + } + else if (tmpVar.IsContentVariable) + { + tmpVar.IsHeading = true; + tmpVar.IsStub = false; + tmpVar.Index = -100; + } + else + { + tmpVar.IsStub = true; + tmpVar.IsHeading = false; + } + } + } + break; + case DefaultPivot.alg4: + foreach (PXSqlVariable tmpVar in this.Values) + { + if (tmpVar.isSelected) + { + if (tmpVar.IsTimevariable) + { + tmpVar.IsStub = false; + tmpVar.IsHeading = true; + tmpVar.Index = 1; + } + else if (tmpVar.IsContentVariable) + { + tmpVar.IsHeading = false; + tmpVar.IsStub = true; + tmpVar.Index = 1; + } + else + { + log.Warn("Variable " + tmpVar.Name + " isSelected, but neither time nor contents, something wring with algorithm . Setting it to stub"); + tmpVar.IsStub = true; + tmpVar.IsHeading = false; + } + } + } + break; + case DefaultPivot.alg5: + foreach (PXSqlVariable tmpVar in this.Values) + { + if (tmpVar.isSelected) + { + if (tmpVar.IsContentVariable) + { + tmpVar.IsHeading = true; + tmpVar.IsStub = false; + tmpVar.Index = -300; + } + else if (tmpVar.IsTimevariable) + { + tmpVar.IsStub = false; + tmpVar.IsHeading = true; + tmpVar.Index = -200; + } + else if (tmpVar.Name == VariableWithLowestSelected) + { + tmpVar.IsHeading = true; + tmpVar.IsStub = false; + tmpVar.Index = -100; + } + else + { + tmpVar.IsHeading = false; + tmpVar.IsStub = true; + } + } + } + break; + default: + break; + } } + internal void setStubHeadDefault() { //int stubIndex = 1;// eller 0 ?????? diff --git a/PCAxis.Sql/Parser_24/PXSqlVariables.cs b/PCAxis.Sql/Parser_24/PXSqlVariables.cs index b87d666..ccc594f 100644 --- a/PCAxis.Sql/Parser_24/PXSqlVariables.cs +++ b/PCAxis.Sql/Parser_24/PXSqlVariables.cs @@ -5,6 +5,7 @@ using PCAxis.Sql.QueryLib_24; using PCAxis.Paxiom; using PCAxis.Sql.Pxs; +using System.Configuration; using log4net; namespace PCAxis.Sql.Parser_24 @@ -15,12 +16,24 @@ public class PXSqlVariables : Dictionary private static readonly ILog log = LogManager.GetLogger(typeof(PXSqlVariables)); PXSqlMeta_24 meta; + VariableSortForSelection sortForSelection; public PXSqlVariables(PXSqlMeta_24 meta) { this.meta = meta; + sortForSelection = new VariableSortForSelection(); } + internal enum DefaultPivot + { + alg1, + alg2, + alg3, + alg4, + alg5, + alg6 + } + /// /// True if one or more variable has applied grouping and the grouping requires a sum in the dataextraction, i.e. not all data are stored . /// @@ -72,10 +85,186 @@ internal void setStubHeadPxs() } } + string shouldPivot = ConfigurationManager.AppSettings["autopivot"]; + if (shouldPivot != null) { + if (shouldPivot.ToLower() == "yes") + { + setStubHeadOverridden(); + } + } + } + internal void setStubHeadOverridden() + { + int numberOfVariables = this.Count; + DefaultPivot pivotAlg; + int selectedClassCount = 0; + int selectedTimeValuesCount = 0; + int selectedContentsValuesCount = 0; + int selectedTimeContentsValuesCount = 0; + int lowestSelectedClassValues = Int32.MaxValue; + string VariableWithLowestSelected=""; + + //int stubIndex = 1;// eller 0 ?????? + foreach (PXSqlVariable tmpVar in this.Values) + { + if (tmpVar.isSelected) + { + if (tmpVar.IsTimevariable) + { + selectedTimeValuesCount = tmpVar.Values.Count; + } + else if (tmpVar.IsContentVariable) + { + selectedContentsValuesCount = tmpVar.Values.Count; + } + else + { + selectedClassCount += 1; + if (tmpVar.Values.Count < lowestSelectedClassValues) + { + lowestSelectedClassValues = tmpVar.Values.Count; + VariableWithLowestSelected = tmpVar.Name; + } + } + } + + } + selectedTimeContentsValuesCount = selectedTimeValuesCount * selectedContentsValuesCount; + pivotAlg = DefaultPivot.alg1; + if (selectedTimeContentsValuesCount <= 12 && selectedClassCount > 0){ + pivotAlg = DefaultPivot.alg1; + } + if (selectedTimeContentsValuesCount > 12 && selectedTimeValuesCount <= 24) { + pivotAlg = DefaultPivot.alg2; + } + if(selectedTimeValuesCount > 24){ + pivotAlg = DefaultPivot.alg3; + } + if(selectedTimeContentsValuesCount <= 12 && selectedClassCount == 0){ + pivotAlg = DefaultPivot.alg4; + } + if ((selectedTimeContentsValuesCount == 1 && selectedClassCount > 1) && (lowestSelectedClassValues <= 24) ){ + pivotAlg = DefaultPivot.alg5; + } + switch(pivotAlg) + { + case DefaultPivot.alg1: + break; + case DefaultPivot.alg2: + foreach (PXSqlVariable tmpVar in this.Values) + { + if (tmpVar.isSelected) + { + if (tmpVar.IsTimevariable) + { + tmpVar.IsHeading = true; + tmpVar.IsStub = false; + tmpVar.Index = -2; + } + else if (tmpVar.IsContentVariable) + { + tmpVar.IsStub = true; + tmpVar.IsHeading = false; + tmpVar.Index = -2; + } + else + { + tmpVar.IsStub = true; + tmpVar.IsHeading = false; + } + } + } + break; + case DefaultPivot.alg3: + foreach (PXSqlVariable tmpVar in this.Values) + { + if (tmpVar.isSelected) + { + if (tmpVar.IsTimevariable) + { + tmpVar.IsStub = true; + tmpVar.IsHeading = false; + tmpVar.Index = 100; + } + else if (tmpVar.IsContentVariable) + { + tmpVar.IsHeading = true; + tmpVar.IsStub = false; + tmpVar.Index = -100; + } + else + { + tmpVar.IsStub = true; + tmpVar.IsHeading = false; + } + } + } + break; + case DefaultPivot.alg4: + foreach (PXSqlVariable tmpVar in this.Values) + { + if (tmpVar.isSelected) + { + if (tmpVar.IsTimevariable) + { + tmpVar.IsStub = false; + tmpVar.IsHeading = true; + tmpVar.Index = 1; + } + else if (tmpVar.IsContentVariable) + { + tmpVar.IsHeading = false; + tmpVar.IsStub = true; + tmpVar.Index = 1; + } + else + { + log.Warn("Variable " + tmpVar.Name + " isSelected, but neither time nor contents, something wring with algorithm . Setting it to stub"); + tmpVar.IsStub = true; + tmpVar.IsHeading = false; + } + } + } + break; + case DefaultPivot.alg5: + foreach (PXSqlVariable tmpVar in this.Values) + { + if (tmpVar.isSelected) + { + if (tmpVar.IsContentVariable) + { + tmpVar.IsHeading = true; + tmpVar.IsStub = false; + tmpVar.Index = -300; + } + else if (tmpVar.IsTimevariable) + { + tmpVar.IsStub = false; + tmpVar.IsHeading = true; + tmpVar.Index = -200; + } + else if (tmpVar.Name == VariableWithLowestSelected) + { + tmpVar.IsHeading = true; + tmpVar.IsStub = false; + tmpVar.Index = -100; + } + else + { + tmpVar.IsHeading = false; + tmpVar.IsStub = true; + } + } + } + break; + default: + break; + } } + internal void setStubHeadDefault() { //int stubIndex = 1;// eller 0 ?????? @@ -85,18 +274,18 @@ internal void setStubHeadDefault() { if (tmpVar.IsTimevariable) { - // tmpVar.Index = 1; + // tmpVar.Index = 1; tmpVar.IsHeading = true; } else if (tmpVar.IsContentVariable) { - // tmpVar.Index = 2; + // tmpVar.Index = 2; tmpVar.IsHeading = true; } else { - // tmpVar.Index = stubIndex; - // stubIndex++; + // tmpVar.Index = stubIndex; + // stubIndex++; tmpVar.IsStub = true; } } @@ -132,7 +321,14 @@ internal List GetHeadingSorted() } } } + // if (this.meta.inSelectionModus) + // { + // mHeadings.Sort(sortForSelection); + // } + // else + // { mHeadings.Sort(); + // } return mHeadings; } internal List GetStubSorted() @@ -148,7 +344,14 @@ internal List GetStubSorted() } } } - mStubs.Sort(); + // if (this.meta.inSelectionModus) + // { + // mStubs.Sort(sortForSelection); + // } + //else + // { + mStubs.Sort(); + // } return mStubs; } internal void ParseMeta(PCAxis.Paxiom.IPXModelParser.MetaHandler handler, StringCollection LanguageCodes) From f8a5e89b7cb1871c29fc02e2d1cef3ee1b72e60d Mon Sep 17 00:00:00 2001 From: Per Inge Vaaje Date: Thu, 18 Feb 2021 14:43:55 +0100 Subject: [PATCH 2/3] Remove commented code --- PCAxis.Sql/Parser_24/PXSqlVariables.cs | 87 ++++++++++++-------------- 1 file changed, 41 insertions(+), 46 deletions(-) diff --git a/PCAxis.Sql/Parser_24/PXSqlVariables.cs b/PCAxis.Sql/Parser_24/PXSqlVariables.cs index ccc594f..4918485 100644 --- a/PCAxis.Sql/Parser_24/PXSqlVariables.cs +++ b/PCAxis.Sql/Parser_24/PXSqlVariables.cs @@ -39,28 +39,29 @@ internal enum DefaultPivot /// internal bool HasAnyoneGroupingOnNonstoredData() { - - foreach (PXSqlVariable var in this.Values) + + foreach (PXSqlVariable var in this.Values) + { + if (var.UsesGroupingOnNonstoredData()) { - if (var.UsesGroupingOnNonstoredData() ) - { - return true; - } + return true; } - return false; - + } + return false; + } internal void setStubHeadPxs() { - int highestUsedStubIndex = 0 ; + int highestUsedStubIndex = 0; if (meta.PxsFile.Presentation.Stub != null) - foreach ( AxisType stub in meta.PxsFile.Presentation.Stub) + foreach (AxisType stub in meta.PxsFile.Presentation.Stub) { //mSqlVariable = this[stub.code]; this[stub.code].Index = stub.index; - if(stub.index > highestUsedStubIndex ) { + if (stub.index > highestUsedStubIndex) + { highestUsedStubIndex = stub.index; } this[stub.code].IsStub = true; @@ -71,13 +72,15 @@ internal void setStubHeadPxs() foreach (AxisType heading in meta.PxsFile.Presentation.Heading) { //mSqlVariable = this[heading.code]; - this[heading.code].Index = heading.index; - this[heading.code].IsHeading = true; + this[heading.code].Index = heading.index; + this[heading.code].IsHeading = true; } } - foreach (PXSqlVariable tmpVar in this.Values) { - if (tmpVar.isSelected && (!tmpVar.IsHeading) && (!tmpVar.IsStub)) { + foreach (PXSqlVariable tmpVar in this.Values) + { + if (tmpVar.isSelected && (!tmpVar.IsHeading) && (!tmpVar.IsStub)) + { log.Warn("Variable " + tmpVar.Name + " isSelected, but neither Heading nor Stub. Setting it to stub"); highestUsedStubIndex++; tmpVar.IsStub = true; @@ -85,11 +88,12 @@ internal void setStubHeadPxs() } } - string shouldPivot = ConfigurationManager.AppSettings["autopivot"]; - if (shouldPivot != null) { + string shouldPivot = ConfigurationManager.AppSettings["autopivot"]; + if (shouldPivot != null) + { if (shouldPivot.ToLower() == "yes") - { - setStubHeadOverridden(); + { + setStubHeadOverridden(); } } } @@ -102,7 +106,7 @@ internal void setStubHeadOverridden() int selectedContentsValuesCount = 0; int selectedTimeContentsValuesCount = 0; int lowestSelectedClassValues = Int32.MaxValue; - string VariableWithLowestSelected=""; + string VariableWithLowestSelected = ""; //int stubIndex = 1;// eller 0 ?????? foreach (PXSqlVariable tmpVar in this.Values) @@ -131,22 +135,27 @@ internal void setStubHeadOverridden() } selectedTimeContentsValuesCount = selectedTimeValuesCount * selectedContentsValuesCount; pivotAlg = DefaultPivot.alg1; - if (selectedTimeContentsValuesCount <= 12 && selectedClassCount > 0){ + if (selectedTimeContentsValuesCount <= 12 && selectedClassCount > 0) + { pivotAlg = DefaultPivot.alg1; } - if (selectedTimeContentsValuesCount > 12 && selectedTimeValuesCount <= 24) { + if (selectedTimeContentsValuesCount > 12 && selectedTimeValuesCount <= 24) + { pivotAlg = DefaultPivot.alg2; } - if(selectedTimeValuesCount > 24){ + if (selectedTimeValuesCount > 24) + { pivotAlg = DefaultPivot.alg3; } - if(selectedTimeContentsValuesCount <= 12 && selectedClassCount == 0){ + if (selectedTimeContentsValuesCount <= 12 && selectedClassCount == 0) + { pivotAlg = DefaultPivot.alg4; } - if ((selectedTimeContentsValuesCount == 1 && selectedClassCount > 1) && (lowestSelectedClassValues <= 24) ){ + if ((selectedTimeContentsValuesCount == 1 && selectedClassCount > 1) && (lowestSelectedClassValues <= 24)) + { pivotAlg = DefaultPivot.alg5; - } - switch(pivotAlg) + } + switch (pivotAlg) { case DefaultPivot.alg1: break; @@ -321,19 +330,12 @@ internal List GetHeadingSorted() } } } - // if (this.meta.inSelectionModus) - // { - // mHeadings.Sort(sortForSelection); - // } - // else - // { - mHeadings.Sort(); - // } - return mHeadings; + mHeadings.Sort(); + return mHeadings; } internal List GetStubSorted() { - List mStubs = new List(); + List mStubs = new List(); foreach (PXSqlVariable var in this.Values) { if (var.isSelected) @@ -344,14 +346,7 @@ internal List GetStubSorted() } } } - // if (this.meta.inSelectionModus) - // { - // mStubs.Sort(sortForSelection); - // } - //else - // { - mStubs.Sort(); - // } + mStubs.Sort(); return mStubs; } internal void ParseMeta(PCAxis.Paxiom.IPXModelParser.MetaHandler handler, StringCollection LanguageCodes) @@ -382,5 +377,5 @@ internal void ParseMeta(PCAxis.Paxiom.IPXModelParser.MetaHandler handler, String } } - + From 6e55c5cc6dfcc78029589e7a9bc9d311a235ce01 Mon Sep 17 00:00:00 2001 From: Per Inge Vaaje Date: Fri, 19 Feb 2021 07:04:02 +0100 Subject: [PATCH 3/3] Removed unused code --- PCAxis.Sql/Parser_24/PXSqlVariables.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/PCAxis.Sql/Parser_24/PXSqlVariables.cs b/PCAxis.Sql/Parser_24/PXSqlVariables.cs index 4918485..3db00bf 100644 --- a/PCAxis.Sql/Parser_24/PXSqlVariables.cs +++ b/PCAxis.Sql/Parser_24/PXSqlVariables.cs @@ -16,11 +16,9 @@ public class PXSqlVariables : Dictionary private static readonly ILog log = LogManager.GetLogger(typeof(PXSqlVariables)); PXSqlMeta_24 meta; - VariableSortForSelection sortForSelection; public PXSqlVariables(PXSqlMeta_24 meta) { this.meta = meta; - sortForSelection = new VariableSortForSelection(); }