Big Data (COMP6210)
Assignment 1- MapReduce
Student Name: Arjun Krishangi Mahawar
Student ID: 48341924
Table of Contents
INTRODUCTION..............................................................................................3
FLOWCHART AND PSEUDOCODE.....................................................................4
TOTAL COFFEE SALES CALCULATION.......................................................................................4
BOTTOM 3 COFFEE TYPES MONTHLY SALES ANALYSIS................................................................5
MONTHLY SPENDING OF TOP 5 USERS....................................................................................6
CONCLUSION:................................................................................................ 8
Introduction
This report presents a data-driven analysis of coffee sales transactions using the MapReduce
programming paradigm. The primary objective was to derive meaningful insights from a large dataset
by implementing scalable, distributed processing workflows. The analysis was structured into three
main tasks. Task 1 focused on the extraction and pre-processing of raw transactional data to generate a
cleaned and structured format, followed by a MapReduce program to calculate total sales for each
coffee type. Task 2 extended this analysis by identifying the three bottom-selling coffee products and
tracking their monthly sales trends, as well as determining the top five customers based on total
historical spending and analysing their monthly expenditures. Each task involved the development of
MapReduce logic, output generation in textual form, and data visualization through time-series plots.
The final task encapsulates the development journey through flowcharts and pseudocode for each
MapReduce component, promoting transparency and reproducibility. The implementation was carried
out in Python using the mrjob library, with output presented in both .txt and .pdf formats for clarity
and reporting purposes.
Flowchart and Pseudocode
The following section illustrates the internal working logic of each MapReduce program developed in
this project. For every task, a detailed flowchart outlines the step-by-step process from input to final
output, and accompanying pseudocode describes the key computational logic used in the mapper and
reducer functions. These visual and textual representations are intended to clearly communicate how
data was transformed, grouped, and aggregated to produce meaningful analytical results. Each
MapReduce task is documented individually for clarity.
Total Coffee Sales Calculation
Fig. 1 Flowchart for Task 1.2 – Total Coffee Sales Calculation
Pseudocode:
Function mapper(line):
Split the input line by commas to extract fields:
coffee_type, user_id, money, day, month, year, time
Convert the 'money' field to float
Emit (coffee_type, money)
Function reducer(coffee_type, sales_values):
total_sales = Sum of all sales_values for the given coffee_type
Emit (coffee_type, round(total_sales, 2))
Main:
For each line in task1_1_output.txt:
Run mapper to extract (coffee_type, money)
Group by coffee_type
Apply reducer to calculate total sales for each coffee_type
Output final results as (coffee_type, total_sales)
Bottom 3 Coffee Types Monthly Sales Analysis
Fig. 2 Flowchart for Task 2.1 – Bottom 3 Coffee Types Monthly Sales Analysis
Pseudocode:
Define constant BOTTOM_THREE as {"Espresso", "Cocoa", "Cortado"}
Function mapper(line):
Split line by commas into fields
If fields are valid and coffee_type is in BOTTOM_THREE:
Extract coffee_type, money, year, and month
Emit ((coffee_type, "YYYY-MM"), money)
Function reducer((coffee_type, month), values):
total = sum(values)
Emit ((coffee_type, month), round(total, 2))
Main:
Run MapReduce job on 'task1_1_output.txt'
Collect and store output in a buffer
Initialize data dictionary: coffee_type → {month: value}
For each line in MapReduce output:
Extract (coffee_type, month) and corresponding sales value
Store in data[coffee_type][month]
For each coffee_type:
Sort its monthly records chronologically
Write (coffee_type, month) and total sales to 'task2_1_output.txt'
Prepare line plot:
X-axis: Sorted months (e.g., "Mar 2024", "Apr 2024", ...)
Y-axis: Monthly sales values
Each line: One coffee type from BOTTOM_THREE
Annotate each point with sales amount
Save the plot to 'task2_1_output.pdf'
Monthly Spending of Top 5 Users
Fig. 2 Flowchart for Task 2.2 - Monthly Spending of Top 5 Users
Pseudocode:
Class MonthlySpendingTopUsers(MRJob):
Function mapper(_, line):
Split line into 7 fields by comma
If line is valid and user_id is not "nan":
Extract user_id, money, month, year
Emit ((user_id, "YYYY-MM"), money)
Function reducer((user_id, month), values):
total = sum(values)
Emit ((user_id, month), round(total, 2))
Main:
Step 1: Run MapReduce on 'task1_1_output.txt'
→ Output: ((user_id, "YYYY-MM"), total_spent_in_month)
Step 2: Parse MR Output
For each line in output:
Extract user_id, month, and spending
Store in data[user_id][month]
Accumulate totals[user_id] += amount
Step 3: Identify Top 5 Spenders
Sort totals in descending order
Select top 5 users based on total spending
Step 4: Save Output to 'task2_2_output.txt'
For each top user:
Sort their months by descending spending
Write formatted records to file
Step 5: Plot Monthly Trends
X-axis: All months in chronological order
Y-axis: Monthly spending
Each line represents one top user's spending pattern
Annotate each point with dollar value
Save the plot to 'task2_2_output.pdf'
Conclusion:
Through the use of MapReduce programming, this project demonstrated the efficiency and flexibility
of distributed data processing in extracting key business intelligence from a transactional dataset. Task
1 enabled a smooth transition from raw CSV data to a cleaned, query-ready structure, while Task 2
highlighted critical insights into product performance and customer behaviour. By identifying the
lowest-selling coffee types and visualizing their chronological sales trends, businesses can make more
informed inventory and marketing decisions. Simultaneously, analysing the top five customers based
on cumulative spending helps in recognizing loyal consumers and targeting personalized offers. The
inclusion of comprehensive visualizations and structured output files ensures that insights are
accessible and actionable. Overall, this report validates the effectiveness of MapReduce in managing
and analysing large-scale sales data, reinforcing its relevance in real-world data analytics scenarios.