How to use the predicthq.endpoints.schemas.ModelType function in predicthq

To help you get started, we’ve selected a few predicthq examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github predicthq / sdk-py / tests / endpoints / test_schemas.py View on Github external
def test_location_around_type():
    class SchemaExample(schemas.Model):
        around = schemas.ModelType(schemas.LocationAround)

    m = SchemaExample()

    assert m.import_data({"around": {"origin": '40.730610,-73.935242', "offset": "1km", "scale": "2km", "decay": "0.1"}}).to_primitive() == {'around': {'origin': u'40.730610,-73.935242', 'decay': 0.1, 'scale': u'2km', 'offset': u'1km'}}

    with pytest.raises(schemas.SchematicsDataError):
        m.import_data({"around": "40.730610,-73.935242"}, validate=True)
github predicthq / sdk-py / tests / endpoints / test_schemas.py View on Github external
def test_date_around_type():

    class SchemaExample(schemas.Model):
        around = schemas.ModelType(schemas.DateAround)

    m = SchemaExample()

    assert m.import_data({"around": {"origin": '2020-01-01', "offset": "1d", "scale": "0d", "decay": "0.1"}}).to_primitive() == {'around': {'origin': '2020-01-01', 'decay': 0.1, 'scale': u'0d', 'offset': u'1d'}}

    with pytest.raises(schemas.SchematicsDataError):
        m.import_data({"around": "2020-01-01"}, validate=True)
github predicthq / sdk-py / predicthq / endpoints / v1 / events / schemas.py View on Github external
StringListType, StringModelType, Area, ModelType, IntRange, IntType, DateTimeRange,
    DateTimeType, FloatType, ResultType, DictType, DateType, Place, DateAround,
    LocationAround, BooleanType, BrandUnsafe, Entity
)


class SearchParams(PaginatedMixin, SortableMixin, Model):

    class Options:
        serialize_when_none = False

    id = ListType(StringType)
    q = StringType()
    label = ListType(StringType)
    category = ListType(StringType)
    start = ModelType(DateTimeRange)
    start_around = ModelType(DateAround)
    end = ModelType(DateTimeRange)
    end_around = ModelType(DateAround)
    active = ModelType(DateTimeRange)
    updated = ModelType(DateTimeRange)
    state = StringType(choices=('active', 'deleted'))
    deleted_reason = StringType(choices=('cancelled', 'duplicate', 'invalid', 'postponed'))
    rank = ModelType(IntRange)
    rank_level = ListType(IntType(min_value=1, max_value=5))

    # `local_rank`, `aviation_rank`, and `phq_attendance` are paid features.
    # If you haven't subscribed to a paid feature, using it as a
    # search param will have no effect on your search results.
    local_rank = ModelType(IntRange)
    local_rank_level = ListType(IntType(min_value=1, max_value=5))
    aviation_rank = ModelType(IntRange)
github predicthq / sdk-py / predicthq / endpoints / v1 / signals / schemas.py View on Github external
excess = FloatType()


class CountAnalysisComponent(Model):

    count = IntType()
    expected = FloatType()
    excess = FloatType()


class DailyAnalysis(Model):

    date = DateType()
    demand = ModelType(CountAnalysisComponent)
    lead = ModelType(MeanAnalysisComponent)
    span = ModelType(MeanAnalysisComponent)


class AnalysisResultSet(ResultSet):

    results = ResultType(DailyAnalysis)


class AnalysisParams(PaginatedMixin, SortableMixin, Model):

    class Options:
        serialize_when_none = False

    id = StringType(required=True)
    date = ModelType(DateTimeRange)
    initiated = ModelType(DateTimeRange)
    completed = ModelType(DateTimeRange)
github predicthq / sdk-py / predicthq / endpoints / v1 / signals / schemas.py View on Github external
span = ModelType(MeanAnalysisComponent)


class AnalysisResultSet(ResultSet):

    results = ResultType(DailyAnalysis)


class AnalysisParams(PaginatedMixin, SortableMixin, Model):

    class Options:
        serialize_when_none = False

    id = StringType(required=True)
    date = ModelType(DateTimeRange)
    initiated = ModelType(DateTimeRange)
    completed = ModelType(DateTimeRange)
    within = StringListType(StringModelType(Area), separator="+")
    significance = FloatType(min_value=0, max_value=100)
    place = ModelType(Place)
github predicthq / sdk-py / predicthq / endpoints / v1 / events / schemas.py View on Github external
# `local_rank`, `aviation_rank`, and `phq_attendance` are paid features.
    # If you haven't subscribed to a paid feature, using it as a
    # search param will have no effect on your search results.
    local_rank = ModelType(IntRange)
    local_rank_level = ListType(IntType(min_value=1, max_value=5))
    aviation_rank = ModelType(IntRange)
    aviation_rank_level = ListType(IntType(min_value=1, max_value=5))
    phq_attendance = ModelType(IntRange)

    country = ListType(StringType)
    location_around = ModelType(LocationAround)
    within = StringListType(StringModelType(Area), separator="+")
    place = ModelType(Place)
    relevance = ListType(StringType)
    brand_unsafe = ModelType(BrandUnsafe)
    entity = ModelType(Entity)


class Entities(Model):

    class Options:
        serialize_when_none = True

    entity_id = StringType()
    name = StringType()
    type = StringType()
    formatted_address = StringType()


class Event(Model):

    class Options:
github predicthq / sdk-py / predicthq / endpoints / v1 / signals / schemas.py View on Github external
std_deviation = FloatType()
    expected = FloatType()
    excess = FloatType()


class CountAnalysisComponent(Model):

    count = IntType()
    expected = FloatType()
    excess = FloatType()


class DailyAnalysis(Model):

    date = DateType()
    demand = ModelType(CountAnalysisComponent)
    lead = ModelType(MeanAnalysisComponent)
    span = ModelType(MeanAnalysisComponent)


class AnalysisResultSet(ResultSet):

    results = ResultType(DailyAnalysis)


class AnalysisParams(PaginatedMixin, SortableMixin, Model):

    class Options:
        serialize_when_none = False

    id = StringType(required=True)
    date = ModelType(DateTimeRange)
github predicthq / sdk-py / predicthq / endpoints / v1 / signals / schemas.py View on Github external
class AnalysisResultSet(ResultSet):

    results = ResultType(DailyAnalysis)


class AnalysisParams(PaginatedMixin, SortableMixin, Model):

    class Options:
        serialize_when_none = False

    id = StringType(required=True)
    date = ModelType(DateTimeRange)
    initiated = ModelType(DateTimeRange)
    completed = ModelType(DateTimeRange)
    within = StringListType(StringModelType(Area), separator="+")
    significance = FloatType(min_value=0, max_value=100)
    place = ModelType(Place)