Esempio n. 1
0
class MineMapViewLocation(Base):
    """
    Read-only model that represents the mine_map database view.
    """
    __tablename__ = "mine_map_view"
    mine_guid = db.Column(UUID(as_uuid=True), primary_key=True)
    latitude = db.Column(db.Numeric(9, 7), nullable=False)
    longitude = db.Column(db.Numeric(11, 7), nullable=False)
    mine_no = db.Column(db.String(10))
    mine_name = db.Column(db.String(60), nullable=False)

    def __repr__(self):
        return '<MineMapView %r>' % self.mine_guid

    def json(self):
        return {
            'mine_guid': str(self.mine_guid),
            'latitude': str(self.latitude),
            'longitude': str(self.longitude),
            'mine_no': str(self.mine_no),
            'mine_name': str(self.mine_name),
        }

    def json_for_map(self):
        return {
            'mine_guid': str(self.mine_guid),
            'mine_name': str(self.mine_name),
            'mine_no': str(self.mine_no),
            'mine_location': {
                'latitude': str(self.latitude),
                'longitude': str(self.longitude)
            }
        }
Esempio n. 2
0
class Grade(db.Model):
    __tablename__ = "grades"
    id = db.Column(db.Integer, primary_key=True)
    course_id = db.Column(db.Integer, db.ForeignKey("courses.id"), index=True)
    user_id = db.Column(db.Integer, db.ForeignKey("users.id"))
    grade = db.Column(db.String)
    outcomes = db.Column(db.JSON)
    record_id = db.Column(db.Integer, db.ForeignKey("records.id"))
    threshold = db.Column(db.Numeric(asdecimal=False))
    min_score = db.Column(db.Numeric(asdecimal=False))

    def to_dict(self):
        """
        Helper to return dictionary with the joined data included
        :return:
        """
        d = {k: v for k, v in self.__dict__.items() if not k.startswith("_")}

        d["user"] = {
            k: v
            for k, v in self.user.__dict__.items() if not k.startswith("_")
        }
        # del d['_sa_instance_state']
        # del d['user']['_sa_instance_state']

        return d

    def __repr__(self):
        return str(self.__dict__)
Esempio n. 3
0
class ActivityDetailBase(AuditMixin, Base):
    __tablename__ = 'activity_detail'

    activity_detail_id = db.Column(db.Integer,
                                   primary_key=True,
                                   server_default=FetchedValue())
    activity_type_description = db.Column(db.String)
    disturbed_area = db.Column(db.Numeric(14, 2))
    timber_volume = db.Column(db.Numeric(14, 2))
    number_of_sites = db.Column(db.Integer)
    width = db.Column(db.Integer)
    length = db.Column(db.Integer)
    depth = db.Column(db.Integer)
    quantity = db.Column(db.Integer)
    incline = db.Column(db.Numeric(14, 2))
    incline_unit_type_code = db.Column(
        db.String, db.ForeignKey('unit_type.unit_type_code'))
    cut_line_length = db.Column(db.Integer)
    water_quantity = db.Column(db.Integer)
    water_quantity_unit_type_code = db.Column(
        db.String, db.ForeignKey('unit_type.unit_type_code'))

    activity_summaries = db.relationship(
        'ActivitySummaryBase', secondary='activity_summary_detail_xref')
    activity_type_code = db.column_property(
        db.select([ActivitySummaryBase.activity_type_code],
                  and_(
                      ActivitySummaryDetailXref.activity_summary_id ==
                      ActivitySummaryBase.activity_summary_id,
                      ActivitySummaryDetailXref.activity_detail_id ==
                      activity_detail_id)).as_scalar())

    __mapper_args__ = {'polymorphic_on': activity_type_code}
Esempio n. 4
0
class NOWApplication(Base, AuditMixin):
    __tablename__ = "now_application"

    now_application_id = db.Column(db.Integer, primary_key=True, server_default=FetchedValue())
    now_application_guid = db.Column(UUID(as_uuid=True))
    mine_guid = db.Column(UUID(as_uuid=True), db.ForeignKey('mine.mine_guid'))
    now_message_id = db.Column(db.Integer, nullable=False)
    now_tracking_number = db.Column(db.Integer)
    notice_of_work_type_code = db.Column(
        db.String, db.ForeignKey('notice_of_work_type.notice_of_work_type_code'), nullable=False)
    now_application_status_code = db.Column(
        db.String,
        db.ForeignKey('now_application_status.now_application_status_code'),
        nullable=False)
    submitted_date = db.Column(db.Date, nullable=False)
    received_date = db.Column(db.Date, nullable=False)
    latitude = db.Column(db.Numeric(9, 7))
    longitude = db.Column(db.Numeric(11, 7))
    property_name = db.Column(db.String)
    tenure_number = db.Column(db.String)
    description_of_land = db.Column(db.String)
    proposed_start_date = db.Column(db.Date)
    proposed_end_date = db.Column(db.Date)

    exploration_access_acts = db.relationship('ExplorationAccess', lazy='joined')
    exploration_surface_drilling_acts = db.relationship('ExplorationSurfaceDrilling', lazy='joined')

    #placer_operations = db.relationship(
    #    'PlacerOperation', lazy='select', secondary='now_application_place_xref')

    def __repr__(self):
        return '<Application %r>' % self.application_guid
Esempio n. 5
0
class MineLocation(AuditMixin, Base):
    __tablename__ = "mine_location"
    mine_location_guid = db.Column(UUID(as_uuid=True), primary_key=True)
    mine_guid = db.Column(UUID(as_uuid=True), db.ForeignKey('mine.mine_guid'))
    latitude = db.Column(db.Numeric(9, 7))
    longitude = db.Column(db.Numeric(11, 7))
    geom = db.Column(Geometry('POINT', 3005))
    effective_date = db.Column(db.DateTime,
                               nullable=False,
                               default=datetime.utcnow)
    expiry_date = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.strptime('9999-12-31',
                                                      '%Y-%m-%d'))

    def __repr__(self):
        return '<MineLocation %r>' % self.mine_guid

    def json(self):
        if not self.latitude:
            return None
        lat = self.latitude
        lon = self.longitude
        return {
            'mine_location_guid': str(self.mine_location_guid),
            'mine_guid': str(self.mine_guid),
            'latitude': str(lat),
            'longitude': str(lon),
        }

    @classmethod
    def find_by_mine_guid(cls, _id):
        return cls.query.filter_by(mine_guid=_id).first()

    @classmethod
    def find_by_mine_location_guid(cls, _id):
        return cls.query.filter_by(mine_location_guid=_id).first()

    @classmethod
    def create_mine_location(cls,
                             mine,
                             random_location,
                             user_kwargs,
                             save=True):
        mine_location = cls(mine_location_guid=uuid.uuid4(),
                            mine_guid=mine.mine_guid,
                            latitude=random_location.get('latitude', 0),
                            longitude=random_location.get('longitude', 0),
                            geom='SRID=3005;POINT(%f %f)' %
                            (float(random_location.get('longitude', 0)),
                             float(random_location.get('latitude', 0))),
                            effective_date=datetime.today(),
                            expiry_date=datetime.today(),
                            **user_kwargs)
        if save:
            mine_location.save(commit=False)
        return mine_location
Esempio n. 6
0
class ActivityDetailBase(AuditMixin, Base):
    __tablename__ = 'activity_detail'
    _edit_groups = [NOW_APPLICATION_EDIT_GROUP]

    activity_detail_id = db.Column(db.Integer,
                                   primary_key=True,
                                   server_default=FetchedValue())
    activity_type_description = db.Column(db.String)
    disturbed_area = db.Column(db.Numeric(14, 2))
    disturbed_area_unit_type_code = db.Column(
        db.String, db.ForeignKey('unit_type.unit_type_code'))
    timber_volume = db.Column(db.Numeric(14, 2))
    timber_volume_unit_type_code = db.Column(
        db.String, db.ForeignKey('unit_type.unit_type_code'))
    number_of_sites = db.Column(db.Integer)
    width = db.Column(db.Integer)
    width_unit_type_code = db.Column(db.String,
                                     db.ForeignKey('unit_type.unit_type_code'))
    length = db.Column(db.Integer)
    length_unit_type_code = db.Column(
        db.String, db.ForeignKey('unit_type.unit_type_code'))
    depth = db.Column(db.Integer)
    depth_unit_type_code = db.Column(db.String,
                                     db.ForeignKey('unit_type.unit_type_code'))
    height = db.Column(db.Integer)
    height_unit_type_code = db.Column(
        db.String, db.ForeignKey('unit_type.unit_type_code'))
    quantity = db.Column(db.Integer)
    incline = db.Column(db.Numeric(14, 2))
    incline_unit_type_code = db.Column(
        db.String, db.ForeignKey('unit_type.unit_type_code'))
    cut_line_length = db.Column(db.Integer)
    cut_line_length_unit_type_code = db.Column(
        db.String, db.ForeignKey('unit_type.unit_type_code'))
    water_quantity = db.Column(db.Integer)
    water_quantity_unit_type_code = db.Column(
        db.String, db.ForeignKey('unit_type.unit_type_code'))

    _etl_activity_details = db.relationship('ETLActivityDetail',
                                            load_on_pending=True)

    activity_type_code = db.column_property(
        db.select([ActivitySummaryBase.activity_type_code],
                  and_(
                      ActivitySummaryDetailXref.activity_summary_id ==
                      ActivitySummaryBase.activity_summary_id,
                      ActivitySummaryDetailXref.activity_detail_id ==
                      activity_detail_id)).limit(1).as_scalar())

    __mapper_args__ = {'polymorphic_on': activity_type_code}

    def delete(self, commit=True):
        for item in self.detail_associations:
            item.delete(commit)
        super(ActivityDetailBase, self).delete(commit)
class MMSSurfaceBulkSampleActivity(Base):
    __tablename__ = "surface_bulk_sample_activity"
    __table_args__ = {"schema": "mms_now_submissions"}
    id = db.Column(db.Integer, primary_key=True)
    messageid = db.Column(db.Integer, db.ForeignKey('mms_now_submissions.application.messageid'))
    mms_cid = db.Column(db.Integer)
    type = db.Column(db.String)
    disturbedarea = db.Column(db.Numeric(14, 2))
    timbervolume = db.Column(db.Numeric(14, 2))

    def __repr__(self):
        return '<MMSSurfaceBulkSampleActivity %r>' % self.id
Esempio n. 8
0
class SandGrvQryActivity(Base):
    __tablename__ = "sand_grv_qry_activity"
    __table_args__ = {"schema": "now_submissions"}
    id = db.Column(db.Integer, primary_key=True)
    messageid = db.Column(
        db.Integer, db.ForeignKey('now_submissions.application.messageid'))
    type = db.Column(db.String)
    disturbedarea = db.Column(db.Numeric(14, 2))
    timbervolume = db.Column(db.Numeric(14, 2))

    def __repr__(self):
        return '<SandGrvQryActivity %r>' % self.id
class UnderExpSurfaceActivity(Base):
    __tablename__ = "under_exp_surface_activity"
    __table_args__ = {"schema": "now_submissions"}
    id = db.Column(db.Integer, primary_key=True, server_default=FetchedValue())
    messageid = db.Column(db.Integer, db.ForeignKey('now_submissions.application.messageid'))
    type = db.Column(db.String)
    quantity = db.Column(db.Integer)
    disturbedarea = db.Column(db.Numeric(14, 2))
    timbervolume = db.Column(db.Numeric(14, 2))

    def __repr__(self):
        return '<UnderExpSurfaceActivity %r>' % self.id
Esempio n. 10
0
class ExpSurfaceDrillActivity(Base):
    __tablename__ = "exp_surface_drill_activity"
    __table_args__ = {"schema": "now_submissions"}
    id = db.Column(db.Integer, primary_key=True)
    messageid = db.Column(
        db.Integer, db.ForeignKey('now_submissions.application.messageid'))
    type = db.Column(db.String)
    numberofsites = db.Column(db.Integer)
    disturbedarea = db.Column(db.Numeric(14, 2))
    timbervolume = db.Column(db.Numeric(14, 2))

    def __repr__(self):
        return '<ExpSurfaceDrillActivity %r>' % self.id
Esempio n. 11
0
class MMSMechTrenchingActivity(Base):
    __tablename__ = "mech_trenching_activity"
    __table_args__ = {"schema": "mms_now_submissions"}
    id = db.Column(db.Integer, primary_key=True)
    messageid = db.Column(db.Integer, db.ForeignKey('mms_now_submissions.application.messageid'))
    mms_cid = db.Column(db.Integer)
    type = db.Column(db.String)
    numberofsites = db.Column(db.Integer)
    disturbedarea = db.Column(db.Numeric(14, 2))
    timbervolume = db.Column(db.Numeric(14, 2))

    def __repr__(self):
        return '<MMSMechTrenchingActivity %r>' % self.id
class SandGravelQuarryOperation(ActivitySummaryBase):
    __tablename__ = "sand_gravel_quarry_operation"
    __mapper_args__ = {
        'polymorphic_identity': 'sand_gravel_quarry_operation',  ## type code
    }
    activity_summary_id = db.Column(
        db.Integer,
        db.ForeignKey('activity_summary.activity_summary_id'),
        primary_key=True)

    average_overburden_depth = db.Column(db.Numeric(14, 2))
    average_overburden_depth_unit_type_code = db.Column(
        db.String, db.ForeignKey('unit_type.unit_type_code'), nullable=False)
    average_top_soil_depth = db.Column(db.Numeric(14, 2))
    average_top_soil_depth_unit_type_code = db.Column(
        db.String, db.ForeignKey('unit_type.unit_type_code'), nullable=False)
    stability_measures_description = db.Column(db.String)
    is_agricultural_land_reserve = db.Column(db.Boolean)
    agri_lnd_rsrv_permit_application_number = db.Column(db.String)
    has_local_soil_removal_bylaw = db.Column(db.Boolean)
    community_plan = db.Column(db.String)
    land_use_zoning = db.Column(db.String)
    proposed_land_use = db.Column(db.String)
    total_mineable_reserves = db.Column(db.Integer)
    total_mineable_reserves_unit_type_code = db.Column(
        db.String, db.ForeignKey('unit_type.unit_type_code'), nullable=False)
    total_annual_extraction = db.Column(db.Integer)
    total_annual_extraction_unit_type_code = db.Column(
        db.String, db.ForeignKey('unit_type.unit_type_code'), nullable=False)
    average_groundwater_depth = db.Column(db.Numeric(14, 1))
    has_groundwater_from_existing_area = db.Column(db.Boolean)
    has_groundwater_from_test_pits = db.Column(db.Boolean)
    has_groundwater_from_test_wells = db.Column(db.Boolean)
    groundwater_from_other_description = db.Column(db.String)
    groundwater_protection_plan = db.Column(db.String)
    nearest_residence_distance = db.Column(db.Integer)
    nearest_residence_distance_unit_type_code = db.Column(
        db.String, db.ForeignKey('unit_type.unit_type_code'), nullable=False)
    nearest_water_source_distance = db.Column(db.Integer)
    nearest_water_source_distance_unit_type_code = db.Column(
        db.String, db.ForeignKey('unit_type.unit_type_code'), nullable=False)
    noise_impact_plan = db.Column(db.String)
    secure_access_plan = db.Column(db.String)
    dust_impact_plan = db.Column(db.String)
    visual_impact_plan = db.Column(db.String)

    reclamation_backfill_detail = db.Column(db.String)

    details = db.relationship('SandGravelQuarryOperationDetail',
                              secondary='activity_summary_detail_xref',
                              load_on_pending=True)
Esempio n. 13
0
class PlacerActivity(Base):
    __tablename__ = "placer_activity"
    __table_args__ = {"schema": "now_submissions"}
    placeractivityid = db.Column(db.Integer, primary_key=True)
    type = db.Column(db.String)
    quantity = db.Column(db.Integer)
    depth = db.Column(db.Integer)
    length = db.Column(db.Integer)
    width = db.Column(db.Integer)
    disturbedarea = db.Column(db.Numeric(14, 2))
    timbervolume = db.Column(db.Numeric(14, 2))

    def __repr__(self):
        return '<PlacerActivity %r>' % self.placeractivityid
Esempio n. 14
0
class Cliente(db.Model):
    __tablename__ = 'cliente_tb'

    clienteid = db.Column(db.Integer, primary_key=True)
    cpf_cnpj = db.Column(db.Numeric(asdecimal=False, decimal_return_scale=None), unique=True)
    nome = db.Column(db.String)
    email = db.Column(db.String, unique=True)
    logradouro = db.Column(db.String)
    cep = db.Column(db.Numeric(asdecimal=False, decimal_return_scale=None))
    numero = db.Column(db.Numeric(asdecimal=False, decimal_return_scale=None))
    cidade = db.Column(db.String)
    uf  = db.Column(db.String)
    telefone = db.Column(db.Numeric(asdecimal=False, decimal_return_scale=None))

    def __init__(self, nome, cpf_cnpj, email, logradouro, cep, numero, cidade, uf, telefone, clienteid=None):
        self.clienteid = clienteid
        self.cpf_cnpj = cpf_cnpj
        self.nome = nome
        self.email = email
        self.logradouro = logradouro
        self.cep = cep  
        self.numero = numero
        self.cidade = cidade
        self.uf = uf
        self.telefone = telefone

    def __repr__(self):
        return f'<id {self.clienteid}>'
        
    def serialize(self):
        return {
            'clienteid': self.clienteid,
            'nome': self.nome,
            'cpf_cnpj': self.cpf_cnpj,
            'email': self.email,
            'logradouro': self.logradouro,
            'cep': self.cep,
            'numero': self.numero,
            'cidade': self.cidade,
            'uf': self.uf,
            'telefone': self.telefone
        }

    def serialize_min(self):
        return {
            'clienteid': self.clienteid,
            'nome': self.nome,
            'email': self.email,
            'telefone': self.telefone
        }
Esempio n. 15
0
class SettlingPondSubmission(Base):
    __tablename__ = "settling_pond"
    __table_args__ = {"schema": "now_submissions"}
    settlingpondid = db.Column(db.Integer, primary_key=True)
    pondid = db.Column(db.String)
    watersource = db.Column(db.String)
    width = db.Column(db.Integer)
    length = db.Column(db.Integer)
    depth = db.Column(db.Integer)
    constructionmethod = db.Column(db.String)
    disturbedarea = db.Column(db.Numeric(14, 2))
    timbervolume = db.Column(db.Numeric(14, 2))

    def __repr__(self):
        return '<SettlingPondSubmission %r>' % self.settlingpondid
Esempio n. 16
0
class AdminUserQuery(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    admin_user_id = db.Column(db.Integer, nullable=False, index=True)
    sql = db.Column(db.Text)
    status = db.Column(db.String(255))
    rows = db.Column(db.Integer)
    error_message = db.Column(db.Text)
    sql_key = db.Column(db.String(255), nullable=False, index=True)
    run_time = db.Column(db.Numeric(precision=20, scale=6))
    created_at = db.Column(AwareDateTime,
                           default=current_time,
                           nullable=False,
                           index=True)
    updated_at = db.Column(AwareDateTime, onupdate=current_time, index=True)

    def to_dict(self):
        return {
            'id': self.id,
            'sql': self.sql,
            'status': self.status,
            'rows': self.rows,
            'error_message': self.error_message,
            'run_time': self.run_time,
            'created_at': self.created_at,
            'updated_at': self.updated_at
        }

    def query_key(self):
        return hashlib.md5(
            '%s_%s_%s' % (self.id, self.sql_key, self.upadted_at)).hexdigest()
Esempio n. 17
0
class IndicatorValue(db.Model):
    __tablename__ = 'indicatorvalue'

    timestamp = db.Column(db.DateTime(), nullable=False)
    value = db.Column(db.Numeric(), nullable=False)

    indicator_id = db.Column(db.Integer(),
                             db.ForeignKey('indicator.id', ondelete='CASCADE'),
                             nullable=False,
                             index=True)

    __table_args__ = (db.PrimaryKeyConstraint(
        'timestamp',
        'indicator_id',
        name='indicatorvalue_timestamp_indicator_id_pkey'), )

    def as_dict(self):
        return {
            'timestamp': self.timestamp,
            'value': self.value,
            'indicator_id': self.indicator_id
        }

    def update_dict(self):
        return {'value': self.value}

    def __repr__(self):
        return '<SLI value {} | {}: {}>'.format(self.indicator.name,
                                                self.timestamp, self.value)
Esempio n. 18
0
class Bond(Base, AuditMixin):
    __tablename__ = "bond"

    class _ModelSchema(Base._ModelSchema):
        bond_id = fields.Integer(dump_only=True)
        bond_guid = fields.UUID(dump_only=True)
        bond_type_code = FieldTemplate(field=fields.String, one_of='BondType')
        bond_status_code = FieldTemplate(field=fields.String,
                                         one_of='BondStatus')

    bond_id = db.Column(db.Integer,
                        primary_key=True,
                        server_default=FetchedValue())
    bond_guid = db.Column(UUID(as_uuid=True),
                          nullable=False,
                          unique=True,
                          server_default=FetchedValue())
    amount = db.Column(db.Numeric(14, 2), nullable=False)
    bond_type_code = db.Column(db.String,
                               db.ForeignKey('bond_type.bond_type_code'))
    issue_date = db.Column(db.DateTime)
    payer_party_guid = db.Column(UUID(as_uuid=True),
                                 db.ForeignKey('party.party_guid'),
                                 nullable=False)
    bond_status_code = db.Column(db.String,
                                 db.ForeignKey('bond_status.bond_status_code'))
    reference_number = db.Column(db.String)
    institution_name = db.Column(db.String)
    institution_street = db.Column(db.String)
    institution_city = db.Column(db.String)
    institution_province = db.Column(
        db.String, db.ForeignKey('sub_division_code.sub_division_code'))
    institution_postal_code = db.Column(db.String)
    note = db.Column(db.String)
    project_id = db.Column(db.String)

    payer = db.relationship('Party', lazy='joined')
    permit = db.relationship('Permit',
                             uselist=False,
                             lazy='joined',
                             secondary='bond_permit_xref')
    documents = db.relationship('BondDocument', lazy='select')

    def __repr__(self):
        return '<Bond %r>' % self.bond_guid

    def save_bond_history(self):
        bond_json = marshal(self, BOND)
        del bond_json['bond_guid']
        del bond_json['documents']

        bond_json['payer_name'] = bond_json['payer']['party_name']
        current_app.logger.info(bond_json)
        bond_hist = BondHistory._schema().load(bond_json)
        bond_hist.save()
        return bond_hist

    @classmethod
    def find_by_bond_guid(cls, bond_guid):
        return cls.query.filter_by(bond_guid=bond_guid).first()
Esempio n. 19
0
class MMSWaterSourceActivity(Base):
    __tablename__ = "water_source_activity"
    __table_args__ = {"schema": "mms_now_submissions"}
    id = db.Column(db.Integer, primary_key=True)
    messageid = db.Column(
        db.Integer, db.ForeignKey('mms_now_submissions.application.messageid'))
    mms_cid = db.Column(db.Integer)
    type = db.Column(db.String)
    useofwater = db.Column(db.String)
    estimateratewater = db.Column(db.Numeric(14, 2))
    pumpsizeinwater = db.Column(db.Numeric(14, 2))
    locationwaterintake = db.Column(db.String)
    sourcewatersupply = db.Column(db.String)

    def __repr__(self):
        return '<MMSWaterSourceActivity %r>' % self.id
Esempio n. 20
0
class ReclamationInvoice(Base, AuditMixin):
    __tablename__ = "reclamation_invoice"

    class _ModelSchema(Base._ModelSchema):
        reclamation_invoice_id = fields.Integer(dump_only=True)
        reclamation_invoice_guid = fields.String(dump_only=True)

    reclamation_invoice_id = db.Column(db.Integer,
                                       primary_key=True,
                                       server_default=FetchedValue())
    reclamation_invoice_guid = db.Column(UUID(as_uuid=True),
                                         nullable=False,
                                         unique=True,
                                         server_default=FetchedValue())
    permit_id = db.Column(db.Integer, db.ForeignKey('permit.permit_id'))
    project_id = db.Column(db.String, nullable=False)
    amount = db.Column(db.Numeric(14, 2), nullable=False)
    vendor = db.Column(db.String, nullable=False)

    permit = db.relationship('Permit', lazy='joined')
    documents = db.relationship('ReclamationInvoiceDocument', lazy='select')

    def __repr__(self):
        return '<ReclamationInvoice %r>' % self.reclamation_invoice_guid

    @classmethod
    def find_by_reclamation_invoice_guid(cls, reclamation_invoice_guid):
        return cls.query.filter_by(
            reclamation_invoice_guid=reclamation_invoice_guid).first()
Esempio n. 21
0
class UnderExpNewActivity(Base):
    __tablename__ = "under_exp_new_activity"
    __table_args__ = { "schema": "now_submissions" }
    id = db.Column(db.Integer, primary_key=True)
    messageid = db.Column(db.Integer, db.ForeignKey('now_submissions.application.messageid'))
    type = db.Column(db.String)
    incline = db.Column(db.Numeric(14,1))
    inclineunits = db.Column(db.String)
    quantity = db.Column(db.Integer)
    length = db.Column(db.Numeric(14,1))
    width = db.Column(db.Numeric(14,1))
    height = db.Column(db.Numeric(14,1))
    seq_no = db.Column(db.Integer)


    def __repr__(self):
        return '<UnderExpNewActivity %r>' % self.id
Esempio n. 22
0
class WaterSupplyDetail(ActivityDetailBase):
    __tablename__ = 'water_supply_detail'
    __mapper_args__ = {
        'polymorphic_identity': 'water_supply',  ## type code
    }

    activity_detail_id = db.Column(
        db.Integer,
        db.ForeignKey('activity_detail.activity_detail_id'),
        primary_key=True)

    supply_source_description = db.Column(db.String)
    supply_source_type = db.Column(db.String)
    water_use_description = db.Column(db.String)
    estimate_rate = db.Column(db.Numeric(14, 2))
    pump_size = db.Column(db.Numeric(14, 2))
    intake_location = db.Column(db.String)
Esempio n. 23
0
class WaterSupply(ActivitySummaryBase):
    __tablename__ = "water_supply"
    __mapper_args__ = {
        'polymorphic_identity': 'water_supply',  ## type code
    }

    activity_summary_id = db.Column(
        db.Integer,
        db.ForeignKey('activity.activity_summary_id'),
        primary_key=True)

    water_use_description = db.Column(db.String)
    estimate_rate = db.Column(db.Numeric(14, 2))
    pump_size = db.Column(db.Numeric(14, 2))
    intake_location = db.Column(db.String)

    def __repr__(self):
        return '<WaterSupply %r>' % self.activity_summary_id
Esempio n. 24
0
class MineLocation(AuditMixin, Base):
    __tablename__ = "mine_location"
    mine_location_guid = db.Column(UUID(as_uuid=True),
                                   primary_key=True,
                                   server_default=FetchedValue())
    mine_guid = db.Column(UUID(as_uuid=True), db.ForeignKey('mine.mine_guid'))
    latitude = db.Column(db.Numeric(9, 7))
    longitude = db.Column(db.Numeric(11, 7))
    geom = db.Column(Geometry('POINT', 3005))
    effective_date = db.Column(db.DateTime,
                               nullable=False,
                               default=datetime.utcnow)
    expiry_date = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.strptime('9999-12-31',
                                                      '%Y-%m-%d'))

    def __repr__(self):
        return '<MineLocation %r>' % self.mine_guid
Esempio n. 25
0
class ActivitySummaryBase(AuditMixin, Base):
    __tablename__ = "activity_summary"
    _edit_groups = [NOW_APPLICATION_EDIT_GROUP]

    activity_summary_id = db.Column(db.Integer, primary_key=True, server_default=FetchedValue())

    now_application_id = db.Column(db.Integer, db.ForeignKey('now_application.now_application_id'))
    now_application = db.relationship('NOWApplication')

    activity_type_code = db.Column(db.String, db.ForeignKey('activity_type.activity_type_code'))

    reclamation_description = db.Column(db.String)
    reclamation_cost = db.Column(db.Numeric(10, 2))
    total_disturbed_area = db.Column(db.Numeric(14, 2))
    total_disturbed_area_unit_type_code = db.Column(db.String,
                                                    db.ForeignKey('unit_type.unit_type_code'))

    equipment = db.relationship(
        'Equipment', secondary='activity_equipment_xref', load_on_pending=True)

    __mapper_args__ = {'polymorphic_on': activity_type_code}
Esempio n. 26
0
class UnderExpNewActivity(Base):
    __tablename__ = "under_exp_new_activity"
    __table_args__ = {"schema": "now_submissions"}

    class _ModelSchema(Base._ModelSchema):
        id = fields.Integer(dump_only=True)
        inclineunits = fields.String(validate=validate.OneOf(
            choices=unit_type_map.keys()))

    id = db.Column(db.Integer, primary_key=True, server_default=FetchedValue())
    messageid = db.Column(
        db.Integer, db.ForeignKey('now_submissions.application.messageid'))
    type = db.Column(db.String)
    incline = db.Column(db.Numeric(14, 1))
    inclineunits = db.Column(db.String)
    quantity = db.Column(db.Integer)
    length = db.Column(db.Numeric(14, 1))
    width = db.Column(db.Numeric(14, 1))
    height = db.Column(db.Numeric(14, 1))
    seq_no = db.Column(db.Integer)

    def __repr__(self):
        return '<UnderExpNewActivity %r>' % self.id
Esempio n. 27
0
class Package(AbstractModel):
    """Class to represent a sponsorship package."""

    __tablename__ = "packages"
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(64), nullable=False)
    price = db.Column(db.Numeric(6, 2), nullable=False)
    audience = db.Column(db.String(64), nullable=False)
    description = db.Column(db.Text, nullable=True)
    num_purchased = db.Column(db.Integer, default=0, nullable=False)
    available_packages = db.Column(
        db.Integer, nullable=False)  # num packages made avaiable originally
    package_type = db.Column(db.String(64), nullable=False)
    event_id = db.Column(db.Integer,
                         db.ForeignKey("events.id"),
                         nullable=False)
    sponsorships = db.relationship("Sponsorship", back_populates="package")

    def is_sold_out(self):
        """Return True if the package is sold out."""
        return self.num_purchased == self.available_packages

    def num_for_sale(self):
        """Return the number of available packages."""
        return self.available_packages - self.num_purchased

    def was_purchased(self):
        """Return True if the package was purchased by at least one sponsor."""
        return len(self.sponsorships) > 0

    def to_dict(self):
        """Return the attributes of the model as a dictionary."""
        return {
            "id": self.id,
            "name": self.name,
            "price": self.price,
            "audience": self.audience,
            "description": self.description,
            "num_purchased": self.num_purchased,
            "available_packages": self.available_packages,
            "package_type": self.package_type,
            "sponsorships": self.sponsorships
        }

    def __repr__(self):
        """Return the string representation of a Package.
        Used for debugging purposes.
        """
        return "<Package Name: %r>" % self.name
Esempio n. 28
0
class ActivitySummaryBase(AuditMixin, Base):
    __tablename__ = "activity_summary"

    activity_summary_id = db.Column(db.Integer,
                                    primary_key=True,
                                    server_default=FetchedValue())

    now_application_id = db.Column(
        db.Integer, db.ForeignKey('now_application.now_application_id'))
    now_application = db.relationship('NOWApplication')

    activity_type_code = db.Column(
        db.String, db.ForeignKey('activity_type.activity_type_code'))

    reclamation_description = db.Column(db.String)
    reclamation_cost = db.Column(db.Numeric(10, 2))
    total_disturbed_area = db.Column(db.Numeric(14, 2))
    total_disturbed_area_unit_type_code = db.Column(
        db.String, db.ForeignKey('unit_type.unit_type_code'))

    activity_details = db.relationship(
        'ActivityDetailBase', secondary='activity_summary_detail_xref')

    __mapper_args__ = {'polymorphic_on': activity_type_code}
Esempio n. 29
0
class PlacerOperation(ActivitySummaryBase):
    __tablename__ = 'placer_operation'
    __mapper_args__ = {
        'polymorphic_identity': 'placer',  ## type code
    }
    activity_summary_id = db.Column(
        db.Integer, db.ForeignKey('activity_summary.activity_summary_id'), primary_key=True)

    is_underground = db.Column(db.Boolean, nullable=False)
    is_hand_operation = db.Column(db.Boolean, nullable=False)
    reclamation_area = db.Column((db.Numeric(14, 2)))
    reclamation_unit_type_code = db.Column(
        db.String, db.ForeignKey('unit_type.unit_type_code'), nullable=False)

    def __repr__(self):
        return '<PlacerOperation %r>' % self.activity_summary_id
Esempio n. 30
0
class MineralTenureXref(AuditMixin, Base):
    __tablename__ = "mineral_tenure_xref"
    mineral_tenure_xref_guid = db.Column(UUID(as_uuid=True), primary_key=True)
    mine_guid = db.Column(UUID(as_uuid=True), db.ForeignKey('mine.mine_guid'))
    tenure_number_id = db.Column(db.Numeric(10), unique=True)
    effective_date = db.Column(db.DateTime,
                               nullable=False,
                               default=datetime.utcnow)
    expiry_date = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.strptime('9999-12-31',
                                                      '%Y-%m-%d'))

    def __repr__(self):
        return '<MineralTenureXref %r>' % self.tenure_number_id

    def json(self):
        return {'tenure_number_id': str(self.tenure_number_id)}

    @classmethod
    def find_by_tenure(cls, _id):
        return cls.query.filter_by(tenure_number_id=_id).first()

    @classmethod
    def create_mine_tenure(cls,
                           mine,
                           tenure_number_id,
                           user_kwargs,
                           save=True):
        mine_tenure = cls(mineral_tenure_xref_guid=uuid.uuid4(),
                          mine_guid=mine.mine_guid,
                          tenure_number_id=tenure_number_id,
                          **user_kwargs)
        if save:
            mine_tenure.save(commit=False)
        return mine_tenure

    @validates('tenure_number_id')
    def validate_tenure_number_id(self, key, tenure_number_id):
        if len(str(tenure_number_id)) not in [6, 7]:
            raise AssertionError('Tenure number must be 6 or 7 digits long.')
        return tenure_number_id