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 return [ 51 { 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 63 @staticmethod 64 def from_views(views: List[View]) -> Iterator[ClientCountsExplore]: 65 """ 66 If possible, generate a Client Counts explore for this namespace. 67 68 Client counts explores are only created for client_counts views. 69 """ 70 for view in views: 71 if view.name == "client_counts": 72 yield ClientCountsExplore( 73 view.name, 74 { 75 "base_view": "client_counts", 76 "extended_view": "baseline_clients_daily_table", 77 }, 78 ) 79 80 @staticmethod 81 def from_dict(name: str, defn: dict, views_path: Path) -> ClientCountsExplore: 82 """Get an instance of this explore from a dictionary definition.""" 83 return ClientCountsExplore(name, defn["views"], views_path)
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 return [ 52 { 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 64 @staticmethod 65 def from_views(views: List[View]) -> Iterator[ClientCountsExplore]: 66 """ 67 If possible, generate a Client Counts explore for this namespace. 68 69 Client counts explores are only created for client_counts views. 70 """ 71 for view in views: 72 if view.name == "client_counts": 73 yield ClientCountsExplore( 74 view.name, 75 { 76 "base_view": "client_counts", 77 "extended_view": "baseline_clients_daily_table", 78 }, 79 ) 80 81 @staticmethod 82 def from_dict(name: str, defn: dict, views_path: Path) -> ClientCountsExplore: 83 """Get an instance of this explore from a dictionary definition.""" 84 return ClientCountsExplore(name, defn["views"], views_path)
A Client Counts Explore, from Baseline Clients Last Seen.
@staticmethod
def
from_views( views: List[generator.views.view.View]) -> Iterator[ClientCountsExplore]:
64 @staticmethod 65 def from_views(views: List[View]) -> Iterator[ClientCountsExplore]: 66 """ 67 If possible, generate a Client Counts explore for this namespace. 68 69 Client counts explores are only created for client_counts views. 70 """ 71 for view in views: 72 if view.name == "client_counts": 73 yield ClientCountsExplore( 74 view.name, 75 { 76 "base_view": "client_counts", 77 "extended_view": "baseline_clients_daily_table", 78 }, 79 )
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:
81 @staticmethod 82 def from_dict(name: str, defn: dict, views_path: Path) -> ClientCountsExplore: 83 """Get an instance of this explore from a dictionary definition.""" 84 return ClientCountsExplore(name, defn["views"], views_path)
Get an instance of this explore from a dictionary definition.