Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f376132
Adding lesson1_assignments for student visokoo
visokoo Jan 17, 2019
681724b
fixing new line
visokoo Jan 17, 2019
bb63986
fixing indentation
visokoo Jan 17, 2019
42558c7
adding initial python pushups from warmup2
visokoo Jan 17, 2019
7da1242
adding grid_printer.py
visokoo Jan 19, 2019
23a86c9
adding completed series.py
visokoo Jan 20, 2019
2997b46
add fizz_buzz.py
visokoo Jan 20, 2019
3669e83
mixed up numbers, corrected to 3 and 5
visokoo Jan 21, 2019
0bb4919
adding comments for grid_printer.py and adding in slicing.py for lesson3
visokoo Jan 24, 2019
b29228f
adding strformat_lab.py to lesson3 folder
visokoo Jan 25, 2019
a6bb80f
adding list_lab.py to lesson3_assignments
visokoo Jan 26, 2019
f085810
adding mailroom-p1.py
visokoo Jan 27, 2019
1925d10
Fixing typo for lesson1 folder
visokoo Jan 31, 2019
5900ba6
adding mailroom-p2.py for lesson4
visokoo Feb 3, 2019
3d03e13
adding dict_lab.py to lesson4_assignments
visokoo Feb 3, 2019
189ccd5
Adding trigrams.py to lesson4_assignments
visokoo Feb 3, 2019
746e874
add if __name__ == main block
Feb 5, 2019
75c0abe
adding files for exceptions exercise for lesson5_assignments
visokoo Feb 7, 2019
16170bc
adding mailroom-p3.py to lesson5_assignments
visokoo Feb 11, 2019
2986143
adding unit tests for mailroom
visokoo Feb 16, 2019
285efc0
removed some unnecessary code and refactored a function for comprehen…
Feb 17, 2019
6a060e5
initial commit for lesson7
visokoo Feb 25, 2019
1e2c75e
final touches
visokoo Feb 25, 2019
d50a850
fix tests
visokoo Feb 25, 2019
4b7ca3c
fixing indent tests
visokoo Feb 28, 2019
1acb0e6
base DBProcessor class
visokoo Mar 1, 2019
a846c5b
Added execute_sql() def and removed some unnecessary code
visokoo Mar 3, 2019
56547f1
adding other classes
visokoo Mar 3, 2019
e260593
moving class code into libs/ and created main.py for testing code
visokoo Mar 12, 2019
e225bdd
combining all dbprocessor subclasses to one file
visokoo Mar 12, 2019
3fb7113
Functionality Complete
visokoo Mar 17, 2019
ea7bdfb
adding error handling and tests
visokoo Mar 17, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions students/visokoo/00-README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
### About Me

### Intro
I started out in the tech world as a Helpdesk Specialist and was given
the opportunity move into the DevOps space about 2 years ago. It was a
rollercoaster ride going from full Windows to Linux but I loved every
moment of it.

I've done some basic coding with ruby for some day to day tasks but I'm
really hoping to be able to do more with python like writing full-fledged
web apps or just something better than your standard script.

In my freetime I generally enjoy:

- Playing boardgames...
- Playing console/PC games...
- Thinking about solutions for work...
- Eating too much...
- Outdoor activities such as hiking, snowboarding, etc.

### Goal

I've done some basic coding with ruby for some day to day tasks but I'm
really hoping to be able to do more with python like writing full-fledged
web apps/cli tools or just something better than your standard sc
1 change: 1 addition & 0 deletions students/visokoo/Final/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.db
136 changes: 136 additions & 0 deletions students/visokoo/Final/DBProcessor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
"""
DB Processor Base class
"""

import sqlite3


class DBProcessor(object):
table_name = ""
columns = {}

def __init__(self, db_con, db_name=":memory:"):
self.__db_name = db_name
self.__db_con = self.create_db(self.db_name)

@property
def db_name(self):
return self.__db_name

@property
def db_con(self):
return self.__db_con

def create_db(self, db_name):
conn = sqlite3.connect(db_name)
return conn

def execute_sql(self, statement):
db_con = self.db_con
try:
with db_con:
conn = db_con.cursor()
conn.execute(statement)
except Exception as e:
raise Exception(e)
return conn

def create_table(self):
table_name = self.table_name
columns = self.columns
col_collection = ""
p_key = ""
if columns is None:
raise Exception("Must provide at least one column.")
for column, field_def in columns.items():
if column == "Primary Key":
p_key = f", {column}({field_def})"
else:
col_collection += f"{column} {field_def}, "
sql_str = f"create table {table_name.capitalize()}({col_collection[:-2]}{p_key});"
return sql_str

@staticmethod
def create_select_statement(table_name, columns=[], filters={}):
statement = ""
col_collection = ""
filter_statement = ""
if columns is None:
raise Exception("Must provide at least one column.")
for column in columns:
col_collection += f"{column}, "
col_collection = col_collection[:-2]
if filters != {}:
for f, v in filters.items():
filter_statement += f"{f}='{v}'"
statement = f"select {col_collection} from {table_name} where {filter_statement};"
else:
statement = f"select {col_collection} from {table_name};"
return statement

def create_insert_statement(self, table_name, columns={}):
table_name = self.table_name
statement = ""
col_collection = ""
val_collection = ""
if columns is None:
raise Exception("Must provide at least one column.")
for column, value in columns.items():
col_collection += f"{column}, "
val_collection += f"'{value}', "
col_collection = col_collection[:-2]
val_collection = val_collection[:-2]
statement = f"insert into {table_name} ({col_collection}) values ({val_collection});"
return statement

def create_delete_statement(self, table_name, filters={}):
statement = ""
filter_statement = ""
if filters is None:
raise Exception("You must provide a filter condition statement.")
for f, v in filters.items():
filter_statement += f"{f}='{v}'"
statement = f"delete from {table_name} where {filter_statement};"
return statement

def create_update_statement(self, table_name, columns={}, filters={}):
statement = ""
col_collection = ""
filter_statement = ""
if columns is None:
raise Exception("Must provide at least one column.")
for column, value in columns.items():
col_collection += f"{column} = '{value}', "
col_collection = col_collection[:-2]
if filters is None:
raise Exception("You must provide a filter condition statement.")
for f, v in filters.items():
filter_statement += f"{f}='{v}'"
statement = f"update {table_name} set {col_collection} where {filter_statement};"
return statement


class InventoryCountProcessor(DBProcessor):
table_name = "inventorycounts"
columns = {
"InventoryID": "int not null",
"ProductID": "int not null",
"InventoryCount": "int not null",
"Primary Key": "InventoryID, ProductID"
}


class ProductProcessor(DBProcessor):
table_name = "products"
columns = {
"ProductID": "primary key not null",
"ProductName": "varchar(100) not null"
}


class InventoryProcessor(DBProcessor):
table_name = "inventories"
columns = {
"InventoryID": "primary key not null",
"InventoryDate": "date not null"
}
73 changes: 73 additions & 0 deletions students/visokoo/Final/Inventory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
"""
Inventory class
"""
from datetime import datetime
from InventoryCount import InventoryCount
from Product import Product


class Inventory(object):
def __init__(
self,
inventory_id: int,
inventory_date: datetime.date,
inventory_count: InventoryCount = [None],
):
self.__inventory_id = inventory_id
if inventory_date != datetime.strptime(
inventory_date, '%Y-%m-%d').strftime('%Y-%m-%d'):
raise ValueError("Not a proper date! E.g. '2020-01-01'")
else:
self.__inventory_date = inventory_date
if inventory_count is not [None]:
self.__inventory_count = inventory_count

@property
def inventory_date(self):
return self.__inventory_date

@inventory_date.setter
def inventory_date(self, inventory_date):
if inventory_date != datetime.strptime(
inventory_date, '%Y-%m-%d').strftime('%Y-%m-%d'):
raise TypeError("Not a proper date! E.g. '2020-01-01'")
else:
self.__inventory_date = inventory_date

@property
def inventory_id(self):
return self.__inventory_id

@property
def inventory_count(self):
return self.__inventory_count

def __str__(self):
return f"Inventory ID: {self.__inventory_id} | Inventory Date: {self.__inventory_date} | Inventory Count [{self.__inventory_count}]"

def __dict__(self):
return {
"Inventory ID": self.__inventory_id,
"Inventory Date": self.__inventory_date,
"Product Name": self.__inventory_count.product.product_name,
"Product ID": self.__inventory_count.product.product_id,
"Inventory Count": self.__inventory_count.product_inventory_count
}

def __repr__(self):
return f"Inventory:[{self.__dict__()}]"


if __name__ == '__main__':
p1 = Product(1, "Mouse")
p2 = Product(2, "Keyboard")
p3 = Product(3, "Laptop")
ic1 = InventoryCount(p1, 2)
ic2 = InventoryCount(p2, 3)
ic3 = InventoryCount(p3, 5)
i1 = Inventory(1, "2020-01-02", ic1)
i2 = Inventory(2, "2018-12-31", ic2)
i3 = Inventory(3, "2017-06-22", ic3)
print(i1)
print(i2)
print(i3)
52 changes: 52 additions & 0 deletions students/visokoo/Final/InventoryCount.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""
InventoryCount class
"""

from Product import Product


class InventoryCount(object):
def __init__(self, product: Product, product_inventory_count: int):
self.__product = product
self.__product_inventory_count = product_inventory_count

@property
def product(self):
return self.__product

@product.setter
def product(self, product: str):
self.__product = self.__product.strip()

@property
def product_inventory_count(self):
return self.__product_inventory_count

@product_inventory_count.setter
def product_inventory_count(self, product_inventory_count: int):
if type(product_inventory_count) is not int:
raise Exception("Product Inventory count must be an int.")
else:
self.__product_inventory_count = product_inventory_count

def __str__(self):
return f"Product [{self.__product}] | Inventory Count: {self.__product_inventory_count}"

def __dict__(self):
return {
"Product ID": self.__product.product_id,
"Product Name": self.__product.product_name,
"Inventory Count": self.__product_inventory_count
}

def __repr__(self):
return f"Inventory Count:[{self.__dict__()}]"


if __name__ == '__main__':
p1 = Product(1, "Mouse")
p2 = Product(2, "Keyboard")
i1 = InventoryCount(p1, 2)
i2 = InventoryCount(p2, 40)
print(i1)
print(i2)
48 changes: 48 additions & 0 deletions students/visokoo/Final/Product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""
Product class
"""


class Product(object):
def __init__(self, product_id: int, product_name: str):
self.__product_id = product_id
self.__product_name = product_name

@property
def product_id(self):
return self.__product_id

@product_id.setter
def product_id(self, product_id: int):
if type(product_id) is not int: raise TypeError("Requires integer!")
if product_id <= 0:
raise ValueError("Requires value greater than zero!")
else:
self.__product_id = product_id

@property
def product_name(self):
return self.__product_name

@product_name.setter
def product_name(self, product_name: str):
self.__product_name = product_name.strip()

def __str__(self):
return f"Product ID: {self.__product_id} | Product Name: {self.__product_name}"

def __dict__(self):
return {
"Product ID": self.__product_id,
"Product Name": self.__product_name
}

def __repr__(self):
return f"Product:[{self.__dict__()}]"


if __name__ == '__main__':
p1 = Product(100, "Mouse")
p2 = Product(200, "Keyboard")
print(p1)
print(p2)
Loading