models.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. """Database models"""
  2. from sqlalchemy import Column, ForeignKey, Integer, String, \
  3. DateTime, BigInteger, SmallInteger, Date, Boolean
  4. from sqlalchemy.orm import relationship, backref
  5. from sqlalchemy.ext.declarative import declarative_base
  6. Base = declarative_base()
  7. class State(Base):
  8. """Model for state"""
  9. __tablename__ = 'state'
  10. id = Column(Integer, primary_key=True)
  11. name = Column(String)
  12. class Region(Base):
  13. """Model for region"""
  14. __tablename__ = 'region'
  15. id = Column(Integer, primary_key=True)
  16. name = Column(String)
  17. class Player(Base):
  18. """Model for player"""
  19. __tablename__ = 'player'
  20. id = Column(BigInteger, primary_key=True)
  21. name = Column(String)
  22. nation = Column(String)
  23. registration_date = Column(Date)
  24. class MarketTrack(Base):
  25. """Model for market track"""
  26. __tablename__ = 'market_track'
  27. id = Column(Integer, primary_key=True)
  28. date_time = Column(DateTime)
  29. player_resources = Column(Boolean, server_default='f', default=False)
  30. state_resources = Column(Boolean, server_default='f', default=False)
  31. items = Column(Boolean, server_default='f', default=False)
  32. class PlayerMarketStat(Base):
  33. """Model for market stat"""
  34. __tablename__ = 'player_market_stat'
  35. id = Column(Integer, primary_key=True)
  36. item_type = Column(SmallInteger)
  37. price = Column(Integer)
  38. amount = Column(BigInteger)
  39. base_average = Column(BigInteger)
  40. one_average = Column(Integer)
  41. two_average = Column(Integer)
  42. three_average = Column(Integer)
  43. four_average = Column(Integer)
  44. five_average = Column(Integer)
  45. six_average = Column(Integer)
  46. seven_average = Column(Integer)
  47. eight_average = Column(Integer)
  48. nine_average = Column(Integer)
  49. ten_average = Column(Integer)
  50. total_offers = Column(Integer)
  51. player_id = Column(BigInteger, ForeignKey('player.id'))
  52. player = relationship(
  53. 'Player',
  54. backref=backref('player_market_stats', lazy='dynamic')
  55. )
  56. market_track_id = Column(Integer, ForeignKey('market_track.id'))
  57. market_track = relationship(
  58. 'MarketTrack',
  59. backref=backref('player_market_stats', lazy='dynamic')
  60. )
  61. class StateMarketStat(Base):
  62. """Model for market stat"""
  63. __tablename__ = 'state_market_stat'
  64. id = Column(Integer, primary_key=True)
  65. item_type = Column(SmallInteger)
  66. price = Column(Integer)
  67. amount = Column(BigInteger)
  68. region_id = Column(Integer, ForeignKey('region.id'))
  69. region = relationship(
  70. 'Region',
  71. backref=backref('region_market_stats', lazy='dynamic')
  72. )
  73. market_track_id = Column(Integer, ForeignKey('market_track.id'))
  74. market_track = relationship(
  75. 'MarketTrack',
  76. backref=backref('state_market_stats', lazy='dynamic')
  77. )