New to Nutbox?

SLC S21 Week3 || Mastering Records and Record Arrays with Python

2 comments

josepha
78
7 days agoSteemit4 min read

1000213123.png

Exercise 1: Advanced Employee Records Management (2points)

Here I have implemented an advanced employee records management system using Python data class as requested by the professor. The program supports the following; adding, updating, and displaying employee information, and also supports the calculation of the average performance scores and identifying top performers which you can see below.

Code

em.PNGem1.PNG
em2.PNGem3.PNGem4.PNG

Output

em5.PNG

Interpretation

  • Employee Dataclass: This contains the following;

  • Defines an Employee with name, id, salary, position and scores performance.

  • The average_score is what helps to calculate the employee average score performance.

  • EmployeeRecords Class:

  • This manages a list of employees and provides methods they can add, display, update, identify top performers, and calculate average scores. In the code, other classes help to display all employees alongside their average scores performance display_employees and a class that returns the average performance score for a specific employee calculate_average_scores.

In the program, the top performers are;

  • ID: 1, Name: Josepha, Average Score: 4.70
  • ID: 3, Name: Kouba01, Average Score: 4.70

Exercise 2: Comprehensive Student Grades Analysis (2points)

Here I have shared a program that uses NumPy structured arrays to store and analyze student grades as requested by the professor. The program also has functions that calculate averages, identify top students, analyze subject-wise performance, etc which you can see below.

Code:
st1.PNG
st2.PNG
st3.PNG

Output
st.PNG

Interpretation

  • Structured Array: In the program the structured Array is defined as student_dtype to include fields for student_id, name, and grades for each of the subjects; Mathematics, Science, English, and History.

  • Functions: This helps us to calculate each student's average grade by averaging the four subject grades which the class name is calculate_average_grade and other classes that identify students with average grades above a specified threshold.


Exercise 3: Enhanced Inventory Management System (2points)

Here I have implemented an enhanced inventory management system using named tuple which is a Python program to track products. In the program, there are functions to add products, update quantities, generate low stock alerts, etc which you can see below.

Code

cv.PNGcv1.PNGcv3.PNG

Output
cv4.PNG

The program especially the code provided us with a comprehensive inventory management system that can be further expanded with additional functionalities like product removal or tracking product suppliers.


Exercise 4: Advanced Customer Orders Processing (2points)

Here I have created a program that uses NumPy structured arrays to process customer orders as requested by the professor. This program includes several functions for calculating order totals, identifying large orders, analyzing customer spending, and as well finding frequently ordered products as seen below.

cv5.PNGcv6.PNGcv7.PNG

Interpretation

The Order structured Array: We can define a structured Array order"type, with a field for order_id, customer_name, product,quantity,order date, andprice_per_unit`.

  • To track pairs of products ordered on the same date by the same customer, display pairs ordered together more than once a frequently_ordered_together function which uses counter is been used.

Exercise 5: In-Depth Weather Data Analysis (2points)

Here I have implemented an in-depth weather data analysis using dataclass and NumPy. The program includes functionalities for calculating averages, identifying trends, and detecting anomalies in weather data which you can see below.

wh.PNGwh1.PNGwh2.PNGwh3.PNG

wh4.PNG

Interpretation

  • Convert to NumPy Array:
  • This is where the weather data is stored as a list of WeatherRecord instances.
  • The convert_to_numpy function then converts the list into a structured NumPy Array for efficient numerical operations.
  • Functions:

  • The calculate_averages computes average temperature, max humidity, total precipitation, and average wind speed using the function of NumPy.

  • identify_temperature_thresholds: This finds days where temperatures are below or above specified thresholds.

  • detect_trends: this makes use of np. Diff to calculate the differences between consecutive values and detect the overall trend.

  • detect_anomalies: this identified sudden drops or spikes in temperature using nipdiff and a specified threshold.

I am inviting; @dove11, @simonmwigwe, and @ruthjoe

Cc:-
@kouba01

Comments

Sort byBest