Hi everyone! Welcome to my project for calculating labor cost. Just upload your Excel (.xlsx) file containing the process data and lot quantites, and it will compute everything automaticly.
How The Math Works (The Logic)
So, to calculate the exact cost per process, I used the provided master data. Here is a breakdown of how I did the maths, using Process A as an example:
- First, I need the hourly wage. The master data says Male Workers get ₹800 per 8 hours and Females get ₹700 per 8 hours. So, 800/8 = ₹100 per hour for males, and 700/8 = ₹87.5 per hour for females.
- For Process A, we need 5 males and 3 females. So the cost for one hour of work is (5 * 100) + (3 * 87.5) = ₹762.5 per hour.
- Process A takes exactly 30 minutes (which is 0.5 hours). Therefore, the labor cost to complete just ONE lot is 762.5 * 0.5 = ₹381.25.
- The input quantity for Process A is 600 kg, and the yield is 98%. This means the actual usable output is 600 * 0.98 = 588 kg.
- Finally, the cost per kg for Process A is 381.25 divided by 588, which equals ₹0.648 per kg!
When you upload the excel sheet, my python backend reads the "Lot Quantity" for each process. It multiplys the cost per lot and the output per lot by the number of lots to get the total cost and total output for the whole batch. Then it sums it all up across all processes and divides total cost by total output to generate the final Overall Labor Cost per kg.
Tech Stack I Used & My Implementation Details
For this assignment, I decided to build my solution using a decoupled architecture. This means I separated the "frontend" (what you see on this page) from the "backend" (the engine doing the math). Even though I could have put it all in one script, separating them makes the application much more scalable and easier to maintain. Here is a detailed breakdown of the exact technologies I used and why I chose them:
- FastAPI (Backend Framework):
Why I used it: I needed a Python backend to handle the complex math and logic required by the assignment. While Flask is a popular choice, I specifically chose FastAPI because it is modern, incredibly fast, and automatically handles data validation.
How it's implemented: In my `main.py` file, I initialized a FastAPI application. I created a single POST endpoint called `/analyze-costs`. This endpoint listens for incoming files. When you click the upload button, FastAPI receives the Excel file and passes it to the math logic. It then formats the final calculated labor costs into a clean JSON response and sends it back to the browser.
- Uvicorn (ASGI Web Server):
Why I used it: FastAPI itself is just a framework; it needs a server to actually listen to web traffic. Uvicorn is an ultra-fast ASGI (Asynchronous Server Gateway Interface) server designed specifically for modern asynchronous Python apps.
How it's implemented: When I run my project from the command line, I execute `uvicorn main:app --reload`. This tells Uvicorn to start up, load my FastAPI application (`app` inside `main.py`), and continuously listen on `localhost:8000` for your file uploads. The `--reload` flag is just a handy tool I used during development so the server restarts automaticly when I save my code.
- Pandas (Data Processing):
Why I used it: The assignment required reading production data from an Excel (.xlsx) file. Parsing Excel files manually is extremely difficult, so I brought in the `pandas` library, which is the industry standard for data manipulation in Python.
How it's implemented: Instead of doing the traditional (and slower) method of saving the uploaded Excel file to my hard drive and then opening it, I used a more advanced approach. I used Python's `io.BytesIO` module to read the uploaded file as a raw byte stream straight from memory. Pandas then reads this memory stream directly into a "DataFrame" (a table structure). From there, my code simply iterates through the rows, extracts the "Lot Quantity", matches the "Process" name to my hardcoded Master Data, and calculates the total costs.
- Vanilla HTML, CSS & JavaScript (Frontend):
Why I used it: The assignment requested an HTML application. While I could have used a heavy frontend framework like React or Angular, I wanted to keep the UI lightweight, reliable, and perfectly aligned with the "old style / minimalist" aesthetic.
How it's implemented: This entire page is just one `index.html` file! I used standard HTML forms to create the file uploader. I added some simple, old-school CSS directly in the <style> tag to keep it centered and readable with a slight retro vibe. For the functionality, I wrote a standard asynchronous JavaScript function. When you submit the form, Javascript prevents the page from reloading, takes the file, and uses the modern `fetch()` API to send it to my FastAPI server. Once the server responds with the JSON data, my Javascript loops through the results and injects the text directly into the DOM (the results box above).
Overall, this architecture perfectly satisfies the functional requirements of the assignment. It securely applies the predefined master data (labor wages and standards), accurately extracts the lot quantities from your Excel sheet, dynamically computes the costs per kg, and neatly displays everything without any page reloads.
Other Approaches I Considered
Before writing the code, I thought about a few different ways to build this project:
Approach 1: The Minimalist Python Web Server (Flask/Jinja)
This is the most literal interpretation of the assignment, keeping everything within a single framework.
- How it works: You build a Flask application. The HTML is served via Jinja2 templates directly from the Python backend. The user uploads the Excel file, the server saves it temporarily, parses it using the pandas library, runs the math, and renders a new HTML page with the results.
- Pros: Very quick to set up. Requires minimal boilerplate.
- Cons: Tightly couples the frontend and backend, which isn't ideal for scalability.
Approach 2: Modern Decoupled Architecture (FastAPI + Next.js)
Instead of mixing HTML rendering into Python, you separate concerns. This approach results in a much more professional application.
- How it works: Backend: You write a Python FastAPI service with a single endpoint (/analyze). It accepts a multipart file upload, uses pandas to read the Excel buffer straight from memory (no saving to disk), computes the yields and costs, and returns a clean JSON response. Frontend: You build a React/Next.js interface. It handles the file selection, sends an API request to FastAPI, and then beautifully maps the JSON response onto a sleek, metallic, cyber-glass UI dashboard.
- Pros: Lightning fast, highly scalable, and allows you to build a highly interactive user experience.
Approach 3: The Data Pipeline Approach (Streamlit)
If the goal is to build an internal tool purely for data analysis without worrying about complex frontend routing or DOM manipulation, Streamlit is a fantastic Python-native option.
- How it works: Streamlit allows you to write standard Python code that automatically generates an interactive HTML/JS frontend. You would write a single Python script that provides a file uploader widget, reads the Excel sheet with pandas, applies the master data wages, and immediately plots the resulting Process A, B, and C costs onto data tables or charts.
- Pros: Fastest time-to-deployment for data tools. No HTML/CSS/JS knowledge required; everything is written in Python.
- Cons: Less customizable UI aesthetics.