generator.explores.funnel_analysis_explore

Funnel Analysis explore type.

 1"""Funnel Analysis explore type."""
 2
 3from __future__ import annotations
 4
 5from pathlib import Path
 6from typing import Any, Dict, Iterator, List, Optional
 7
 8from ..views import View
 9from . import Explore
10
11
12class FunnelAnalysisExplore(Explore):
13    """A Funnel Analysis Explore, from Baseline Clients Last Seen."""
14
15    type: str = "funnel_analysis_explore"
16    n_funnel_steps: int = 4
17
18    @staticmethod
19    def from_views(views: List[View]) -> Iterator[FunnelAnalysisExplore]:
20        """
21        If possible, generate a Funnel Analysis explore for this namespace.
22
23        Funnel analysis explores are only created for funnel_analysis views.
24        """
25        for view in views:
26            if view.name == "funnel_analysis":
27                yield FunnelAnalysisExplore(
28                    "funnel_analysis",
29                    {"base_view": view.name},
30                )
31
32    @staticmethod
33    def from_dict(name: str, defn: dict, views_path: Path) -> FunnelAnalysisExplore:
34        """Get an instance of this explore from a dictionary definition."""
35        return FunnelAnalysisExplore(name, defn["views"], views_path)
36
37    def _to_lookml(self, v1_name: Optional[str]) -> List[Dict[str, Any]]:
38        view_lookml = self.get_view_lookml("funnel_analysis")
39        views = view_lookml["views"]
40        n_events = len([d for d in views if d["name"].startswith("step_")])
41
42        explore_lookml = {
43            "name": "funnel_analysis",
44            "description": "Count funnel completion over time. Funnels are limited to a single day.",
45            "view_label": " User-Day Funnels",
46            "always_filter": {
47                "filters": [
48                    {"submission_date": "14 days"},
49                ]
50            },
51            "joins": [
52                {
53                    "name": f"step_{n}",
54                    "relationship": "many_to_one",
55                    "type": "cross",
56                }
57                for n in range(1, n_events + 1)
58            ],
59            "sql_always_where": "${funnel_analysis.submission_date} >= '2010-01-01'",
60        }
61
62        if datagroup := self.get_datagroup():
63            explore_lookml["persist_with"] = datagroup
64
65        defn: List[Dict[str, Any]] = [
66            explore_lookml,
67            {"name": "event_names", "hidden": "yes"},
68        ]
69
70        return defn
class FunnelAnalysisExplore(generator.explores.explore.Explore):
13class FunnelAnalysisExplore(Explore):
14    """A Funnel Analysis Explore, from Baseline Clients Last Seen."""
15
16    type: str = "funnel_analysis_explore"
17    n_funnel_steps: int = 4
18
19    @staticmethod
20    def from_views(views: List[View]) -> Iterator[FunnelAnalysisExplore]:
21        """
22        If possible, generate a Funnel Analysis explore for this namespace.
23
24        Funnel analysis explores are only created for funnel_analysis views.
25        """
26        for view in views:
27            if view.name == "funnel_analysis":
28                yield FunnelAnalysisExplore(
29                    "funnel_analysis",
30                    {"base_view": view.name},
31                )
32
33    @staticmethod
34    def from_dict(name: str, defn: dict, views_path: Path) -> FunnelAnalysisExplore:
35        """Get an instance of this explore from a dictionary definition."""
36        return FunnelAnalysisExplore(name, defn["views"], views_path)
37
38    def _to_lookml(self, v1_name: Optional[str]) -> List[Dict[str, Any]]:
39        view_lookml = self.get_view_lookml("funnel_analysis")
40        views = view_lookml["views"]
41        n_events = len([d for d in views if d["name"].startswith("step_")])
42
43        explore_lookml = {
44            "name": "funnel_analysis",
45            "description": "Count funnel completion over time. Funnels are limited to a single day.",
46            "view_label": " User-Day Funnels",
47            "always_filter": {
48                "filters": [
49                    {"submission_date": "14 days"},
50                ]
51            },
52            "joins": [
53                {
54                    "name": f"step_{n}",
55                    "relationship": "many_to_one",
56                    "type": "cross",
57                }
58                for n in range(1, n_events + 1)
59            ],
60            "sql_always_where": "${funnel_analysis.submission_date} >= '2010-01-01'",
61        }
62
63        if datagroup := self.get_datagroup():
64            explore_lookml["persist_with"] = datagroup
65
66        defn: List[Dict[str, Any]] = [
67            explore_lookml,
68            {"name": "event_names", "hidden": "yes"},
69        ]
70
71        return defn

A Funnel Analysis Explore, from Baseline Clients Last Seen.

type: str = 'funnel_analysis_explore'
n_funnel_steps: int = 4
@staticmethod
def from_views( views: List[generator.views.view.View]) -> Iterator[FunnelAnalysisExplore]:
19    @staticmethod
20    def from_views(views: List[View]) -> Iterator[FunnelAnalysisExplore]:
21        """
22        If possible, generate a Funnel Analysis explore for this namespace.
23
24        Funnel analysis explores are only created for funnel_analysis views.
25        """
26        for view in views:
27            if view.name == "funnel_analysis":
28                yield FunnelAnalysisExplore(
29                    "funnel_analysis",
30                    {"base_view": view.name},
31                )

If possible, generate a Funnel Analysis explore for this namespace.

Funnel analysis explores are only created for funnel_analysis views.

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

Get an instance of this explore from a dictionary definition.