コード例 #1
0
ファイル: schema.py プロジェクト: walexi/ichnaea
class ValidWifiSchema(ValidMeasureSchema):
    """
    A Schema which validates the fields present in a a wifi measurement.
    """
    channel = SchemaNode(Integer(), missing=0, validator=Range(
        constants.MIN_WIFI_CHANNEL, constants.MAX_WIFI_CHANNEL))
    key = WifiKeyNode(String())
    signal = DefaultNode(Integer(), missing=0, validator=Range(
        constants.MIN_WIFI_SIGNAL, constants.MAX_WIFI_SIGNAL))
    signalToNoiseRatio = DefaultNode(
        Integer(), missing=0, validator=Range(0, 100))

    def deserialize(self, data):
        if data:
            channel = int(data.get('channel', 0))

            if not (constants.MIN_WIFI_CHANNEL
                    < channel
                    < constants.MAX_WIFI_CHANNEL):
                # if no explicit channel was given, calculate
                freq = data.get('frequency', 0)

                if 2411 < freq < 2473:
                    # 2.4 GHz band
                    data['channel'] = (freq - 2407) // 5

                elif 5169 < freq < 5826:
                    # 5 GHz band
                    data['channel'] = (freq - 5000) // 5

                else:
                    data['channel'] = self.fields['channel'].missing

        return super(ValidWifiSchema, self).deserialize(data)
コード例 #2
0
 def deserialize(self, cstruct=null):
     deserialized = super(PointNode, self).deserialize(cstruct)
     longitude = Range(min=-180.0, max=180.0)
     latitude = Range(min=-90.0, max=90.0)
     if self.gps:
         longitude(self, deserialized[0])
         latitude(self, deserialized[1])
     return deserialized
コード例 #3
0
ファイル: schema.py プロジェクト: boostrack/ichnaea
class ValidPositionSchema(FieldSchema, CopyingSchema):
    """A schema which validates the fields present in a position."""

    lat = SchemaNode(Float(),
                     missing=0.0,
                     validator=Range(constants.MIN_LAT, constants.MAX_LAT))
    lon = SchemaNode(Float(),
                     missing=0.0,
                     validator=Range(constants.MIN_LON, constants.MAX_LON))
コード例 #4
0
ファイル: FTIRModel.py プロジェクト: sarahjeeeze/FTIRDB
class molecules_in_sample(Base):
    __tablename__ = 'molecules_in_sample'

    molecular_composition_ID = Column(
        INTEGER(4),
        primary_key=True,
        unique=True,
        autoincrement=True,
        default=0,
        info={'colanderalchemy': {
            'exclude': True
        }})
    descriptive_name = Column(String(45))
    molecule_1_name = Column(String(45))
    concentration_1 = Column(INTEGER(11),
                             default=100,
                             info={
                                 'colanderalchemy': {
                                     'validator': Range(min=1, max=100),
                                     'description': 'as a %'
                                 }
                             })
    molecule_2_name = Column(String(45))
    concentration_2 = Column(INTEGER(11),
                             default=100,
                             info={
                                 'colanderalchemy': {
                                     'validator': Range(min=1, max=100),
                                     'description': 'as a %'
                                 }
                             })
    molecule_3_name = Column(String(45))
    concentration_3 = Column(INTEGER(11),
                             default=100,
                             info={
                                 'colanderalchemy': {
                                     'validator': Range(min=1, max=100),
                                     'description': 'as a %'
                                 }
                             })
    molecule_4_name = Column(String(45))
    concentration_4 = Column(INTEGER(11),
                             default=100,
                             info={
                                 'colanderalchemy': {
                                     'validator': Range(min=1, max=100),
                                     'description': 'as a %'
                                 }
                             })

    #child
    sample_ID = Column(Integer,
                       ForeignKey('sample.sample_ID'),
                       info={'colanderalchemy': {
                           'exclude': True
                       }})
コード例 #5
0
class Dropout(MappingSchema):
    year = general_rules.year
    dropouts_with_mbo1_dimploma = SchemaNode(Int(), validator=Range(min=0,
        max=5000))
    dropouts_with_vmbo_diploma = SchemaNode(Int(), validator=Range(min=0,
        max=5000))
    dropouts_without_diploma = SchemaNode(Int(), validator=Range(min=0,
        max=5000))
    education_structure = SchemaNode(String(), validator=Length(min=3, max=75))
    total_dropouts = SchemaNode(Int(), validator=Range(min=0, max=5000))
    total_students = SchemaNode(Int(), validator=Range(min=0, max=5000))
コード例 #6
0
ファイル: cleanup.py プロジェクト: shhw2019/noaa_pyGnome
class ChemicalDispersionSchema(WeathererSchema):
    fraction_sprayed = SchemaNode(Float(),
                                  save=True,
                                  update=True,
                                  validator=Range(0, 1.0))
    efficiency = SchemaNode(Float(),
                            save=True,
                            update=True,
                            missing=drop,
                            validator=Range(0, 1.0))
    _rate = SchemaNode(Float(), save=True, update=True, missing=drop)
    waves = WavesSchema(save=True,
                        update=True,
                        missing=drop,
                        save_reference=True)
コード例 #7
0
class CostPerYear(MappingSchema):
    amount_euro = SchemaNode(Int(), validator=Range(min=0, max=1000))
    explanation = SchemaNode(String())
    link = SchemaNode(String())
    other_costs = SchemaNode(Boolean())
    # Year can be a bunch of things ("Leerjaar 1", "alle jaren", ...)
    year = SchemaNode(String(), validator=Length(min=3, max=75))
コード例 #8
0
class SchoolVOBranch(MappingSchema):
    address = general_rules.Address()
    avg_education_hours_per_student = AverageEducationHours()
    avg_education_hours_per_student_url = SchemaNode(String(), validator=url)
    board = SchemaNode(String(), validator=Length(min=3, max=100))
    board_id = general_rules.board_id
    branch_id = general_rules.branch_id
    brin = general_rules.brin
    building_img_url = SchemaNode(String(), validator=url)
    costs = Costs()
    costs_url = SchemaNode(String(), validator=url)
    denomination = general_rules.denomination
    education_structures = general_rules.EducationStructures()
    email = SchemaNode(String(), validator=Email())
    logo_img_url = SchemaNode(String(), validator=url)
    municipality = general_rules.municipality
    municipality_id = general_rules.municipality_code
    name = general_rules.name
    parent_satisfaction = Satisfactions()
    parent_satisfaction_url = SchemaNode(String(), validator=url)
    phone = general_rules.phone
    profile = SchemaNode(String(), validator=Length(min=3, max=500))
    province = general_rules.province
    schoolkompas_status_id = SchemaNode(Int(), validator=Range(min=0,\
        max=1000))
    schoolvo_code = SchemaNode(String(), validator=Length(min=14, max=14))
    student_satisfaction = Satisfactions()
    student_satisfaction_url = SchemaNode(String(), validator=url)
    website = general_rules.website
コード例 #9
0
ファイル: wind.py プロジェクト: simomartini/PyGnome
class MagnitudeDirectionTuple(DefaultTupleSchema):
    speed = SchemaNode(Float(),
                       default=0,
                       validator=Range(min=0,
                                       min_err='wind speed must be '
                                       'greater than or equal to 0'))
    direction = SchemaNode(Float(),
                           default=0,
                           validator=Range(0,
                                           360,
                                           min_err='wind direction must be '
                                           'greater than or equal to '
                                           '0',
                                           max_err='wind direction must be '
                                           'less than or equal to '
                                           '360deg'))
コード例 #10
0
class AddEntrySchema(MappingSchema):
    project_id = SchemaNode(Integer())
    ticket_id = SchemaNode(TicketObject())
    time = SchemaNode(TimeObject(), validator=Range(0.0, 24.00))
    description = SchemaNode(String())
    timer = SchemaNode(Boolean())
    add_to_harvest = SchemaNode(Boolean())
コード例 #11
0
ファイル: validationapp.py プロジェクト: timgates42/cornice
 class BodySchema(MappingSchema):
     # foo and bar are required, baz is optional
     foo = SchemaNode(String())
     bar = SchemaNode(String(), validator=validate_bar)
     baz = SchemaNode(String(), missing=None)
     ipsum = SchemaNode(Integer(), missing=1, validator=Range(0, 3))
     integers = Integers(missing=())
コード例 #12
0
class CurrentRating(MappingSchema):
    # education_structure = None # TODO
    owinsp_id = SchemaNode(Int(), validator=Range(min=0))
    owinsp_url = general_rules.url()
    rating = SchemaNode(String(), validator=Length(min=4, max=20))
    rating_excerpt = SchemaNode(String(), validator=Length(min=4, max=500))
    rating_valid_since = general_rules.publication_date()
コード例 #13
0
    class Fees(colander.Schema):
        member_type = colander.SchemaNode(
            colander.String(),
            title=_(u'Please tell us wether you\'re an individual, '
                    u'freelancer or company or want to support us '
                    u'generously as a sustaining member'),
            widget=deform.widget.RadioChoiceWidget(
                values=[(member_type, t_description) for fee, member_type,
                        t_description in customization.membership_fees]),
            oid='member_type')

        # not validating here: depends on ^
        # http://deformdemo.repoze.org/require_one_or_another/
        member_custom_fee = colander.SchemaNode(
            colander.Decimal('1.00'),
            title=_(u'custom membership fee'),
            widget=deform.widget.MoneyInputWidget(
                symbol=customization.currency,
                showSymbol=True,
                defaultZero=True),
            description=_(
                u'Sustaining members: You can set your fees (minimum 100 €)'),
            oid='membership_custom_fee',
            default=customization.membership_fee_custom_min,
            validator=Range(
                min=customization.membership_fee_custom_min,
                max=None,
                min_err=
                _(u'please enter at least the minimum fee for sustaining members'
                  )))
コード例 #14
0
ファイル: mercator.py プロジェクト: olivierh59500/adhocracy3
class FinanceSchema(MappingSchema):
    """Data structure for financial aspects."""

    budget = CurrencyAmount(missing=required)
    requested_funding = CurrencyAmount(missing=required,
                                       validator=Range(min=0, max=50000))
    other_sources = SingleLine()
    granted = Boolean()
コード例 #15
0
ファイル: schema.py プロジェクト: satcomlabs/PyGnome
class ModelSchema(MappingSchema):
    id = SchemaNode(String(), missing=drop)
    start_time = SchemaNode(LocalDateTime(),
                            default=now,
                            validator=validators.convertible_to_seconds)
    duration_days = SchemaNode(Int(), default=1, validator=Range(min=0))
    duration_hours = SchemaNode(Int(), default=0, validator=Range(min=0))
    uncertain = SchemaNode(Bool(), default=False)
    time_step = SchemaNode(Float(), default=0.1)
    surface_release_spills = PointSourceReleasesSchema(default=[],
                                                       missing=drop)
    wind_movers = WindMoversSchema(default=[], missing=drop)
    random_movers = RandomMoversSchema(default=[], missing=drop)
    cats_movers = CatsMoversSchema(default=[], missing=drop)
    grid_current_movers = GridCurrentMoversSchema(default=[], missing=drop)
    winds = WindsSchema(default=[], missing=drop)
    map = MapSchema(missing=drop)
コード例 #16
0
class Indicator(MappingSchema):
    grade = SchemaNode(
        Float(),
        validator=Range(min=0.0, max=10.0),
        title="The average grade student/parents awarded this indicator.")
    indicator = SchemaNode(String(),
                           validator=Length(min=10, max=200),
                           title="The indicator.")
コード例 #17
0
class PoolQueryDepth(Integer):
    """The nesting depth of descendants in a pool response.

    Either a positive number or the string 'all' to return descendants of
    arbitrary depth.
    """

    missing = drop
    validator = Range(min=1)
コード例 #18
0
class ProposalSchema(MappingSchema):
    """Data structure for organizational information."""

    # TODO: check exact length restrictions

    budget = CurrencyAmount(missing=required,
                            validator=Range(min=0, max=50000))
    creator_participate = Boolean()
    location_text = SingleLine(validator=Length(max=100))
コード例 #19
0
class DomainDefaults(Schema):
    password_valid = SchemaNode(
        Integer(),
        default=MAX_PASSWORD_VALID,
        title="Password valid",
        description="Indicate the system default time in minutes that a "
                    "password should be valid (must be >= 0)",
        validator=Range(min=0),
    )
コード例 #20
0
class WebMercatorLatitude(MappingSchema):
    """A a web mercator latitude value.

    Validation values taken from http://epsg.io/3857.
    """

    schema_type = Float
    default = 0
    missing = drop
    validator = Range(min=-20048966.10, max=20048966.10)
コード例 #21
0
 class FooBarSchema(MappingSchema):
     # foo and bar are required, baz is optional
     foo = SchemaNode(String(), type='str')
     bar = SchemaNode(String(), type='str', validator=validate_bar)
     baz = SchemaNode(String(), type='str', missing=None)
     yeah = SchemaNode(String(), location="querystring", type='str')
     ipsum = SchemaNode(Integer(),
                        type='int',
                        missing=1,
                        validator=Range(0, 3))
     integers = Integers(location="body", type='list', missing=())
コード例 #22
0
class BeachingTupleSchema(DefaultTupleSchema):
    '''
    Schema for each tuple in TimeSeries list
    '''
    datetime = SchemaNode(LocalDateTime(default_tzinfo=None),
                          default=base_schema.now,
                          validator=validators.convertible_to_seconds)
    amount = SchemaNode(Float(), default=0,
                        validator=Range(min=0,
                                        min_err='amount must be '
                                                'greater than or equal to 0'))
コード例 #23
0
class StudentByStructure(MappingSchema):
    department = SchemaNode(String(), validator=Length(min=3, max=300))
    education_name = SchemaNode(String(), validator=Length(min=3, max=300))
    education_structure = general_rules.education_structure
    elementcode = SchemaNode(Int(), validator=Range(min=0))
    lwoo = SchemaNode(Boolean())
    vmbo_sector = SchemaNode(String(), validator=Length(min=3, max=300))
    year_1 = StudentsEnrolledInStructure()
    year_2 = StudentsEnrolledInStructure()
    year_3 = StudentsEnrolledInStructure()
    year_4 = StudentsEnrolledInStructure()
    year_5 = StudentsEnrolledInStructure()
    year_6 = StudentsEnrolledInStructure()
コード例 #24
0
ファイル: schema.py プロジェクト: boostrack/ichnaea
class ValidReportSchema(ValidPositionSchema):
    """A schema which validates the fields present in a report."""

    accuracy = DefaultNode(Float(),
                           missing=0,
                           validator=Range(0, constants.MAX_ACCURACY))
    altitude = DefaultNode(Float(),
                           missing=0,
                           validator=Range(constants.MIN_ALTITUDE,
                                           constants.MAX_ALTITUDE))
    altitude_accuracy = DefaultNode(Float(),
                                    missing=0,
                                    validator=Range(
                                        0, constants.MAX_ALTITUDE_ACCURACY))
    heading = DefaultNode(Float(),
                          missing=-1,
                          validator=Range(0, constants.MAX_HEADING))
    speed = DefaultNode(Float(),
                        missing=-1,
                        validator=Range(0, constants.MAX_SPEED))
    report_id = ReportIDNode(UUIDType())
    created = SchemaNode(DateTimeFromString(), missing=None)
    time = RoundToMonthDateNode(DateTimeFromString(), missing=None)
コード例 #25
0
class Authentication(Schema):
    token_duration = SchemaNode(
        Integer(),
        default=TOKEN_DURATION,
        description=u'Duration (in minutes) password reset tokens are valid for.'
    )
    max_attempts = SchemaNode(
        Integer(),
        default=MAX_DOMAIN_ATTEMPTS,
        title="Maximum login attempts",
        description="Indicate the system default number of times a user may "
                    "fail a login attempt before being disabled (must be >= 1)",
        validator=Range(min=1),
    )
コード例 #26
0
class Satisfaction(MappingSchema):
    average_grade = SchemaNode(
        Float(),
        validator=Range(min=0.0, max=10.0),
        title=
        "The average satisfaction grade of this structure (*0.0 <= average_grade <= 10.0*)."
    )
    national_grade = SchemaNode(
        Float(),
        validator=Range(min=0.0, max=10.0),
        title=
        "The average grade for all these structures in the Netherlands (*0.0 <= average_grade <= 10.0*)."
    )
    education_structure = SchemaNode(
        String(),
        validator=Length(min=3, max=15),
        title=
        "String representing the education structure [#edu_in_holland]_ this satisfaction surveys were collected for."
    )
    indicators = Indicators(
        title=
        "Array of :ref:`indicator`, which indicate satisfaction scores for specific indicators [#tevr_stud]_ [#tevr_par]_."
    )
コード例 #27
0
class ColanderSchemaTestModel(Base, ColanderAlchemyMixin):
    __tablename__ = 'colander_schema_test'

    id = sa.Column(BigInteger, autoincrement=True, primary_key=True)
    foreign_key_field = sa.Column(None, sa.ForeignKey(RelatedClassA.id))
    foreign_key_field2 = sa.Column(None, sa.ForeignKey(RelatedClassB.id))
    foreign_key_field3 = sa.Column(None, sa.ForeignKey(RelatedClassC.id))
    big_integer_field = sa.Column(BigInteger)
    integer_field = sa.Column(sa.Integer, nullable=False)
    numeric_field = sa.Column(sa.Numeric)
    float_field = sa.Column(sa.Float)
    datetime_field = sa.Column(sa.DateTime, index=True)
    date_field = sa.Column(sa.Date)
    time_field = sa.Column(sa.Time)
    text_field = sa.Column(sa.Text)
    unicode_field = sa.Column(sa.Unicode(255))
    unicode_field2 = sa.Column(sa.Unicode(20))
    unicode_field3 = sa.Column(sa.Unicode(20))
    unicode_field4 = sa.Column(sa.Unicode(20))
    unicode_text_field = sa.Column(sa.UnicodeText)
    field_with_range = sa.Column(sa.Integer)
    nullable_field = sa.Column(sa.Boolean, nullable=True)
    not_nullable_field = sa.Column(sa.Boolean, nullable=False, default=False)
    read_only_field = sa.Column(sa.Integer)

    whitelisted_relation = orm.relationship(RelatedClassA)
    read_only_relation = orm.relationship(RelatedClassB)
    not_nullable_relation = orm.relationship(RelatedClassC)

    __schema__ = {
        'read_only_field': {
            'readonly': True
        },
        'field_with_range': {
            'validator': Range(min=1, max=99)
        },
        'whitelisted_relation': {},
        'not_nullable_relation': {
            'nullable': False
        },
        'unicode_field3': {
            'validator': OneOf(['choice'])
        },
        'unicode_field4': {
            'validator': All(OneOf(['choice']), Email())
        }
    }
コード例 #28
0
class StudentResidence(MappingSchema):
    municipality = general_rules.municipality
    municipality_code = general_rules.municipality_code
    city = general_rules.city
    zip_code = SchemaNode(String(), validator=Length(min=4, max=4))
    year_1 = SchemaNode(Int(), validator=Range(min=0))
    year_2 = SchemaNode(Int(), validator=Range(min=0))
    year_3 = SchemaNode(Int(), validator=Range(min=0))
    year_4 = SchemaNode(Int(), validator=Range(min=0))
    year_5 = SchemaNode(Int(), validator=Range(min=0))
    year_6 = SchemaNode(Int(), validator=Range(min=0))
コード例 #29
0
class CostPerYear(MappingSchema):
    amount_euro = SchemaNode(Int(),
                             validator=Range(min=0, max=1000),
                             title="Costs in &euro; (euro) for this year.")
    explanation = SchemaNode(
        String(),
        title=
        "Optional explanation of the details of the costs (*for a labcoat, for travel, ...*)"
    )
    link = SchemaNode(String(),
                      title="Optional URL to a document detailing costs.")
    other_costs = SchemaNode(
        Boolean(),
        title=
        "Indication whether parents should expect additional costs, other than the costs mentioned here."
    )
    # Year can be a bunch of things ("Leerjaar 1", "alle jaren", ...)
    year = SchemaNode(
        String(),
        validator=Length(min=3, max=75),
        title="String representation of the years these costs apply to.")
コード例 #30
0
ファイル: schema.py プロジェクト: walexi/ichnaea
class ValidMeasureSchema(FieldSchema, CopyingSchema):
    """
    A Schema which validates the fields present in a measurement,
    regardless of whether it is a Cell or Wifi measurement.
    """
    lat = SchemaNode(Float(), missing=0.0, validator=Range(
        constants.MIN_LAT, constants.MAX_LAT))
    lon = SchemaNode(Float(), missing=0.0, validator=Range(
        constants.MIN_LON, constants.MAX_LON))
    accuracy = DefaultNode(
        Float(), missing=0, validator=Range(0, constants.MAX_ACCURACY))
    altitude = DefaultNode(
        Float(), missing=0, validator=Range(
            constants.MIN_ALTITUDE, constants.MAX_ALTITUDE))
    altitude_accuracy = DefaultNode(
        Float(), missing=0, validator=Range(
            0, constants.MAX_ALTITUDE_ACCURACY))
    heading = DefaultNode(
        Float(), missing=-1, validator=Range(0, constants.MAX_HEADING))
    speed = DefaultNode(
        Float(), missing=-1, validator=Range(0, constants.MAX_SPEED))
    report_id = ReportIDNode(String(), missing='')
    time = RoundToMonthDateNode(DateTimeToString(), missing=None)