Changeset 1108
- Timestamp:
- 01/11/09 19:30:54 (16 years ago)
- Location:
- branches/CEDMA-Refactoring-Ticket419
- Files:
-
- 9 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Charting/BubbleChart.cs
r1106 r1108 31 31 namespace HeuristicLab.CEDMA.Charting { 32 32 public class BubbleChart : Chart { 33 private const string X_JITTER = "__X_JITTER"; 34 private const string Y_JITTER = "__Y_JITTER"; 33 35 private const double maxXJitterPercent = 0.05; 34 36 private const double maxYJitterPercent = 0.05; … … 50 52 private double maxX = double.NegativeInfinity; 51 53 private double maxY = double.NegativeInfinity; 52 private List<Re cord> records;54 private List<ResultsEntry> records; 53 55 private Results results; 54 private Dictionary<IPrimitive, Re cord> primitiveToRecordDictionary;55 private Dictionary<Re cord, IPrimitive> recordToPrimitiveDictionary;56 private Dictionary<IPrimitive, ResultsEntry> primitiveToEntryDictionary; 57 private Dictionary<ResultsEntry, IPrimitive> entryToPrimitiveDictionary; 56 58 private Random random = new Random(); 57 59 private Group points; … … 59 61 public BubbleChart(Results results, PointD lowerLeft, PointD upperRight) 60 62 : base(lowerLeft, upperRight) { 61 records = new List<Re cord>();62 primitiveTo RecordDictionary = new Dictionary<IPrimitive, Record>();63 recordToPrimitiveDictionary = new Dictionary<Record, IPrimitive>();63 records = new List<ResultsEntry>(); 64 primitiveToEntryDictionary = new Dictionary<IPrimitive, ResultsEntry>(); 65 entryToPrimitiveDictionary = new Dictionary<ResultsEntry, IPrimitive>(); 64 66 this.results = results; 65 foreach(Record r in results.Records) {66 records.Add(r);67 }68 results.OnRecordAdded += new EventHandler<RecordAddedEventArgs>(results_OnRecordAdded);69 results.Changed += new EventHandler(results_Changed);70 67 } 71 68 … … 75 72 } 76 73 77 public BubbleChart(Result Listresults, double x1, double y1, double x2, double y2)74 public BubbleChart(Results results, double x1, double y1, double x2, double y2) 78 75 : this(results, new PointD(x1, y1), new PointD(x2, y2)) { 79 76 } 80 77 81 void results_OnRecordAdded(object sender, RecordAddedEventArgs e) {82 lock(records) {83 records.Add(e.Record);84 }85 }78 //void results_OnRecordAdded(object sender, RecordAddedEventArgs e) { 79 // lock(records) { 80 // records.Add(e.Record); 81 // } 82 //} 86 83 87 84 public void SetBubbleSizeDimension(string dimension, bool inverted) { … … 93 90 94 91 public void ShowXvsY(string xDimension, string yDimension) { 95 if (this.xDimension != xDimension || this.yDimension != yDimension) {92 if (this.xDimension != xDimension || this.yDimension != yDimension) { 96 93 this.xDimension = xDimension; 97 94 this.yDimension = yDimension; 95 96 foreach (var resultsEntry in results.SelectRows()) { 97 resultsEntry.Set(X_JITTER, random.NextDouble() * 2.0 - 1.0); 98 resultsEntry.Set(Y_JITTER, random.NextDouble() * 2.0 - 1.0); 99 records.Add(resultsEntry); 100 } 98 101 ResetViewSize(); 99 102 Repaint(); … … 110 113 111 114 private void Repaint() { 112 if(xDimension == null || yDimension == null) return; 113 lock(records) { 114 double maxSize = 1; 115 double minSize = 1; 116 if(sizeDimension != null) { 117 var sizes = records.Select(r => r.Get(sizeDimension)).Where(x => !double.IsInfinity(x) && x != double.MaxValue && x != double.MinValue).OrderBy(x=>x); 115 if (xDimension == null || yDimension == null) return; 116 double maxSize = 1; 117 double minSize = 1; 118 try { 119 if (sizeDimension != null && Results.OrdinalVariables.Contains(sizeDimension)) { 120 var sizes = records 121 .Select(x => Convert.ToDouble(x.Get(sizeDimension))) 122 .Where(size => !double.IsInfinity(size) && size != double.MaxValue && size != double.MinValue) 123 .OrderBy(r => r); 118 124 minSize = sizes.ElementAt((int)(sizes.Count() * 0.1)); 119 125 maxSize = sizes.ElementAt((int)(sizes.Count() * 0.9)); 120 126 } 121 UpdateEnabled = false; 122 Group.Clear(); 123 primitiveToRecordDictionary.Clear(); 124 recordToPrimitiveDictionary.Clear(); 125 points = new Group(this); 126 Group.Add(new Axis(this, 0, 0, AxisType.Both)); 127 UpdateViewSize(0, 0, 5); 128 foreach(Record r in records) { 129 double x = r.Get(xDimension) + r.Get(Record.X_JITTER) * xJitterFactor; 130 double y = r.Get(yDimension) + r.Get(Record.Y_JITTER) * yJitterFactor; 131 int size = CalculateSize(r.Get(sizeDimension), minSize, maxSize); 132 133 if(double.IsInfinity(x) || x == double.MaxValue || x == double.MinValue) x = double.NaN; 134 if(double.IsInfinity(y) || y == double.MaxValue || y == double.MinValue) y = double.NaN; 135 if(!double.IsNaN(x) && !double.IsNaN(y)) { 136 UpdateViewSize(x, y, size); 137 int alpha = CalculateAlpha(size); 138 Pen pen = new Pen(Color.FromArgb(alpha, r.Selected ? selectionColor : defaultColor)); 139 Brush brush = pen.Brush; 140 FixedSizeCircle c = new FixedSizeCircle(this, x, y, size, pen, brush); 141 c.ToolTipText = r.GetToolTipText(); 142 points.Add(c); 143 if(!r.Selected) c.IntoBackground(); 144 primitiveToRecordDictionary[c] = r; 145 recordToPrimitiveDictionary[r] = c; 146 } 147 } 148 Group.Add(points); 149 UpdateEnabled = true; 150 } 127 } 128 catch (InvalidCastException) { 129 minSize = 1; 130 maxSize = 1; 131 } 132 UpdateEnabled = false; 133 Group.Clear(); 134 primitiveToEntryDictionary.Clear(); 135 entryToPrimitiveDictionary.Clear(); 136 points = new Group(this); 137 Group.Add(new Axis(this, 0, 0, AxisType.Both)); 138 UpdateViewSize(0, 0, 5); 139 foreach (ResultsEntry r in records) { 140 double x, y; 141 int size; 142 try { 143 x = Convert.ToDouble(r.Get(xDimension)) + (double)r.Get(X_JITTER) * xJitterFactor; 144 y = Convert.ToDouble(r.Get(yDimension)) + (double)r.Get(Y_JITTER) * yJitterFactor; 145 size = CalculateSize(Convert.ToDouble(r.Get(sizeDimension)), minSize, maxSize); 146 } 147 catch (InvalidCastException) { 148 x = double.NaN; 149 y = double.NaN; 150 size = minBubbleSize; 151 } 152 if (double.IsInfinity(x) || x == double.MaxValue || x == double.MinValue) x = double.NaN; 153 if (double.IsInfinity(y) || y == double.MaxValue || y == double.MinValue) y = double.NaN; 154 if (!double.IsNaN(x) && !double.IsNaN(y)) { 155 UpdateViewSize(x, y, size); 156 int alpha = CalculateAlpha(size); 157 Pen pen = new Pen(Color.FromArgb(alpha, r.Selected ? selectionColor : defaultColor)); 158 Brush brush = pen.Brush; 159 FixedSizeCircle c = new FixedSizeCircle(this, x, y, size, pen, brush); 160 c.ToolTipText = r.GetToolTipText(); 161 points.Add(c); 162 if (!r.Selected) c.IntoBackground(); 163 primitiveToEntryDictionary[c] = r; 164 entryToPrimitiveDictionary[r] = c; 165 } 166 } 167 Group.Add(points); 168 UpdateEnabled = true; 151 169 } 152 170 153 171 private int CalculateSize(double size, double minSize, double maxSize) { 154 if(double.IsNaN(size) || double.IsInfinity(size) || size == double.MaxValue || size == double.MinValue) return minBubbleSize; 155 if(size > maxSize) size = maxSize; 156 if(size < minSize) size = minSize; 172 if (double.IsNaN(size) || double.IsInfinity(size) || size == double.MaxValue || size == double.MinValue) return minBubbleSize; 173 if (size > maxSize) size = maxSize; 174 if (size < minSize) size = minSize; 175 if (Math.Abs(maxSize - minSize) < 1.0E-10) return minBubbleSize; 157 176 double sizeDifference = ((size - minSize) / (maxSize - minSize) * (maxBubbleSize - minBubbleSize)); 158 if (invertSize) return maxBubbleSize - (int)sizeDifference;177 if (invertSize) return maxBubbleSize - (int)sizeDifference; 159 178 else return minBubbleSize + (int)sizeDifference; 160 179 } … … 165 184 166 185 private void ZoomToViewSize() { 167 if (minX < maxX && minY < maxY) {186 if (minX < maxX && minY < maxY) { 168 187 // enlarge view by 5% on each side 169 188 double width = maxX - minX; … … 178 197 179 198 private void UpdateViewSize(double x, double y, double size) { 180 if (x - size < minX) minX = x - size;181 if (x + size > maxX) maxX = x + size;182 if (y - size < minY) minY = y + size;183 if (y + size > maxY) maxY = y + size;199 if (x - size < minX) minX = x - size; 200 if (x + size > maxX) maxX = x + size; 201 if (y - size < minY) minY = y + size; 202 if (y + size > maxY) maxY = y + size; 184 203 } 185 204 … … 191 210 } 192 211 193 internal Re cord GetRecord(Point point) {194 Re cordr = null;212 internal ResultsEntry GetResultsEntry(Point point) { 213 ResultsEntry r = null; 195 214 IPrimitive p = points.GetPrimitive(TransformPixelToWorld(point)); 196 if (p != null) {197 primitiveTo RecordDictionary.TryGetValue(p, out r);215 if (p != null) { 216 primitiveToEntryDictionary.TryGetValue(p, out r); 198 217 } 199 218 return r; … … 202 221 203 222 public override void MouseDrag(Point start, Point end, MouseButtons button) { 204 if (button == MouseButtons.Left && Mode == ChartMode.Select) {223 if (button == MouseButtons.Left && Mode == ChartMode.Select) { 205 224 PointD a = TransformPixelToWorld(start); 206 225 PointD b = TransformPixelToWorld(end); … … 214 233 primitives.AddRange(points.Primitives); 215 234 216 foreach (FixedSizeCircle p in primitives) {217 if (rect.ContainsPoint(p.Point)) {218 Re cordr;219 primitiveTo RecordDictionary.TryGetValue(p, out r);220 if (r != null) r.ToggleSelected();235 foreach (FixedSizeCircle p in primitives) { 236 if (rect.ContainsPoint(p.Point)) { 237 ResultsEntry r; 238 primitiveToEntryDictionary.TryGetValue(p, out r); 239 if (r != null) r.ToggleSelected(); 221 240 } 222 241 } 223 results.FireChanged();242 // results.FireChanged(); 224 243 } else { 225 244 base.MouseDrag(start, end, button); … … 228 247 229 248 public override void MouseClick(Point point, MouseButtons button) { 230 if (button == MouseButtons.Left) {231 Re cord r = GetRecord(point);232 if (r != null) r.ToggleSelected();233 results.FireChanged();249 if (button == MouseButtons.Left) { 250 ResultsEntry r = GetResultsEntry(point); 251 if (r != null) r.ToggleSelected(); 252 // results.FireChanged(); 234 253 } else { 235 254 base.MouseClick(point, button); … … 237 256 } 238 257 239 public override void MouseDoubleClick(Point point, MouseButtons button) {240 if(button == MouseButtons.Left) {241 Record r = GetRecord(point);242 if(r != null) r.OpenModel();243 } else {244 base.MouseDoubleClick(point, button);245 }246 }258 //public override void MouseDoubleClick(Point point, MouseButtons button) { 259 // if(button == MouseButtons.Left) { 260 // Record r = GetRecord(point); 261 // if(r != null) r.OpenModel(); 262 // } else { 263 // base.MouseDoubleClick(point, button); 264 // } 265 //} 247 266 } 248 267 } -
branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Charting/BubbleChartView.cs
r1106 r1108 12 12 13 13 namespace HeuristicLab.CEDMA.Charting { 14 public partial class BubbleChartView : ViewBase {14 public partial class BubbleChartView : ViewBase, IResultsView { 15 15 private Results results; 16 16 private const string CONSTANT_SIZE = "<constant>"; 17 17 private Label pleaseSelectAxisLabel = new Label(); 18 18 19 public BubbleChartView(Results results) { 20 this.results = results; 19 public BubbleChartView() { 21 20 InitializeComponent(); 22 bubbleChartControl.Chart = new BubbleChart(results, 0, 0, 100, 100);23 xAxisComboBox.Items.AddRange(results.OrdinalVariableNames);24 yAxisComboBox.Items.AddRange(results.OrdinalVariableNames);25 sizeComboBox.Items.Add(CONSTANT_SIZE);26 sizeComboBox.Items.AddRange(results.VariableNames);27 sizeComboBox.SelectedItem = sizeComboBox.Items[0];28 sizeComboBox.Enabled = false;29 invertCheckbox.Enabled = false;30 sizeLabel.Enabled = false;31 yAxisComboBox.SelectedItem = yAxisComboBox.Items[0];32 xAxisComboBox.SelectedItem = xAxisComboBox.Items[0];33 21 } 34 22 … … 39 27 private void UpdateChart() { 40 28 if (xAxisComboBox.SelectedItem == null || yAxisComboBox.SelectedItem == null) return; 41 xJitterlabel.Enabled = true;42 xTrackBar.Enabled = true;43 yJitterLabel.Enabled = true;44 yTrackBar.Enabled = true;45 sizeComboBox.Enabled = true;46 invertCheckbox.Enabled = true;47 sizeLabel.Enabled = true;48 29 bubbleChartControl.Chart.ShowXvsY((string)xAxisComboBox.SelectedItem, (string)yAxisComboBox.SelectedItem); 49 30 } … … 64 45 } 65 46 } 47 48 #region IResultsView Members 49 50 public Control Control { 51 get { return this; } 52 } 53 54 string IResultsView.Name { 55 get { return "Bubble chart"; } 56 } 57 58 public void ShowResults(Results results) { 59 this.results = results; 60 bubbleChartControl.Chart = new BubbleChart(results, 0, 0, 100, 100); 61 xAxisComboBox.Items.AddRange(Results.OrdinalVariables); 62 xAxisComboBox.Items.AddRange(Results.CategoricalVariables); 63 yAxisComboBox.Items.AddRange(Results.OrdinalVariables); 64 yAxisComboBox.Items.AddRange(Results.CategoricalVariables); 65 sizeComboBox.Items.Add(CONSTANT_SIZE); 66 sizeComboBox.Items.AddRange(Results.OrdinalVariables); 67 sizeComboBox.SelectedItem = sizeComboBox.Items[0]; 68 yAxisComboBox.SelectedItem = yAxisComboBox.Items[0]; 69 xAxisComboBox.SelectedItem = xAxisComboBox.Items[0]; 70 } 71 72 #endregion 66 73 } 67 74 } -
branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Charting/HeuristicLab.CEDMA.Charting.csproj
r1106 r1108 66 66 </ItemGroup> 67 67 <ItemGroup> 68 <Compile Include="BubbleChart.cs" /> 69 <Compile Include="BubbleChartControl.cs"> 70 <SubType>UserControl</SubType> 71 </Compile> 72 <Compile Include="BubbleChartControl.Designer.cs"> 73 <DependentUpon>BubbleChartControl.cs</DependentUpon> 74 </Compile> 75 <Compile Include="BubbleChartView.cs"> 76 <SubType>UserControl</SubType> 77 </Compile> 78 <Compile Include="BubbleChartView.Designer.cs"> 79 <DependentUpon>BubbleChartView.cs</DependentUpon> 80 </Compile> 68 81 <Compile Include="HeuristicLabCedmaChartingPlugin.cs" /> 69 82 <Compile Include="Properties\AssemblyInfo.cs" /> … … 98 111 <Name>HeuristicLab.Data</Name> 99 112 </ProjectReference> 100 <ProjectReference Include="..\HeuristicLab.GP.StructureIdentification\HeuristicLab.GP.StructureIdentification.csproj">101 <Project>{74223A32-C726-4978-BE78-37113A18373C}</Project>102 <Name>HeuristicLab.GP.StructureIdentification</Name>103 </ProjectReference>104 <ProjectReference Include="..\HeuristicLab.GP\HeuristicLab.GP.csproj">105 <Project>{1F1CF3ED-374C-4288-995B-93F6B872F571}</Project>106 <Name>HeuristicLab.GP</Name>107 </ProjectReference>108 113 <ProjectReference Include="..\HeuristicLab.Logging\HeuristicLab.Logging.csproj"> 109 114 <Project>{4095C92C-5A4C-44BC-9963-5F384CF5CC3F}</Project> … … 118 123 <None Include="HeuristicLab.snk" /> 119 124 <None Include="Properties\AssemblyInfo.frame" /> 125 </ItemGroup> 126 <ItemGroup> 127 <EmbeddedResource Include="BubbleChartControl.resx"> 128 <DependentUpon>BubbleChartControl.cs</DependentUpon> 129 </EmbeddedResource> 130 <EmbeddedResource Include="BubbleChartView.resx"> 131 <DependentUpon>BubbleChartView.cs</DependentUpon> 132 </EmbeddedResource> 120 133 </ItemGroup> 121 134 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> -
branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/DataSetView.Designer.cs
r1106 r1108 45 45 /// </summary> 46 46 private void InitializeComponent() { 47 this.editorGroupBox = new System.Windows.Forms.GroupBox();48 this.activateButton = new System.Windows.Forms.Button();49 this.resultsButton = new System.Windows.Forms.Button();50 this.SuspendLayout();51 //52 // editorGroupBox53 //54 this.editorGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)55 | System.Windows.Forms.AnchorStyles.Left)56 | System.Windows.Forms.AnchorStyles.Right)));57 this.editorGroupBox.Location = new System.Drawing.Point(0, 3);58 this.editorGroupBox.Name = "editorGroupBox";59 this.editorGroupBox.Size = new System.Drawing.Size(274, 119);60 this.editorGroupBox.TabIndex = 0;61 this.editorGroupBox.TabStop = false;62 this.editorGroupBox.Text = "&Editor:";63 //64 // activateButton65 //66 this.activateButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));67 this.activateButton.Location = new System.Drawing.Point(3, 128);68 this.activateButton.Name = "activateButton";69 this.activateButton.Size = new System.Drawing.Size(75, 23);70 this.activateButton.TabIndex = 2;71 this.activateButton.Text = "&Activate";72 this.activateButton.UseVisualStyleBackColor = true;73 this.activateButton.Click += new System.EventHandler(this.activateButton_Click);74 //75 // resultsButton76 //77 this.resultsButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));78 this.resultsButton.Location = new System.Drawing.Point(84, 128);79 this.resultsButton.Name = "resultsButton";80 this.resultsButton.Size = new System.Drawing.Size(75, 23);81 this.resultsButton.TabIndex = 3;82 this.resultsButton.Text = "Show results";83 this.resultsButton.UseVisualStyleBackColor = true;84 this.resultsButton.Click += new System.EventHandler(this.resultsButton_Click);85 //86 // DataSetView87 //88 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);89 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;90 this.Controls.Add(this.resultsButton);91 this.Controls.Add(this.activateButton);92 this.Controls.Add(this.editorGroupBox);93 this.Name = "DataSetView";94 this.Size = new System.Drawing.Size(274, 154);95 this.ResumeLayout(false);47 this.editorGroupBox = new System.Windows.Forms.GroupBox(); 48 this.activateButton = new System.Windows.Forms.Button(); 49 this.resultsButton = new System.Windows.Forms.Button(); 50 this.SuspendLayout(); 51 // 52 // editorGroupBox 53 // 54 this.editorGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 55 | System.Windows.Forms.AnchorStyles.Left) 56 | System.Windows.Forms.AnchorStyles.Right))); 57 this.editorGroupBox.Location = new System.Drawing.Point(0, 3); 58 this.editorGroupBox.Name = "editorGroupBox"; 59 this.editorGroupBox.Size = new System.Drawing.Size(274, 119); 60 this.editorGroupBox.TabIndex = 0; 61 this.editorGroupBox.TabStop = false; 62 this.editorGroupBox.Text = "&Editor:"; 63 // 64 // activateButton 65 // 66 this.activateButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 67 this.activateButton.Location = new System.Drawing.Point(3, 128); 68 this.activateButton.Name = "activateButton"; 69 this.activateButton.Size = new System.Drawing.Size(75, 23); 70 this.activateButton.TabIndex = 2; 71 this.activateButton.Text = "&Activate"; 72 this.activateButton.UseVisualStyleBackColor = true; 73 this.activateButton.Click += new System.EventHandler(this.activateButton_Click); 74 // 75 // resultsButton 76 // 77 this.resultsButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 78 this.resultsButton.Location = new System.Drawing.Point(84, 128); 79 this.resultsButton.Name = "resultsButton"; 80 this.resultsButton.Size = new System.Drawing.Size(86, 23); 81 this.resultsButton.TabIndex = 3; 82 this.resultsButton.Text = "Show results"; 83 this.resultsButton.UseVisualStyleBackColor = true; 84 this.resultsButton.Click += new System.EventHandler(this.resultsButton_Click); 85 // 86 // DataSetView 87 // 88 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 89 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 90 this.Controls.Add(this.resultsButton); 91 this.Controls.Add(this.activateButton); 92 this.Controls.Add(this.editorGroupBox); 93 this.Name = "DataSetView"; 94 this.Size = new System.Drawing.Size(274, 154); 95 this.ResumeLayout(false); 96 96 97 97 } -
branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/HeuristicLab.CEDMA.Core.csproj
r1106 r1108 72 72 </ItemGroup> 73 73 <ItemGroup> 74 <Compile Include="ResultsEntry.cs" /> 74 75 <Compile Include="TableResultsView.cs"> 75 76 <SubType>UserControl</SubType> -
branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/IResultsView.cs
r1106 r1108 33 33 public interface IResultsView { 34 34 Control Control { get; } 35 string Name { get; } 35 36 void ShowResults(Results results); 36 37 } -
branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/Results.cs
r1106 r1108 63 63 } 64 64 65 internal IEnumerable<object[]> SelectRows(List<string> columnNames) { 66 if (store == null) yield return null; 67 68 Resource[] columnNamesRes = columnNames.Select(x => new Literal(x)).ToArray(); 65 public IEnumerable<ResultsEntry> SelectRows() { 66 if (store == null) yield break; 69 67 70 68 var results = store.Select(new Statement(dataSetEntity, Ontology.PredicateHasModel, Ontology.AnyEntity)) … … 78 76 new Entity[] { (Entity)x.Property }, 79 77 new Entity[] { Ontology.PredicateModelAttributeName }, 80 columnNamesRes)).Select(y =>78 new Entity[] { Ontology.AnyEntity })).Select(y => 81 79 new { 82 80 Model = x.Subject, … … 92 90 AttributeName = x.AttributeName.Value, 93 91 AttributeValue = ((Literal)y.Property).Value 94 })).GroupBy(x =>x.Model);92 })).GroupBy(x => x.Model); 95 93 96 94 97 95 Random random = new Random(); 98 96 foreach (var row in results) { 97 ResultsEntry entry = new ResultsEntry(row.First().Model); 98 foreach (var attr in row) { 99 entry.Set((string)attr.AttributeName, attr.AttributeValue); 100 } 101 yield return entry; 102 } 103 } 99 104 100 yield return row.Select(x => x.AttributeValue).ToArray(); 101 //if (ss.Length > 0) { 102 // Record r = new Record(this, ss[0].Subject.Uri); 103 // r.Set(Record.X_JITTER, random.NextDouble() * 2.0 - 1.0); 104 // r.Set(Record.Y_JITTER, random.NextDouble() * 2.0 - 1.0); 105 // foreach (Statement s in ss) { 106 // string varName; 107 // predicateToVariableName.TryGetValue(s.Predicate, out varName); 108 // if (varName != null) { 109 // if (varName == Record.TREE_HEIGHT || varName == Record.TREE_SIZE || varName == Record.TARGET_VARIABLE) { 110 // r.Set(varName, (double)(int)((Literal)s.Property).Value); 111 // } else { 112 // r.Set(varName, (double)((Literal)s.Property).Value); 113 // } 114 // } 115 // } 116 //} 105 internal IEnumerable<string> SelectModelAttributes() { 106 if (store == null) yield break; 107 108 var attributeNames = 109 store.Select(new Statement(Ontology.AnyEntity, Ontology.PredicateModelAttributeName, Ontology.AnyEntity)) 110 .Select(s => (string)((Literal)s.Property).Value) 111 .Distinct(); 112 foreach (var name in attributeNames) { 113 yield return name; 117 114 } 118 115 } -
branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/ResultsEntry.cs
r1107 r1108 1 1 #region License Information 2 /* HeuristicLab3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)4 *5 * This file is part of HeuristicLab.6 *7 * HeuristicLab is free software: you can redistribute it and/or modify8 * it under the terms of the GNU General Public License as published by9 * the Free Software Foundation, either version 3 of the License, or10 * (at your option) any later version.11 *12 * HeuristicLab is distributed in the hope that it will be useful,13 * but WITHOUT ANY WARRANTY; without even the implied warranty of14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15 * GNU General Public License for more details.16 *17 * You should have received a copy of the GNU General Public License18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.19 */20 #endregion21 22 #region License Information23 2 /* HeuristicLab 24 3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL) … … 53 32 using HeuristicLab.PluginInfrastructure; 54 33 55 namespace HeuristicLab.CEDMA.Charting { 56 public class Record { 57 public const string MAPE_TRAINING = "MAPE (training)"; 58 public const string MAPE_VALIDATION = "MAPE (validation)"; 59 public const string MAPE_TEST = "MAPE (test)"; 60 public const string R2_TRAINING = "R2 (training)"; 61 public const string R2_VALIDATION = "R2 (validation)"; 62 public const string R2_TEST = "R2 (test)"; 63 public const string TARGET_VARIABLE = "Target variable"; 64 public const string TREE_SIZE = "Tree size"; 65 public const string TREE_HEIGHT = "Tree height"; 66 public const string SELECTIONPRESSURE = "Selection pressure"; 67 68 public const string X_JITTER = "__X_JITTER"; 69 public const string Y_JITTER = "__Y_JITTER"; 70 71 private Dictionary<string, double> values = new Dictionary<string, double>(); 72 private ResultList resultList; 34 namespace HeuristicLab.CEDMA.Core { 35 public class ResultsEntry { 36 private Dictionary<string, object> values = new Dictionary<string, object>(); 73 37 74 38 private bool selected = false; … … 77 41 private string uri; 78 42 public string Uri { get { return uri; } } 79 public Record(ResultList resultList, string uri) { 43 44 public ResultsEntry(string uri) { 80 45 this.uri = uri; 81 this.resultList = resultList;82 46 } 83 47 84 public void Set(string name, doublevalue) {48 public void Set(string name, object value) { 85 49 values.Add(name, value); 86 50 } 87 51 88 public doubleGet(string name) {89 if (name == null || !values.ContainsKey(name)) return double.NaN;52 public object Get(string name) { 53 if (name == null || !values.ContainsKey(name)) return null; 90 54 return values[name]; 91 55 } … … 95 59 } 96 60 97 internalstring GetToolTipText() {61 public string GetToolTipText() { 98 62 StringBuilder b = new StringBuilder(); 99 foreach(KeyValuePair<string, double> v in values) { 100 if(v.Key != X_JITTER && v.Key != Y_JITTER) { 101 b.Append(v.Key).Append(" = ").Append(v.Value).AppendLine(); 102 } 63 foreach (KeyValuePair<string, object> v in values) { 64 b.Append(v.Key).Append(" = ").Append(v.Value).AppendLine(); 103 65 } 104 66 return b.ToString(); 105 67 } 106 68 107 internal void OpenModel() {108 resultList.OpenModel(this);109 }69 //internal void OpenModel() { 70 // resultList.OpenModel(this); 71 //} 110 72 111 internal void OpenGeneratingAlgorithm() {112 resultList.OpenAlgorithm(this);113 }73 //internal void OpenGeneratingAlgorithm() { 74 // resultList.OpenAlgorithm(this); 75 //} 114 76 } 115 77 } -
branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/ResultsViewContainer.cs
r1106 r1108 18 18 InitializeComponent(); 19 19 PopulateViewComboBox(); 20 showButton.Enabled = false;20 showButton.Enabled = viewComboBox.SelectedItem != null; 21 21 } 22 22 23 23 private void PopulateViewComboBox() { 24 24 DiscoveryService service = new DiscoveryService(); 25 Type[] viewTypes = service.GetTypes(typeof(IResultsView));26 foreach (Type t in viewTypes)27 viewComboBox.Items.Add(t);25 IResultsView[] views = service.GetInstances<IResultsView>(); 26 viewComboBox.DataSource = views; 27 viewComboBox.ValueMember = "Name"; 28 28 } 29 29 … … 31 31 viewPanel.Controls.Clear(); 32 32 try { 33 Type type = (Type)viewComboBox.SelectedItem; 34 IResultsView view = (IResultsView)Activator.CreateInstance(type); 33 IResultsView view = (IResultsView)viewComboBox.SelectedItem; 35 34 Control control = view.Control; 36 35 viewPanel.Controls.Add(control); -
branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/TableResultsView.cs
r1106 r1108 21 21 } 22 22 23 string IResultsView.Name { 24 get { return "Table"; } 25 } 26 23 27 public void ShowResults(Results results) { 24 28 this.results = results; … … 29 33 base.UpdateControls(); 30 34 if (results == null) return; 31 List<string> columnNames = new List<string>();32 columnNames.AddRange(Results.CategoricalVariables);33 columnNames.AddRange(Results.OrdinalVariables);34 35 dataGridView.Rows.Clear(); 35 36 dataGridView.Columns.Clear(); 36 foreach (string varName in columnNames) { 37 dataGridView.Columns.Add(varName, varName); 37 List<string> attributeNames = results.SelectModelAttributes().ToList(); 38 foreach (var attribute in attributeNames) { 39 dataGridView.Columns.Add(attribute, attribute); 38 40 } 39 41 40 foreach (object[] row in results.SelectRows(columnNames)) { 42 var entries = results.SelectRows(); 43 foreach (var entry in entries) { 44 int rowIndex = dataGridView.Rows.Add(); 45 foreach (string attrName in attributeNames) { 46 dataGridView.Rows[rowIndex].Cells[attrName].Value = entry.Get(attrName); 47 } 41 48 dataGridView.Rows.Add(row); 42 49 }
Note: See TracChangeset
for help on using the changeset viewer.