How to use the predicthq.endpoints.schemas.ResultType 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 / decorators_tests.py View on Github external
def test_returns_resultset_of_models(self):

        class ModelExample(schemas.ResultSet):

            name = schemas.StringType()

        class SchemaExample(schemas.ResultSet):

            results = schemas.ResultType(ModelExample)

        class EndpointExample(BaseEndpoint):

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

        endpoint = EndpointExample(None)
        results = endpoint.func(results=[{"name": "item1"}, {"name": "item2"}])
        self.assertEqual(results, SchemaExample({"results": [{"name": "item1"}, {"name": "item2"}]}))
        self.assertEqual(endpoint.func()._more(results=[{"name": "item2"}, {"name": "item4"}]), SchemaExample({'results': [{"name": "item2"}, {"name": "item4"}]}))

        for item in results:
            self.assertEqual(item._endpoint, endpoint)
github predicthq / sdk-py / tests / endpoints / test_schemas.py View on Github external
def test_resultset():

    class ResultExample(schemas.Model):

        value = schemas.IntType()

    class ResultSetExample(schemas.ResultSet):

        results = schemas.ResultType(ResultExample)

    class EndpointExample(BaseEndpoint):

        @decorators.returns(ResultSetExample)
        def load_page(self, page):
            page = int(page)
            return {
                "count": 9,
                "next": "http://example.org/?page={}".format(page + 1) if page < 3 else None,
                "previous": "http://example.org/?page={}".format(page - 1) if page > 1 else None,
                "results": [{"value": 1 + (3 * (page - 1))}, {"value": 2 + (3 * (page - 1))}, {"value": 3 + (3 * (page - 1))}]
            }

    endpoint = EndpointExample(None)

    p1 = endpoint.load_page(page=1)
github predicthq / sdk-py / predicthq / endpoints / schemas.py View on Github external
def __init__(self, field, *args, **kwargs):
        super(ResultType, self).__init__(ModelType(field), *args, **kwargs)
github predicthq / sdk-py / predicthq / endpoints / v1 / events / schemas.py View on Github external
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'))


class ImpactDay(Model):

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

    rank_levels = DictType(IntType, export_level=NONEMPTY)
    rank_levels_impact = DictType(IntType, export_level=NONEMPTY)
github predicthq / sdk-py / predicthq / endpoints / v1 / signals / schemas.py View on Github external
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)
    within = StringListType(StringModelType(Area), separator="+")
    significance = FloatType(min_value=0, max_value=100)
    place = ModelType(Place)
github predicthq / sdk-py / predicthq / endpoints / v1 / signals / schemas.py View on Github external
class NewSignal(Signal):

    class Options(Signal.Options):
        pass


class SavedSignal(SignalID, Signal):

    class Options(Signal.Options):
        pass


class SignalResultSet(ResultSet):

    results = ResultType(SavedSignal)


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)
github predicthq / sdk-py / predicthq / endpoints / v1 / events / schemas.py View on Github external
location = GeoJSONPointType()
    place_hierarchies = ListType(ListType(StringType()))
    scope = StringType()
    relevance = FloatType()
    state = StringType()
    first_seen = DateTimeType()
    updated = DateTimeType()
    deleted_reason = StringType()
    duplicate_of_id = StringType()


class EventResultSet(ResultSet):

    overflow = BooleanType()

    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)
github predicthq / sdk-py / predicthq / endpoints / v1 / events / schemas.py View on Github external
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)