######################## Simulation Code Writing ############################
from tkinter import *
import random
import math

def makeModel(data): 
    data["cx"] = 200 
    data["cy"] = 200 
    data["size"] = 50 
    data["color"] = "red"

def makeView(data, canvas): 
    color = data["color"]
    canvas.create_oval(data["cx"] - data["size"], data["cy"] - data["size"], data["cx"] + data["size"], data["cy"] + data["size"], fill=color)

#FILL THIS OUT
def runRules(data,call):
    pass


######################## Working with Data ##################################

import csv 

def readCSVFile(path):
    pass

"""
Write a function to create a dictionary from the input 2D list, 
where the department_name for each inner list is the key and the value 
is a 2 element list of the corresponding location_id and department_expenses
for that inner list.
Note that department_name is at index 1 of each row of data, 
location_id is at index 2, and department expenses is at index 3
"""

def departmentNameDict(data):
    pass

"""
Write a function that given a dictionary like the one created above and a list
of departments, finds the mean expenses across the given departments and the 
most common location among the departments (hint: you can use mode on 
non-numerical data) and prints them to the user.
You may want to import a package to help you with this function!
"""

def departmentInfo(d, departments):
    pass


# Write a line of code below to call readCSVFile and store the result in 
# a variable called data! Then uncomment the following lines of code to run the test cases!


'''
departmentDictionary = departmentNameDict(data[1:])
departments1 = ["Purchasing", "Recruiting", "Payroll", "Marketing", "IT", "Construction"]
departments2 = ["Control And Credit", "Government Sales", "Shareholder Services", "Executive", "NOC"]
departmentInfo(departmentDictionary, departments1)
departmentInfo(departmentDictionary, departments2)
'''

########################### DO NOT ALTER: SIMULATION FRAMEWORK CODE ##########################

def timeLoop(data, canvas, call):
    runRules(data, call)
    canvas.delete(ALL)
    makeView(data, canvas)
    canvas.update()
    canvas.after(data["timeRate"], timeLoop, data, canvas, call + 1)

    
def runSimulation(w, h, timeRate):
    data = { }
    data["timeRate"] = int(timeRate * 1000) # call will be in ms
    makeModel(data)
    
    root = Tk()
    canvas = Canvas(root, width=w, height=h)
    canvas.configure(bd=0, highlightthickness=0)
    canvas.pack()
    makeView(data, canvas)
    
    canvas.after(data["timeRate"], timeLoop, data, canvas, 1)
    
    root.mainloop()


runSimulation(500,500, 0.3)