generator.explores.client_counts_explore

Client Counts explore type.

 1"""Client Counts 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 ClientCountsExplore(Explore):
13    """A Client Counts Explore, from Baseline Clients Last Seen."""
14
15    type: str = "client_counts_explore"
16
17    def _to_lookml(self, v1_name: Optional[str]) -> List[Dict[str, Any]]:
18        """Generate LookML to represent this explore."""
19        queries = []
20        if time_partitioning_group := self.get_view_time_partitioning_group(
21            self.views["extended_view"]
22        ):
23            date_dimension = f"{time_partitioning_group}_date"
24            queries.append(
25                {
26                    "description": "Client Counts of weekly cohorts over the past N days.",
27                    "dimensions": ["days_since_first_seen", "first_seen_week"],
28                    "measures": ["client_count"],
29                    "pivots": ["first_seen_week"],
30                    "filters": [
31                        {date_dimension: "8 weeks"},
32                        {"first_seen_date": "8 weeks"},
33                        {"have_completed_period": "yes"},
34                    ],
35                    "sorts": [{"days_since_first_seen": "asc"}],
36                    "name": "cohort_analysis",
37                }
38            )
39            if self.has_view_dimension(self.views["extended_view"], "app_build"):
40                queries.append(
41                    {
42                        "description": "Number of clients per build.",
43                        "dimensions": [date_dimension, "app_build"],
44                        "measures": ["client_count"],
45                        "pivots": ["app_build"],
46                        "sorts": [{date_dimension: "asc"}],
47                        "name": "build_breakdown",
48                    }
49                )
50
51        explore_lookml = {
52            "name": self.name,
53            "view_name": self.views["base_view"],
54            "description": "Client counts across dimensions and cohorts.",
55            "always_filter": {
56                "filters": self.get_required_filters("extended_view"),
57            },
58            "queries": queries,
59            "joins": self.get_unnested_fields_joins_lookml(),
60        }
61
62        if datagroup := self.get_datagroup():
63            explore_lookml["persist_with"] = datagroup
64
65        return [explore_lookml]
66
67    @staticmethod
68    def from_views(views: List[View]) -> Iterator[ClientCountsExplore]:
69        """
70        If possible, generate a Client Counts explore for this namespace.
71
72        Client counts explores are only created for client_counts views.
73        """
74        for view in views:
75            if view.name == "client_counts":
76                yield ClientCountsExplore(
77                    view.name,
78                    {
79                        "base_view": "client_counts",
80                        "extended_view": "baseline_clients_daily_table",
81                    },
82                )
83
84    @staticmethod
85    def from_dict(name: str, defn: dict, views_path: Path) -> ClientCountsExplore:
86        """Get an instance of this explore from a dictionary definition."""
87        return ClientCountsExplore(name, defn["views"], views_path)
class ClientCountsExplore(generator.explores.explore.Explore):
13class ClientCountsExplore(Explore):
14    """A Client Counts Explore, from Baseline Clients Last Seen."""
15
16    type: str = "client_counts_explore"
17
18    def _to_lookml(self, v1_name: Optional[str]) -> List[Dict[str, Any]]:
19        """Generate LookML to represent this explore."""
20        queries = []
21        if time_partitioning_group := self.get_view_time_partitioning_group(
22            self.views["extended_view"]
23        ):
24            date_dimension = f"{time_partitioning_group}_date"
25            queries.append(
26                {
27                    "description": "Client Counts of weekly cohorts over the past N days.",
28                    "dimensions": ["days_since_first_seen", "first_seen_week"],
29                    "measures": ["client_count"],
30                    "pivots": ["first_seen_week"],
31                    "filters": [
32                        {date_dimension: "8 weeks"},
33                        {"first_seen_date": "8 weeks"},
34                        {"have_completed_period": "yes"},
35                    ],
36                    "sorts": [{"days_since_first_seen": "asc"}],
37                    "name": "cohort_analysis",
38                }
39            )
40            if self.has_view_dimension(self.views["extended_view"], "app_build"):
41                queries.append(
42                    {
43                        "description": "Number of clients per build.",
44                        "dimensions": [date_dimension, "app_build"],
45                        "measures": ["client_count"],
46                        "pivots": ["app_build"],
47                        "sorts": [{date_dimension: "asc"}],
48                        "name": "build_breakdown",
49                    }
50                )
51
52        explore_lookml = {
53            "name": self.name,
54            "view_name": self.views["base_view"],
55            "description": "Client counts across dimensions and cohorts.",
56            "always_filter": {
57                "filters": self.get_required_filters("extended_view"),
58            },
59            "queries": queries,
60            "joins": self.get_unnested_fields_joins_lookml(),
61        }
62
63        if datagroup := self.get_datagroup():
64            explore_lookml["persist_with"] = datagroup
65
66        return [explore_lookml]
67
68    @staticmethod
69    def from_views(views: List[View]) -> Iterator[ClientCountsExplore]:
70        """
71        If possible, generate a Client Counts explore for this namespace.
72
73        Client counts explores are only created for client_counts views.
74        """
75        for view in views:
76            if view.name == "client_counts":
77                yield ClientCountsExplore(
78                    view.name,
79                    {
80                        "base_view": "client_counts",
81                        "extended_view": "baseline_clients_daily_table",
82                    },
83                )
84
85    @staticmethod
86    def from_dict(name: str, defn: dict, views_path: Path) -> ClientCountsExplore:
87        """Get an instance of this explore from a dictionary definition."""
88        return ClientCountsExplore(name, defn["views"], views_path)

A Client Counts Explore, from Baseline Clients Last Seen.

type: str = 'client_counts_explore'
@staticmethod
def from_views( views: List[generator.views.view.View]) -> Iterator[ClientCountsExplore]:
68    @staticmethod
69    def from_views(views: List[View]) -> Iterator[ClientCountsExplore]:
70        """
71        If possible, generate a Client Counts explore for this namespace.
72
73        Client counts explores are only created for client_counts views.
74        """
75        for view in views:
76            if view.name == "client_counts":
77                yield ClientCountsExplore(
78                    view.name,
79                    {
80                        "base_view": "client_counts",
81                        "extended_view": "baseline_clients_daily_table",
82                    },
83                )

If possible, generate a Client Counts explore for this namespace.

Client counts explores are only created for client_counts views.

@staticmethod
def from_dict( name: str, defn: dict, views_path: pathlib.Path) -> ClientCountsExplore:
85    @staticmethod
86    def from_dict(name: str, defn: dict, views_path: Path) -> ClientCountsExplore:
87        """Get an instance of this explore from a dictionary definition."""
88        return ClientCountsExplore(name, defn["views"], views_path)

Get an instance of this explore from a dictionary definition.