Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
stop: str,
*,
table: Union[None, List[str]] = None,
spatial_unit: AnySpatialUnit = make_spatial_unit("cell"),
interval: str = "hour",
direction: Union[str, Direction] = Direction.BOTH,
hours="all",
subscriber_subset=None,
subscriber_identifier="msisdn",
):
self.start = standardise_date(start)
self.stop = standardise_date(stop)
self.table = table
self.spatial_unit = spatial_unit
self.interval = interval
self.direction = Direction(direction)
if self.interval not in self.allowed_intervals:
raise ValueError(
"'Interval must be one of: {} got: {}".format(
self.allowed_intervals, self.interval
)
)
self.time_cols = ["(datetime::date)::text AS date"]
if self.interval == "hour" or self.interval == "min":
self.time_cols.append("extract(hour FROM datetime) AS hour")
if self.interval == "min":
self.time_cols.append("extract(minute FROM datetime) AS min")
events_tables_union_cols = ["location_id", "datetime", subscriber_identifier]
# if we need to filter on outgoing/incoming calls, we will also fetch this
def __init__(
self,
start,
stop,
contact_reciprocal,
*,
direction: Union[str, Direction] = Direction.OUT,
subscriber_identifier="msisdn",
hours="all",
subscriber_subset=None,
tables="all",
exclude_self_calls=True,
):
self.start = start
self.stop = stop
self.subscriber_identifier = subscriber_identifier
self.hours = hours
self.exclude_self_calls = exclude_self_calls
self.direction = Direction(direction)
self.tables = tables
column_list = [
def __init__(
self,
start,
stop,
numerator,
*,
numerator_direction: Union[str, Direction] = Direction.BOTH,
subscriber_identifier="msisdn",
direction: Union[str, Direction] = Direction.BOTH,
hours="all",
subscriber_subset=None,
tables="all",
):
self.start = standardise_date(start)
self.stop = standardise_date(stop)
self.subscriber_identifier = subscriber_identifier
self.direction = Direction(direction)
self.numerator_direction = Direction(numerator_direction)
self.hours = hours
self.tables = tables
self.numerator = numerator if isinstance(numerator, list) else [numerator]
self.numerator_query = EventCount(
start,
stop,
phase="hour",
*,
subscriber_identifier="msisdn",
direction: Union[str, Direction] = Direction.BOTH,
hours="all",
subscriber_subset=None,
tables="all",
):
self.tables = tables
self.start = standardise_date(start)
self.stop = standardise_date(stop)
self.subscriber_identifier = subscriber_identifier
self.direction = Direction(direction)
self.hours = hours
column_list = [
self.subscriber_identifier,
"datetime",
*self.direction.required_columns,
]
# extracted from the POSTGRES manual
allowed_phases = (
"century",
"day",
"decade",
"dow",
"doy",
"epoch",
stop: str,
statistic: str = "avg",
*,
hours: Union[str, Tuple[int, int]] = "all",
tables: Union[str, List[str]] = "all",
subscriber_identifier: str = "msisdn",
subscriber_subset: Optional[Query] = None,
direction: Union[str, Direction] = Direction.OUT,
):
self.start = standardise_date(start)
self.stop = standardise_date(stop)
self.hours = hours
self.tables = tables
self.subscriber_identifier = subscriber_identifier
self.direction = Direction(direction)
column_list = [
self.subscriber_identifier,
"datetime",
*self.direction.required_columns,
]
self.statistic = statistic.lower()
if self.statistic not in valid_stats:
raise ValueError(
"{} is not a valid statistic. Use one of {}".format(
self.statistic, valid_stats
)
)
self.unioned_query = EventsTablesUnion(
def __init__(
self,
start,
stop,
*,
hours="all",
tables="all",
subscriber_identifier="msisdn",
direction: Union[str, Direction] = Direction.BOTH,
exclude_self_calls=True,
subscriber_subset=None,
):
self.start = standardise_date(start)
self.stop = standardise_date(stop)
self.hours = hours
self.direction = Direction(direction)
self.subscriber_identifier = subscriber_identifier
self.exclude_self_calls = exclude_self_calls
self.tables = tables
column_list = [
self.subscriber_identifier,
"msisdn_counterpart",
*self.direction.required_columns,
]
self.stop,
hours=self.hours,
tables=self.tables,
subscriber_identifier="msisdn",
direction=Direction.IN,
exclude_self_calls=self.exclude_self_calls,
subscriber_subset=subscriber_subset,
)
self.contact_out_query = ContactBalance(
self.start,
self.stop,
hours=self.hours,
tables=self.tables,
subscriber_identifier="msisdn",
direction=Direction.OUT,
exclude_self_calls=self.exclude_self_calls,
subscriber_subset=subscriber_subset,
)
super().__init__()
self,
start,
stop,
numerator,
*,
numerator_direction: Union[str, Direction] = Direction.BOTH,
subscriber_identifier="msisdn",
direction: Union[str, Direction] = Direction.BOTH,
hours="all",
subscriber_subset=None,
tables="all",
):
self.start = standardise_date(start)
self.stop = standardise_date(stop)
self.subscriber_identifier = subscriber_identifier
self.direction = Direction(direction)
self.numerator_direction = Direction(numerator_direction)
self.hours = hours
self.tables = tables
self.numerator = numerator if isinstance(numerator, list) else [numerator]
self.numerator_query = EventCount(
self.start,
self.stop,
subscriber_identifier=self.subscriber_identifier,
direction=self.numerator_direction,
hours=self.hours,
subscriber_subset=subscriber_subset,
tables=self.numerator,
)
self.denominator_query = EventCount(
start,
stop,
numerator,
*,
numerator_direction: Union[str, Direction] = Direction.BOTH,
subscriber_identifier="msisdn",
direction: Union[str, Direction] = Direction.BOTH,
hours="all",
subscriber_subset=None,
tables="all",
):
self.start = standardise_date(start)
self.stop = standardise_date(stop)
self.subscriber_identifier = subscriber_identifier
self.direction = Direction(direction)
self.numerator_direction = Direction(numerator_direction)
self.hours = hours
self.tables = tables
self.numerator = numerator if isinstance(numerator, list) else [numerator]
self.numerator_query = EventCount(
self.start,
self.stop,
subscriber_identifier=self.subscriber_identifier,
direction=self.numerator_direction,
hours=self.hours,
subscriber_subset=subscriber_subset,
tables=self.numerator,
)
self.denominator_query = EventCount(
self.start,
contact_reciprocal,
*,
direction: Union[str, Direction] = Direction.OUT,
subscriber_identifier="msisdn",
hours="all",
subscriber_subset=None,
tables="all",
exclude_self_calls=True,
):
self.start = start
self.stop = stop
self.subscriber_identifier = subscriber_identifier
self.hours = hours
self.exclude_self_calls = exclude_self_calls
self.direction = Direction(direction)
self.tables = tables
column_list = [
self.subscriber_identifier,
"msisdn",
"msisdn_counterpart",
*self.direction.required_columns,
]
self.unioned_query = EventsTablesUnion(
self.start,
self.stop,
tables=self.tables,
columns=column_list,
hours=hours,
subscriber_identifier=subscriber_identifier,