private static string AllGranularDescendantsHaveNullValues(MetricBase metricBase) { if (metricBase.MetricType == MetricType.GranularMetric) { if (((IGranularMetric) metricBase).Value == null) return "true"; else return "false"; } if (metricBase.MetricType == MetricType.ContainerMetric || metricBase.MetricType == MetricType.AggregateMetric) { bool anyGranularsWithValues = (from m in ((ContainerMetric) metricBase).Descendants where m.MetricType == MetricType.GranularMetric && ((IGranularMetric) m).Value != null select m) .Any(); if (!anyGranularsWithValues) return "true"; else return "false"; } return "false"; // TODO: Should we throw an exception to call out this condition if it were ever to occur? // throw new Exception(string.Format("Unrecognized metric type '{0}'.", metricBase.MetricType)); }
public void ProvideContext(MetricBase metric, IDictionary<string, object> context) { if(!context.ContainsKey("MetricRenderingContext")) { context["MetricRenderingContext"] = new Dictionary<string, object>(); } }
public byte[] Serialize(MetricBase metric) { var memStream = new MemoryStream(); _formatter.Serialize(memStream, metric); return(memStream.GetBuffer()); }
private static Dictionary<string, string> GetMetricRenderingContextValues(MetricBase metricBase, int depth, RenderingMode renderingMode, bool open) { var contextValues = new Dictionary<string, string> { { "MetricInstanceSetType", string.IsNullOrEmpty(metricBase.DomainEntityType) ? "" : metricBase.DomainEntityType.Replace(" ","") }, { "MetricType", metricBase.MetricType.ToString() }, { "Depth", "Level" + depth.ToString(CultureInfo.InvariantCulture) }, { "Enabled", metricBase.Enabled.ToString(CultureInfo.InvariantCulture).ToLower() }, { "GrandParentMetricId", metricBase.Parent==null || metricBase.Parent.Parent==null ? string.Empty : metricBase.Parent.Parent.MetricId.ToString(CultureInfo.InvariantCulture) }, { "ParentMetricId", metricBase.Parent==null ? string.Empty : metricBase.Parent.MetricId.ToString(CultureInfo.InvariantCulture) }, { "MetricId", metricBase.MetricId.ToString(CultureInfo.InvariantCulture) }, { "ParentMetricVariantId", metricBase.Parent==null ? string.Empty : metricBase.Parent.MetricVariantId.ToString(CultureInfo.InvariantCulture) }, { "MetricVariantId", metricBase.MetricVariantId.ToString(CultureInfo.InvariantCulture) }, { "RenderingMode", renderingMode.ToString() }, { "NullValue", AllGranularDescendantsHaveNullValues(metricBase)}, { "MetricVariantType", metricBase.MetricVariantType.ToString() }, { "Open", open.ToString(CultureInfo.InvariantCulture).ToLower() }, // Note: We may want to introduce an extensibility point here to populate domain-specific values into the rendering context to allow for template overriding based on domain values //{ "LocalEducationAgencyId", "" }, //{ "SchoolId","" }, //{ "StudentUSI", "" }, }; return contextValues; }
public static void RenderMetrics(this HtmlHelper<object> helper, MetricBase metric, RenderingMode renderingMode) { var renderer = (AspNetMvcMetricRenderer) IoC.Resolve<IMetricRenderer>(); renderer.Html = helper; var engine = IoC.Resolve<IMetricRenderingEngine>(); engine.RenderMetrics(metric, renderingMode, renderer, helper.ViewData); }
public void ReportMetric(MetricBase metric) { var metricSerialized = new MetricsContainer { MetricsSerialized = _serializator.Serialize(metric) }; channel.Register(metricSerialized); }
public bool GetMetricFlag(MetricBase metricBase, MetricMetadataNode metadataNode, MetricData metricData) { var metricInstance = metricData.MetricInstancesByMetricId.GetValueOrDefault(metricBase.MetricId); if (metricInstance == null) return false; return metricInstance.Flag.GetValueOrDefault(); }
protected override void EstablishContext() { metricTemplateBinder.Setup(x => x.GetTemplateName(It.IsAny<Dictionary<string, string>>())).Callback<Dictionary<string, string>>(x => postedContextValues.Add(x)).Returns("template name"); metricRenderer.Setup(x => x.Render(It.IsAny<String>(), It.IsAny<MetricBase>(), It.IsAny<int>(), It.IsAny<IDictionary<string, object>>())).Callback((string templateName, object mb, int depth, IDictionary<string, object> dictionary) => postedMetricRenderingValues.Add(new MetricRenderingParameters { TemplateName = templateName, MetricBase = (MetricBase)mb, Depth = depth })); metricBase = GetSuppliedMetricBase(); metricRenderingContextProvider.Setup(x => x.ProvideContext(It.IsAny<MetricBase>(), It.IsAny<IDictionary<string, object>>())).Callback((MetricBase m, IDictionary<string, object> d) => contextDictionary["AggregateMetricId"] = m.MetricId); rootMetric = (ContainerMetric) metricBase; suppliedRenderingMode = RenderingMode.Overview; }
private void SaveMetric(MetricBase metric, TObjectState state, BsonValue id, string collectionName, Dictionary <string, BsonValue> values) { IMongoDatabase database = GetDatabase(DATABASE_NAME, true); IMongoCollection <BsonDocument> collection = database.GetCollection <BsonDocument>(collectionName); if (state == TObjectState.Add) { BsonDocument newItem = new BsonDocument(); BsonHelper.SetValue(newItem, "Name", metric.Name); BsonHelper.SetValue(newItem, "Value", metric.Value); foreach (KeyValuePair <string, BsonValue> pair in values) { newItem[pair.Key] = pair.Value; } FilterDefinition <BsonDocument> filter = Builders <BsonDocument> .Filter.Eq("_id", id); UpdateDefinition <BsonDocument> update = Builders <BsonDocument> .Update.AddToSet("Metrics", newItem); UpdateOptions options = new UpdateOptions(); options.IsUpsert = true; collection.UpdateOne(filter, update, options); } else if (state == TObjectState.Update) { FilterDefinition <BsonDocument> clientOrOrganisationIDFilter = Builders <BsonDocument> .Filter.Eq("_id", id); FilterDefinition <BsonDocument> metricNameFilter = Builders <BsonDocument> .Filter.Eq("Metrics.Name", metric.Name); FilterDefinition <BsonDocument> filter = Builders <BsonDocument> .Filter.And(clientOrOrganisationIDFilter, metricNameFilter); UpdateDefinition <BsonDocument> update = Builders <BsonDocument> .Update.Set("Metrics.$.Value", metric.Value); collection.UpdateOne(filter, update); } else if (state == TObjectState.Delete) { FilterDefinition <BsonDocument> filter = Builders <BsonDocument> .Filter.Eq("_id", id); UpdateDefinition <BsonDocument> update = Builders <BsonDocument> .Update.PullFilter("Metrics", Builders <BsonDocument> .Filter.Eq("Name", metric.Name)); collection.UpdateOne(filter, update); } }
private string GetStatName(StatisticBase input) { // ⇉ Metric with two input vectors (e.g. t-test) // → Statistic with one input vector (e.g. mean) // ↣ Calculated from other statistics (e.g. most significant t-test) if (input is MetricBase) // check in this order since all metrics are statistics { MetricBase m = (MetricBase)input; return(" ⇉ " + input.DisplayName); } else if (input is StatisticConsumer) { StatisticBase s = (StatisticBase)input; return(" ↣ " + input.DisplayName); } else { return(" → " + input.DisplayName); } }
public void Aggregate(MetricBase metric) { var procMetric = metric as ProcessDescriptorMetric; if (procMetric == null) { return; } try { _lock.AcquireWriterLock(Timeout.Infinite); if (procMetric.MemoryUsage > _maxMemoryUsage) { _maxMemoryUsage = procMetric.MemoryUsage; _maxMemoryUsagePid = procMetric.Pid; } if (procMetric.CpuPerc > _maxCpuUsage) { _maxCpuUsage = procMetric.CpuPerc; _maxCpuUsagePid = procMetric.Pid; } if (procMetric.Pid == _maxCpuUsagePid) { _maxCpuUsage = procMetric.CpuPerc; } if (procMetric.Pid == _maxMemoryUsagePid) { _maxMemoryUsage = procMetric.MemoryUsage; } } finally { _lock.ReleaseWriterLock(); } }
private void CheckAndChange(object sender, EventArgs e) { ClustererBase stat = (ClustererBase)this._ecbMethod.SelectedItem; MetricBase met = this._ecbMeasure.SelectedItem as MetricBase; // Stat has params? bool paramsVisible = stat != null && stat.Parameters.HasCustomisableParams; this._txtParams.Enabled = paramsVisible; this._btnEditParameters.Enabled = paramsVisible; this._lblParams.Enabled = paramsVisible; this._lblParams.Text = paramsVisible ? stat.Parameters.ParamNames() : "Parameters"; // Distance this.linkLabel1.Visible = stat != null && !stat.SupportsDistanceMetrics; // Distance params bool distParamsVisible = met != null && met.Parameters != null && met.Parameters.HasCustomisableParams; this._txtMeasureParams.Enabled = distParamsVisible; this._btnEditDistanceParameters.Enabled = distParamsVisible; this._lblMeasureParams.Enabled = distParamsVisible; this._lblMeasureParams.Text = distParamsVisible ? met.Parameters.ParamNames() : "Parameters"; // Input vector bool obsFilterVisible = stat != null && stat.SupportsObservationFilters; this._lblApply.Visible = obsFilterVisible; this._ecbSource.Enabled = obsFilterVisible; //_btnTrendHelp.Enabled = obsFilterVisible; this._lblAVec.Enabled = obsFilterVisible; this._ecbObsFilter.Enabled = obsFilterVisible; this._chkSepGroups.Enabled = obsFilterVisible; // Is OK? this.Check(null, null); }
private void RenderMetrics(MetricBase metricBase, RenderingMode renderingMode, IMetricRenderer renderer, int depth, IDictionary<string, object> viewData) { try { var renderingContextValues = GetMetricRenderingContextValues(metricBase, depth, renderingMode, true); renderer.Render(metricTemplateBinder.GetTemplateName(renderingContextValues), metricBase, depth, viewData); var containerMetric = metricBase as ContainerMetric; if (containerMetric != null) { foreach (var child in containerMetric.Children) { metricRenderingContextProvider.ProvideContext(child, viewData); RenderMetrics(child, renderingMode, renderer, depth + 1, viewData); } } renderingContextValues = GetMetricRenderingContextValues(metricBase, depth, renderingMode, false); renderer.Render(metricTemplateBinder.GetTemplateName(renderingContextValues), metricBase, depth, viewData); } catch (Exception ex) { throw new InvalidOperationException(string.Format("Failed to render metricId:{0} metricVariantId:{1} name:{2}", metricBase.MetricId, metricBase.MetricVariantId, metricBase.Name), ex); } }
//Method used to tag the parents to the hierarchy private void setParents(MetricBase metric, MetricBase parentMetric) { metric.Parent = parentMetric; var container = metric as ContainerMetric; if (container != null) foreach (var childMetric in container.Children) setParents(childMetric, metric); }
private string createPropName(MetricBase metric) { var parentName = ""; var grandParentName = ""; if (metric.Parent != null) { parentName = metric.Parent.DisplayName + " - "; if (metric.Parent.Parent != null) if (metric.Parent.Parent.MetricType == MetricType.ContainerMetric) grandParentName = metric.Parent.Parent.DisplayName + " - "; } return grandParentName + parentName + metric.DisplayName; }
protected override void ExecuteTest() { var leaTestService = windsorContainer.Resolve<ITestService<LocalEducationAgencyMetricInstanceSetRequest>>(); var schoolTestService = windsorContainer.Resolve<ITestService<SchoolMetricInstanceSetRequest>>(); MetricTree metricTree; if (EdFiDashboardContext.Current.SchoolId.HasValue) { var schoolMetricInstanceSetRequest = new SchoolMetricInstanceSetRequest { SchoolId = (int) EdFiDashboardContext.Current.SchoolId, MetricVariantId = schoolRoot }; metricTree = schoolTestService.Get(schoolMetricInstanceSetRequest); actualSchoolRootWithFilter = metricTree == null ? null : metricTree.RootNode; metricTree = schoolTestService.GetMetrics(schoolRoot, DateTime.Now); actualSchoolRoot = metricTree == null ? null : metricTree.RootNode; schoolMetricInstanceSetRequest = new SchoolMetricInstanceSetRequest { SchoolId = (int) EdFiDashboardContext.Current.SchoolId, MetricVariantId = (int) SchoolMetricEnum.ExperienceEducationCertifications }; metricTree = schoolTestService.Get(schoolMetricInstanceSetRequest); actualSchoolOperationalMetricWithFilter = metricTree == null ? null : metricTree.RootNode; metricTree = schoolTestService.GetMetrics((int) SchoolMetricEnum.ExperienceEducationCertifications, DateTime.Now); actualSchoolOperationalMetric = metricTree == null ? null : metricTree.RootNode; } var leaMetricInstanceSetRequest = new LocalEducationAgencyMetricInstanceSetRequest { LocalEducationAgencyId = (int) EdFiDashboardContext.Current.LocalEducationAgencyId, MetricVariantId = localEducationAgencyRoot }; metricTree = leaTestService.Get(leaMetricInstanceSetRequest); actualLocalEducationAgencyRootWithFilter = metricTree == null ? null : metricTree.RootNode; metricTree = leaTestService.GetMetrics(localEducationAgencyRoot, DateTime.Now); actualLocalEducationAgencyRoot = metricTree == null ? null : metricTree.RootNode; leaMetricInstanceSetRequest = new LocalEducationAgencyMetricInstanceSetRequest { LocalEducationAgencyId = (int) EdFiDashboardContext.Current.LocalEducationAgencyId, MetricVariantId = (int)LocalEducationAgencyMetricEnum.ExperienceEducationCertifications }; metricTree = leaTestService.Get(leaMetricInstanceSetRequest); actualLocalEducationAgencyOperationalMetricWithFilter = metricTree == null ? null : metricTree.RootNode; actualLocalEducationAgencyOperationalMetric = leaTestService.GetMetrics((int)LocalEducationAgencyMetricEnum.ExperienceEducationCertifications, DateTime.Now).RootNode; }
protected override void ExecuteTest() { if (EdFiDashboardContext.Current.SchoolId.HasValue) { var metricInstanceSetRequest = new SchoolMetricInstanceSetRequest(); var testService = windsorContainer.Resolve<ITestService<SchoolMetricInstanceSetRequest>>(); metricInstanceSetRequest.SchoolId = (int)EdFiDashboardContext.Current.SchoolId; metricInstanceSetRequest.MetricVariantId = schoolRoot; fakedMetrics = testService.Get(metricInstanceSetRequest).RootNode; } else { var metricInstanceSetRequest = new LocalEducationAgencyMetricInstanceSetRequest(); var testService = windsorContainer.Resolve<ITestService<LocalEducationAgencyMetricInstanceSetRequest>>(); metricInstanceSetRequest.LocalEducationAgencyId = (int)EdFiDashboardContext.Current.LocalEducationAgencyId; metricInstanceSetRequest.MetricVariantId = schoolRoot; fakedMetrics = testService.Get(metricInstanceSetRequest).RootNode; } }
public static string GetMenuActionScript(MetricBase model, MetricAction action, string moreActionDivId, string contextValues) { const string dynamicFormat = "closeMoreMenu(); showDynamicContent('#{0}','{1}{2}','#{3}', '{4}', '{5}');"; const string linkFormat = "closeMoreMenu(); NavigateToPage('{1}');"; if (action == null) throw new ArgumentNullException("action", "Action cannot be null."); if (action.Url == null) throw new ApplicationException("Action does not have it's Url property set. Metric Variant Id: " + action.MetricVariantId + " Title: " + action.Title); if (action == null) throw new ArgumentNullException("action", "Action cannot be null."); if (action.Url == null) throw new ApplicationException("Action does not have it's Url property set. Metric Variant Id: " + action.MetricVariantId + " Title: " + action.Title); if (action == null) throw new ArgumentNullException("action", "Action cannot be null."); if (action.Url == null) throw new ApplicationException("Action does not have it's Url property set. Metric Variant Id: " + action.MetricVariantId + " Title: " + action.Title); string parameterValues; if (!action.Url.Contains(".aspx"))//converted resources { parameterValues = action.Url.Resolve() + "?" + DateTime.Now.Ticks; string subjectArea = GetSubjectArea(model.MetricVariantId); if (!string.IsNullOrEmpty(subjectArea)) { parameterValues += ("&subjectArea=" + subjectArea.Replace(" ", "%20")); } if (action.ActionType == MetricActionType.DynamicContent || action.ActionType == MetricActionType.AlwaysDisplayedDynamicContent) { string divId = "DynamicContentDiv" + GetDynamicContentNameFromAction(action); return String.Format(dynamicFormat, divId, parameterValues + "&Title=" + action.GetTitleSafeForHtmlId(), "", moreActionDivId, action.GetTitleSafeForHtmlId() + action.MetricVariantId, model.Parent == null ? model.MetricVariantId : model.Parent.MetricVariantId); } else { return String.Format(linkFormat, moreActionDivId, parameterValues); } } else { parameterValues = ReplaceParametersWithValues(action.Url, contextValues); if (action.Url.Contains("{schoolId}") && !action.Url.Contains("{localEducationAgencyId}")) parameterValues = parameterValues.AppendParameters("localEducationAgencyId=" + EdFiDashboardContext.Current.LocalEducationAgencyId); if (action.ActionType == MetricActionType.DynamicContent || action.ActionType == MetricActionType.AlwaysDisplayedDynamicContent) { string divId = "DynamicContentDiv" + action.MetricVariantId + action.GetTitleSafeForHtmlId(); string additionalQstrings = "&" + DateTime.Now.Ticks + "&divId=" + divId + "&moreImageId=" + moreActionDivId + "&metricActionTitle=" + action.Title.Replace(" ", "%20") + "&blueHeaderSpan=blueHeaderSpan" + model.MetricVariantId + action.GetTitleSafeForHtmlId(); return String.Format(dynamicFormat, divId, parameterValues, additionalQstrings, moreActionDivId, action.GetTitleSafeForHtmlId() + action.MetricVariantId, model.Parent == null ? model.MetricVariantId : model.Parent.MetricVariantId); } else { return String.Format(linkFormat, moreActionDivId, parameterValues); } } }
public static IEnumerable<MetricAction> GetModelActions(MetricBase metric) { var granular = metric as IGranularMetric; if (granular == null || granular.Value != null) return metric.Actions; return metric.Actions.Where(x => x.ActionType == MetricActionType.AlwaysDisplayedDynamicContent); }
protected override void ExecuteTest() { var service = new DomainSpecificMetricResolver(domainEntityKeyResolver, metricService); actualModel = service.GetSchoolHighSchoolGraduationPlan(suppliedSchoolId); }
private void LoadMetricBase(MetricBase result, BsonDocument item) { result.Name = BsonHelper.GetString(item, "Name"); result.Value = BsonHelper.GetLong(item, "Value").Value; }
private void OnMetricHasArrived(MetricBase metric) { _queue.Enqueue(metric); _onNewMessage.Set(); }
public static Matcher Equal(MetricBase otherMetric) { return(new MetricMatcher(otherMetric)); }
public ExpectedActualPairing(MetricBase expected, Dictionary<string, string> actual) { this._expected = expected; this._actual = actual; }
private void OnMetricsHasArrived(MetricBase metric) { _aggregator.Aggregate(metric); }
public void Add(MetricBase metric) { _metrics.Add(metric); }
protected virtual void InvokeInitializationActivities(MetricBase metric, MetricInstanceSetRequestBase metricInstanceSetRequest, MetricMetadataNode metadataNode, MetricData metricData, Dictionary<string, object> initializationActivityData) { foreach (var initializationActivity in metricInitializationActivities) initializationActivity.InitializeMetric(metric, metricInstanceSetRequest, metadataNode, metricData, initializationActivityData); }
public void Aggregate(MetricBase metric) { _metricsToAggregate.Enqueue(metric); _onNewMetric.Set(); }
private MetricBase CreateMetric(MetricInstanceSetRequestBase metricInstanceSetRequest, MetricMetadataNode metricMetadataNode, MetricDataContainer metricDataContainer, MetricBase parentMetric, Dictionary<string, object> initializationActivityData) { MetricBase metric; var metricData = metricDataContainer.GetMetricData(metricMetadataNode); switch (metricMetadataNode.MetricType) { case MetricType.ContainerMetric: metric = containerMetricFactory.CreateMetric(metricInstanceSetRequest, metricMetadataNode, metricData, parentMetric); break; case MetricType.AggregateMetric: metric = aggregateMetricFactory.CreateMetric(metricInstanceSetRequest, metricMetadataNode, metricData, parentMetric); break; case MetricType.GranularMetric: metric = granularMetricFactory.CreateMetric(metricInstanceSetRequest, metricMetadataNode, metricData, parentMetric); break; default: throw new NotSupportedException(string.Format("Unsupported metric type '{0}'.", metricMetadataNode.MetricType)); } // Process children var metricWithChildren = metric as ContainerMetric; // If this is a node type that has children if (metricWithChildren != null) ProcessForChildren(metricInstanceSetRequest, metricMetadataNode, metricDataContainer, metricWithChildren, initializationActivityData); // Execute initialization activities InvokeInitializationActivities(metric, metricInstanceSetRequest, metricMetadataNode, metricData, initializationActivityData); return metric; }
public void RenderMetrics(MetricBase metricBase, RenderingMode renderingMode, IMetricRenderer renderer, IDictionary<string, object> viewData) { RenderMetrics(metricBase, renderingMode, renderer, 0, viewData); }
public void Append(MetricBase metric) { _processor(metric); }
/// <summary> /// Initializes a new instance of the <see cref="MetricTree"/> class with the specified root metric node. /// </summary> /// <param name="rootMetricNode">The root metric node of the tree.</param> public MetricTree(MetricBase rootMetricNode) { RootNode = rootMetricNode; }
protected override void ExecuteTest() { service = new MetricService<SomeMetricInstanceSetRequest>(metricMetadataTreeService, metricDataService, metricInstanceTreeFactory, metricNodeResolver); metricBase = service.Get(suppliedMetricInstanceSetRequest); }
public MetricMatcher(MetricBase metric) { this.metric = metric; }