Question

In: Computer Science

Part 1 The questions in this part of the assignment will be graded. The Hay System...

Part 1

The questions in this part of the assignment will be graded.

The Hay System is a job performance evaluation method that is widely used by organizations around the world. Corporations use the system to map out their job roles in the context of the organizational structure. One of the key benefits of the method is that it allows for setting competitive, value-based pay policies. The main idea is that for each job evaluation, a number of factors (such as Skill, Effort, Responsibility and Working Conditions) are evaluated and scored by using a point system. Then, the cumulative total of points obtained will be correlated with the salary associated with the job position. As a Comp208 student, you have been commissioned to implement a simplified version of the Hay method. Particularly, the hiring company (which is called David and Joseph Ltd) is interested in getting the salary (or hay system score) for several job descriptions currently performed in the company.

Data Representation

Unfortunately, the company David and Joseph Ltd. has very strict security policies. Then, you will not be granted access to the main data base (which is called mycourses). Instead, all the information needed has been compiled in files with the following characteristics.

File 1

  1. The first line of the file contains 1 positive integer: num words≤ 10000, the number of words in the Hay Point dictionary.
  2. num words lines follow; each contains a word (a string of up to 16 lower-case letters) and a dollar value (an integer between 0 and 1000000). You can safely assume that the num words words in the dictionary are distinct. Each description word-value is terminated by a line containing a period.

You can take a look about how File 1 looks below.

7 administer 100000 .

spending 200000 .

manage 50000 .

responsibility 25000 .

expertise 100 .

skill 50 .

money 75000 .

Please note that for this file, num words is equal to 7.

File 2

  1. The first lines of the file contains a varyingly number of comments that must be ignored. You can recognize a comment line because it always start with the # character.
  2. Following the comments there is one job description. A job description consists of between 1 and 200 lines of text; for your convenience the text has been converted to lower case and has no characters other than letters, numbers, and spaces. Each line is at most 200 characters long.

You can take a look about how File 2 looks below.

#Comp208 is an amazing class

# This comment does not make sense

# It is just to make it harder

# The job description starts after this comment, notice that it has 4 lines.

# This job description has 700150 hay system points the incumbent will administer the spending of kindergarden milk money and exercise responsibility for making change he or she will share responsibility for the task of managing the money with the assistant whose skill and expertise shall ensure the successful spending exercise

Below, you can find a second example of how File 2 could look like.

#This example has only one comment

this individual must have the skill to perform a heart transplant and expertise in rocket science

The Hay System

When applying the Hay System to the latest File 2 example (i.e., this individual must have the skill to perform a heart transplant and expertise in rocket science ) on the Hay Point dictionary coded in File 1, the job description gets a total of 150 points (or salary in dollars). This score is obtained because exactly two words (i.e., expertise and skill) of the job description are found in the dictionary. Particularly, expertise and skill have a score of 100 and 50 dollars, respectivelly.

Question 1: create dictionary             (24 points)

Complete the create dictionary function, which reads the information coded in the File 1 and returns a hay points dictionary. See below for an explanation of exactly what is expected.

from typing import Dict, TextIO def create_dictionary(file1: TextIO) -> Dict[str, int]:

’’’Return a dictionary populated with the information coded in file1.

>>> File_1 = open(’File1.txt’)

>>> hay_dict = create_dictionary(File_1)

>>> hay_dict

{’administer’: 100000,

’spending’: 200000,

’manage’: 50000,

’responsibility’: 25000,

’expertise’: 100,

’skill’: 50,

’money’: 75000}

"""

Please note that the variable file1 is of type TextIO, then you can assume that file was already open and it is ready to be read.

Question 2: job description          (24 points)

Complete the job description function, which reads the information coded in the File 2 to return a list of strings with the job description. See below for an explanation of exactly what is expected.

def job_description(file2: TextIO) -> List[str]:

’’’Return a string with the job description information coded in file2.

>>> File_2 = open(’File2_1.txt’)

>>> job_desc = job_description(File_2)

>>> job_desc

[’the’, ’incumbent’, ’will’, ’administer’, ’the’, ’spending’, ’of’, ’kindergarden’, ’milk’,

’money’, ’and’, ’exercise’, ’responsibility’, ’for’, ’making’, ’change’, ’he’, ’or’,

’she’, ’will’, ’share’, ’responsibility’, ’for’, ’the’, ’task’, ’of’, ’managing’,

’the’, ’money’, ’with’, ’the’, ’assistant’, ’whose’, ’skill’, ’and’, ’expertise’,

’shall’, ’ensure’, ’the’, ’successful’, ’spending’, ’exercise’]

’’’

Please note that the variable file2 is of type TextIO, then you can assume that file was already open and it is ready to be read.

Question 3: hay points          (24 points)

Complete the hay points function, which for a job description, output the corresponding salary computed as the sum of the Hay Point values for all words that appear in the description. Words that do not appear in the dictionary have a value of 0. See below for an explanation of exactly what is expected.

def hay_points(hay_dictionary: Dict[str, int], job_description: List[str]) -> int:

’’’Returns the salary computed as the sum of the Hay Point values for all words that appear in job_description based on the points coded in hay_dictionary

>>> File_1 = open(’File1.txt’)

>>> File_2 = open(’File2_1.txt’)

>>> hay_dict = create_dictionary(File_1)

>>> job_desc = job_description(File_2)

>>> points = hay_points(hay_dict, job_desc)

>>> print(points) >>> 700150

’’’

Question 4: my test            (0 points)

The function my test is there to give you a starting point to test your functions. Please note that this function will not be graded, and it is there only to make sure that you understand what every function is expected to do and to test your own code. Note: In order for you to test your functions one at a time, comment out the portions of the my test() function that call functions you have not yet written. The expected output for the function calls is as follows:

The dictionary read from File1.txt is: {’administer’: 100000, ’spending’: 200000, ’manage’:

50000, ’responsibility’: 25000, ’expertise’: 100, ’skill’: 50, ’money’: 75000}

The string read from File2_1.txt is: [’the’, ’incumbent’, ’will’, ’administer’, ’the’,

’spending’, ’of’, ’kindergarden’, ’milk’, ’money’, ’and’, ’exercise’, ’responsibility’,

’for’, ’making’, ’change’, ’he’, ’or’, ’she’, ’will’, ’share’, ’responsibility’, ’for’,

’the’, ’task’, ’of’, ’managing’, ’the’, ’money’, ’with’, ’the’, ’assistant’, ’whose’,

’skill’, ’and’, ’expertise’, ’shall’, ’ensure’, ’the’, ’successful’, ’spending’, ’exercise’]

The salary computed is 700150

Solutions

Expert Solution

PYTHON PROGRAM

The explanation is provided as comments in grey and italic

def create_dictionary(file1):
    words=[]
    wordcount={}
    for word in file1.read().split():
        words.append(word)
    #words[0] contains number of words
    #The pattern is starting from first index,
        #The word followed by amount followed by .
    i=1
    #Traverse the entire list
    while(i<len(words)):
        wordcount[words[i]]=int(words[i+1])
        i=i+3
    file1.close()
    return wordcount
def job_description(file2):
    job=[]
    words=[]
    job_description=[]
    #Read all lines 
    lines=file2.readlines()
    #For every line
    for line in lines:
        if line[0]!="#":
            #Add the line as separate words in one list in job
                words=line.split()
                job.append(words)
    #For every list in job,split as separate words  
    for i in job:
        for j in i:
            job_description.append(j)
    file2.close()
    return job_description
def hay_points(hay_dict,job_desc):
    total_points=0
    #keys hold all the keys in dictionary as a list
    keys=[]
    for i in hay_dict.keys():
        keys.append(i)
    #Read every word in job_desc- if the word is in keys, add its corresponding points
    for i in job_desc:
        for j in keys:
            if i==j:
                total_points+=hay_dict[i]
    return total_points
def mytest():
    file1=open("File1.txt","r")
    hay_dict=create_dictionary(file1)
    print("The dictionary read from file1.txt",hay_dict)
    file_2=open("File2.txt","r")
    job_desc=job_description(file_2)
    print("The string read from file2.txt",job_desc)
    points = hay_points(hay_dict, job_desc)
    print("The salary computed is",points)
mytest()

SCREENSHOT OF CODE TO ASSIST IN INDENTATION

OUTPUT SCREENSHOT

FILE1.TXT

FILE2.TXT

OUTPUT SCREENSHOT


Related Solutions

Graded Homework Assignment 1​​​​​​​Unit 1 – Lessons 1 and 2 1. Athletes’ salaries. Here is a...
Graded Homework Assignment 1​​​​​​​Unit 1 – Lessons 1 and 2 1. Athletes’ salaries. Here is a small part of a data set that describes Major League Baseball players as of opening day of the 2011 season: (a) What individuals does this data set describe? (b) In addition to the player’s name, how many variables does the data set contain? Which of these variables take numerical values? Which of the variables are not numerical variables? (c) What do you think are...
HA 440                  GRADED Assignment # 2               Name _____________________________ Compl
HA 440                  GRADED Assignment # 2               Name _____________________________ Completion Complete each statement.             1.   Expenses are ________________________ costs that have been __________________________ while doing business             2.   Three categories of healthcare expenses are ______________________________, ________________________________ and Operations Expenses             3.   A program can be defined as a __________________________ that has its own objectives             4.   _____________________ costs can be specifically associated with a particular unit, department or patient             5.   A Responsibility Center makes a manager responsible for both the...
Question 5 0/1 point (graded) The following is the full path to a homework assignment file...
Question 5 0/1 point (graded) The following is the full path to a homework assignment file called "assignment.txt": /Users/student/Documents/projects/homeworks/assignment.txt. Which line of code will allow you to move the assignment.txt file from the “homeworks” directory into the parent directory “projects”? mv assignment.txt mv assignment.txt . mv assignment.txt .. mv assignment.txt /projects incorrect Answer Incorrect: Try again. This code does not provide enough information about where to move the file. You need to specify a relative or full path to the...
please answer all questions and not just part: 1. Is the pay system in the british...
please answer all questions and not just part: 1. Is the pay system in the british government equitable? What is the reward system based on? 2. How does an organization achieve internal consistency?
Graded Homework Assignment 4 Unit 3, Lessons 1-3 Lesson 1 - Ethics (a light lesson –...
Graded Homework Assignment 4 Unit 3, Lessons 1-3 Lesson 1 - Ethics (a light lesson – know the definitions and principles!) 1. The most complex issues of data ethics can arise when we collect data from A. A census B. Randomized experiments on people C. Observational studies D. Surveys Stat 1350 - Elementary Statistics 2. Some basic standards of data ethics that must be obeyed by any study that gathers information from human subjects are to: A. Have an institutional...
Module 6 - Assignment - Part 1
Module 6 - Assignment - Part 1  Household Management, Nutrition and Hydration General Directions:  Household Management  A. Individual Take Home Assignment  B. A minimum mark of 14 out of 20 (70%) must be achieved to pass.  C. The assignment will count for 20% of your final mark in Module 6.  In the following situations, describe the most appropriate actions or responses to be taken by the Personal Support Worker and explain why this is correct. Your answer should reflect knowledge...
Write a Python program The Hay System is a job performance evaluation method that is widely...
Write a Python program The Hay System is a job performance evaluation method that is widely used by organizations around the world. Corporations use the system to map out their job roles in the context of the organizational structure. One of the key benefits of the method is that it allows for setting competitive, value-based pay policies. The main idea is that for each job evaluation, a number of factors (such as Skill, Effort, Responsibility and Working Conditions) are evaluated...
Problem 3.4 Part A 1 point possible (graded) An isotropic alloy contains 5% by volume of...
Problem 3.4 Part A 1 point possible (graded) An isotropic alloy contains 5% by volume of a precipitate of radius 10nm. Assume the primary metal is in a simple cubic arrangement. The alloy has a Young's modulus E=70GPa and a Poisson's ratio ν=0.35. If Γ=0.9J/m2 (the energy needed to cut through the precipitate lattice per unit surface area), and b=0.25nm, what is the precipitate spacing L in the alloy? L (in nm):   unanswered Submit You have used 0 of 20...
Stat 1350 - Elementary Statistics Graded Homework Assignment 4​​​​​​​​Unit 3, Lessons 1-3 Lesson 1 - Ethics...
Stat 1350 - Elementary Statistics Graded Homework Assignment 4​​​​​​​​Unit 3, Lessons 1-3 Lesson 1 - Ethics (a light lesson – know the definitions and principles!) 1. The most complex issues of data ethics can arise when we collect data from A. A census B. Randomized experiments on people C. Observational studies D. Surveys 2. Some basic standards of data ethics that must be obeyed by any study that gathers information from human subjects are to: A. Have an institutional board...
For Part 2 of this assignment, you will use the “Assignment 1 – Linear Kinematics Data”...
For Part 2 of this assignment, you will use the “Assignment 1 – Linear Kinematics Data” excel file. In the data set you are provided with vertical position and time data for a person’s vertical center of mass motion for an unspecified movement task. You will utilize excel in all (well, some…) of its glory to calculate the vertical velocity and vertical acceleration data from the position and time data provided in the excel file. Again you will use the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT