Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class SimCustomerStat(Base):
- __tablename__ = 'sim_customer_stat'
- id = Column(Integer, primary_key=True)
- sim_id = Column(Integer, ForeignKey('simulation.id'))
- simulation = relationship('Simulation', back_populates='customer_stats')
- customer_id = Column(Integer, ForeignKey('customer.id'))
- customer = relationship('Customer', back_populates='sim_stats')
- n = Column(Integer, nullable=False, default=0)
- stat_type = Column(String, nullable=False)
- cust_quals = relationship('SimQualStat', back_populates='customer_stat',
- foreign_keys=[SimQualStat.customer_stat_id])
- @hybrid_property
- def ct(self):
- return sum([qual.ct*qual.n for qual in self.cust_quals])
- @ct.expression
- def ct(cls):
- return select([func.sum(SimQualStat.ct*SimQualStat.n)])
- .where(SimQualStat.customer_stat_id == cls.id).label('customer_ct')
- class SimQualStat(Base):
- __tablename__ = 'sim_qual_stat'
- id = Column(Integer, primary_key=True)
- sim_id = Column(Integer, ForeignKey('simulation.id'))
- simulation = relationship('Simulation', back_populates='qual_stats', foreign_keys=[sim_id])
- stat_type = Column(String, nullable=False)
- customer_stat_id = Column(Integer, ForeignKey('sim_customer_stat.id'))
- customer_stat = relationship('SimCustomerStat', back_populates='cust_quals', foreign_keys=[customer_stat_id])
- n = Column(Integer, nullable=False, default=0)
- ct = Column(Float, nullable=False, default=0)
Add Comment
Please, Sign In to add comment