generator.explores.events_explore

An explore for Events Views.

 1"""An explore for Events Views."""
 2
 3from __future__ import annotations
 4
 5from pathlib import Path
 6from typing import Any, Dict, Iterator, List, Optional
 7
 8from ..views import EventsView, View
 9from .explore import Explore
10
11
12class EventsExplore(Explore):
13    """An Events Explore, from any unnested events table."""
14
15    type: str = "events_explore"
16
17    @staticmethod
18    def from_views(views: List[View]) -> Iterator[EventsExplore]:
19        """Where possible, generate EventsExplores for Views."""
20        for view in views:
21            if isinstance(view, EventsView):
22                yield EventsExplore(
23                    view.name,
24                    {
25                        "base_view": "events",
26                        "extended_view": view.tables[0]["events_table_view"],
27                    },
28                )
29
30    @staticmethod
31    def from_dict(name: str, defn: dict, views_path: Path) -> EventsExplore:
32        """Get an instance of this explore from a dictionary definition."""
33        return EventsExplore(name, defn["views"], views_path)
34
35    def _to_lookml(self, v1_name: Optional[str]) -> List[Dict[str, Any]]:
36        name = self.name
37        if not name.endswith("_counts"):
38            name = "event_counts"
39
40        lookml: Dict[str, Any] = {
41            "name": name,
42            "view_name": self.views["base_view"],
43            "description": "Event counts over time.",
44            "joins": self.get_unnested_fields_joins_lookml(),
45        }
46        if required_filters := self.get_required_filters("extended_view"):
47            lookml["always_filter"] = {"filters": required_filters}
48        if time_partitioning_group := self.get_view_time_partitioning_group(
49            self.views["extended_view"]
50        ):
51            date_dimension = f"{time_partitioning_group}_date"
52            lookml["queries"] = [
53                {
54                    "description": "Event counts from all events over the past two weeks.",
55                    "dimensions": [date_dimension],
56                    "measures": ["event_count"],
57                    "filters": [
58                        {date_dimension: "14 days"},
59                    ],
60                    "name": "all_event_counts",
61                },
62            ]
63        return [lookml]
class EventsExplore(generator.explores.explore.Explore):
13class EventsExplore(Explore):
14    """An Events Explore, from any unnested events table."""
15
16    type: str = "events_explore"
17
18    @staticmethod
19    def from_views(views: List[View]) -> Iterator[EventsExplore]:
20        """Where possible, generate EventsExplores for Views."""
21        for view in views:
22            if isinstance(view, EventsView):
23                yield EventsExplore(
24                    view.name,
25                    {
26                        "base_view": "events",
27                        "extended_view": view.tables[0]["events_table_view"],
28                    },
29                )
30
31    @staticmethod
32    def from_dict(name: str, defn: dict, views_path: Path) -> EventsExplore:
33        """Get an instance of this explore from a dictionary definition."""
34        return EventsExplore(name, defn["views"], views_path)
35
36    def _to_lookml(self, v1_name: Optional[str]) -> List[Dict[str, Any]]:
37        name = self.name
38        if not name.endswith("_counts"):
39            name = "event_counts"
40
41        lookml: Dict[str, Any] = {
42            "name": name,
43            "view_name": self.views["base_view"],
44            "description": "Event counts over time.",
45            "joins": self.get_unnested_fields_joins_lookml(),
46        }
47        if required_filters := self.get_required_filters("extended_view"):
48            lookml["always_filter"] = {"filters": required_filters}
49        if time_partitioning_group := self.get_view_time_partitioning_group(
50            self.views["extended_view"]
51        ):
52            date_dimension = f"{time_partitioning_group}_date"
53            lookml["queries"] = [
54                {
55                    "description": "Event counts from all events over the past two weeks.",
56                    "dimensions": [date_dimension],
57                    "measures": ["event_count"],
58                    "filters": [
59                        {date_dimension: "14 days"},
60                    ],
61                    "name": "all_event_counts",
62                },
63            ]
64        return [lookml]

An Events Explore, from any unnested events table.

type: str = 'events_explore'
@staticmethod
def from_views( views: List[generator.views.view.View]) -> Iterator[EventsExplore]:
18    @staticmethod
19    def from_views(views: List[View]) -> Iterator[EventsExplore]:
20        """Where possible, generate EventsExplores for Views."""
21        for view in views:
22            if isinstance(view, EventsView):
23                yield EventsExplore(
24                    view.name,
25                    {
26                        "base_view": "events",
27                        "extended_view": view.tables[0]["events_table_view"],
28                    },
29                )

Where possible, generate EventsExplores for Views.

@staticmethod
def from_dict( name: str, defn: dict, views_path: pathlib.Path) -> EventsExplore:
31    @staticmethod
32    def from_dict(name: str, defn: dict, views_path: Path) -> EventsExplore:
33        """Get an instance of this explore from a dictionary definition."""
34        return EventsExplore(name, defn["views"], views_path)

Get an instance of this explore from a dictionary definition.