basic calculations on time, figuring hours clocked
This commit is contained in:
14
database.py
14
database.py
@@ -1,6 +1,6 @@
|
||||
import sqlite3
|
||||
from user_input import *
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
# establish a connection to a .db file and create a cursor object
|
||||
con = sqlite3.connect('data.db')
|
||||
@@ -50,12 +50,14 @@ def get_table_length():
|
||||
table_rows.append(row)
|
||||
return len(table_rows)
|
||||
|
||||
|
||||
def get_stamp_by_date():
|
||||
pass
|
||||
|
||||
def get_weekly_hours():
|
||||
pass
|
||||
current_time = datetime.now()
|
||||
minus_week = current_time - timedelta(days = 7)
|
||||
|
||||
return cur.execute("""
|
||||
SELECT time_in, time_out FROM TIMESTAMPS
|
||||
WHERE time_in>:minus_week
|
||||
""", {"minus_week": minus_week})
|
||||
|
||||
def get_all_hours():
|
||||
pass
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
from time import time
|
||||
|
||||
timestamp1 = "Feb 12 08:02:32 2014"
|
||||
@@ -7,17 +7,21 @@ timestamp2 = "Feb 21 11:52:02 2014"
|
||||
converted1 = datetime.strptime(timestamp1, "%b %d %H:%M:%S %Y")
|
||||
converted2 = datetime.strptime(timestamp2, "%b %d %H:%M:%S %Y")
|
||||
|
||||
# print(converted1)
|
||||
# print(converted2)
|
||||
|
||||
# difference = converted2 - converted1
|
||||
# days_extracted = difference.days
|
||||
|
||||
# print(difference)
|
||||
|
||||
# def days_to_minutes(days):
|
||||
# hours = days * 24
|
||||
# minutes = hours * 60
|
||||
# return minutes
|
||||
|
||||
# print(days_to_minutes(days_extracted))
|
||||
|
||||
|
||||
print(converted1)
|
||||
print(converted2)
|
||||
|
||||
difference = converted2 - converted1
|
||||
days_extracted = difference.days
|
||||
|
||||
print(difference)
|
||||
|
||||
def days_to_minutes(days):
|
||||
hours = days * 24
|
||||
minutes = hours * 60
|
||||
return minutes
|
||||
|
||||
print(days_to_minutes(days_extracted))
|
||||
print(converted1 - timedelta(days=7))
|
||||
|
||||
4
main.py
4
main.py
@@ -1,4 +1,8 @@
|
||||
from user_input import *
|
||||
from database import *
|
||||
|
||||
print("""
|
||||
Welcome to the personal time stamp program.
|
||||
This program is intended to help you keep track of your work hours on personal projects.""")
|
||||
|
||||
parse_input()
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
from database import *
|
||||
from datetime import *
|
||||
|
||||
user_prompt = """
|
||||
Welcome to the personal time stamp program.
|
||||
This program is intended to help you keep track of your work hours on personal projects.
|
||||
# String format for datetime string
|
||||
# "%Y-%m-%d %H:%M:%S.%f"
|
||||
|
||||
user_prompt = """
|
||||
Please choose from the following options:
|
||||
1) Insert a new timestamp
|
||||
1) New time punch
|
||||
2) Select all timestamps (option: limit number of results)
|
||||
3) Find a timestamp by session id
|
||||
4) Calculate total hours for the week
|
||||
5) Calculate complete sum of hours
|
||||
"""
|
||||
|
||||
# Inner functions detailed below:
|
||||
# New time punch:
|
||||
def handle_first_option():
|
||||
in_out = input("Punching in or out? i/o \n")
|
||||
|
||||
@@ -23,8 +23,7 @@ def handle_first_option():
|
||||
print("Please enter the following details:")
|
||||
name = input("Your name: ")
|
||||
purpose = input("Current task: ")
|
||||
|
||||
print("\nPlease confirm your details:")
|
||||
print("Please confirm your details:")
|
||||
confirmation = input(f'{name} clocking in at {time_of_stamp} for {purpose}. Confirm? y/n ')
|
||||
|
||||
if confirmation == 'n':
|
||||
@@ -48,7 +47,7 @@ def handle_first_option():
|
||||
elif in_out == 'o':
|
||||
time_of_stamp = datetime.now()
|
||||
print("Preparing to punch out.")
|
||||
session = input("Please provide your session ID." )
|
||||
session = input("Please provide your session ID: ")
|
||||
punch_out(time_of_stamp, session)
|
||||
print("Punch out successful. Returning...")
|
||||
parse_input()
|
||||
@@ -56,7 +55,7 @@ def handle_first_option():
|
||||
print("Invalid input. Please try again:")
|
||||
handle_first_option()
|
||||
|
||||
|
||||
# Select time stamps:
|
||||
def handle_second_option():
|
||||
limit_results = input("Returning all timestamps. Limit results? y/n \n")
|
||||
if limit_results == 'n':
|
||||
@@ -64,6 +63,17 @@ def handle_second_option():
|
||||
for row in output:
|
||||
print(row)
|
||||
|
||||
another_selection = input("Make another selection? y/n \n")
|
||||
|
||||
if another_selection == 'y':
|
||||
parse_input()
|
||||
elif another_selection == 'n':
|
||||
pass
|
||||
else:
|
||||
print("Make another selection:")
|
||||
parse_input()
|
||||
|
||||
|
||||
elif limit_results == 'y':
|
||||
def find_row_limit():
|
||||
user_limit = input("How many rows? \n")
|
||||
@@ -105,11 +115,51 @@ def handle_second_option():
|
||||
print("Please provide a valid selection.")
|
||||
handle_second_option()
|
||||
|
||||
|
||||
# Find stamp by session id
|
||||
def handle_third_option():
|
||||
stamp = datetime.now()
|
||||
array = test_select_new(stamp, 'mikayla', 'not python')
|
||||
print(array)
|
||||
user_id = input("Provide your session id: ")
|
||||
response = get_created_id(user_id)
|
||||
|
||||
print("Data fetched successfully:")
|
||||
for data in response:
|
||||
print(data)
|
||||
|
||||
new_selection = input("Make another selection? y/n ")
|
||||
if new_selection == 'y':
|
||||
parse_input()
|
||||
elif new_selection == 'n':
|
||||
pass
|
||||
else:
|
||||
print("Invalid input.")
|
||||
parse_input()
|
||||
|
||||
# Calculate weekly hours
|
||||
def handle_fourth_option():
|
||||
print("Find weekly hours.")
|
||||
# target = input("Enter a target user name: ")
|
||||
# print(f'Find weekly hours for {target}')
|
||||
result = get_weekly_hours()
|
||||
|
||||
total_hours = []
|
||||
for data in result:
|
||||
inner_comparison = []
|
||||
for each in data:
|
||||
inner_comparison.append(datetime.strptime(each, "%Y-%m-%d %H:%M:%S.%f"))
|
||||
total_hours.append(inner_comparison[1] - inner_comparison[0])
|
||||
|
||||
print(total_hours)
|
||||
|
||||
hours = 0
|
||||
minutes = 0
|
||||
total = 0
|
||||
for item in total_hours:
|
||||
total += item.seconds + (item.microseconds / 10 ** 6)
|
||||
|
||||
hours = total / (60 * 60)
|
||||
minutes = total / 60
|
||||
print(f'Weekly hours: {round(hours, 3)}')
|
||||
print(f'In minutes: {round(minutes, 3)}')
|
||||
|
||||
|
||||
def __admin__():
|
||||
print("ADMIN PORTAL")
|
||||
@@ -118,6 +168,7 @@ def __admin__():
|
||||
1) Delete all rows from table (table and schema will persist)
|
||||
2) Drop table (database will reinitialize on next render)
|
||||
3) Backup data from SQLite file.
|
||||
4) Populate with hard coded values
|
||||
|
||||
Take care, some actions will permanently delete all data.\n
|
||||
""")
|
||||
@@ -131,6 +182,8 @@ def __admin__():
|
||||
print("Drop table. Confirm?")
|
||||
elif int(admin_prompt) == 3:
|
||||
print("Back up all SQLite data.")
|
||||
elif int(admin_prompt) == 4:
|
||||
print("Populate hard coded data.")
|
||||
else:
|
||||
print("Invalid input.")
|
||||
|
||||
@@ -142,6 +195,7 @@ def parse_input():
|
||||
print(user_prompt)
|
||||
response = input("Enter your selection: ")
|
||||
|
||||
# Error handling
|
||||
try:
|
||||
response = int(response)
|
||||
except ValueError:
|
||||
@@ -151,12 +205,10 @@ def parse_input():
|
||||
print("Please provide a valid input.")
|
||||
parse_input()
|
||||
|
||||
|
||||
|
||||
if type(response) == int:
|
||||
print(f'You selected {response}. Working...')
|
||||
|
||||
|
||||
# Directing to secondary functions
|
||||
if response == 1:
|
||||
handle_first_option()
|
||||
elif response == 2:
|
||||
@@ -164,7 +216,7 @@ def parse_input():
|
||||
elif response == 3:
|
||||
handle_third_option()
|
||||
elif response == 4:
|
||||
pass
|
||||
handle_fourth_option()
|
||||
elif response == 5:
|
||||
pass
|
||||
elif response == 90909:
|
||||
|
||||
Reference in New Issue
Block a user