Created
November 8, 2022 13:59
-
-
Save cdeil/3d8bd71d46a07b23534c5ee21f763ab8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy import JSON | |
from sqlalchemy import Column | |
from sqlalchemy import Enum | |
from sqlalchemy import Float | |
from sqlalchemy import ForeignKey | |
from sqlalchemy import Integer | |
from sqlalchemy import String | |
from sqlalchemy.ext.declarative import declarative_base | |
from sqlalchemy.orm import relationship | |
Base = declarative_base() | |
class Plant(Base): | |
__tablename__ = "plants" | |
I_id = Column(Integer, primary_key=True) | |
name = Column(String, nullable=False, unique=True) | |
latitude = Column(Float, nullable=False) | |
longitude = Column(Float, nullable=False) | |
country = Column(String, nullable=False) | |
state_province = Column(String, nullable=False) | |
city = Column(String, nullable=False) | |
street = Column(String, nullable=True) | |
zip_code = Column(String, nullable=True) | |
description = Column(String, nullable=True) | |
G_account_id = Column(String, nullable=True) | |
G_id = Column(String, nullable=True) | |
class Material(Base): | |
__tablename__ = "materials" | |
I_id = Column(Integer, primary_key=True) | |
general_type = Column( | |
Enum( | |
"portlandcement", | |
"coarseaggregate", | |
"fineaggregate", | |
"water", | |
"flyash", | |
"silicafume", | |
"slag", | |
"admixture", | |
"limestone", | |
"fiber", | |
"naturalpozzolan", | |
"custommaterial", | |
), | |
nullable=False, | |
) | |
name = Column(String, nullable=False, unique=True) | |
revision_name = Column(String, nullable=False) | |
specific_gravity = Column(Float, nullable=False) | |
unit_cost = Column(Float, nullable=False) | |
portlandcement_type = Column( | |
Enum("I", "II", "III", "IV", "V", "GU", "MS", "HE", "MH", "HS"), | |
nullable=True, | |
) | |
admixture_type = Column( | |
Enum( | |
"water_reducer", | |
"high_range_water_reducer", | |
"viscosity_modifier", | |
"rheology_modifier", | |
"accelerator", | |
"shrinkage_reducer", | |
"porosity_inhibitor", | |
"air_entrainer", | |
"retarder", | |
"anti_washout_admixture", | |
"air_detrainer", | |
"corrosion_inhibitor", | |
"hydration_controller", | |
"density_controller", | |
"foaming_agent", | |
"bonding_agent", | |
"strength_enhancer", | |
"workability_retainer", | |
"antifreeze", | |
"waterproofing_admixture", | |
"other", | |
), | |
nullable=True, | |
) | |
fiber_type = Column(Enum("steel", "synthetic", "glass"), nullable=True) | |
naturalpozzolan_type = Column(String, nullable=True) | |
custommaterial_type = Column(String, nullable=True) | |
water_absorption = Column(Float, nullable=True) | |
grade = Column(String, nullable=True) | |
blaine_fineness = Column(Float, nullable=True) | |
standard_cement_strength = Column(JSON, nullable=True) | |
G_id = Column(String, nullable=True) | |
G_revision_group_id = Column(String, nullable=True) | |
G_revision = Column(Integer, nullable=True) | |
plants = relationship(Plant, secondary="material_plants", backref="materials") | |
class MaterialPlant(Base): | |
__tablename__ = "material_plants" | |
I_material_id = Column(Integer, ForeignKey(Material.I_id), primary_key=True) | |
I_plant_id = Column(Integer, ForeignKey(Plant.I_id), primary_key=True) | |
class Mix(Base): | |
__tablename__ = "mixes" | |
I_id = Column(Integer, primary_key=True) | |
name = Column(String, nullable=False, unique=True) | |
revision_name = Column(String, nullable=False) | |
G_id = Column(String, nullable=True) | |
G_revision_group_id = Column(String, nullable=True) | |
G_revision = Column(Integer, nullable=True) | |
plants = relationship(Plant, secondary="mix_plants", backref="mixes") | |
proportions = relationship("MixProportion") | |
class MixPlant(Base): | |
__tablename__ = "mix_plants" | |
I_mix_id = Column(Integer, ForeignKey(Mix.I_id), primary_key=True) | |
I_plant_id = Column(Integer, ForeignKey(Plant.I_id), primary_key=True) | |
class MixProportion(Base): | |
__tablename__ = "mix_proportions" | |
I_mix_id = Column(Integer, ForeignKey(Mix.I_id), primary_key=True) | |
I_material_id = Column(Integer, ForeignKey(Material.I_id), primary_key=True) | |
quantity = Column(Float, nullable=False) | |
materials = relationship(Material, uselist=False) | |
@property | |
def revision_group_id(self): | |
if self.materials is not None: | |
return self.materials.G_revision_group_id | |
return None | |
@property | |
def revision(self): | |
if self.materials is not None: | |
return self.materials.G_revision | |
return None | |
class Ticket(Base): | |
__tablename__ = "tickets" | |
I_id = Column(Integer, primary_key=True) | |
I_plant_id = Column(Integer, ForeignKey(Plant.I_id), nullable=False) | |
I_mix_id = Column(Integer, ForeignKey(Mix.I_id), nullable=False) | |
name = Column(String, nullable=False) | |
country = Column(String, nullable=False) | |
state_province = Column(String, nullable=False) | |
city = Column(String, nullable=False) | |
street = Column(String, nullable=False) | |
sample_geometry = Column( | |
Enum("100*200 mm cylinder", "150*300 mm cylinder", "150*150 mm cube"), nullable=True | |
) | |
load_size = Column(Float, nullable=True) | |
planned_delivery_date = Column(String, nullable=True) | |
batched_date = Column(String, nullable=True) | |
actual_delivery_date = Column(String, nullable=True) | |
pouring_date = Column(String, nullable=True) | |
curing = Column(String, nullable=True) | |
specified_performance = Column(JSON, nullable=True) | |
current_performance = Column(JSON, nullable=True) | |
G_id = Column(String, nullable=True) | |
G_results_perfpreds = Column(JSON, nullable=True) | |
G_results_cementreductions = Column(JSON, nullable=True) | |
G_results_mixopts = Column(JSON, nullable=True) | |
plant = relationship(Plant, uselist=False) | |
mix = relationship(Mix, uselist=False) | |
proportions = relationship("TicketProportion") | |
@property | |
def plant_id(self): | |
if self.plant is not None: | |
return self.plant.G_id | |
return None | |
@property | |
def mix_revision_group_id(self): | |
if self.mix is not None: | |
return self.mix.G_revision_group_id | |
return None | |
@property | |
def mix_revision(self): | |
if self.mix is not None: | |
return self.mix.G_revision | |
return None | |
@property | |
def mix_proportions(self): | |
if self.mix is not None: | |
return self.mix.proportions | |
return None | |
class TicketProportion(Base): | |
__tablename__ = "ticket_proportions" | |
I_ticket_id = Column(Integer, ForeignKey(Ticket.I_id), primary_key=True) | |
I_material_id = Column(Integer, ForeignKey(Material.I_id), primary_key=True) | |
specified_quantity = Column(Float, nullable=True) | |
delivered_quantity = Column(Float, nullable=True) | |
materials = relationship(Material, uselist=False) | |
@property | |
def revision_group_id(self): | |
if self.materials is not None: | |
return self.materials.G_revision_group_id | |
return None | |
@property | |
def revision(self): | |
if self.materials is not None: | |
return self.materials.G_revision | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment