Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add event and interval annotation support to chart data ep #11665

Merged
merged 3 commits into from Dec 4, 2020

Conversation

villebro
Copy link
Member

@villebro villebro commented Nov 12, 2020

SUMMARY

Implements event, interval and line annotations on V1 chart data endpoint and ECharts Timeseries plugin. Also refactor the annotation unit test fixtures by moving them into tests/annotation_layers/fixtures.py so they can more easily be used in other tests.

SCREENSHOT

image

TEST PLAN

ADDITIONAL INFORMATION

  • Has associated issue:
  • Changes UI
  • Requires DB Migration.
  • Confirm DB Migration upgrade and downgrade tested.
  • Introduces new feature or API
  • Removes existing feature or API

@codecov-io
Copy link

codecov-io commented Nov 12, 2020

Codecov Report

Merging #11665 (21053cf) into master (8c063ef) will decrease coverage by 12.61%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master   #11665       +/-   ##
===========================================
- Coverage   67.59%   54.98%   -12.62%     
===========================================
  Files         928      421      -507     
  Lines       45053    14812    -30241     
  Branches     4309     3822      -487     
===========================================
- Hits        30455     8144    -22311     
+ Misses      14495     6668     -7827     
+ Partials      103        0      -103     
Flag Coverage Δ
cypress 54.98% <100.00%> (+0.07%) ⬆️
javascript ?
python ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
superset-frontend/src/chart/chartAction.js 71.50% <100.00%> (-7.85%) ⬇️
...uperset-frontend/src/dashboard/util/dnd-reorder.js 0.00% <0.00%> (-100.00%) ⬇️
...rset-frontend/src/dashboard/util/getEmptyLayout.js 0.00% <0.00%> (-100.00%) ⬇️
...dashboard/components/resizable/ResizableHandle.jsx 0.00% <0.00%> (-100.00%) ⬇️
.../src/dashboard/util/getFilterScopeFromNodesTree.js 0.00% <0.00%> (-93.48%) ⬇️
...src/dashboard/components/gridComponents/Header.jsx 10.52% <0.00%> (-86.85%) ⬇️
...rc/dashboard/components/gridComponents/Divider.jsx 13.33% <0.00%> (-86.67%) ⬇️
...ontend/src/dashboard/util/getDashboardFilterKey.ts 14.28% <0.00%> (-85.72%) ⬇️
...nd/src/views/CRUD/data/query/QueryPreviewModal.tsx 14.70% <0.00%> (-82.97%) ⬇️
...set-frontend/src/views/CRUD/welcome/EmptyState.tsx 5.71% <0.00%> (-82.10%) ⬇️
... and 771 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8c063ef...21053cf. Read the comment docs.

@junlincc junlincc requested review from junlincc, bkyryliuk, ktmud and dpgaspar and removed request for ktmud November 12, 2020 16:40
@junlincc junlincc removed their request for review November 12, 2020 17:49
@john-bodley
Copy link
Member

@junlincc this still looks like WIP. @villebro could you ping this thread when the PR is ready for review?

@villebro
Copy link
Member Author

@john-bodley sure thing, I'll add some tests, will ping you shortly once it's done.

@villebro villebro changed the title [WIP] feat: add event and interval annotation support to chart data ep feat: add event and interval annotation support to chart data ep Dec 3, 2020
Comment on lines -39 to -102
def insert_annotation_layer(
self, name: str = "", descr: str = ""
) -> AnnotationLayer:
annotation_layer = AnnotationLayer(name=name, descr=descr,)
db.session.add(annotation_layer)
db.session.commit()
return annotation_layer

def insert_annotation(
self,
layer: AnnotationLayer,
short_descr: str,
long_descr: str,
json_metadata: Optional[str] = "",
start_dttm: Optional[datetime] = None,
end_dttm: Optional[datetime] = None,
) -> Annotation:
annotation = Annotation(
layer=layer,
short_descr=short_descr,
long_descr=long_descr,
json_metadata=json_metadata,
start_dttm=start_dttm,
end_dttm=end_dttm,
)
db.session.add(annotation)
db.session.commit()
return annotation

@pytest.fixture()
def create_annotation_layers(self):
"""
Creates ANNOTATION_LAYERS_COUNT-1 layers with no annotations
and a final one with ANNOTATION_COUNT childs
:return:
"""
with self.create_app().app_context():
annotation_layers = []
annotations = []
for cx in range(ANNOTATION_LAYERS_COUNT - 1):
annotation_layers.append(
self.insert_annotation_layer(name=f"name{cx}", descr=f"descr{cx}")
)
layer_with_annotations = self.insert_annotation_layer(
"layer_with_annotations"
)
annotation_layers.append(layer_with_annotations)
for cx in range(ANNOTATIONS_COUNT):
annotations.append(
self.insert_annotation(
layer_with_annotations,
short_descr=f"short_descr{cx}",
long_descr=f"long_descr{cx}",
)
)
yield annotation_layers

# rollback changes
for annotation_layer in annotation_layers:
db.session.delete(annotation_layer)
for annotation in annotations:
db.session.delete(annotation)
db.session.commit()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These fixtures were moved to a separate fixtures.py file to make them more reusable in different contexts (in this case for testing the chart data endpoint)

@villebro
Copy link
Member Author

villebro commented Dec 3, 2020

@john-bodley this is now ready for review if you have time, sorry for the delay

Copy link
Member

@dpgaspar dpgaspar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just of couple of comments

superset/charts/api.py Outdated Show resolved Hide resolved
@@ -1383,3 +1386,44 @@ def test_import_chart_invalid(self):
assert response == {
"message": {"metadata.yaml": {"type": ["Must be equal to Slice."]}}
}

@pytest.mark.usefixtures("create_annotation_layers")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should think about moving all these tests away from unittest.TestCase if possible, there are some really cool pytest features that we are missing out

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, some functions like login, get_table_by_name should be already available as direct ( not object ) methods

superset/common/query_context.py Outdated Show resolved Hide resolved
Copy link
Member

@bkyryliuk bkyryliuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks really good, just 2 nits / suggestions

tests/annotation_layers/fixtures.py Show resolved Hide resolved
@@ -1383,3 +1386,44 @@ def test_import_chart_invalid(self):
assert response == {
"message": {"metadata.yaml": {"type": ["Must be equal to Slice."]}}
}

@pytest.mark.usefixtures("create_annotation_layers")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, some functions like login, get_table_by_name should be already available as direct ( not object ) methods

@villebro villebro merged commit 327a281 into apache:master Dec 4, 2020
@villebro villebro deleted the villebro/echarts-annotations branch December 4, 2020 12:51
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.0.0 labels Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/L 🚢 1.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants