Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quantium job simulation #17

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Quantium_certificate.pdf
Binary file not shown.
40 changes: 39 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,40 @@
# Quantium starter repo
This repo contains everything you need to get started on the program! Good luck!

__Task1:__
Setting up the local repo.

__Task2:__

Initial datasets daily_sales_data_0.csv, daily_sales_data_1.csv, daily_sales_data_2.csv
The attributes in the above datasets are
1. product - {'gold morsel', 'magenta morsel', 'periwinkle morsel', 'vermilion morsel', 'chartreuse morsel', 'lapis morsel', 'pink morsel'}
2. price
3. quantity
4. date
5. region - {'west', 'east', 'north', 'south'}

Combining the three datasets into a single dataset i.e combined_data.csv. The Soul Foods is only interested in Pink Morsels

The output file contains three fields:
1. sales = price * quantity
2. date
3. region

__Task3:__

Outputs:
![alt text](newplot.png)
![alt text](newplot_s.png)
![alt text](newplot_e.png)
![alt text](newplot_w.png)

(*Threshold : sales on Jan 15 2021*)

__Task4:__

Added some UI to it so it is convenient to use.
![alt text](newplot_ui.png)

__Task5:__

Add some unit test cases to verify the Dash application.
190 changes: 190 additions & 0 deletions Task3.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 8,
"id": "7a281ff7",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
" <iframe\n",
" width=\"100%\"\n",
" height=\"650\"\n",
" src=\"http://127.0.0.1:8050/\"\n",
" frameborder=\"0\"\n",
" allowfullscreen\n",
" \n",
" ></iframe>\n",
" "
],
"text/plain": [
"<IPython.lib.display.IFrame at 0x19c544cc280>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from dash import Dash, dcc, html\n",
"import plotly.express as px\n",
"import pandas as pd\n",
"import os\n",
"\n",
"app = Dash(__name__)\n",
"\n",
"#reading csv file\n",
"\n",
"# Get the absolute path to the data folder\n",
"data_folder = os.path.abspath('data')\n",
"\n",
"# Construct the absolute path to the CSV file\n",
"\n",
"# Read the CSV file\n",
"df_0 = pd.read_csv(os.path.join(data_folder, 'daily_sales_data_0.csv'))\n",
"\n",
"\n",
"#filtering only pink morsel\n",
"df_0 = df_0[df_0['product'] == 'pink morsel']\n",
"\n",
"# from price column removing $ and converting to number\n",
"df_0['price'] = pd.to_numeric(df_0['price'].str.replace('$', '', regex=False), errors='coerce') \n",
"\n",
"#adding new column named sales where sales=price*quantity\n",
"df_0['sales'] = df_0['price'] * df_0['quantity']\n",
"\n",
"#dropping the columns\n",
"columns_to_drop = ['price', 'quantity']\n",
"df_0 = df_0.drop(columns=columns_to_drop)\n",
"\n",
"df_1 = pd.read_csv(os.path.join(data_folder, 'daily_sales_data_1.csv'))\n",
"\n",
"df_1 = df_1[df_1['product'] == 'pink morsel']\n",
"\n",
"df_1['price'] = pd.to_numeric(df_1['price'].str.replace('$', '', regex=False), errors='coerce')\n",
"\n",
"df_1['sales'] = df_1['price'] * df_1['quantity']\n",
"\n",
"columns_to_drop = ['price', 'quantity']\n",
"df_1 = df_1.drop(columns=columns_to_drop)\n",
"\n",
"df_2 = pd.read_csv(os.path.join(data_folder, 'daily_sales_data_2.csv'))\n",
"\n",
"df_2 = df_2[df_2['product'] == 'pink morsel']\n",
"\n",
"df_2['price'] = pd.to_numeric(df_2['price'].str.replace('$', '', regex=False), errors='coerce')\n",
"\n",
"df_2['sales'] = df_2['price'] * df_2['quantity']\n",
"\n",
"columns_to_drop = ['price', 'quantity']\n",
"df_2 = df_2.drop(columns=columns_to_drop)\n",
"\n",
"# combining all three different datasets into single dataset\n",
"combined_df = pd.concat([df_0,df_1,df_2],ignore_index = True)\n",
"combined_df = combined_df.drop(columns = 'product')\n",
"\n",
"# sorting dataset by region \n",
"c_north = combined_df[combined_df['region'] == 'north']\n",
"c_south = combined_df[combined_df['region'] == 'south']\n",
"c_east = combined_df[combined_df['region'] == 'east']\n",
"c_west = combined_df[combined_df['region'] == 'west']\n",
"\n",
"# thresold value for north region where threshold=sales on Jan 15, 2021\n",
"sales_on_query_data_north = c_north.loc[c_north['date']== '2021-01-15','sales'] \n",
"north_range=sales_on_query_data_north.values[0] if not sales_on_query_data_north.empty else 0\n",
"\n",
"line_color = ['sales greater than thresold' if y > north_range else 'sales lesser than thresold' for y in c_north['sales']]\n",
"c_north.loc[:, 'Color'] = line_color\n",
"\n",
"# thresold value for south region where threshold=sales on Jan 15, 2021\n",
"sales_on_query_data_south = c_south.loc[c_south['date']== '2021-01-15','sales'] \n",
"south_range=sales_on_query_data_south.values[0] if not sales_on_query_data_south.empty else 0\n",
"line_color = ['sales greater than thresold' if y > south_range else 'sales lesser than thresold' for y in c_south['sales']]\n",
"c_south.loc[:, 'Color'] = line_color\n",
"\n",
"# thresold value for east region where threshold=sales on Jan 15, 2021\n",
"sales_on_query_data_east = c_east.loc[c_east['date']== '2021-01-15','sales'] \n",
"east_range=sales_on_query_data_east.values[0] if not sales_on_query_data_east.empty else 0\n",
"line_color = ['sales greater than thresold' if y > east_range else 'sales lesser than thresold' for y in c_east['sales']]\n",
"c_east.loc[:, 'Color'] = line_color\n",
"\n",
"# thresold value for west region where threshold=sales on Jan 15, 2021\n",
"sales_on_query_data_west = c_west.loc[c_west['date']== '2021-01-15','sales'] \n",
"west_range=sales_on_query_data_west.values[0] if not sales_on_query_data_west.empty else 0\n",
"line_color = ['sales greater than thresold' if y > west_range else 'sales lesser than thresold' for y in c_west['sales']]\n",
"c_west.loc[:, 'Color'] = line_color\n",
"\n",
"app.layout = html.Div(children=[\n",
" html.H1(\n",
" children='Soul Foods',\n",
" style={\n",
" 'textAlign': 'center'\n",
" }\n",
" ),\n",
"\n",
" html.Div(children='Sales of Pink Morsel', style={\n",
" 'textAlign': 'center',\n",
" 'fontSize': '30px'\n",
" }),\n",
" \n",
" html.Div(children='Sales = Price*Quantity',style={\n",
" 'border':'2px solid black',\n",
" 'margin-right':'800px'\n",
" }),\n",
"\n",
" dcc.Graph(\n",
" id='line chart 1',\n",
" figure=px.line(c_north, x='date', y='sales', color='Color',title='North region: Sales on each day')\n",
" ),\n",
" dcc.Graph(\n",
" id='line chart 2',\n",
" figure=px.line(c_south, x='date', y='sales', color='Color',title='South region: Sales on each day')\n",
" ),\n",
" dcc.Graph(\n",
" id='line chart 3',\n",
" figure=px.line(c_east, x='date', y='sales', color='Color',title='East region: Sales on each day')\n",
" ),\n",
" dcc.Graph(\n",
" id='line chart 4',\n",
" figure=px.line (c_west, x='date', y='sales', color='Color',title='West region: Sales on each day')\n",
" )\n",
"])\n",
"\n",
"if __name__ == '__main__':\n",
" app.run(debug=True)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "56f4e847",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading