Guest User

Untitled

a guest
Jan 22nd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. class SimCustomerStat(Base):
  2.  
  3. __tablename__ = 'sim_customer_stat'
  4. id = Column(Integer, primary_key=True)
  5. sim_id = Column(Integer, ForeignKey('simulation.id'))
  6. simulation = relationship('Simulation', back_populates='customer_stats')
  7. customer_id = Column(Integer, ForeignKey('customer.id'))
  8. customer = relationship('Customer', back_populates='sim_stats')
  9. n = Column(Integer, nullable=False, default=0)
  10. stat_type = Column(String, nullable=False)
  11. cust_quals = relationship('SimQualStat', back_populates='customer_stat',
  12. foreign_keys=[SimQualStat.customer_stat_id])
  13.  
  14. @hybrid_property
  15. def ct(self):
  16. return sum([qual.ct*qual.n for qual in self.cust_quals])
  17.  
  18. @ct.expression
  19. def ct(cls):
  20. return select([func.sum(SimQualStat.ct*SimQualStat.n)])
  21. .where(SimQualStat.customer_stat_id == cls.id).label('customer_ct')
  22.  
  23.  
  24. class SimQualStat(Base):
  25.  
  26. __tablename__ = 'sim_qual_stat'
  27. id = Column(Integer, primary_key=True)
  28. sim_id = Column(Integer, ForeignKey('simulation.id'))
  29. simulation = relationship('Simulation', back_populates='qual_stats', foreign_keys=[sim_id])
  30. stat_type = Column(String, nullable=False)
  31. customer_stat_id = Column(Integer, ForeignKey('sim_customer_stat.id'))
  32. customer_stat = relationship('SimCustomerStat', back_populates='cust_quals', foreign_keys=[customer_stat_id])
  33. n = Column(Integer, nullable=False, default=0)
  34. ct = Column(Float, nullable=False, default=0)
Add Comment
Please, Sign In to add comment