Exemple #1
0
###############################################################
# do not modify the code in here ##############################
from helper.JsonReadWriter import JsonReadWriter
from helper.TableDisplay import TableDisplay
from helper.NavigationDisplay import NavigationDisplay

DATA_PATH_JSON = "data/patients.json"

# load data
jsonRW = JsonReadWriter(DATA_PATH_JSON)
data = jsonRW.load()

DATA_FIELDS = data[0].keys()

# create display instance
tableDisplay = TableDisplay(DATA_FIELDS)
navDisplay = NavigationDisplay()
# do not delete the code in here ##############################
###############################################################
# 1. Open the data file patients.json in the data folder. Observe the keys of each data item
# 2. Create a Patient class, defining a constructor and initialising the instance variables.
# In the constructor, you need to use the EXACT field names as you saw in step 1.
# 3. Observe the functionalities available in the NavigationDisplay class's displaymainMenu method
# 4. Use input to get user action and cast it to integer.
# 5. Use if statements to handle multiple functionalities. For example, if user inputs 1, you should write code
# to handle adding new data.
# 6. To display the table with data, use tableDisplay.display(data)
# 7. To save data to JSON file, use jsonRW.save(data)
# 8. To add new entry to the data variable, append it with the Dictionary form of the Patient class instance
# 9. This is a fairly open-ended coding challenge. Time to put that Creative mind to good use. Happy coding!
# do not delete the code in here ##############################
from helper.CsvReadWriter import CsvReadWriter
from helper.TableDisplay import TableDisplay
from helper.NavigationDisplay import NavigationDisplay

# do not delete the code in here ##############################
DATA_PATH_CSV = "data/contactList.csv"

# load data
csvRW = CsvReadWriter(DATA_PATH_CSV)
data = csvRW.loadAsDictionary()

# create display instance
tableDisplay = TableDisplay(data[0].keys())
navDisplay = NavigationDisplay()
# do not delete the code in here ##############################

def showInvalidOrSuccess(message):
    print(message)
    input("Press any key to continue: ")

while(True):
    tableDisplay.display(data)
    navDisplay.printMainMenu()

    userAction = input("What would you like to do? : ")
    userAction = int(userAction)

    if(userAction == 1):
        tableDisplay.display(data)
Exemple #3
0
# do not delete the code in here ##############################
from helper.JsonReadWriter import JsonReadWriter
from helper.TableDisplay import TableDisplay
from helper.NavigationDisplay import NavigationDisplay

DATA_PATH_JSON = "data/contactList.json"

# load data
jsonRW = JsonReadWriter(DATA_PATH_JSON)
data = jsonRW.load()

# create display instance
tableDisplay = TableDisplay(data[0].keys())
navDisplay = NavigationDisplay()
# do not delete the code in here ##############################


def showInvalidOrSuccess(message):
    print(message)
    input("Press any key to continue: ")


while (True):
    tableDisplay.display(data)
    navDisplay.printMainMenu()

    userAction = input("What would you like to do? : ")
    userAction = int(userAction)

    if (userAction == 1):
        ...
from helper.CsvReadWriter import CsvReadWriter
from helper.NavigationDisplay import NavigationDisplay
from helper.TableDisplay import TableDisplay
from helper.Utility import clearScreen
from InventoryItem import InventoryItem

####################

csvRW = CsvReadWriter("data/inventory.csv")
data = csvRW.loadAsDictionary()

DATA_FIELDS = list(data[0].keys())

navDisplay = NavigationDisplay()
tableDisplay = TableDisplay(DATA_FIELDS)

####################


def showMessage(message):
    print(message)
    input("Press enter to continue: ")


def generateDataID():
    listOfIDs = [int(item["ID"]) for item in data]
    maxId = max(listOfIDs)
    return maxId + 1


def printFields():
import random
import time

###################################
SYMBOLS = ["'", "/", "\\", "?", "."]
DATA_PATH_CSV_QUESTIONS = "data/questions.csv"
DATA_PATH_JSON_SCOREBOARD = "data/scoreBoard.json"

jsonRW = JsonReadWriter(DATA_PATH_JSON_SCOREBOARD)
scoreBoardData = jsonRW.load()

csvRW = CsvReadWriter(DATA_PATH_CSV_QUESTIONS)
questionsData = csvRW.loadAsDictionary()

SCOREBOARD_FIELDS = scoreBoardData[0].keys()
tableDisplay = TableDisplay(SCOREBOARD_FIELDS)

scoreBoardData.sort(key=lambda x: x["score"], reverse=True)
highestScore = scoreBoardData[0]["score"]

navDisplay = NavigationDisplay()
####################################


def showMessage(message):
    print(message)
    input("Press enter to continue: ")


def seedQuestions(data):
    questions = []
Exemple #6
0
questionsData = csvRW.loadAsDictionary()

SCOREBOARD_FIELDS = scoreBoardData[0].keys()

# this is to sort items in a list
# To sort the list in place...
# ut.sort(key=lambda x: x.count, reverse=True)
# # To return a new list, use the sorted() built-in function...
# newlist = sorted(ut, key=lambda x: x.count, reverse=True)
# https://stackoverflow.com/questions/403421/how-to-sort-a-list-of-objects-based-on-an-attribute-of-the-objects

scoreBoardData.sort(key=lambda x: x["score"], reverse=True)
highestScore = scoreBoardData[0]["score"]

# create display instance
tableDisplay = TableDisplay(scoreBoardData[0].keys())
navDisplay = NavigationDisplay()
##############################################

def runCountdown():
    print()
    for i in range(0, 4):
        print(str(4-i) + "...")
        time.sleep(1)

def removeSpaceSymbolsAndLower(ans):
    result = ""
    result = ans.replace(" ", "")

    for char in result:
        if char in SYMBOLS:
# do not delete the code in here ##############################
from helper.CsvReadWriter import CsvReadWriter
from helper.TableDisplay import TableDisplay
from helper.NavigationDisplay import NavigationDisplay

# do not delete the code in here ##############################
DATA_PATH_CSV = "data/contactList.csv"

# load data
...

# create display instance
tableDisplay = TableDisplay(data[0].keys())
navDisplay = NavigationDisplay()
# do not delete the code in here ##############################

def showInvalidOrSuccess(message):
    print(message)
    input("Press any key to continue: ")

while(True):
    ...
        

navDisplay.printExit()