Skip to content

Commit

Permalink
The detail information of the 'metrics' metric with Quality-time as s…
Browse files Browse the repository at this point in the history
…ource would show 'NaN' (not a number) as the value of the measurements and targets of the measured metrics. Fixes #3811.
  • Loading branch information
fniessink committed May 13, 2022
1 parent b4319cc commit 4976311
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ def __update_entity( # pylint: disable=too-many-arguments
entity["status"] = status
status_start = self.__metric_status_start(metric)
entity["status_start_date"] = status_start.isoformat() if status_start else ""
unit = metric.get("unit") or self._data_model["metrics"][metric["type"]]["unit"]
entity["measurement"] = f"{value or '?'} {unit}"
entity["unit"] = metric.get("unit") or self._data_model["metrics"][metric["type"]]["unit"]
entity["measurement"] = value
direction = str(metric.get("direction") or self._data_model["metrics"][metric["type"]]["direction"])
direction = {"<": "≦", ">": "≧"}.get(direction, direction)
target = metric.get("target") or self._data_model["metrics"][metric["type"]]["target"]
entity["target"] = f"{direction} {target} {unit}"
entity["target"] = f"{direction} {target}"

@staticmethod
def __metric_is_to_be_measured(metric, metric_types, source_types, tags) -> bool:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ async def test_nr_of_metrics(self):
report_url=f"{self.url}/r1",
subject_url=f"{self.url}/r1#s1",
metric_url=f"{self.url}/r1#m2",
measurement="20 violations",
target="≦ 2 violations",
measurement="20",
target="≦ 2",
unit="violations",
status="target_not_met",
status_start_date="2020-05-23T07:53:17+00:00",
)
Expand Down Expand Up @@ -82,8 +83,9 @@ async def test_nr_of_metrics_with_min_status_duration(self):
report_url=f"{self.url}/r1",
subject_url=f"{self.url}/r1#s1",
metric_url=f"{self.url}/r1#m2",
measurement="20 violations",
target="≦ 2 violations",
measurement="20",
target="≦ 2",
unit="violations",
status="target_not_met",
status_start_date="2020-05-23T07:53:17+00:00",
)
Expand Down
9 changes: 7 additions & 2 deletions components/frontend/src/source/SourceEntities.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { SourceEntity } from './SourceEntity';
import { capitalize } from '../utils';
import { DataModel } from '../context/DataModel';

export function alignment(column_type) {
export function alignment(column_type, alignment) {
if (alignment === "left" || alignment == "right") {
return alignment
}
return { text: "left", integer: "right", float: "right", date: "left", datetime: "left", minutes: "right" }[column_type];
}

Expand Down Expand Up @@ -59,8 +62,10 @@ export function SourceEntities({ metric, metric_uuid, source, reload }) {
</Table.HeaderCell>
{entity_attributes.map((entity_attribute) =>
<Table.HeaderCell
key={entity_attribute.key} sorted={sorted(entity_attribute.key)} textAlign={alignment(entity_attribute.type)}
key={entity_attribute.key}
onClick={() => sort(entity_attribute.key, entity_attribute.type)}
sorted={sorted(entity_attribute.key)}
textAlign={alignment(entity_attribute.type, entity_attribute.alignment)}
>
<span>{entity_attribute.name}</span>
{
Expand Down
4 changes: 4 additions & 0 deletions components/frontend/src/source/SourceEntities.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const data_model = {
{ key: "integer", type: "integer", name: "integer" },
{ key: "float", type: "float", name: "float" },
{ key: "text", type: "text", name: "text", help: "help text" },
{ key: "rightalign", type: "text", name: "rightalign", alignment: "right" },
{ key: "date", type: "date", name: "date only" },
{ key: "datetime", type: "datetime", name: "datetime" },
{ key: "minutes", type: "minutes", name: "minutes" }
Expand Down Expand Up @@ -42,6 +43,7 @@ const source = {
integer: "1",
float: "0.3",
text: "CCC",
rightalign: "right aligned",
date: "01-01-2000",
datetime: "2000-01-01T10:00:00Z",
minutes: "1"
Expand All @@ -51,6 +53,7 @@ const source = {
integer: "3",
float: "0.2",
text: "BBB",
rightalign: "right aligned",
date: "01-01-2002",
datetime: "2002-01-01T10:00:00Z",
minutes: "2"
Expand All @@ -60,6 +63,7 @@ const source = {
integer: "2",
float: "0.1",
text: "AAA",
rightalign: "right aligned",
date: "01-01-2001",
datetime: "2001-01-01T10:00:00Z",
minutes: "3"
Expand Down
6 changes: 5 additions & 1 deletion components/frontend/src/source/SourceEntity.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ export function SourceEntity({ metric_uuid, source_uuid, hide_ignored_entities,
<Table.Cell style={style}>{status_end_date}</Table.Cell>
<Table.Cell style={style}>{rationale}</Table.Cell>
{entity_attributes.map((entity_attribute, col_index) =>
<Table.Cell key={col_index} textAlign={alignment(entity_attribute.type)} style={style}>
<Table.Cell
key={col_index}
style={style}
textAlign={alignment(entity_attribute.type, entity_attribute.alignment)}
>
<SourceEntityAttribute entity={entity} entity_attribute={entity_attribute} />
</Table.Cell>)}
</>;
Expand Down
8 changes: 8 additions & 0 deletions components/server/src/external/data_model/meta/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ class EntityAttributeType(str, Enum):
STATUS = "status"


class EntityAttributeAligment(str, Enum):
"""Alignment of the entity attribute."""

LEFT = "left"
RIGHT = "right"


class EntityAttribute(NamedModel): # pylint: disable=too-few-public-methods
"""Attributes of measurement entities."""

Expand All @@ -39,6 +46,7 @@ class EntityAttribute(NamedModel): # pylint: disable=too-few-public-methods
url: Optional[str] = None # Which key to use to get the URL for this attribute
color: Optional[dict[str, Color]] = None
type: Optional[EntityAttributeType] = None
alignment: Optional[EntityAttributeAligment] = None # If not given, the aligment is based on the attribute type
pre: Optional[bool] = None # Should the attribute be formatted using <pre></pre>? Defaults to False
visible: Optional[bool] = None # Should this attribute be visible in the UI? Defaults to True

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Quality-time source."""

from ..meta.entity import Color, EntityAttributeType
from ..meta.entity import Color, EntityAttributeAligment, EntityAttributeType
from ..meta.source import Source
from ..meta.unit import Unit
from ..parameters import IntegerParameter, MultipleChoiceParameter, MultipleChoiceWithAdditionParameter, URL
Expand Down Expand Up @@ -254,7 +254,8 @@
),
dict(name="Status start date", type=EntityAttributeType.DATE),
dict(name="Measurement", type=EntityAttributeType.INTEGER),
dict(name="Target", type=EntityAttributeType.INTEGER),
dict(name="Target", alignment=EntityAttributeAligment.RIGHT),
dict(name="Unit"),
],
),
missing_metrics=dict(
Expand Down
1 change: 1 addition & 0 deletions docs/src/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### Fixed

- Adding values to input fields in the user interface that allow for multiple values didn't work. Fixes [#3801](https://github.com/ICTU/quality-time/issues/3801).
- The detail information of the 'metrics' metric with *Quality-time* as source would show "NaN" (not a number) as the value of the measurements and targets of the measured metrics. Fixes [#3811](https://github.com/ICTU/quality-time/issues/3811).

### Changed

Expand Down

0 comments on commit 4976311

Please sign in to comment.