/// <summary> /// Build a suitable collection of valid Metrics based on the selected MetricSet. /// <remarks>An empty MetricSet will result in all metrics being added, with the exception of Project /// level metrics which are always omitted.</remarks> /// </summary> /// <param name="metricSet">Selected MetricSet, acting as a filter on the columns to be displayed.</param> /// <returns></returns> protected MetricCollection ChooseMetrics(MetricSet metricSet) { MetricCollection rval = new MetricCollection(); foreach (Metric m in KrakatauSettings.Settings.Metrics) { bool include = false; if (m.Level == MetricLevel.Project) { include = false; } else if (metricSet == null) { include = true; } else { include = metricSet.Contains(m); } if (include) { rval.Add(m); } } return(rval); }
/// <summary> /// Retrieve the results from the database, building a crosstab with key Sourcefile attributes followed by all the /// metrics in the selected MetricSet (if any). /// </summary> /// <param name="set">DataSet into which the results should be added.</param> /// <param name="tableName"></param> /// <param name="tableName">Desired name for the results table.</param> /// <param name="metricSet">Selected MetricSet to use as a filter (may be null to include all metrics).</param> public void GetResults(DataSet set, string tableName, MetricSet metricSet) { lock (_semaphore) { if ((_cmdResults == null) || (_cmdResults.Connection != Connection)) { string sql = "SELECT sf.sfid, p.pr_name, sf.sf_shortname, sf.sf_type, cf.status, sm.mid, sm.mvalue " + "FROM sourcefile sf, comparefile cf, project p, sourcemetric sm " + "WHERE cf.sfid = sf.sfid " + "AND p.projid = sf.projid " + "AND sm.sfid = sf.sfid " + "AND sm.mvalue <> 0 " + "ORDER BY sf.sfid, sm.mid"; _cmdResults = new MySqlCommand(sql, Connection); _cmdResults.Prepare(); } } MetricCollection metrics = ChooseMetrics(metricSet); DataTable table = BuildTable(set, tableName, metrics); MySqlDataReader dr = _cmdResults.ExecuteReader(); DataRow row = null; long id; long prevousId = -1; long mid = 0; Metric m = null; while (dr.Read()) { id = long.Parse(dr["sfid"].ToString()); if (id != prevousId) { row = table.NewRow(); table.Rows.Add(row); row["Project"] = dr["pr_name"].ToString(); row["Filename"] = dr["sf_shortname"].ToString(); row["Lang"] = dr["sf_type"].ToString(); row["Status"] = ChurnStatuses.GetShortCode(dr["status"].ToString()); } mid = long.Parse(dr["mid"].ToString()); if (metrics.Contains(mid)) { m = metrics[mid]; if (table.Columns.Contains(m.Code)) { row[m.Code] = double.Parse(dr["mvalue"].ToString()); } } prevousId = id; } }
private void FormMetricSet_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (_btnLastPressed != null && _btnLastPressed == btnOK) { MetricSet ms = XmlConfig.Config.GetMetricSet(txtName.Text); if (ms != null && ms != this._msi.MetricSet) { btnOK.Enabled = false; stbMsg.Text = "The name you have entered already exists - please specify another."; e.Cancel = true; } } }
public FormMetricSets(IEnumerator metricSets) { InitializeComponent(); ItemsDeleted = false; while (metricSets.MoveNext()) { MetricSet ms = (MetricSet)metricSets.Current; ListViewItem lvi = new MetricSetItem(ms); this.lsvMetricSets.Items.Add(lvi); } }
public void RefreshView(object sender, RefreshViewArgs e) { if (OpenDatabase(e.Project)) { bool fullRefresh = false; if ((_view.Columns.Count == 0) || (_lastRefreshedMetricSet == null && _metricSet != null) || (_lastRefreshedMetricSet != null && _metricSet == null) || (_lastRefreshedMetricSet != _metricSet)) { fullRefresh = true; _view.DataSource = null; _view.Columns.Clear(); } DatabaseLayer.Instance.GetResults(_set, ResultsTable, _metricSet); _view.DataSource = new BindingSource(_set, ResultsTable); if (fullRefresh) { foreach (DataGridViewColumn col in _view.Columns) { if (col.Index == 0) { col.Width = 50; } if (col.Index == 1) { col.Width = 200; } else if (col.Index == 2 || col.Index == 3) { col.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; col.Width = 40; } else if (col.Index == (_view.Columns.Count - 1)) { col.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; col.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; } else if (col.Index > 3) { col.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; col.Width = 42; } } } _lastRefreshedMetricSet = _metricSet; } }
internal static MetricSet ToMetricSet(this HistoricalUsageMetricData data) { var metrics = new MetricSet { Name = data.Name, PrimaryAggregationType = data.PrimaryAggregationType, TimeGrain = data.TimeGrain, StartTime = data.StartTime, EndTime = data.EndTime, Unit = data.Unit, Values = data.Values.ToMetricSamples().ToList(), }; return(metrics); }
private void AppendMetricDefs(SortedList mets) { MetricSet ms = this._msi.MetricSet; IEnumerator defs = mets.Values.GetEnumerator(); Hashtable f; while (defs.MoveNext()) { f = (Hashtable)defs.Current; MetricDef md = (MetricDef)f["MetricDef"]; if (md != null && md.Active) { ms.Add(md); } } }
private void RegisterAll(MetricName prefix, MetricSet metricSet) { if (prefix == null) { prefix = MetricName.EMPTY; } foreach (KeyValuePair <MetricName, IMetric> entry in metricSet.Metrics) { if (entry.Value is MetricSet) { RegisterAll(MetricName.join(prefix, entry.Key), (MetricSet)entry.Value); } else { Register(MetricName.join(prefix, entry.Key), entry.Value); } } }
internal static MetricSet ToMetricSet(this HistoricalUsageMetricData data) { var metrics = new MetricSet { Name = data.Name, PrimaryAggregationType = data.PrimaryAggregationType, TimeGrain = data.TimeGrain, StartTime = data.StartTime, EndTime = data.EndTime, Unit = data.Unit, Values = data.Values.ToMetricSamples().ToList(), }; return metrics; }