class Chemical_Use(db.Model): chemuseid = db.Column(db.Integer, primary_key=True) chemicalid = db.Column(db.Integer, db.ForeignKey("chemicals.chemicalid"), nullable=False) used_date = db.Column(db.DateTime, nullable=False) used_qty = db.Column(db.Integer, nullable=False)
class Chemicals(db.Model): chemicalid = db.Column(db.Integer, primary_key=True) chemical_name = db.Column(db.String(50), nullable=False) chemical_brand = db.Column(db.String(50), nullable=False) chemical_unit = db.Column(db.String(10), nullable=False) def __repr__(self): return "Chemical({}, {}, {})".format(chemicalid, chemical_name, chemical_brand)
class ScrapedImage(db.Model): __tablename__ = 'scraped_image' job_id = db.Column(db.Integer, db.ForeignKey("scrape_job.id"), primary_key=True) id = db.Column(db.Integer, primary_key=True) url = db.Column(db.String(2048)) alt = db.Column(db.String(2048)) path = db.Column(db.String) @classmethod def get_by_job_and_img_id(cls, job_id, img_id): return cls.query.filter(cls.job_id == job_id, cls.id==img_id).one_or_none()
class Test(db.Model): # ToDo: Lookup callback to add test_name chemtestid = db.Column(db.Integer, primary_key=True) testtypeid = db.Column(db.Integer, nullable=False) chl_free = db.Column(db.Float(precision=2), nullable=False) ph = db.Column(db.Float(precision=2), nullable=False) alk = db.Column(db.Integer, nullable=False) chl_tot = db.Column(db.Integer) stab = db.Column(db.Integer) hrd = db.Column(db.Integer)
class Service(db.Model): serviceid = db.Column(db.Integer, primary_key=True) service_date = db.Column(db.DateTime, nullable=False) service_code = db.Column(db.String(50), nullable=False) service_desc = db.Column(db.String(250)) company = db.Column(db.String(150)) cost = db.Column(db.Numeric(precision=7, scale=2), nullable=False)
class Chemicals_Purchase(db.Model): chempurchid = db.Column(db.Integer, primary_key=True) chemicalid = db.Column(db.Integer, db.ForeignKey("chemicals.chemicalid"), nullable=False) storeid = db.Column(db.Integer, db.ForeignKey("store.storeid"), nullable=False) purchase_date = db.Column(db.DateTime, nullable=False) purchase_qty = db.Column(db.Integer, nullable=False) purchase_cost = db.Column(db.Numeric(precision=6, scale=2), nullable=False)
class ScrapedText(db.Model): __tablename__ = 'scraped_text' job_id = db.Column(db.Integer, db.ForeignKey("scrape_job.id"), primary_key=True) text = db.Column(db.Text, nullable=True)
class ScrapeJob(db.Model): __tablename__ = 'scrape_job' id = db.Column(db.Integer, primary_key=True) url = db.Column(db.String(2048)) scrape_text = db.Column(db.Boolean, default=True) scrape_images = db.Column(db.Boolean, default=True) is_finished = db.Column(db.Boolean, default=False) timestamp = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow) error = db.Column(db.Text, default=None) scraped_text = db.relationship( "ScrapedText", backref="scrape_job", cascade="all, delete, delete-orphan", uselist=False, ) scraped_images = db.relationship( "ScrapedImage", backref="scrape_job", cascade="all, delete, delete-orphan", lazy='dynamic', order_by="asc(ScrapedImage.id)", ) @classmethod def get_by_id(cls, id): return cls.query.filter(cls.id == id).one_or_none() @classmethod def get_most_recent_match(cls, job): """ This returns the most recent scrape job scheduled for the given URL. It strips off anything afater '#' to limit duplicate requests. :return: ScrapeJob or None if there is none """ url = clean_url(job['url']) scrape_text = job.get('scrape_text', True) scrape_images = job.get('scrape_images', True) query = cls.query.filter(cls.url == url).order_by(cls.id.desc()) if scrape_text: query = query.filter(cls.scrape_text == True) if scrape_images: query = query.filter(cls.scrape_images == True) return query.first() @classmethod def from_dict(cls, dic): job = ScrapeJob(url=clean_url(dic['url'])) if 'scrape_text' in dic: job.scrape_text = dic['scrape_text'] if 'scrape_images' in dic: job.scrape_images = dic['scrape_images'] return job def to_dict(self): dic = { 'id': self.id, 'url': self.url, 'scrape_text': self.scrape_text, 'scrape_images': self.scrape_images, 'is_finished': self.is_finished, } if self.error is not None: dic['error'] = self.error if self.is_finished and self.timestamp is not None: dic['timestamp'] = self.timestamp return dic
class Clean(db.Model): cleanid = db.Column(db.Integer, primary_key=True) clean_date = db.Column(db.DateTime, nullable=False) clean_code = db.Column(db.String(50), nullable=False) clean_desc = db.Column(db.String(250))
class Water(db.Model): wateraddid = db.Column(db.Integer, primary_key=True) add_date = db.Column(db.DateTime, nullable=False) duration = db.Column(db.Integer, nullable=False) qty = db.Column(db.Numeric(precision=5, scale=2), nullable=False) cost = db.Column(db.Numeric(precision=6, scale=2), nullable=False)
class TestType(db.Model): testtypeid = db.Column(db.Integer, primary_key=True) test_name = db.Column(db.String(50), nullable=False) def __repr__(self): return "Test({} - {})".format(self.testtypeid, self.test_name)
class Store(db.Model): storeid = db.Column(db.Integer, primary_key=True) store_name = db.Column(db.String(50), nullable=False)