├── Pre -Assesment ├── data │ ├── ASDE Assignment - Departments.csv │ ├── ASDE Assignment - Employees.csv │ └── ASDE Assignment - Salaries.csv ├── Output_Report.docx ├── ASDE Interview Assignments.docx ├── task1.sql ├── task3.py └── task2.py ├── README.md └── Interview Assignment ├── Fitness Assignment ├── Problem Statement.docx ├── company_data.json └── FitnessAssesment.py.py ├── sqlTask.sql └── Convert.java /Pre -Assesment/data/ASDE Assignment - Departments.csv: -------------------------------------------------------------------------------- 1 | ID,NAME 2 | 1,HR 3 | 2,Finance 4 | 3,IT 5 | 4,Ops 6 | 5,Sales -------------------------------------------------------------------------------- /Pre -Assesment/Output_Report.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arjundhav/Onlinesales.ai-Assesments/main/Pre -Assesment/Output_Report.docx -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Onlinesales.ai - Assesments 2 | Repository contains the tasks I was assigned by OnlineSales.ai for assesment of my technical skills. 3 | -------------------------------------------------------------------------------- /Pre -Assesment/ASDE Interview Assignments.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arjundhav/Onlinesales.ai-Assesments/main/Pre -Assesment/ASDE Interview Assignments.docx -------------------------------------------------------------------------------- /Interview Assignment/Fitness Assignment/Problem Statement.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arjundhav/Onlinesales.ai-Assesments/main/Interview Assignment/Fitness Assignment/Problem Statement.docx -------------------------------------------------------------------------------- /Pre -Assesment/task1.sql: -------------------------------------------------------------------------------- 1 | -- Our database name is company which has data imported from worksheet 1 & worksheet 2 2 | use company; 3 | 4 | SELECT D.NAME, AVG(S.SALARY) AS avg_salary 5 | FROM employees E 6 | LEFT JOIN departments D on D.ID = E.DEPT_ID 7 | LEFT JOIN salaries S on S.EMP_ID = E.ID 8 | GROUP BY D.NAME 9 | ORDER BY avg_salary DESC 10 | LIMIT 3; -------------------------------------------------------------------------------- /Interview Assignment/sqlTask.sql: -------------------------------------------------------------------------------- 1 | 2 | -- table with fields : 3 | 4 | -- id name dept salary 5 | 6 | -- give highest salary id name for each department 7 | 8 | 9 | SELECT dept,id,name,salary 10 | FROM employees 11 | WHERE (dept,salary) IN ( 12 | SELECT department,MAX(salary) 13 | from employees 14 | Group by dept 15 | ); -------------------------------------------------------------------------------- /Pre -Assesment/data/ASDE Assignment - Employees.csv: -------------------------------------------------------------------------------- 1 | ID,NAME,DEPT ID 2 | 1,Jack,1 3 | 2,John,1 4 | 3,Jim,2 5 | 4,Harry,3 6 | 5,Ben,2 7 | 6,Elizabeth,4 8 | 7,Mary,5 9 | 8,Cameron,2 10 | 9,Anthony,3 11 | 10,Shirley,1 12 | 11,Tom,2 13 | 12,Catherine,3 14 | 13,Patrick,2 15 | 14,Olivia,4 16 | 15,Emma,5 17 | 16,Howard,5 18 | 17,Caronline,4 19 | 18,Anna,2 20 | 19,Mike,2 21 | 20,Chris,2 22 | 21,Bruce,5 23 | 22,Maggie,2 24 | 23,Paul,3 25 | 24,Pete,1 -------------------------------------------------------------------------------- /Interview Assignment/Convert.java: -------------------------------------------------------------------------------- 1 | // I was asked to debug the below code 2 | 3 | public class Convert { 4 | public static void main(String[] args) { 5 | int num = 101; 6 | int binary_val = num; 7 | int decimal_val = 0; 8 | int base = 1; 9 | while (num > 0) { 10 | int rem = num % 10; 11 | decimal_val = decimal_val + rem * base; 12 | num = num / 10; // Incorrect logic = (num / 2) 13 | base = base * 2; // Incorrect logic = (base*2) 14 | } 15 | System.out.println("The decimal of " + binary_val + " is " + decimal_val); 16 | } 17 | } -------------------------------------------------------------------------------- /Pre -Assesment/task3.py: -------------------------------------------------------------------------------- 1 | """ 2 | Task 2: Debugging 3 | 4 | Given below is a Bash / Python script that performs following computation on an integer input (n): 5 | If n is less than 10: Calculate its Square 6 | Example: 4 => 16 7 | 8 | If n is between 10 and 20: Calculate the factorial of (n-10) 9 | Example: 15 => 120 10 | 11 | If n is greater than 20: Calculate the sum of all integers between 1 and (n-20) 12 | Example: 25 => 15 13 | 14 | The task is to identify the bugs in the script, fix them and share the new script. 15 | Only one of the two scripts required Bash or Python. Hint: You can correct the script by only changing 3-4 characters. 16 | 17 | """ 18 | 19 | #Corrections 20 | """ 21 | In the given python script the range for second condition is given as range(1,n-10) which is incorrect,that must be corrected as range(1,n-9). 22 | Similarly, for third condition the range (n-20) is incorrect which must be corrected as (n-19) 23 | Also, the integer division operator is used which must be corrected as floor division operator. 24 | """ 25 | 26 | def compute(n): 27 | if n < 10: 28 | out = n ** 2 29 | elif 10 <= n < 20: 30 | out = 1 31 | for i in range(1, n - 9): # Adjusted range from (n-9) 32 | out *= i 33 | 34 | else: 35 | lim = n - 19 # Adjusted range 36 | out = lim * lim 37 | out = out - lim 38 | out = out // 2 # Corrected integer division operator 39 | 40 | print(out) 41 | 42 | n = int(input("Enter an integer: ")) 43 | compute(n) -------------------------------------------------------------------------------- /Interview Assignment/Fitness Assignment/company_data.json: -------------------------------------------------------------------------------- 1 | { 2 | "data": [ 3 | { 4 | "user": "Ezra Miller", 5 | "date": "2020-11-01", 6 | "steps": 9999, 7 | "department": "Information Technology" 8 | }, 9 | { 10 | "user": "Ezra Miller", 11 | "date": "2020-11-02", 12 | "steps": 15000, 13 | "department": "Information Technology" 14 | }, 15 | { 16 | "user": "Bruce Banner", 17 | "date": "2020-12-02", 18 | "steps": 1000, 19 | "department": "Management" 20 | }, 21 | { 22 | "user": "Thanos", 23 | "date": "2020-12-05", 24 | "steps": 4523, 25 | "department": "Human Resources" 26 | }, 27 | { 28 | "user": "Bruce Banner", 29 | "date": "2020-12-03", 30 | "steps": 2000, 31 | "department": "Management" 32 | }, 33 | { 34 | "user": "Tony Stark", 35 | "date": "2020-10-03", 36 | "steps": 2233, 37 | "department": "Research and Development" 38 | }, 39 | { 40 | "user": "Thanos", 41 | "date": "2020-12-05", 42 | "steps": 6000, 43 | "department": "Human Resources" 44 | }, 45 | { 46 | "user": "Ezra Miller", 47 | "date": "2020-11-02", 48 | "steps": 4000, 49 | "department": "Information Technology" 50 | }, 51 | { 52 | "user": "Bruce Banner", 53 | "date": "2020-10-04", 54 | "steps": 2345, 55 | "department": "Research and Development" 56 | }, 57 | { 58 | "user": "Scarlet Witch", 59 | "date": "2020-11-13", 60 | "steps": 1000, 61 | "department": "DevOps" 62 | }, 63 | { 64 | "user": "Tony Stark", 65 | "date": "2020-11-13", 66 | "steps": 4033, 67 | "department": "Research and Development" 68 | }, 69 | { 70 | "user": "Tony Stark", 71 | "date": "2020-10-04", 72 | "steps": 5033, 73 | "department": "Research and Development" 74 | } 75 | ] 76 | } -------------------------------------------------------------------------------- /Interview Assignment/Fitness Assignment/FitnessAssesment.py.py: -------------------------------------------------------------------------------- 1 | import json 2 | import csv 3 | 4 | # Read the json file 5 | def read_data(input_file): 6 | with open(input_file,'r') as file: 7 | data = json.load(file) 8 | 9 | #calculate department-wise,month-wise steps 10 | department_month_totals = {} 11 | for record in data: 12 | department = record['department'] 13 | month =record['date'] 14 | steps = record['steps'] 15 | 16 | if department not in department_month_totals: 17 | department_month_totals[department] = {} 18 | 19 | if month not in department_month_totals[department]: 20 | department_month_totals[department][month] = 0 21 | 22 | department_month_totals[department][month] += steps 23 | 24 | 25 | #generate TSV file 26 | with open('output.tsv','w',newline='') as file: 27 | writer = csv.write(file,delimeter='\t') 28 | writer.writerow(['Department','Month','Total Steps']) 29 | 30 | for department in department_month_totals.items(): 31 | for month,total_steps in month.items(): 32 | writer.writerow([department,month,total_steps]) 33 | 34 | 35 | def read_leaderboard(input_file): 36 | with open(input_file,'r') as file: 37 | data = json.load(file) 38 | 39 | #leaderboard_months 40 | leaderboard_months = ['October', 'November', 'December'] 41 | 42 | for month in leaderboard_months: 43 | leaderboard =[] 44 | for record in data: 45 | if record['month'] == month: 46 | employee_name = record['empolyee_name'] 47 | steps = record['steps'] 48 | leaderboard.append(({"Employee_Name":employee_name,"Steps":steps,"Month":month})) 49 | 50 | #sort leaderboard in descending order based on steps 51 | leaderboard.sort(key = lambda x: x['Steps'],reverse=True) 52 | 53 | #generate TSV file 54 | with open(f'{month}.leaderboard.tsv','w',newline=''): 55 | writer = csv.writer(file,fieldnames = ['Employee_Name','Steps','Month'],delimiter='\t') 56 | writer.header() 57 | writer.writerows(leaderboard) 58 | 59 | 60 | def main(): 61 | input_file = "assignment\company_data.json" 62 | read_data(input_file) 63 | read_leaderboard(input_file) 64 | 65 | if __name__ == "__main__": 66 | main() 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /Pre -Assesment/task2.py: -------------------------------------------------------------------------------- 1 | import csv 2 | from tabulate import tabulate 3 | 4 | # Read data from CSV files 5 | def read_department_data(filename): 6 | department = {} 7 | with open(filename, 'r') as file: 8 | reader = csv.reader(file) 9 | next(reader) # To Skip the header row from csv file 10 | 11 | for row in reader: 12 | #print(row) 13 | department[row[1]] = row[0] 14 | return department 15 | 16 | def read_employee_data(filename): 17 | employee = [] 18 | with open(filename, 'r') as file: 19 | reader = csv.reader(file) 20 | next(reader) # To Skip the header row from csv file 21 | 22 | for row in reader: 23 | employee.append(row) 24 | 25 | return employee 26 | 27 | def read_salary_data(filename): 28 | salaries = [] 29 | with open(filename, 'r') as file: 30 | reader = csv.reader(file) 31 | next(reader) # To Skip the header row from csv file 32 | 33 | for row in reader: 34 | salaries.append(row) 35 | 36 | return salaries 37 | 38 | #Provide appropiate paths to read functions 39 | department = read_department_data('./data/ASDE Assignment - Departments.csv') 40 | employee = read_employee_data('./data/ASDE Assignment - Employees.csv') 41 | salaries = read_salary_data('./data/ASDE Assignment - Salaries.csv') 42 | 43 | # Get list of employees in each department 44 | def get_emplist(department): 45 | emp_list = {} 46 | for x in department.values(): 47 | temp = [] 48 | for emp in employee: 49 | if x == emp[2]: 50 | temp.append(emp[0]) 51 | emp_list[x] = temp 52 | return emp_list 53 | 54 | employees_list = get_emplist(department) 55 | 56 | # Get average salary of each department 57 | def get_avg_dept_salaries(employees_list, salaries): 58 | dept_id = 0 59 | dept_salaries = {} 60 | for dept_employees in employees_list.values(): 61 | avg_sal = 0 62 | count = 0 63 | for individual_employee in dept_employees: 64 | for salary in salaries: 65 | if(individual_employee == salary[0]): 66 | count += 1 67 | avg_sal += int(salary[2]) 68 | dept_id += 1 69 | avg_sal = avg_sal/count 70 | dept_salaries[str(dept_id)] = avg_sal 71 | 72 | return dept_salaries 73 | 74 | # Get top 3 departments with their average monthly salary 75 | def get_top_departments(avg_dept_sal_with_names): 76 | sorted_top_3_dept_by_avg_salary = sorted(avg_dept_sal_with_names.items(), key=lambda x:x[1], reverse=True)[:3] 77 | return sorted_top_3_dept_by_avg_salary 78 | 79 | # Print top 3 departments with their average monthly salary 80 | dept_salaries = get_avg_dept_salaries(employees_list, salaries) 81 | 82 | #Inverting department & department salaries dictionaries to get desired dictionary 83 | avg_dept_sal_with_names = {key: dept_salaries[value] for key, value in department.items() if value in dept_salaries} 84 | top_departments = get_top_departments(avg_dept_sal_with_names) 85 | 86 | 87 | 88 | # Main function that will give us the final output report 89 | def generate_report(top_departments): 90 | headers = ["DEPT_NAME", "AVG_MONTHLY_SALARY(USD)"] 91 | rows = [] 92 | for department, salaries in top_departments: 93 | rows.append([department, f"{salaries:.2f}"]) 94 | print(tabulate(rows, headers, tablefmt="grid")) 95 | print('\n') 96 | 97 | generate_report(top_departments) -------------------------------------------------------------------------------- /Pre -Assesment/data/ASDE Assignment - Salaries.csv: -------------------------------------------------------------------------------- 1 | EMP_ID,MONTH (YYYYMM),AMT (USD) 2 | 1,202207,5000 3 | 2,202207,4000 4 | 3,202207,8000 5 | 4,202207,4000 6 | 5,202207,5500 7 | 6,202207,4500 8 | 7,202207,6500 9 | 8,202207,5800 10 | 9,202207,5500 11 | 10,202207,4800 12 | 11,202207,6000 13 | 1,202208,5000 14 | 2,202208,4000 15 | 3,202208,8000 16 | 4,202208,7000 17 | 5,202208,5500 18 | 6,202208,4500 19 | 7,202208,6500 20 | 8,202208,5800 21 | 9,202208,5500 22 | 10,202208,4800 23 | 11,202208,6000 24 | 12,202208,5200 25 | 3,202209,8000 26 | 4,202209,7000 27 | 5,202209,5500 28 | 6,202209,4500 29 | 7,202209,6500 30 | 8,202209,5800 31 | 9,202209,5500 32 | 10,202209,4800 33 | 11,202209,6000 34 | 12,202209,5200 35 | 3,202210,8000 36 | 4,202210,7000 37 | 5,202210,5500 38 | 6,202210,4500 39 | 7,202210,6500 40 | 8,202210,5800 41 | 9,202210,5500 42 | 10,202210,4800 43 | 11,202210,6000 44 | 12,202210,5200 45 | 13,202210,7500 46 | 3,202211,8000 47 | 4,202211,7000 48 | 5,202211,5500 49 | 6,202211,4500 50 | 7,202211,6500 51 | 8,202211,5800 52 | 9,202211,5500 53 | 10,202211,4800 54 | 11,202211,6000 55 | 12,202211,5200 56 | 13,202211,7500 57 | 14,202211,7500 58 | 15,202211,7500 59 | 16,202211,7500 60 | 17,202211,7500 61 | 3,202212,8000 62 | 4,202212,7000 63 | 5,202212,5500 64 | 6,202212,4500 65 | 7,202212,6500 66 | 8,202212,5800 67 | 9,202212,5500 68 | 10,202212,4800 69 | 11,202212,6000 70 | 12,202212,5200 71 | 13,202212,7500 72 | 14,202212,7500 73 | 15,202212,7500 74 | 16,202212,7500 75 | 17,202212,7500 76 | 3,202301,8000 77 | 4,202301,7000 78 | 5,202301,6500 79 | 6,202301,4500 80 | 7,202301,6500 81 | 8,202301,5800 82 | 9,202301,5500 83 | 10,202301,4800 84 | 11,202301,6000 85 | 12,202301,5200 86 | 13,202301,7500 87 | 14,202301,7500 88 | 15,202301,7500 89 | 16,202301,7500 90 | 17,202301,7500 91 | 5,202302,6500 92 | 6,202302,4500 93 | 7,202302,6500 94 | 8,202302,5800 95 | 9,202302,5500 96 | 10,202302,4800 97 | 11,202302,6000 98 | 12,202302,7200 99 | 13,202302,7500 100 | 14,202302,7500 101 | 15,202302,7500 102 | 16,202302,7500 103 | 17,202302,7500 104 | 18,202302,5700 105 | 5,202303,6500 106 | 6,202303,4500 107 | 7,202303,6500 108 | 8,202303,5800 109 | 9,202303,5500 110 | 10,202303,4800 111 | 11,202303,6000 112 | 12,202303,7200 113 | 13,202303,7500 114 | 14,202303,7500 115 | 15,202303,7500 116 | 16,202303,7500 117 | 17,202303,7500 118 | 18,202303,5700 119 | 7,202304,8500 120 | 8,202304,6500 121 | 9,202304,5500 122 | 10,202304,5500 123 | 11,202304,6000 124 | 12,202304,7200 125 | 13,202304,7500 126 | 14,202304,7500 127 | 15,202304,7500 128 | 16,202304,7500 129 | 17,202304,7500 130 | 18,202304,5700 131 | 19,202304,6200 132 | 20,202304,5500 133 | 21,202304,4800 134 | 22,202304,5800 135 | 23,202304,4500 136 | 24,202304,7500 137 | 7,202305,8500 138 | 8,202305,6500 139 | 9,202305,5500 140 | 10,202305,5500 141 | 11,202305,6000 142 | 12,202305,7200 143 | 13,202305,7500 144 | 14,202305,7500 145 | 15,202305,7500 146 | 16,202305,7500 147 | 17,202305,7500 148 | 18,202305,5700 149 | 19,202305,6200 150 | 20,202305,5500 151 | 21,202305,4800 152 | 22,202305,5800 153 | 23,202305,4500 154 | 24,202305,7500 155 | 7,202306,8500 156 | 8,202306,6500 157 | 9,202306,5500 158 | 10,202306,5500 159 | 11,202306,6000 160 | 12,202306,7200 161 | 13,202306,7500 162 | 14,202306,7500 163 | 15,202306,7500 164 | 16,202306,7500 165 | 17,202306,7500 166 | 18,202306,5700 167 | 19,202306,6200 168 | 20,202306,5500 169 | 21,202306,4800 170 | 22,202306,5800 171 | 23,202306,4500 172 | 24,202306,7500 --------------------------------------------------------------------------------