How to use the predicthq.endpoints.schemas.IntType 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_string_model_and_string_model_type():

    class MyModel(schemas.StringModel):

        import_format = r"(?P.*)==(?P\d*)"
        export_format = "{left}=={right}"

        left = schemas.StringType()
        right = schemas.IntType()

    class SchemaExample(schemas.Model):

        my_model = schemas.StringModelType(MyModel)

    short_data = {"my_model": "ten==10"}
    long_data = {"my_model": {"left": "ten", "right": 10}}
    model_data = {"my_model": MyModel("ten==10")}
    invalid_data = {"my_model": "10==ten"}

    expected_data = {"my_model": "ten==10"}

    m = SchemaExample()

    assert m.import_data(short_data).to_primitive() == expected_data
    assert m.import_data(long_data).to_primitive() == expected_data
github predicthq / sdk-py / tests / endpoints / decorators_tests.py View on Github external
def test_returns(self):

        class SchemaExample(schemas.Model):
            arg1 = schemas.StringType(required=True)
            arg2 = schemas.ListType(schemas.IntType)

        class EndpointExample(BaseEndpoint):

            @decorators.returns(SchemaExample)
            def func(self, **kwargs):
                return kwargs

        endpoint = EndpointExample(None)
        self.assertEqual(endpoint.func(arg1="test", arg2=[1, 2]), SchemaExample({'arg1': 'test', 'arg2': [1, 2]}))

        with self.assertRaises(ValidationError):
            endpoint.func(arg2=[1, 2])

        with self.assertRaises(ValidationError):
            endpoint.func(arg1="value", arg2="invalid")
github predicthq / sdk-py / predicthq / endpoints / v1 / events / schemas.py View on Github external
class TopEventsSearchParams(SortableMixin, Model):

    limit = IntType(min_value=0, max_value=10)


class CalendarParams(SearchParams):

    top_events = ModelType(TopEventsSearchParams)


class CalendarDay(Model):

    date = DateType()
    count = IntType()
    top_rank = FloatType()
    rank_levels = DictType(IntType)
    categories = DictType(IntType)
    labels = DictType(IntType)
    top_events = ModelType(EventResultSet)


class CalendarResultSet(ResultSet):

    results = ResultType(CalendarDay)


class ImpactParams(SearchParams):

    top_events = ModelType(TopEventsSearchParams)
    impact_rank = StringType(choices=('rank', 'aviation_rank'))
github predicthq / sdk-py / predicthq / endpoints / v1 / events / schemas.py View on Github external
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)
    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:
github predicthq / sdk-py / predicthq / endpoints / v1 / signals / schemas.py View on Github external
class DataPoint(Model):

    uid = StringType(required=True)
    date = DateTimeType(required=True)
    latitude = FloatType(min_value=-90, max_value=90, required=True)
    longitude = FloatType(min_value=-180, max_value=180, required=True)
    initiated = DateTimeType()
    completed = DateTimeType()
    # @todo: Support custom dimensions from signal


class SignalDataPoints(Model):

    id = StringType(required=True)
    data_points = ListType(ModelType(DataPoint), required=True)
    chunk_size = IntType(default=1000, max_value=5000, required=True)


class DateDimension(Model):

    type = StringType()
    count = IntType()
    min = DateTimeType()
    max = DateTimeType()


class GeoDimension(Model):

    type = StringType()
    bbox = ListType(FloatType)
github predicthq / sdk-py / predicthq / endpoints / v1 / events / schemas.py View on Github external
class CalendarResultSet(ResultSet):

    results = ResultType(CalendarDay)


class ImpactParams(SearchParams):

    top_events = ModelType(TopEventsSearchParams)
    impact_rank = StringType(choices=('rank', 'aviation_rank'))


class ImpactDay(Model):

    date = DateType()
    count = IntType()
    impact = IntType()

    rank_levels = DictType(IntType, export_level=NONEMPTY)
    rank_levels_impact = DictType(IntType, export_level=NONEMPTY)

    aviation_rank_levels = DictType(IntType, export_level=NONEMPTY)
    aviation_rank_levels_impact = DictType(IntType, export_level=NONEMPTY)

    categories = DictType(IntType)
    categories_impact = DictType(IntType)


class ImpactResultSet(ResultSet):

    results = ResultType(ImpactDay)
github predicthq / sdk-py / predicthq / endpoints / v1 / signals / schemas.py View on Github external
type = StringType()
    count = IntType()
    min = DateTimeType()
    max = DateTimeType()


class GeoDimension(Model):

    type = StringType()
    bbox = ListType(FloatType)


class CategoryDimensionComponent(Model):

    name = StringType()
    count = IntType()


class CategoryDimension(Model):

    type = StringType()
    options = ListType(ModelType(CategoryDimensionComponent))


class NumberDimension(Model):

    type = StringType()
    count = IntType()
    min = IntType()
    max = IntType()
    avg = FloatType()
    std_deviation = FloatType()
github predicthq / sdk-py / predicthq / endpoints / v1 / events / schemas.py View on Github external
results = ResultType(Event)


class CountResultSet(Model):

    count = IntType()
    top_rank = FloatType()
    rank_levels = DictType(IntType)
    categories = DictType(IntType)
    labels = DictType(IntType)


class TopEventsSearchParams(SortableMixin, Model):

    limit = IntType(min_value=0, max_value=10)


class CalendarParams(SearchParams):

    top_events = ModelType(TopEventsSearchParams)


class CalendarDay(Model):

    date = DateType()
    count = IntType()
    top_rank = FloatType()
    rank_levels = DictType(IntType)
    categories = DictType(IntType)
    labels = DictType(IntType)
    top_events = ModelType(EventResultSet)
github predicthq / sdk-py / predicthq / endpoints / v1 / events / schemas.py View on Github external
type = StringType()
    formatted_address = StringType()


class Event(Model):

    class Options:
        serialize_when_none = True

    id = StringType()
    title = StringType()
    description = StringType()
    start = DateTimeType()
    end = DateTimeType()
    timezone = StringType()
    duration = IntType()
    category = StringType()
    labels = ListType(StringType())
    country = StringType()
    rank = IntType()

    # `local_rank`, `aviation_rank`, and `phq_attendance` are paid features.
    # They will only show up in your response body if you
    # have subscribed to them.
    local_rank = IntType()
    aviation_rank = IntType()
    phq_attendance = IntType()

    entities = ListType(ModelType(Entities))
    location = GeoJSONPointType()
    place_hierarchies = ListType(ListType(StringType()))
    scope = StringType()