def generate(self): """Generate the view.""" self.production() plt.clf() self.lactations() plt.clf() for lact in mongo.lacts(self.cow): self.lactation(lact) plt.clf()
def lactations(self): """Plot lactations of ``cow`` together.""" for lact in sorted(mongo.lacts(self.cow)): prods = mongo.prods(self.cow, lact) days = mongo.days(self.cow, lact) plt.plot(days, prods, label="{}".format(lact)) plt.xlabel(self.DAY_LABEL) plt.ylabel(self.PROD_LABEL) plt.legend() with self.doc.create(pylatex.Section('Lactations')): self.add_plot()
def main(): """Complete the crudedata collection with missing dates.""" for cow in mongo.cows(): print("Completing cow {}...".format(cow)) dates = mongo.dates(cow) missing = get_missing_dates(dates) if missing: for lact in reversed(mongo.lacts(cow)): # The last date and day in database for this lactation last_date, last_day = get_last(cow, lact) # We start at the last day of the lactation then add the # missing lines till we reach the first day of the lactation while last_day > 1: last_day -= 1 last_date -= dt.timedelta(1) if last_date in missing: # If day = 1, we'll have a problem of unique key in # the second loop missing.remove(last_date) insert(cow, last_date, lact, last_day) last_date, last_day = get_last(cow, lact) # We start at the last day of the lactation then add the # missing lines till we reach the next lactation or the end of # the data if this lactation is the last one while last_date + dt.timedelta(1) in missing: last_day += 1 last_date += dt.timedelta(1) insert(cow, last_date, lact, last_day)