remove configloader helper objects (#233)

* remove configloader helper objects

* linting:

* removed deprecated doc files from sphinx

* fixed mistake in docstring

* removed redundant tests

* remove path modification from conftest.py and consolidated desktop metric creation

* linting

* actually add stuff to the file I created instead of being a moron

* import lists in test

* consolidated lists in config_loader_lists
This commit is contained in:
Jared Snyder 2024-05-22 11:11:44 -05:00 коммит произвёл GitHub
Родитель 32737a55e4
Коммит 5e723ef0b7
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
25 изменённых файлов: 119 добавлений и 542 удалений

Просмотреть файл

@ -1,5 +0,0 @@
:mod:`mozanalysis.metrics.desktop`
----------------------------------
.. automodule:: mozanalysis.metrics.desktop
:members:

Просмотреть файл

@ -1,5 +0,0 @@
:mod:`mozanalysis.metrics.fenix`
----------------------------------
.. automodule:: mozanalysis.metrics.fenix
:members:

Просмотреть файл

@ -1,5 +0,0 @@
:mod:`mozanalysis.metrics.firefox_ios`
---------------------------------------
.. automodule:: mozanalysis.metrics.firefox_ios
:members:

Просмотреть файл

@ -1,5 +0,0 @@
:mod:`mozanalysis.segments.desktop`
-----------------------------------
.. automodule:: mozanalysis.segments.desktop
:members:

Просмотреть файл

@ -71,7 +71,10 @@ class Experiment:
from mozanalysis.experiment import Experiment
from mozanalysis.bq import BigQueryContext
from mozanalysis.metrics.desktop import active_hours, uri_count
from mozanalysis.config import ConfigLoader
active_hours = ConfigLoader.get_metric("active_hours", "firefox_desktop")
uri_count = ConfigLoader.get_metric("uri_count", "firefox_desktop")
bq_context = BigQueryContext(
dataset_id='your-dataset-id', # e.g. mine's flawrence

Просмотреть файл

@ -10,30 +10,11 @@ if TYPE_CHECKING:
from mozanalysis.experiment import TimeLimits
import logging
import warnings
import attr
logger = logging.getLogger(__name__)
warnings.simplefilter("default")
warnings.warn(
"""
metrics and data sources created in mozanalysis are deprecated
please create directly from metric-hub with ConfigLoader like
from mozanalysis.config import ConfigLoader
metric=ConfigLoader.get_metric(metric_slug="active_hours",app_name="firefox_desktop")
and data sources like
data_source=ConfigLoader.get_data_source(data_source_slug="active_hours",
app_name="firefox_desktop")
""",
DeprecationWarning,
stacklevel=1,
)
class AnalysisBasis(Enum):
"""Determines what the population used for the analysis will be based on."""

Просмотреть файл

@ -1,82 +0,0 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# These metric definitions are deprecated.
# Instead use the metric slug to reference metrics defined
# in https://github.com/mozilla/metric-hub
from mozanalysis.config import ConfigLoader
clients_daily = ConfigLoader.get_data_source("clients_daily", "firefox_desktop")
search_clients_engines_sources_daily = ConfigLoader.get_data_source(
"search_clients_engines_sources_daily", "firefox_desktop"
)
search_clients_daily = search_clients_engines_sources_daily
main_summary = ConfigLoader.get_data_source("main_summary", "firefox_desktop")
events = ConfigLoader.get_data_source("events", "firefox_desktop")
normandy_events = ConfigLoader.get_data_source("normandy_events", "firefox_desktop")
main = ConfigLoader.get_data_source("main", "firefox_desktop")
crash = ConfigLoader.get_data_source("crash", "firefox_desktop")
cfr = ConfigLoader.get_data_source("cfr", "firefox_desktop")
activity_stream_events = ConfigLoader.get_data_source(
"activity_stream_events", "firefox_desktop"
)
active_hours = ConfigLoader.get_metric("active_hours", "firefox_desktop")
uri_count = ConfigLoader.get_metric("uri_count", "firefox_desktop")
search_count = ConfigLoader.get_metric("search_count", "firefox_desktop")
tagged_search_count = ConfigLoader.get_metric("tagged_search_count", "firefox_desktop")
tagged_follow_on_search_count = ConfigLoader.get_metric(
"tagged_follow_on_search_count", "firefox_desktop"
)
ad_clicks = ConfigLoader.get_metric("ad_clicks", "firefox_desktop")
searches_with_ads = ConfigLoader.get_metric("searches_with_ads", "firefox_desktop")
organic_search_count = ConfigLoader.get_metric(
"organic_search_count", "firefox_desktop"
)
unenroll = ConfigLoader.get_metric("unenroll", "firefox_desktop")
view_about_logins = ConfigLoader.get_metric("view_about_logins", "firefox_desktop")
view_about_protections = ConfigLoader.get_metric(
"view_about_protections", "firefox_desktop"
)
connect_fxa = ConfigLoader.get_metric("connect_fxa", "firefox_desktop")
pocket_rec_clicks = ConfigLoader.get_metric("pocket_rec_clicks", "firefox_desktop")
pocket_spoc_clicks = ConfigLoader.get_metric("pocket_spoc_clicks", "firefox_desktop")
days_of_use = ConfigLoader.get_metric("days_of_use", "firefox_desktop")
qualified_cumulative_days_of_use = ConfigLoader.get_metric(
"qualified_cumulative_days_of_use", "firefox_desktop"
)
disable_pocket_clicks = ConfigLoader.get_metric(
"disable_pocket_clicks", "firefox_desktop"
)
disable_pocket_spocs_clicks = ConfigLoader.get_metric(
"disable_pocket_spocs_clicks", "firefox_desktop"
)

Просмотреть файл

@ -1,30 +0,0 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# These metric definitions are deprecated.
# Instead use the metric slug to reference metrics defined
# in https://github.com/mozilla/metric-hub
from mozanalysis.config import ConfigLoader
baseline = ConfigLoader.get_data_source("baseline", "fenix")
events = ConfigLoader.get_data_source("events", "fenix")
metrics = ConfigLoader.get_data_source("metrics", "fenix")
uri_count = ConfigLoader.get_metric("uri_count", "fenix")
user_reports_site_issue_count = ConfigLoader.get_metric(
"user_reports_site_issue_count", "fenix"
)
user_reload_count = ConfigLoader.get_metric("user_reload_count", "fenix")
baseline_ping_count = ConfigLoader.get_metric("baseline_ping_count", "fenix")
metric_ping_count = ConfigLoader.get_metric("metric_ping_count", "fenix")
first_run_date = ConfigLoader.get_metric("first_run_date", "fenix")

Просмотреть файл

@ -1,21 +0,0 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# These metric definitions are deprecated.
# Instead use the metric slug to reference metrics defined
# in https://github.com/mozilla/metric-hub
from mozanalysis.config import ConfigLoader
baseline = ConfigLoader.get_data_source("baseline", "firefox_ios")
events = ConfigLoader.get_data_source("events", "firefox_ios")
metrics = ConfigLoader.get_data_source("metrics", "firefox_ios")
baseline_ping_count = ConfigLoader.get_metric("baseline_ping_count", "firefox_ios")
metric_ping_count = ConfigLoader.get_metric("metric_ping_count", "firefox_ios")
first_run_date = ConfigLoader.get_metric("first_run_date", "firefox_ios")

Просмотреть файл

@ -1,21 +0,0 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# These metric definitions are deprecated.
# Instead use the metric slug to reference metrics defined
# in https://github.com/mozilla/metric-hub
from mozanalysis.config import ConfigLoader
baseline = ConfigLoader.get_data_source("baseline", "focus_android")
events = ConfigLoader.get_data_source("events", "focus_android")
metrics = ConfigLoader.get_data_source("metrics", "focus_android")
baseline_ping_count = ConfigLoader.get_metric("baseline_ping_count", "focus_android")
metric_ping_count = ConfigLoader.get_metric("metric_ping_count", "focus_android")
first_run_date = ConfigLoader.get_metric("first_run_date", "focus_android")

Просмотреть файл

@ -1,21 +0,0 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# These metric definitions are deprecated.
# Instead use the metric slug to reference metrics defined
# in https://github.com/mozilla/metric-hub
from mozanalysis.config import ConfigLoader
baseline = ConfigLoader.get_data_source("baseline", "focus_ios")
events = ConfigLoader.get_data_source("events", "focus_ios")
metrics = ConfigLoader.get_data_source("metrics", "focus_ios")
baseline_ping_count = ConfigLoader.get_metric("baseline_ping_count", "focus_ios")
metric_ping_count = ConfigLoader.get_metric("metric_ping_count", "focus_ios")
first_run_date = ConfigLoader.get_metric("first_run_date", "focus_ios")

Просмотреть файл

@ -1,22 +0,0 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# These metric definitions are deprecated.
# Instead use the metric slug to reference metrics defined
# in https://github.com/mozilla/metric-hub
from mozanalysis.config import ConfigLoader
baseline = ConfigLoader.get_data_source("baseline", "klar_android")
events = ConfigLoader.get_data_source("events", "klar_android")
metrics = ConfigLoader.get_data_source("metrics", "klar_android")
baseline_ping_count = ConfigLoader.get_metric("baseline_ping_count", "klar_android")
metric_ping_count = ConfigLoader.get_metric("metric_ping_count", "klar_android")
first_run_date = ConfigLoader.get_metric("first_run_date", "klar_android")

Просмотреть файл

@ -1,21 +0,0 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# These metric definitions are deprecated.
# Instead use the metric slug to reference metrics defined
# in https://github.com/mozilla/metric-hub
from mozanalysis.config import ConfigLoader
baseline = ConfigLoader.get_data_source("baseline", "klar_ios")
events = ConfigLoader.get_data_source("events", "klar_ios")
metrics = ConfigLoader.get_data_source("metrics", "klar_ios")
baseline_ping_count = ConfigLoader.get_metric("baseline_ping_count", "klar_ios")
metric_ping_count = ConfigLoader.get_metric("metric_ping_count", "klar_ios")
first_run_date = ConfigLoader.get_metric("first_run_date", "klar_ios")

Просмотреть файл

@ -2,29 +2,8 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import warnings
import attr
warnings.simplefilter("default")
warnings.warn(
"""
segments and segment data source objects created in mozanalysis are deprecated
please create directly from metric-hub with ConfigLoader like
from mozanalysis.config import ConfigLoader
segment=ConfigLoader.get_segment(segment_slug="regular_users_v3",
app_name="firefox_desktop")
and data sources like
segment_data_source=ConfigLoader.get_segment_data_source("clients_last_seen",
"firefox_desktop")
""",
DeprecationWarning,
stacklevel=1,
)
@attr.s(frozen=True, slots=True)
class SegmentDataSource:

Просмотреть файл

@ -1,26 +0,0 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# These segment definitions are deprecated.
# Instead use the segment slug to reference segments defined
# in https://github.com/mozilla/metric-hub
from mozanalysis.config import ConfigLoader
clients_last_seen = ConfigLoader.get_segment_data_source(
"clients_last_seen", "firefox_desktop"
)
regular_users_v3 = ConfigLoader.get_segment("regular_users_v3", "firefox_desktop")
new_or_resurrected_v3 = ConfigLoader.get_segment(
"new_or_resurrected_v3", "firefox_desktop"
)
weekday_regular_v1 = ConfigLoader.get_segment("weekday_regular_v1", "firefox_desktop")
allweek_regular_v1 = ConfigLoader.get_segment("allweek_regular_v1", "firefox_desktop")
new_unique_profiles = ConfigLoader.get_segment("new_unique_profiles", "firefox_desktop")

Просмотреть файл

@ -38,9 +38,15 @@ class HistoricalTarget:
auth.authenticate_user()
print('Authenticated')
from mozanalysis.metrics.desktop import active_hours, uri_count
from mozanalysis.segments.desktop import allweek_regular_v1, \
new_or_resurrected_v3
from mozanalysis.config import ConfigLoader
active_hours = ConfigLoader.get_metric("active_hours", "firefox_desktop")
uri_count = ConfigLoader.get_metric("uri_count", "firefox_desktop")
new_or_resurrected_v3 = ConfigLoader.get_segment("new_or_resurrected_v3",
"firefox_desktop")
allweek_regular_v1 = ConfigLoader.get_segment("allweek_regular_v1",
"firefox_desktop")
bq_context = BigQueryContext(
dataset_id='mbowerman', # e.g. mine's mbowerman

Просмотреть файл

@ -1,12 +0,0 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
def enumerate_included(modules, klass):
collected = []
for module in modules:
collected.extend(
[(k, v) for k, v in module.__dict__.items() if isinstance(v, klass)]
)
return collected

Просмотреть файл

@ -2,10 +2,6 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import logging
import os
import sys
sys.path.append(os.path.join(os.path.dirname(__file__), "helpers"))
def pytest_configure():

Просмотреть файл

@ -6,12 +6,17 @@ from dataclasses import dataclass
import numpy as np
import pandas as pd
import pytest
from mozanalysis.config import ConfigLoader
from mozanalysis.frequentist_stats.sample_size import (
empirical_effect_size_sample_size_calc,
sample_size_curves,
z_or_t_ind_sample_size_calc,
)
from mozanalysis.metrics.desktop import search_clients_daily, uri_count
search_clients_daily = ConfigLoader.get_data_source(
"search_clients_engines_sources_daily", "firefox_desktop"
)
uri_count = ConfigLoader.get_metric("uri_count", "firefox_desktop")
@pytest.fixture()

Просмотреть файл

@ -0,0 +1,58 @@
from mozanalysis.config import ConfigLoader
desktop_segments = [
ConfigLoader.get_segment("regular_users_v3", "firefox_desktop"),
ConfigLoader.get_segment("new_or_resurrected_v3", "firefox_desktop"),
ConfigLoader.get_segment("weekday_regular_v1", "firefox_desktop"),
ConfigLoader.get_segment("allweek_regular_v1", "firefox_desktop"),
ConfigLoader.get_segment("new_unique_profiles", "firefox_desktop"),
]
desktop_metrics = [
ConfigLoader.get_metric("active_hours", "firefox_desktop"),
ConfigLoader.get_metric("uri_count", "firefox_desktop"),
ConfigLoader.get_metric("search_count", "firefox_desktop"),
ConfigLoader.get_metric("tagged_search_count", "firefox_desktop"),
ConfigLoader.get_metric("tagged_follow_on_search_count", "firefox_desktop"),
ConfigLoader.get_metric("ad_clicks", "firefox_desktop"),
ConfigLoader.get_metric("searches_with_ads", "firefox_desktop"),
ConfigLoader.get_metric("organic_search_count", "firefox_desktop"),
ConfigLoader.get_metric("unenroll", "firefox_desktop"),
ConfigLoader.get_metric("view_about_logins", "firefox_desktop"),
ConfigLoader.get_metric("view_about_protections", "firefox_desktop"),
ConfigLoader.get_metric("connect_fxa", "firefox_desktop"),
ConfigLoader.get_metric("pocket_rec_clicks", "firefox_desktop"),
ConfigLoader.get_metric("pocket_spoc_clicks", "firefox_desktop"),
ConfigLoader.get_metric("days_of_use", "firefox_desktop"),
ConfigLoader.get_metric("qualified_cumulative_days_of_use", "firefox_desktop"),
ConfigLoader.get_metric("disable_pocket_clicks", "firefox_desktop"),
ConfigLoader.get_metric("disable_pocket_spocs_clicks", "firefox_desktop"),
]
fenix_metrics = [
ConfigLoader.get_metric("uri_count", "fenix"),
ConfigLoader.get_metric("user_reports_site_issue_count", "fenix"),
ConfigLoader.get_metric("user_reload_count", "fenix"),
ConfigLoader.get_metric("baseline_ping_count", "fenix"),
ConfigLoader.get_metric("metric_ping_count", "fenix"),
ConfigLoader.get_metric("first_run_date", "fenix"),
]
firefox_ios_metrics = [
ConfigLoader.get_metric("baseline_ping_count", "firefox_ios"),
ConfigLoader.get_metric("metric_ping_count", "firefox_ios"),
ConfigLoader.get_metric("first_run_date", "firefox_ios"),
]
klar_android_metrics = [
ConfigLoader.get_metric("baseline_ping_count", "klar_android"),
ConfigLoader.get_metric("metric_ping_count", "klar_android"),
ConfigLoader.get_metric("first_run_date", "klar_android"),
]
klar_ios_metrics = [
ConfigLoader.get_metric("baseline_ping_count", "klar_ios"),
ConfigLoader.get_metric("metric_ping_count", "klar_ios"),
ConfigLoader.get_metric("first_run_date", "klar_ios"),
]

Просмотреть файл

@ -3,7 +3,7 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import pytest
from cheap_lint import sql_lint
from helpers.cheap_lint import sql_lint # local helper file
from mozanalysis.config import ConfigLoader
from mozanalysis.metrics import DataSource, Metric
from mozanalysis.segments import Segment, SegmentDataSource

Просмотреть файл

@ -1,11 +1,14 @@
import mozanalysis.metrics.desktop as mad
import mozanalysis.metrics.fenix
import mozanalysis.metrics.firefox_ios
import mozanalysis.metrics.klar_android
import mozanalysis.metrics.klar_ios
import mozanalysis.segments.desktop as msd
import pytest
from cheap_lint import sql_lint
from helpers.cheap_lint import sql_lint # local helper file
from helpers.config_loader_lists import (
desktop_metrics,
desktop_segments,
fenix_metrics,
firefox_ios_metrics,
klar_android_metrics,
klar_ios_metrics,
)
from mozanalysis.config import ConfigLoader
from mozanalysis.experiment import (
AnalysisWindow,
EnrollmentsQueryType,
@ -319,7 +322,7 @@ def test_megaquery_not_detectably_malformed():
sql_lint(enrollments_sql)
metrics_sql = exp.build_metrics_query(
metric_list=[m for m in mad.__dict__.values() if isinstance(m, Metric)],
metric_list=desktop_metrics,
time_limits=tl,
enrollments_table="enrollments",
)
@ -339,14 +342,14 @@ def test_segments_megaquery_not_detectably_malformed():
enrollments_sql = exp.build_enrollments_query(
time_limits=tl,
segment_list=[s for s in msd.__dict__.values() if isinstance(s, Segment)],
segment_list=desktop_segments,
enrollments_query_type=EnrollmentsQueryType.NORMANDY,
)
sql_lint(enrollments_sql)
metrics_sql = exp.build_metrics_query(
metric_list=[m for m in mad.__dict__.values() if isinstance(m, Metric)],
metric_list=desktop_metrics,
time_limits=tl,
enrollments_table="enrollments",
)
@ -385,11 +388,7 @@ def test_app_id_propagates():
sql_lint(enrollments_sql)
metrics_sql = exp.build_metrics_query(
metric_list=[
m
for m in mozanalysis.metrics.fenix.__dict__.values()
if isinstance(m, Metric)
],
metric_list=fenix_metrics,
time_limits=tl,
enrollments_table="enrollments",
)
@ -460,11 +459,7 @@ def test_firefox_ios_app_id_propagation():
sql_lint(enrollments_sql)
metrics_sql = exp.build_metrics_query(
metric_list=[
m
for m in mozanalysis.metrics.firefox_ios.__dict__.values()
if isinstance(m, Metric)
],
metric_list=firefox_ios_metrics,
time_limits=tl,
enrollments_table="enrollments",
)
@ -508,11 +503,7 @@ def test_firefox_klar_app_id_propagation():
sql_lint(enrollments_sql)
metrics_sql = exp.build_metrics_query(
metric_list=[
m
for m in mozanalysis.metrics.klar_android.__dict__.values()
if isinstance(m, Metric)
],
metric_list=klar_android_metrics,
time_limits=tl,
enrollments_table="enrollments",
)
@ -556,11 +547,7 @@ def test_firefox_ios_klar_app_id_propagation():
sql_lint(enrollments_sql)
metrics_sql = exp.build_metrics_query(
metric_list=[
m
for m in mozanalysis.metrics.klar_ios.__dict__.values()
if isinstance(m, Metric)
],
metric_list=klar_ios_metrics,
time_limits=tl,
enrollments_table="enrollments",
)
@ -631,7 +618,7 @@ def test_exposure_signal_query():
enrollments_query_type=EnrollmentsQueryType.GLEAN_EVENT,
exposure_signal=ExposureSignal(
name="exposures",
data_source=mozanalysis.metrics.fenix.baseline,
data_source=ConfigLoader.get_data_source("baseline", "fenix"),
select_expr="metrics.counter.events_total_uri_count > 0",
friendly_name="URI visited exposure",
description="Exposed when URI visited",
@ -659,7 +646,7 @@ def test_exposure_signal_query_custom_windows():
enrollments_query_type=EnrollmentsQueryType.GLEAN_EVENT,
exposure_signal=ExposureSignal(
name="exposures",
data_source=mozanalysis.metrics.fenix.baseline,
data_source=ConfigLoader.get_data_source("baseline", "fenix"),
select_expr="metrics.counter.events_total_uri_count > 0",
friendly_name="URI visited exposure",
description="Exposed when URI visited",
@ -693,11 +680,7 @@ def test_metrics_query_based_on_exposure():
sql_lint(enrollments_sql)
metrics_sql = exp.build_metrics_query(
metric_list=[
m
for m in mozanalysis.metrics.fenix.__dict__.values()
if isinstance(m, Metric)
],
metric_list=fenix_metrics,
time_limits=tl,
enrollments_table="enrollments",
analysis_basis=AnalysisBasis.EXPOSURES,
@ -725,17 +708,13 @@ def test_metrics_query_with_exposure_signal_custom_windows():
sql_lint(enrollments_sql)
metrics_sql = exp.build_metrics_query(
metric_list=[
m
for m in mozanalysis.metrics.fenix.__dict__.values()
if isinstance(m, Metric)
],
metric_list=fenix_metrics,
time_limits=tl,
enrollments_table="enrollments",
analysis_basis=AnalysisBasis.EXPOSURES,
exposure_signal=ExposureSignal(
name="exposures",
data_source=mozanalysis.metrics.fenix.baseline,
data_source=ConfigLoader.get_data_source("baseline", "fenix"),
select_expr="metrics.counter.events_total_uri_count > 0",
friendly_name="URI visited exposure",
description="Exposed when URI visited",
@ -767,17 +746,13 @@ def test_metrics_query_with_exposure_signal():
sql_lint(enrollments_sql)
metrics_sql = exp.build_metrics_query(
metric_list=[
m
for m in mozanalysis.metrics.fenix.__dict__.values()
if isinstance(m, Metric)
],
metric_list=fenix_metrics,
time_limits=tl,
enrollments_table="enrollments",
analysis_basis=AnalysisBasis.EXPOSURES,
exposure_signal=ExposureSignal(
name="exposures",
data_source=mozanalysis.metrics.fenix.baseline,
data_source=ConfigLoader.get_data_source("baseline", "fenix"),
select_expr="metrics.counter.events_total_uri_count > 0",
friendly_name="URI visited exposure",
description="Exposed when URI visited",

Просмотреть файл

@ -1,51 +0,0 @@
import mozanalysis.metrics.desktop as mmd
import mozanalysis.metrics.fenix as mmf
import mozanalysis.metrics.firefox_ios as mmios
import mozanalysis.metrics.focus_android as mmfoc
import mozanalysis.metrics.focus_ios as iosfoc
import mozanalysis.metrics.klar_android as mmk
import mozanalysis.metrics.klar_ios as iosk
import pytest
from cheap_lint import sql_lint
from mozanalysis.metrics import DataSource, Metric
from . import enumerate_included
def test_imported_ok():
assert mmd.active_hours
assert mmf.uri_count
assert mmios.baseline_ping_count
assert mmfoc.metric_ping_count
assert iosfoc.metric_ping_count
assert mmk.baseline_ping_count
assert iosk.baseline_ping_count
@pytest.fixture()
def included_metrics():
return enumerate_included((mmd, mmf, mmios, mmk, mmfoc), Metric)
@pytest.fixture()
def included_datasources():
return enumerate_included((mmd, mmf, mmios, mmk, mmfoc), DataSource)
def test_sql_not_detectably_malformed(included_metrics, included_datasources):
for _, m in included_metrics:
sql_lint(m.select_expr.format(experiment_slug="slug"))
for _, ds in included_datasources:
sql_lint(ds.from_expr_for(None))
def test_consistency_of_metric_and_variable_names(included_metrics):
for name, metric in included_metrics:
assert name == metric.name, metric
def test_included_metrics_have_docs(included_metrics):
for _, m in included_metrics:
assert m.friendly_name, m.name
assert m.description, m.name

Просмотреть файл

@ -1,105 +0,0 @@
import mozanalysis.metrics.desktop as mmd
import mozanalysis.segments.desktop as msd
import pytest
from cheap_lint import sql_lint
from mozanalysis.segments import Segment, SegmentDataSource
from . import enumerate_included
@pytest.fixture()
def included_segments():
return enumerate_included((msd,), Segment)
@pytest.fixture()
def included_segment_datasources():
return enumerate_included((msd,), SegmentDataSource)
def test_imported_ok():
assert msd.regular_users_v3
def test_sql_not_detectably_malformed(included_segments, included_segment_datasources):
for _name, s in included_segments:
sql_lint(s.select_expr)
for _name, sds in included_segment_datasources:
sql_lint(sds.from_expr_for(None))
def test_consistency_of_segment_and_variable_names(included_segments):
for name, segment in included_segments:
assert name == segment.name, segment
def test_segment_data_source_window_end_validates():
SegmentDataSource(
name="bla",
from_expr="bla",
window_start=0,
window_end=0,
)
SegmentDataSource(
name="bla",
from_expr="bla",
window_start=0,
window_end=1,
)
SegmentDataSource(
name="bla",
from_expr="bla",
window_start=1,
window_end=3,
)
def test_segment_data_source_window_start_validates():
SegmentDataSource(
name="bla",
from_expr="bla",
window_start=-1,
window_end=-1,
)
with pytest.raises(ValueError, match="window_start must be <= window_end"):
SegmentDataSource(
name="bla",
from_expr="bla",
window_start=0,
window_end=-1,
)
def test_segment_validates_not_metric_data_source():
with pytest.raises(TypeError):
Segment(
name="bla",
data_source=mmd.clients_daily,
select_expr="bla",
)
def test_included_segments_have_docs(included_segments):
for name, segment in included_segments:
assert segment.friendly_name
assert segment.description, name
def test_complains_about_template_without_default():
with pytest.raises(
ValueError,
match="foo: from_expr contains a dataset template but no value was provided.",
):
SegmentDataSource(
name="foo",
from_expr="moz-fx-data-shared-prod.{dataset}.foo",
)
SegmentDataSource(
name="foo",
from_expr="moz-fx-data-shared-prod.{dataset}.foo",
default_dataset="dataset",
)

Просмотреть файл

@ -1,8 +1,7 @@
import mozanalysis.metrics.desktop as mad
import mozanalysis.segments.desktop as msd
import pandas as pd
import pytest
from cheap_lint import sql_lint
from helpers.cheap_lint import sql_lint # local helper file
from helpers.config_loader_lists import desktop_metrics, desktop_segments
from mozanalysis.config import ConfigLoader
from mozanalysis.experiment import TimeLimits
from mozanalysis.metrics import DataSource, Metric
@ -139,7 +138,11 @@ def test_multiple_datasource():
test_seg = Segment("test_seg", test_sds, "TEST AGG SELECT STATEMENT", "", "")
target_sql = test_target.build_targets_query(
time_limits=tl, target_list=[msd.new_unique_profiles, test_seg]
time_limits=tl,
target_list=[
ConfigLoader.get_segment("new_unique_profiles", "firefox_desktop"),
test_seg,
],
)
sql_lint(target_sql)
@ -158,7 +161,10 @@ def test_query_not_detectably_malformed():
)
target_sql = test_target.build_targets_query(
time_limits=tl, target_list=[msd.new_unique_profiles]
time_limits=tl,
target_list=[
ConfigLoader.get_segment("new_unique_profiles", "firefox_desktop")
],
)
sql_lint(target_sql)
@ -182,18 +188,18 @@ def test_megaquery_not_detectably_malformed():
target_sql = test_target.build_targets_query(
time_limits=tl,
target_list=[s for s in msd.__dict__.values() if isinstance(s, Segment)],
target_list=desktop_segments,
)
sql_lint(target_sql)
desktop_metrics_no_experiment_slug = [
m for m in desktop_metrics if "experiment_slug" not in m.select_expr
]
metrics_sql = test_target.build_metrics_query(
time_limits=tl,
metric_list=[
m
for m in mad.__dict__.values()
if isinstance(m, Metric) and "experiment_slug" not in m.select_expr
],
metric_list=desktop_metrics_no_experiment_slug,
targets_table="targets",
)