Ejemplo n.º 1
0
class Area(Base):
    __tablename__ = "areas"

    id = db.Column(db.Integer(), primary_key=True, autoincrement=True)
    area = db.Column(db.String(25), unique=True, nullable=False)
    h_last_run_at = db.Column(db.DateTime(timezone=True))
    v_last_run_at = db.Column(db.DateTime(timezone=True))
    providers = db.Column(db.JSONB(), nullable=False, server_default="[]")
    # entity_type = db.Column(
    #     db.ChoiceType(EntityType, impl=db.String()), primary_key=True
    # )
    # hole_direction = db.Column(
    #     db.ChoiceType(HoleDirection, impl=db.String()), primary_key=True
    # )

    @classmethod
    def _is_ready(cls, last_run_at: Optional[datetime], cooldown_hours: int):
        if last_run_at:
            utcnow = datetime.now().astimezone(pytz.utc)
            threshold = utcnow - timedelta(hours=cooldown_hours)
            return last_run_at < threshold
        else:
            return True

    @classmethod
    async def next_available(
            cls, hole_dir: HoleDirection) -> Tuple[Area, str, bool, int]:
        """ Get the properties describing the next available execution time of
         the given hole direction and entity type """

        if hole_dir == HoleDirection.H:
            cooldown = conf.PRODSTATS_H_COOLDOWN
        elif hole_dir == HoleDirection.V:
            cooldown = conf.PRODSTATS_V_COOLDOWN
        else:
            cooldown = ONE_WEEK

        attr = f"{hole_dir.value.lower()}_last_run_at"

        area_obj = await cls.query.order_by(  # get stalest area for given hole_dir
            getattr(cls, attr).asc().nullsfirst()).gino.first()

        is_ready = cls._is_ready(getattr(area_obj, attr), cooldown)
        logger.info(
            f"({cls.__name__}[{hole_dir}]) next available: {area_obj.area} {is_ready=}"  # noqa
        )
        return area_obj, attr, is_ready, cooldown

    @classmethod
    async def df(cls) -> pd.DataFrame:
        records = await cls.query.gino.all()
        return pd.DataFrame([x.to_dict() for x in records],
                            columns=cls.c.names).set_index("area")
Ejemplo n.º 2
0
class ProdHeader(Base):
    __tablename__ = "production_header"

    api10 = db.Column(db.String(10), primary_key=True)
    primary_api14 = db.Column(db.String(14), index=True)
    entity12 = db.Column(db.String(12), nullable=False)
    status = db.Column(db.String())
    first_prod_date = db.Column(db.Date())
    last_prod_date = db.Column(db.Date())
    prod_months = db.Column(db.Integer())
    prod_days = db.Column(db.Integer())
    peak_norm_months = db.Column(db.Integer())
    peak_norm_days = db.Column(db.Integer())
    peak30_oil = db.Column(db.Integer())
    peak30_gas = db.Column(db.Integer())
    peak30_date = db.Column(db.Date())
    peak30_month = db.Column(db.Integer())
    perfll = db.Column(db.Integer())
    perf_upper = db.Column(db.Integer())
    perf_lower = db.Column(db.Integer())
    oil_pdp_last3mo_per30kbbl = db.Column(db.Integer())
    boe_pdp_last3mo_per30kbbl = db.Column(db.Integer())
    products = db.Column(db.String())
    provider = db.Column(db.String())
    provider_last_update_at = db.Column(db.DateTime(timezone=True))
    related_well_count = db.Column(db.Integer())
    related_wells = db.Column(db.JSONB(), nullable=False, server_default="[]")
    comments = db.Column(db.JSONB(), nullable=False, server_default="{}")
Ejemplo n.º 3
0
class KnownEntity(Base):
    __tablename__ = "known_entities"

    entity_id = db.Column(db.String(100),
                          primary_key=True)  # ex. 42461409160000
    entity_type = db.Column(db.String(100), primary_key=True)  # ex. api14
    ihs_last_seen_at = db.Column(db.DateTime(timezone=True))
    enverus_last_seen_at = db.Column(db.DateTime(timezone=True))
    fracfocus_last_seen_at = db.Column(db.DateTime(timezone=True))
    ix_known_entities_all = db.Index(  # to avoid heap access
        "ix_known_entities_all",
        "entity_type",
        "entity_id",
        "ihs_last_seen_at",
        "enverus_last_seen_at",
        "fracfocus_last_seen_at",
    )
Ejemplo n.º 4
0
class FracParameters(WellBase):
    __tablename__ = "frac_parameters"

    fluid_bbl = db.Column(db.Integer())
    proppant_lb = db.Column(db.Integer())
    fluid_bbl_ft = db.Column(db.Integer())
    proppant_lb_ft = db.Column(db.Integer())
    lateral_length = db.Column(db.Integer())
    lateral_length_type = db.Column(db.String(25))
    gen = db.Column(db.Integer())
    gen_name = db.Column(db.String(10))
    provider = db.Column(db.String())
    provider_last_update_at = db.Column(db.DateTime(timezone=True))
Ejemplo n.º 5
0
class WellHeader(WellBase):
    __tablename__ = "wells"

    api10 = db.Column(db.String(10), index=True)
    well_name = db.Column(db.String())
    hole_direction = db.Column(db.String(1))
    status = db.Column(db.String(50))
    is_producing = db.Column(db.Boolean(), index=True)
    operator = db.Column(db.String(), index=True)
    operator_alias = db.Column(db.String(), index=True)
    hist_operator = db.Column(db.String(), index=True)
    hist_operator_alias = db.Column(db.String(), index=True)
    tvd = db.Column(db.Integer())
    md = db.Column(db.Integer())
    perfll = db.Column(db.Integer())
    lateral_length = db.Column(db.Integer())
    ground_elev = db.Column(db.Integer())
    kb_elev = db.Column(db.Integer())
    comp_date = db.Column(db.Date())
    spud_date = db.Column(db.Date())
    permit_date = db.Column(db.Date())
    permit_number = db.Column(db.String())
    permit_status = db.Column(db.String())
    rig_release_date = db.Column(db.Date())  # rr_date
    last_activity_date = db.Column(db.Date())
    basin = db.Column(db.String(50), index=True)  # basin
    sub_basin = db.Column(db.String(50), index=True)  # basin
    state = db.Column(db.String(50))  # state_name
    state_code = db.Column(db.String(10))  # state_name
    county = db.Column(db.String(50), index=True)  # county_name
    county_code = db.Column(db.String(10))  # county_name
    provider_status = db.Column(db.String(50))
    provider = db.Column(db.String())
    provider_last_update_at = db.Column(db.DateTime(timezone=True))
    basin_holedir_isprod_idx = db.Index("ix_well_basin_holedir_isprod",
                                        "basin", "hole_direction",
                                        "is_producing")
    basin_status_idx = db.Index("ix_well_basin_status", "basin", "status")