コード例 #1
0
def show_by_period(records):
    left, right = view.enter_period()
    if check_validity_of_date(left) and check_validity_of_date(right):
        records_period = find_by_date_range(records, left, right)
        show_all(records_period)
    else:
        view.invalid_value()
コード例 #2
0
def show_by_date(records):
    date = view.enter_date()
    if check_validity_of_date(date):
        records_daily = find_by_date(records, date)
        show_all(records_daily)
    else:
        view.invalid_value()
コード例 #3
0
    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()
コード例 #4
0
 def add_record(self):
     """add new record to the database"""
     item_list = view.enter_trip_details(input, input, input)
     if mdl.check_validity(item_list):
         self.insert(dt.datetime.strptime(item_list[0], "%d-%m-%Y"),
                     item_list[1], item_list[2])
     else:
         view.invalid_value()
コード例 #5
0
def add_record(records):
    item_list = view.enter_trip_details()
    if check_validity_of_date(item_list[0]) and \
            check_validity_of_length(item_list[1]) and check_validity_of_coefficient(item_list[2]):
        record = Record(item_list[0], item_list[1], item_list[2])
        records.append(record)
    else:
        view.invalid_value()
コード例 #6
0
 def add_record(self):
     """add new record to the database"""
     item_list = view.enter_trip_details(input, input, input)
     if mdl.check_validity(item_list):
         self.model.records.append(
             Record(item_list[0], item_list[1], item_list[2]))
     else:
         view.invalid_value()
コード例 #7
0
 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()
コード例 #8
0
    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()
コード例 #9
0
 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()
コード例 #10
0
 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()
コード例 #11
0
 def add_record(self):
     """add new record to the database"""
     item_list = view.enter_trip_details(input, input, input)
     if mdl.check_validity(item_list):
         date = dt.datetime.strptime(item_list[0],
                                     "%d-%m-%Y").strftime('%Y-%m-%d')
         self.model.cursor.execute(
             'INSERT INTO {} (date, length, coef) VALUES (?, ?, ?)'.format(
                 self.model.db_name), (date, item_list[1], item_list[2]))
         self.model.conn.commit()
     else:
         view.invalid_value()
コード例 #12
0
 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()
コード例 #13
0
    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()
コード例 #14
0
    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()
コード例 #15
0
 def add_record(self):
     """add new record to the database"""
     item_list = view.enter_trip_details(input, input, input)
     if mdl.check_validity(item_list):
         self.cursor.execute(
             "insert into " + self.tablename +
             " (date, length, coef, fuel_used) values (%s, %s, %s, %s)", [
                 dt.datetime.strptime(
                     item_list[0],
                     "%d-%m-%Y").strftime('%Y-%m-%d %H:%M:%S'),
                 item_list[1], item_list[2],
                 item_list[1] * item_list[2] / 100
             ])
         self.dbcon.commit()
     else:
         view.invalid_value()
コード例 #16
0
    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()
コード例 #17
0
    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()
コード例 #18
0
    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()
コード例 #19
0
    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()