Question
Modify the vending status checker to now also report on the status of the machines overall. Be sure to click the vending status checker link
Modify the vending status checker to now also report on the status of the machines overall. Be sure to click the "vending status checker" link above and save the .json files for use in the assignment. Our current vending status checker produces an inventory report. For each machine's inventory file it is counting how many of each beverage were stocked last time, how many of that beverage are currently in stock, and how many slots the beverage occupies (i.e., each slot holds 8 beverages). Your goal is to modify the program such that it can also produce a machines' sales report, something like this: Label Pct Sold Sales Total REID_1F 52.40% $ 230.25 REID_2F 42.02% $ 138.25 REID_3F 52.07% $ 214.75 This report contains three fields: the label of the vending machine, what percentages of the beverages it was last stocked with are sold, and how many total dollars of sales has this generated. You will need to create a new dictionary where the keys are the vending machine labels, and the values are a new type of object called a `MachineStatus`. For each instance, the `MachineStatus` class should store: the label of a vending machine the total amount of beverages the vending machine was previously stocked with the total amount of beverages currently in stock in the vending machine the total income of the machine from the last time it was stocked until now (note: beverages have different prices, so you cannot simply multiply the change in stock times $1.50 to get the total income) Three major modifciations to `vending_status_checker.py` are necessary: adding the `MachineStatus` class adding to the loop for counting beverages additional code for counting and updating a vending machine's `MachineStatus` object values enabling a user to choose the machines' sales report, not just the inventory report, and then display the report as shown in the following example Would you like the (m)achine report or the (i)nventory report? m Label Pct Sold Sales Total REID_1F 52.40% $ 230.25 REID_2F 42.02% $ 138.25 REID_3F 52.07% $ 214.75 HINT: Start by making sure you understand how the counting is done for inventory, most importantly how the dictionary is used to go from the name a beverage to its `InventoryItem` object. Then create a new dictionary with vending machine labels as keys that maps to the vending machine's `MachineStatus` object. There should be only one `MachineStatus` object for each vending machine.
Current Version:
import json
class InventoryItem: def __init__( self, itemName ): self.name = itemName self.totalStocked = 0 self.totalInStock = 0 self.totalSlots = 0 def addToStocked( self, stockAmt ): self.totalStocked = self.totalStocked + stockAmt def addToInStock( self, inStockAmt ): self.totalInStock = self.totalInStock + inStockAmt def incrementSlots( self ): self.totalSlots = self.totalSlots + 1
def getNumberSold( self ): return self.totalStocked - self.totalInStock def getSoldPct( self ): return self.getNumberSold() / self.totalStocked def getStockNeed( self ): return 8 * self.totalSlots - self.totalInStock def getName( self ): return self.name
def getNumberInStock( self ): return self.totalInStock
def __repr__( self ): return '{} In Stock: {}, Stocked: {}, Slots: {}'.format( self.name, self.totalInStock, self.totalStocked, self.totalSlots )
def main(): inventoryFileNames = ["REID_1F_20171004.json", "REID_2F_20171004.json", "REID_3F_20171004.json"] itemNameToInventoryItem = {} for inventoryFileName in inventoryFileNames: inventoryFile = open( inventoryFileName, 'r' ) inventoryData = json.loads( inventoryFile.read() ) contents = inventoryData['contents'] for row in contents: for slot in row['slots']: itemName = slot['item_name'] inventoryItem = itemNameToInventoryItem.get( itemName, InventoryItem( itemName ) ) inventoryItem.addToStocked( slot['last_stock'] ) inventoryItem.addToInStock( slot['current_stock'] ) inventoryItem.incrementSlots(); itemNameToInventoryItem[itemName] = inventoryItem cokeItem = itemNameToInventoryItem['Coke']
sortChoice = '' inventoryItemsList = list( itemNameToInventoryItem.values() ) while sortChoice != 'q': sortChoice = input('Sort by (n)ame, (p)ct sold, (s)tocking need, or (q) to quit: ') if sortChoice == 'n': inventoryItemsList.sort( key=InventoryItem.getName ) elif sortChoice == 'p': inventoryItemsList.sort( key=InventoryItem.getSoldPct ) inventoryItemsList.reverse() elif sortChoice == 's': inventoryItemsList.sort( key=InventoryItem.getStockNeed ) inventoryItemsList.reverse() print( 'Item Name Sold % Sold In Stock Stock needs') for item in inventoryItemsList: print( '{:20} {:8} {:8.2f}% {:8} {:8}'.format( item.getName(), item.getNumberSold(), item.getSoldPct() * 100, item.getNumberInStock(), item.getStockNeed())) print() main()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started