def show_summary_period(self): """show the sum of km's ridden and fuel used in date period (from - to)""" left, right = view.enter_period(input, input) if mdl.check_validity_of_date(left) and mdl.check_validity_of_date( right): left = dt.datetime.strptime( left, "%d-%m-%Y").strftime('%Y-%m-%d %H:%M:%S') right = dt.datetime.strptime( right, "%d-%m-%Y").strftime('%Y-%m-%d %H:%M:%S') self.model.cursor.execute( "SELECT SUM(length) FROM {db_name} WHERE date >= ? AND date <= ?" .format(db_name=self.model.db_name), (left, right)) sum_length = self.model.cursor.fetchone()[0] # print(self.model.cursor.fetchone()) self.model.cursor.execute( "SELECT SUM(coef) FROM {db_name} WHERE date >= ? AND date <= ?" .format(db_name=self.model.db_name), (left, right)) sum_coef = self.model.cursor.fetchone()[0] cons = int(sum_length or 0) * int(sum_coef or 0) / 100 print("\nTotal length: " + str(sum_length) + "\nTotal consumption: " + str(sum_coef) + "\nTotal fuel used: " + str(cons)) else: view.invalid_value()
def show_by_period(self): """show length ridden and fuel used by certain period (from - to)""" left, right = view.enter_period(input, input) if check_validity_of_date(left) and \ check_validity_of_date(right): records_period = self.model.find_by_date_range(left, right) show_records(records_period) else: view.invalid_value()
def show_summary_period(self): """show the sum of km's ridden and fuel used in date period (from - to)""" left, right = view.enter_period(input, input) if check_validity_of_date(left) and \ check_validity_of_date(right): records_period = self.model.find_by_date_range(left, right) show_records_summary(records_period) else: view.invalid_value()
def show_by_period(self): """show length ridden and fuel used by certain period (from - to)""" left, right = view.enter_period(input, input) if mdl.check_validity_of_date(left) and mdl.check_validity_of_date( right): table = self.period(dt.datetime.strptime(left, "%d-%m-%Y"), dt.datetime.strptime(right, "%d-%m-%Y")) view.record_names() for t in table: print("\t\t" + str(t[1]) + "\t\t" + str(t[2]) + "\t\t" + str(t[3]) + "\t\t" + str(t[2] * t[3] / 100)) else: view.invalid_value()
def show_by_period(self): """show length ridden and fuel used by certain period (from - to)""" left, right = view.enter_period(input, input) if mdl.check_validity_of_date(left) and mdl.check_validity_of_date( right): left = self._mk_date_usable(left) right = self._mk_date_usable(right) self.cursor.execute( "select * from " + self.tablename + " where date >= %s and date <= %s", (left, right)) table = self.cursor.fetchall() view.record_names() view.print_table_from_sql(table) else: view.invalid_value()
def show_by_date(self, input_func=input): """show length ridden and fuel used by certain date""" date = view.enter_date(input_func) if check_validity_of_date(date): records_daily = self.model.find_by_date(date) show_records(records_daily) else: view.invalid_value()
def show_summary_period(self): """show the sum of km's ridden and fuel used in date period (from - to)""" left, right = view.enter_period(input, input) if mdl.check_validity_of_date(left) and mdl.check_validity_of_date( right): length = self.sum_period_length( dt.datetime.strptime(left, "%d-%m-%Y"), dt.datetime.strptime(right, "%d-%m-%Y"))[0][0] coef = self.sum_period_coef( dt.datetime.strptime(left, "%d-%m-%Y"), dt.datetime.strptime(right, "%d-%m-%Y"))[0][0] cons = int(length or 0) * int(coef or 0) / 100 print("Total length: " + str(length) + "\nTotal consumption: " + str(coef) + "\nTotal fuel used: " + str(cons)) else: view.invalid_value()
def show_by_date(self): """show length ridden and fuel used by certain date""" date = view.enter_date(input) if mdl.check_validity_of_date(date): table = self.date(dt.datetime.strptime(date, "%d-%m-%Y")) view.record_names() for t in table: print("\t\t" + str(t[1]) + "\t\t" + str(t[2]) + "\t\t" + str(t[3]) + "\t\t" + str(t[2] * t[3] / 100)) else: view.invalid_value()
def show_summary_period(self): """show the sum of km's ridden and fuel used in date period (from - to)""" left, right = view.enter_period(input, input) if mdl.check_validity_of_date(left) and mdl.check_validity_of_date( right): left = self._mk_date_usable(left) right = self._mk_date_usable(right) self.cursor.execute( "select sum(length) from " + self.tablename + " where date >= %s and date <= %s", (left, right)) length = self.cursor.fetchall()[0][0] self.cursor.execute( "select sum(fuel_used) from " + self.tablename + " where date >= %s and date <= %s", (left, right)) used = self.cursor.fetchall()[0][0] view.print_summary(length, used) else: view.invalid_value()
def show_by_date(self): """show length ridden and fuel used by certain date""" date = view.enter_date(input) if mdl.check_validity_of_date(date): date = self._mk_date_usable(date) self.cursor.execute( "select * from " + self.tablename + " where date = %s", (date, )) table = self.cursor.fetchall() view.record_names() view.print_table_from_sql(table) else: view.invalid_value()
def show_by_period(self): """show length ridden and fuel used by certain period (from - to)""" left, right = view.enter_period(input, input) if mdl.check_validity_of_date(left) and mdl.check_validity_of_date( right): left = dt.datetime.strptime( left, "%d-%m-%Y").strftime('%Y-%m-%d %H:%M:%S') right = dt.datetime.strptime( right, "%d-%m-%Y").strftime('%Y-%m-%d %H:%M:%S') self.model.cursor.execute( "SELECT * FROM {db_name} WHERE date >= ? AND date <= ?".format( db_name=self.model.db_name), (left, right)) table = self.model.cursor.fetchall() print(table) view.record_names() if len(table) > 0: for t in table: print( str(t[1]) + "\t\t" + str(t[2]) + "\t\t" + str(t[3]) + "\t\t\t\t" + str(t[2] * t[3] / 100)) else: view.invalid_value()
def show_by_date(self, input_func=input): """show length ridden and fuel used by certain date""" date = view.enter_date(input_func) if mdl.check_validity_of_date(date): date = dt.datetime.strptime(date, "%d-%m-%Y").strftime('%Y-%m-%d') print(date) self.model.cursor.execute( "SELECT * FROM {db_name} WHERE date = ?".format( db_name=self.model.db_name), (date, )) records_daily = self.model.cursor.fetchall() view.record_names() if len(records_daily) > 0: for t in records_daily: print( str(t[1]) + "\t\t" + str(t[2]) + "\t\t" + str(t[3]) + "\t\t\t\t" + str(t[2] * t[3] / 100)) else: view.invalid_value()