2021-04-26 19:25:31 +03:00
|
|
|
"""Growth Accounting explore type."""
|
|
|
|
from __future__ import annotations
|
|
|
|
|
2021-04-29 00:30:41 +03:00
|
|
|
from pathlib import Path
|
2021-06-03 00:30:49 +03:00
|
|
|
from typing import Any, Dict, Iterator, List, Optional
|
2021-04-26 19:25:31 +03:00
|
|
|
|
2021-11-09 18:47:34 +03:00
|
|
|
from google.cloud import bigquery
|
|
|
|
|
2021-04-26 19:25:31 +03:00
|
|
|
from ..views import View
|
|
|
|
from . import Explore
|
|
|
|
|
|
|
|
|
|
|
|
class GrowthAccountingExplore(Explore):
|
|
|
|
"""A Growth Accounting Explore, from Baseline Clients Last Seen."""
|
|
|
|
|
|
|
|
type: str = "growth_accounting_explore"
|
|
|
|
|
2021-11-09 18:47:34 +03:00
|
|
|
def _to_lookml(
|
|
|
|
self, client: bigquery.Client, v1_name: Optional[str], data: Dict = {}
|
|
|
|
) -> List[Dict[str, Any]]:
|
2021-04-26 19:25:31 +03:00
|
|
|
"""Generate LookML to represent this explore."""
|
2021-05-25 23:42:02 +03:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
"name": self.name,
|
|
|
|
"view_name": self.views["base_view"],
|
|
|
|
}
|
|
|
|
]
|
2021-04-26 19:25:31 +03:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def from_views(views: List[View]) -> Iterator[GrowthAccountingExplore]:
|
|
|
|
"""
|
|
|
|
If possible, generate a Growth Accounting explore for this namespace.
|
|
|
|
|
|
|
|
Growth accounting explores are only created for growth_accounting views.
|
|
|
|
"""
|
|
|
|
for view in views:
|
|
|
|
if view.name == "growth_accounting":
|
|
|
|
yield GrowthAccountingExplore(
|
2021-06-03 00:30:49 +03:00
|
|
|
view.name,
|
2021-04-26 19:25:31 +03:00
|
|
|
{"base_view": "growth_accounting"},
|
|
|
|
)
|
|
|
|
|
|
|
|
@staticmethod
|
2021-04-29 00:30:41 +03:00
|
|
|
def from_dict(name: str, defn: dict, views_path: Path) -> GrowthAccountingExplore:
|
2021-04-26 19:25:31 +03:00
|
|
|
"""Get an instance of this explore from a dictionary definition."""
|
2021-04-29 00:30:41 +03:00
|
|
|
return GrowthAccountingExplore(name, defn["views"], views_path)
|