diff --git "a/PeakFIt_analysis2.ipynb" "b/PeakFIt_analysis2.ipynb" new file mode 100644--- /dev/null +++ "b/PeakFIt_analysis2.ipynb" @@ -0,0 +1,6226 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Inventory Management Dashboard and Analysis" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 1. Read & describe the data " + ] + }, + { + "cell_type": "code", + "execution_count": 81, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/javascript": "(function(root) {\n function now() {\n return new Date();\n }\n\n const force = true;\n const py_version = '3.6.3'.replace('rc', '-rc.').replace('.dev', '-dev.');\n const reloading = false;\n const Bokeh = root.Bokeh;\n\n // Set a timeout for this load but only if we are not already initializing\n if (typeof (root._bokeh_timeout) === \"undefined\" || (force || !root._bokeh_is_initializing)) {\n root._bokeh_timeout = Date.now() + 5000;\n root._bokeh_failed_load = false;\n }\n\n function run_callbacks() {\n try {\n root._bokeh_onload_callbacks.forEach(function(callback) {\n if (callback != null)\n callback();\n });\n } finally {\n delete root._bokeh_onload_callbacks;\n }\n console.debug(\"Bokeh: all callbacks have finished\");\n }\n\n function load_libs(css_urls, js_urls, js_modules, js_exports, callback) {\n if (css_urls == null) css_urls = [];\n if (js_urls == null) js_urls = [];\n if (js_modules == null) js_modules = [];\n if (js_exports == null) js_exports = {};\n\n root._bokeh_onload_callbacks.push(callback);\n\n if (root._bokeh_is_loading > 0) {\n // Don't load bokeh if it is still initializing\n console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n return null;\n } else if (js_urls.length === 0 && js_modules.length === 0 && Object.keys(js_exports).length === 0) {\n // There is nothing to load\n run_callbacks();\n return null;\n }\n\n function on_load() {\n root._bokeh_is_loading--;\n if (root._bokeh_is_loading === 0) {\n console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n run_callbacks()\n }\n }\n window._bokeh_on_load = on_load\n\n function on_error(e) {\n const src_el = e.srcElement\n console.error(\"failed to load \" + (src_el.href || src_el.src));\n }\n\n const skip = [];\n if (window.requirejs) {\n window.requirejs.config({'packages': {}, 'paths': {'plotly': 'https://cdn.plot.ly/plotly-3.0.0.min'}, 'shim': {}});\n require([\"plotly\"], function(Plotly) {\n window.Plotly = Plotly\n on_load()\n })\n root._bokeh_is_loading = css_urls.length + 1;\n } else {\n root._bokeh_is_loading = css_urls.length + js_urls.length + js_modules.length + Object.keys(js_exports).length;\n }\n\n const existing_stylesheets = []\n const links = document.getElementsByTagName('link')\n for (let i = 0; i < links.length; i++) {\n const link = links[i]\n if (link.href != null) {\n existing_stylesheets.push(link.href)\n }\n }\n for (let i = 0; i < css_urls.length; i++) {\n const url = css_urls[i];\n const escaped = encodeURI(url)\n if (existing_stylesheets.indexOf(escaped) !== -1) {\n on_load()\n continue;\n }\n const element = document.createElement(\"link\");\n element.onload = on_load;\n element.onerror = on_error;\n element.rel = \"stylesheet\";\n element.type = \"text/css\";\n element.href = url;\n console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n document.body.appendChild(element);\n } if (((window.Plotly !== undefined) && (!(window.Plotly instanceof HTMLElement))) || window.requirejs) {\n var urls = [];\n for (var i = 0; i < urls.length; i++) {\n skip.push(encodeURI(urls[i]))\n }\n } var existing_scripts = []\n const scripts = document.getElementsByTagName('script')\n for (let i = 0; i < scripts.length; i++) {\n var script = scripts[i]\n if (script.src != null) {\n existing_scripts.push(script.src)\n }\n }\n for (let i = 0; i < js_urls.length; i++) {\n const url = js_urls[i];\n const escaped = encodeURI(url)\n if (skip.indexOf(escaped) !== -1 || existing_scripts.indexOf(escaped) !== -1) {\n if (!window.requirejs) {\n on_load();\n }\n continue;\n }\n const element = document.createElement('script');\n element.onload = on_load;\n element.onerror = on_error;\n element.async = false;\n element.src = url;\n console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n document.head.appendChild(element);\n }\n for (let i = 0; i < js_modules.length; i++) {\n const url = js_modules[i];\n const escaped = encodeURI(url)\n if (skip.indexOf(escaped) !== -1 || existing_scripts.indexOf(escaped) !== -1) {\n if (!window.requirejs) {\n on_load();\n }\n continue;\n }\n var element = document.createElement('script');\n element.onload = on_load;\n element.onerror = on_error;\n element.async = false;\n element.src = url;\n element.type = \"module\";\n console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n document.head.appendChild(element);\n }\n for (const name in js_exports) {\n const url = js_exports[name];\n const escaped = encodeURI(url)\n if (skip.indexOf(escaped) >= 0 || root[name] != null) {\n if (!window.requirejs) {\n on_load();\n }\n continue;\n }\n var element = document.createElement('script');\n element.onerror = on_error;\n element.async = false;\n element.type = \"module\";\n console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n element.textContent = `\n import ${name} from \"${url}\"\n window.${name} = ${name}\n window._bokeh_on_load()\n `\n document.head.appendChild(element);\n }\n if (!js_urls.length && !js_modules.length) {\n on_load()\n }\n };\n\n function inject_raw_css(css) {\n const element = document.createElement(\"style\");\n element.appendChild(document.createTextNode(css));\n document.body.appendChild(element);\n }\n\n const js_urls = [\"https://cdn.holoviz.org/panel/1.6.1/dist/bundled/reactiveesm/es-module-shims@^1.10.0/dist/es-module-shims.min.js\", \"https://cdn.holoviz.org/panel/1.6.1/dist/bundled/plotlyplot/plotly-3.0.0.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-3.6.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-3.6.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-3.6.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-3.6.3.min.js\", \"https://cdn.holoviz.org/panel/1.6.1/dist/panel.min.js\"];\n const js_modules = [];\n const js_exports = {};\n const css_urls = [\"https://cdn.holoviz.org/panel/1.6.1/dist/bundled/plotlyplot/maplibre-gl@4.4.1/dist/maplibre-gl.css?v=1.6.1\"];\n const inline_js = [ function(Bokeh) {\n Bokeh.set_log_level(\"info\");\n },\nfunction(Bokeh) {} // ensure no trailing comma for IE\n ];\n\n function run_inline_js() {\n if ((root.Bokeh !== undefined) || (force === true)) {\n for (let i = 0; i < inline_js.length; i++) {\n try {\n inline_js[i].call(root, root.Bokeh);\n } catch(e) {\n if (!reloading) {\n throw e;\n }\n }\n }\n // Cache old bokeh versions\n if (Bokeh != undefined && !reloading) {\n var NewBokeh = root.Bokeh;\n if (Bokeh.versions === undefined) {\n Bokeh.versions = new Map();\n }\n if (NewBokeh.version !== Bokeh.version) {\n Bokeh.versions.set(NewBokeh.version, NewBokeh)\n }\n root.Bokeh = Bokeh;\n }\n } else if (Date.now() < root._bokeh_timeout) {\n setTimeout(run_inline_js, 100);\n } else if (!root._bokeh_failed_load) {\n console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n root._bokeh_failed_load = true;\n }\n root._bokeh_is_initializing = false\n }\n\n function load_or_wait() {\n // Implement a backoff loop that tries to ensure we do not load multiple\n // versions of Bokeh and its dependencies at the same time.\n // In recent versions we use the root._bokeh_is_initializing flag\n // to determine whether there is an ongoing attempt to initialize\n // bokeh, however for backward compatibility we also try to ensure\n // that we do not start loading a newer (Panel>=1.0 and Bokeh>3) version\n // before older versions are fully initialized.\n if (root._bokeh_is_initializing && Date.now() > root._bokeh_timeout) {\n // If the timeout and bokeh was not successfully loaded we reset\n // everything and try loading again\n root._bokeh_timeout = Date.now() + 5000;\n root._bokeh_is_initializing = false;\n root._bokeh_onload_callbacks = undefined;\n root._bokeh_is_loading = 0\n console.log(\"Bokeh: BokehJS was loaded multiple times but one version failed to initialize.\");\n load_or_wait();\n } else if (root._bokeh_is_initializing || (typeof root._bokeh_is_initializing === \"undefined\" && root._bokeh_onload_callbacks !== undefined)) {\n setTimeout(load_or_wait, 100);\n } else {\n root._bokeh_is_initializing = true\n root._bokeh_onload_callbacks = []\n const bokeh_loaded = root.Bokeh != null && (root.Bokeh.version === py_version || (root.Bokeh.versions !== undefined && root.Bokeh.versions.has(py_version)));\n if (!reloading && !bokeh_loaded) {\n if (root.Bokeh) {\n root.Bokeh = undefined;\n }\n console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n }\n load_libs(css_urls, js_urls, js_modules, js_exports, function() {\n console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n run_inline_js();\n });\n }\n }\n // Give older versions of the autoload script a head-start to ensure\n // they initialize before we start loading newer version.\n setTimeout(load_or_wait, 100)\n}(window));", + "application/vnd.holoviews_load.v0+json": "" + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/javascript": "\nif ((window.PyViz === undefined) || (window.PyViz instanceof HTMLElement)) {\n window.PyViz = {comms: {}, comm_status:{}, kernels:{}, receivers: {}, plot_index: []}\n}\n\n\n function JupyterCommManager() {\n }\n\n JupyterCommManager.prototype.register_target = function(plot_id, comm_id, msg_handler) {\n if (window.comm_manager || ((window.Jupyter !== undefined) && (Jupyter.notebook.kernel != null))) {\n var comm_manager = window.comm_manager || Jupyter.notebook.kernel.comm_manager;\n comm_manager.register_target(comm_id, function(comm) {\n comm.on_msg(msg_handler);\n });\n } else if ((plot_id in window.PyViz.kernels) && (window.PyViz.kernels[plot_id])) {\n window.PyViz.kernels[plot_id].registerCommTarget(comm_id, function(comm) {\n comm.onMsg = msg_handler;\n });\n } else if (typeof google != 'undefined' && google.colab.kernel != null) {\n google.colab.kernel.comms.registerTarget(comm_id, (comm) => {\n var messages = comm.messages[Symbol.asyncIterator]();\n function processIteratorResult(result) {\n var message = result.value;\n console.log(message)\n var content = {data: message.data, comm_id};\n var buffers = []\n for (var buffer of message.buffers || []) {\n buffers.push(new DataView(buffer))\n }\n var metadata = message.metadata || {};\n var msg = {content, buffers, metadata}\n msg_handler(msg);\n return messages.next().then(processIteratorResult);\n }\n return messages.next().then(processIteratorResult);\n })\n }\n }\n\n JupyterCommManager.prototype.get_client_comm = function(plot_id, comm_id, msg_handler) {\n if (comm_id in window.PyViz.comms) {\n return window.PyViz.comms[comm_id];\n } else if (window.comm_manager || ((window.Jupyter !== undefined) && (Jupyter.notebook.kernel != null))) {\n var comm_manager = window.comm_manager || Jupyter.notebook.kernel.comm_manager;\n var comm = comm_manager.new_comm(comm_id, {}, {}, {}, comm_id);\n if (msg_handler) {\n comm.on_msg(msg_handler);\n }\n } else if ((plot_id in window.PyViz.kernels) && (window.PyViz.kernels[plot_id])) {\n var comm = window.PyViz.kernels[plot_id].connectToComm(comm_id);\n comm.open();\n if (msg_handler) {\n comm.onMsg = msg_handler;\n }\n } else if (typeof google != 'undefined' && google.colab.kernel != null) {\n var comm_promise = google.colab.kernel.comms.open(comm_id)\n comm_promise.then((comm) => {\n window.PyViz.comms[comm_id] = comm;\n if (msg_handler) {\n var messages = comm.messages[Symbol.asyncIterator]();\n function processIteratorResult(result) {\n var message = result.value;\n var content = {data: message.data};\n var metadata = message.metadata || {comm_id};\n var msg = {content, metadata}\n msg_handler(msg);\n return messages.next().then(processIteratorResult);\n }\n return messages.next().then(processIteratorResult);\n }\n })\n var sendClosure = (data, metadata, buffers, disposeOnDone) => {\n return comm_promise.then((comm) => {\n comm.send(data, metadata, buffers, disposeOnDone);\n });\n };\n var comm = {\n send: sendClosure\n };\n }\n window.PyViz.comms[comm_id] = comm;\n return comm;\n }\n window.PyViz.comm_manager = new JupyterCommManager();\n \n\n\nvar JS_MIME_TYPE = 'application/javascript';\nvar HTML_MIME_TYPE = 'text/html';\nvar EXEC_MIME_TYPE = 'application/vnd.holoviews_exec.v0+json';\nvar CLASS_NAME = 'output';\n\n/**\n * Render data to the DOM node\n */\nfunction render(props, node) {\n var div = document.createElement(\"div\");\n var script = document.createElement(\"script\");\n node.appendChild(div);\n node.appendChild(script);\n}\n\n/**\n * Handle when a new output is added\n */\nfunction handle_add_output(event, handle) {\n var output_area = handle.output_area;\n var output = handle.output;\n if ((output.data == undefined) || (!output.data.hasOwnProperty(EXEC_MIME_TYPE))) {\n return\n }\n var id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n var toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n if (id !== undefined) {\n var nchildren = toinsert.length;\n var html_node = toinsert[nchildren-1].children[0];\n html_node.innerHTML = output.data[HTML_MIME_TYPE];\n var scripts = [];\n var nodelist = html_node.querySelectorAll(\"script\");\n for (var i in nodelist) {\n if (nodelist.hasOwnProperty(i)) {\n scripts.push(nodelist[i])\n }\n }\n\n scripts.forEach( function (oldScript) {\n var newScript = document.createElement(\"script\");\n var attrs = [];\n var nodemap = oldScript.attributes;\n for (var j in nodemap) {\n if (nodemap.hasOwnProperty(j)) {\n attrs.push(nodemap[j])\n }\n }\n attrs.forEach(function(attr) { newScript.setAttribute(attr.name, attr.value) });\n newScript.appendChild(document.createTextNode(oldScript.innerHTML));\n oldScript.parentNode.replaceChild(newScript, oldScript);\n });\n if (JS_MIME_TYPE in output.data) {\n toinsert[nchildren-1].children[1].textContent = output.data[JS_MIME_TYPE];\n }\n output_area._hv_plot_id = id;\n if ((window.Bokeh !== undefined) && (id in Bokeh.index)) {\n window.PyViz.plot_index[id] = Bokeh.index[id];\n } else {\n window.PyViz.plot_index[id] = null;\n }\n } else if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n var bk_div = document.createElement(\"div\");\n bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n var script_attrs = bk_div.children[0].attributes;\n for (var i = 0; i < script_attrs.length; i++) {\n toinsert[toinsert.length - 1].childNodes[1].setAttribute(script_attrs[i].name, script_attrs[i].value);\n }\n // store reference to server id on output_area\n output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n }\n}\n\n/**\n * Handle when an output is cleared or removed\n */\nfunction handle_clear_output(event, handle) {\n var id = handle.cell.output_area._hv_plot_id;\n var server_id = handle.cell.output_area._bokeh_server_id;\n if (((id === undefined) || !(id in PyViz.plot_index)) && (server_id !== undefined)) { return; }\n var comm = window.PyViz.comm_manager.get_client_comm(\"hv-extension-comm\", \"hv-extension-comm\", function () {});\n if (server_id !== null) {\n comm.send({event_type: 'server_delete', 'id': server_id});\n return;\n } else if (comm !== null) {\n comm.send({event_type: 'delete', 'id': id});\n }\n delete PyViz.plot_index[id];\n if ((window.Bokeh !== undefined) & (id in window.Bokeh.index)) {\n var doc = window.Bokeh.index[id].model.document\n doc.clear();\n const i = window.Bokeh.documents.indexOf(doc);\n if (i > -1) {\n window.Bokeh.documents.splice(i, 1);\n }\n }\n}\n\n/**\n * Handle kernel restart event\n */\nfunction handle_kernel_cleanup(event, handle) {\n delete PyViz.comms[\"hv-extension-comm\"];\n window.PyViz.plot_index = {}\n}\n\n/**\n * Handle update_display_data messages\n */\nfunction handle_update_output(event, handle) {\n handle_clear_output(event, {cell: {output_area: handle.output_area}})\n handle_add_output(event, handle)\n}\n\nfunction register_renderer(events, OutputArea) {\n function append_mime(data, metadata, element) {\n // create a DOM node to render to\n var toinsert = this.create_output_subarea(\n metadata,\n CLASS_NAME,\n EXEC_MIME_TYPE\n );\n this.keyboard_manager.register_events(toinsert);\n // Render to node\n var props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n render(props, toinsert[0]);\n element.append(toinsert);\n return toinsert\n }\n\n events.on('output_added.OutputArea', handle_add_output);\n events.on('output_updated.OutputArea', handle_update_output);\n events.on('clear_output.CodeCell', handle_clear_output);\n events.on('delete.Cell', handle_clear_output);\n events.on('kernel_ready.Kernel', handle_kernel_cleanup);\n\n OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n safe: true,\n index: 0\n });\n}\n\nif (window.Jupyter !== undefined) {\n try {\n var events = require('base/js/events');\n var OutputArea = require('notebook/js/outputarea').OutputArea;\n if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n register_renderer(events, OutputArea);\n }\n } catch(err) {\n }\n}\n", + "application/vnd.holoviews_load.v0+json": "" + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.holoviews_exec.v0+json": "", + "text/html": [ + "
\n", + "
\n", + "
\n", + "" + ] + }, + "metadata": { + "application/vnd.holoviews_exec.v0+json": { + "id": "ab1091ca-8b36-4f77-a0d9-13cec3cd5eda" + } + }, + "output_type": "display_data" + } + ], + "source": [ + "# PeakFit_analysis csv data reading\n", + "import pandas as pd\n", + "import numpy as np\n", + "\n", + "import altair as alt\n", + "import panel as pn\n", + "import plotly.graph_objects as go\n", + "import plotly.express as px\n", + "pn.extension('plotly')\n", + "ACCENT = \"teal\"\n" + ] + }, + { + "cell_type": "code", + "execution_count": 82, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
DateTimeItem IDCategoryResponsible StaffExpected QuantityActual QuantityExpired ItemsReturned ItemsItems Out for SalesItems Out for Quality ControlItems Out for Events
802024-01-01EveningITM003CTG003Andrew Cauchi34314371012
1712024-01-01EveningITM005CTG003Jean-Pierre Ellul4744427912
5562024-01-01EveningITM005CTG003Andrew Cauchi5253526912
9322024-01-01AfternoonITM003CTG003Aaron Vella4137537912
18712024-01-01MorningITM006CTG001Aaron Vella44394361012
\n", + "
" + ], + "text/plain": [ + " Date Time Item ID Category Responsible Staff \\\n", + "80 2024-01-01 Evening ITM003 CTG003 Andrew Cauchi \n", + "171 2024-01-01 Evening ITM005 CTG003 Jean-Pierre Ellul \n", + "556 2024-01-01 Evening ITM005 CTG003 Andrew Cauchi \n", + "932 2024-01-01 Afternoon ITM003 CTG003 Aaron Vella \n", + "1871 2024-01-01 Morning ITM006 CTG001 Aaron Vella \n", + "\n", + " Expected Quantity Actual Quantity Expired Items Returned Items \\\n", + "80 34 31 4 3 \n", + "171 47 44 4 2 \n", + "556 52 53 5 2 \n", + "932 41 37 5 3 \n", + "1871 44 39 4 3 \n", + "\n", + " Items Out for Sales Items Out for Quality Control Items Out for Events \n", + "80 7 10 12 \n", + "171 7 9 12 \n", + "556 6 9 12 \n", + "932 7 9 12 \n", + "1871 6 10 12 " + ] + }, + "execution_count": 82, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df = pd.read_excel(r'D:\\K_REPO\\Depi_freelanceYard\\PeakFit Essentials.xlsx',sheet_name='Sheet1')\n", + "df.sort_values(by=\"Date\").head(5)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 2. Clean the data " + ] + }, + { + "cell_type": "code", + "execution_count": 83, + "metadata": {}, + "outputs": [], + "source": [ + "#drop unusfull columns\n", + "df = df.drop(columns=['Expired Items','Returned Items','Items Out for Sales','Items Out for Quality Control','Items Out for Events'])" + ] + }, + { + "cell_type": "code", + "execution_count": 84, + "metadata": {}, + "outputs": [], + "source": [ + "df[\"Date\"] = pd.to_datetime(df[\"Date\"], format=\"%Y-%m-%d\")" + ] + }, + { + "cell_type": "code", + "execution_count": 85, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "42\n" + ] + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
DateTimeItem IDCategoryResponsible StaffInventory Discrepancy
02024-05-29EveningITM006CTG001Robert Tabone-4
12024-08-23AfternoonITM004CTG001Simon Fenech-5
22024-05-12EveningITM001CTG001Jean-Pierre Ellul0
32024-03-27EveningITM003CTG003Andrew Cauchi-4
42024-09-24EveningITM002CTG002Robert Tabone2
\n", + "
" + ], + "text/plain": [ + " Date Time Item ID Category Responsible Staff \\\n", + "0 2024-05-29 Evening ITM006 CTG001 Robert Tabone \n", + "1 2024-08-23 Afternoon ITM004 CTG001 Simon Fenech \n", + "2 2024-05-12 Evening ITM001 CTG001 Jean-Pierre Ellul \n", + "3 2024-03-27 Evening ITM003 CTG003 Andrew Cauchi \n", + "4 2024-09-24 Evening ITM002 CTG002 Robert Tabone \n", + "\n", + " Inventory Discrepancy \n", + "0 -4 \n", + "1 -5 \n", + "2 0 \n", + "3 -4 \n", + "4 2 " + ] + }, + "execution_count": 85, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#replace expected & actual with stocked quantity\n", + "#make column for Inventory Discrepancy\n", + "df['Inventory Discrepancy'] = df['Actual Quantity'] - df['Expected Quantity']\n", + "df = df.drop(columns=['Expected Quantity',\t'Actual Quantity' ])\n", + "print(df['Inventory Discrepancy'].sum()) #total Inventory Discrepancy in 10 monthes [ -N : missing , +N more than expeted ] \n", + "df.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 86, + "metadata": {}, + "outputs": [], + "source": [ + "df['Month'] = df['Date'].dt.month_name()\n" + ] + }, + { + "cell_type": "code", + "execution_count": 87, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "42\n" + ] + } + ], + "source": [ + "print(df['Inventory Discrepancy'].sum())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### the new data discription" + ] + }, + { + "cell_type": "code", + "execution_count": 88, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "RangeIndex: 2000 entries, 0 to 1999\n", + "Data columns (total 7 columns):\n", + " # Column Non-Null Count Dtype \n", + "--- ------ -------------- ----- \n", + " 0 Date 2000 non-null datetime64[ns]\n", + " 1 Time 2000 non-null object \n", + " 2 Item ID 2000 non-null object \n", + " 3 Category 2000 non-null object \n", + " 4 Responsible Staff 2000 non-null object \n", + " 5 Inventory Discrepancy 2000 non-null int64 \n", + " 6 Month 2000 non-null object \n", + "dtypes: datetime64[ns](1), int64(1), object(5)\n", + "memory usage: 109.5+ KB\n" + ] + } + ], + "source": [ + "df.info()" + ] + }, + { + "cell_type": "code", + "execution_count": 89, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
DateTimeItem IDCategoryResponsible StaffInventory DiscrepancyMonth
count200020002000200020002000.000002000
uniqueNaN3636NaN9
topNaNMorningITM001CTG001Jean-Pierre EllulNaNMarch
freqNaN6793591011368NaN247
mean2024-05-16 21:35:16.800000256NaNNaNNaNNaN0.02100NaN
min2024-01-01 00:00:00NaNNaNNaNNaN-5.00000NaN
25%2024-03-09 00:00:00NaNNaNNaNNaN-3.00000NaN
50%2024-05-17 12:00:00NaNNaNNaNNaN0.00000NaN
75%2024-07-25 00:00:00NaNNaNNaNNaN3.00000NaN
max2024-09-30 00:00:00NaNNaNNaNNaN5.00000NaN
stdNaNNaNNaNNaNNaN3.13472NaN
\n", + "
" + ], + "text/plain": [ + " Date Time Item ID Category \\\n", + "count 2000 2000 2000 2000 \n", + "unique NaN 3 6 3 \n", + "top NaN Morning ITM001 CTG001 \n", + "freq NaN 679 359 1011 \n", + "mean 2024-05-16 21:35:16.800000256 NaN NaN NaN \n", + "min 2024-01-01 00:00:00 NaN NaN NaN \n", + "25% 2024-03-09 00:00:00 NaN NaN NaN \n", + "50% 2024-05-17 12:00:00 NaN NaN NaN \n", + "75% 2024-07-25 00:00:00 NaN NaN NaN \n", + "max 2024-09-30 00:00:00 NaN NaN NaN \n", + "std NaN NaN NaN NaN \n", + "\n", + " Responsible Staff Inventory Discrepancy Month \n", + "count 2000 2000.00000 2000 \n", + "unique 6 NaN 9 \n", + "top Jean-Pierre Ellul NaN March \n", + "freq 368 NaN 247 \n", + "mean NaN 0.02100 NaN \n", + "min NaN -5.00000 NaN \n", + "25% NaN -3.00000 NaN \n", + "50% NaN 0.00000 NaN \n", + "75% NaN 3.00000 NaN \n", + "max NaN 5.00000 NaN \n", + "std NaN 3.13472 NaN " + ] + }, + "execution_count": 89, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.describe(include='all')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Date started 2024-01-01 ended 2024-09-30 with 2000 record .\n", + "\n", + "time 3 shifts per day (morning, afternoon, evening).\n", + "\n", + "item ID are only 6 items (Dumbbells, Yoga Mat, Resistance Bands, Protein Powder, Foam Roller, Kettlebells).\n", + "\n", + "category are only 3 items , but 4 in category sheet (Strength Training Equipment, fitness accessories, strength training equipment). there is an issue (miss leading inputs)\n", + "\n", + "responsible staff are only 6 (['Robert Tabone', 'Simon Fenech', 'Jean-Pierre Ellul','Andrew Cauchi', 'Aaron Vella', 'Franklin Attard']).\n", + "\n", + "and no nulls in the data\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 90, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array(['CTG001', 'CTG003', 'CTG002', 'CTG004'], dtype=object)" + ] + }, + "execution_count": 90, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# fixing category\n", + "# assinge ITM001 , ITM003 , ITM006 to ctg001 as they all strength training Items\n", + "df.loc[df['Item ID'].isin(['ITM001', 'ITM003', 'ITM006']), 'Category'] = 'CTG001'\n", + "\n", + "# assinge ITM004 as CTG004 ( protein poweder is supplements )\n", + "df.loc[df[\"Item ID\"].isin([\"ITM004\"]), \"Category\"]= \"CTG003\"\n", + "\n", + "#assinge ITM005 as CTG005 (foam rollers are recovery tools)\n", + "df.loc[df[\"Item ID\"].isin([\"ITM005\"]), \"Category\"]=\"CTG004\"\n", + "\n", + "df['Category'].unique()\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 3. Data proccessing" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### calender heatmap (Heat_fig) ####" + ] + }, + { + "cell_type": "code", + "execution_count": 91, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
DayMonthInventory Discrepancy
01April5
11August0
21February9
31January-13
41July-1
\n", + "
" + ], + "text/plain": [ + " Day Month Inventory Discrepancy\n", + "0 1 April 5\n", + "1 1 August 0\n", + "2 1 February 9\n", + "3 1 January -13\n", + "4 1 July -1" + ] + }, + "execution_count": 91, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Convert DateTime to datetime format\n", + "df['DateTime'] = pd.to_datetime(df['Date'])\n", + "\n", + "# Extract Month and Day\n", + "df['Month'] = df['DateTime'].dt.strftime('%B') # Month name\n", + "df['Day'] = df['DateTime'].dt.day # Day of month\n", + "\n", + "# Aggregate data by Day and Month (sum of Inventory Discrepancy)\n", + "df_agg = df.groupby(['Day', 'Month'])['Inventory Discrepancy'].sum().reset_index()\n", + "\n", + "# Create pivot table for heatmap\n", + "heatmap_data = df_agg.pivot(index='Day', columns='Month', values='Inventory Discrepancy')\n", + "\n", + "# Fill NaN values with 0 (days with no Inventory Discrepancy)\n", + "heatmap_data = heatmap_data.fillna(0)\n", + "\n", + "# Define month order for proper sorting\n", + "month_order = [\"January\", \"February\", \"March\", \"April\", \"May\", \"June\", \n", + " \"July\", \"August\", \"September\", \"October\"]\n", + "\n", + "# Filter to only include months that are in our data\n", + "available_months = [month for month in month_order if month in heatmap_data.columns]\n", + "heatmap_data = heatmap_data.reindex(columns=available_months)\n", + "df_agg.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 92, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.plotly.v1+json": { + "config": { + "plotlyServerURL": "https://plot.ly" + }, + "data": [ + { + "coloraxis": "coloraxis", + "hovertemplate": "Month: %{x}
Day: %{y}
Inventory Discrepancy: %{z}", + "name": "0", + "texttemplate": "%{z}", + "type": "heatmap", + "x": [ + "January", + "February", + "March", + "April", + "May", + "June", + "July", + "August", + "September" + ], + "xaxis": "x", + "y": { + "bdata": "AQAAAAIAAAADAAAABAAAAAUAAAAGAAAABwAAAAgAAAAJAAAACgAAAAsAAAAMAAAADQAAAA4AAAAPAAAAEAAAABEAAAASAAAAEwAAABQAAAAVAAAAFgAAABcAAAAYAAAAGQAAABoAAAAbAAAAHAAAAB0AAAAeAAAAHwAAAA==", + "dtype": "i4" + }, + "yaxis": "y", + "z": { + "bdata": "AAAAAAAAKsAAAAAAAAAiQAAAAAAAACTAAAAAAAAAFEAAAAAAAAAIQAAAAAAAABDAAAAAAAAA8L8AAAAAAAAAAAAAAAAAACrAAAAAAAAACMAAAAAAAAAYwAAAAAAAADZAAAAAAAAAFMAAAAAAAAAgwAAAAAAAAADAAAAAAAAAGMAAAAAAAAAkwAAAAAAAACbAAAAAAAAA8L8AAAAAAAAmQAAAAAAAABhAAAAAAAAAFEAAAAAAAAAAAAAAAAAAACDAAAAAAAAAAEAAAAAAAAA3wAAAAAAAACzAAAAAAAAAFEAAAAAAAAAAQAAAAAAAABxAAAAAAAAALsAAAAAAAAAgQAAAAAAAABTAAAAAAAAAJsAAAAAAAADwPwAAAAAAACZAAAAAAAAAGMAAAAAAAAAmQAAAAAAAACbAAAAAAAAAJEAAAAAAAAAQQAAAAAAAACRAAAAAAAAA8D8AAAAAAAAYwAAAAAAAAABAAAAAAAAA8L8AAAAAAADwPwAAAAAAACpAAAAAAAAA8D8AAAAAAAAUwAAAAAAAAAAAAAAAAAAAEEAAAAAAAAAiwAAAAAAAABTAAAAAAAAAEEAAAAAAAAAUQAAAAAAAACbAAAAAAAAAHMAAAAAAAAAqwAAAAAAAACZAAAAAAAAA8D8AAAAAAAAIwAAAAAAAABzAAAAAAAAAEMAAAAAAAAAzwAAAAAAAABxAAAAAAAAA8L8AAAAAAAAAQAAAAAAAABRAAAAAAAAAHMAAAAAAAAAUQAAAAAAAABRAAAAAAAAAKsAAAAAAAAAIQAAAAAAAAC7AAAAAAAAACMAAAAAAAADwPwAAAAAAACpAAAAAAAAAIMAAAAAAAAAzQAAAAAAAAPA/AAAAAAAA8L8AAAAAAAAIQAAAAAAAAADAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAhAAAAAAAAAJkAAAAAAAAAAAAAAAAAAACrAAAAAAAAA8D8AAAAAAAAiQAAAAAAAABjAAAAAAAAAAAAAAAAAAAAoQAAAAAAAACpAAAAAAAAAHMAAAAAAAAAoQAAAAAAAABTAAAAAAAAAKEAAAAAAAAAgwAAAAAAAAPC/AAAAAAAAAMAAAAAAAAAYQAAAAAAAABzAAAAAAAAAEEAAAAAAAAAYQAAAAAAAABDAAAAAAAAA8D8AAAAAAADwvwAAAAAAABjAAAAAAAAACMAAAAAAAAAiQAAAAAAAADHAAAAAAAAACEAAAAAAAADwPwAAAAAAAPC/AAAAAAAAHMAAAAAAAAAwQAAAAAAAAAjAAAAAAAAACEAAAAAAAAAmwAAAAAAAAAjAAAAAAAAAJsAAAAAAAAAiwAAAAAAAABRAAAAAAAAAAMAAAAAAAAAcQAAAAAAAAAhAAAAAAAAAAEAAAAAAAAAkQAAAAAAAAPA/AAAAAAAAAEAAAAAAAAAAQAAAAAAAAABAAAAAAAAAAAAAAAAAAAAUwAAAAAAAABzAAAAAAAAAAAAAAAAAAAAUwAAAAAAAACDAAAAAAAAACEAAAAAAAAAQQAAAAAAAACZAAAAAAAAACMAAAAAAAAAkwAAAAAAAABDAAAAAAAAAIsAAAAAAAAAmQAAAAAAAAABAAAAAAAAANUAAAAAAAAAgwAAAAAAAAPC/AAAAAAAAAEAAAAAAAAAowAAAAAAAACbAAAAAAAAAEMAAAAAAAAAgQAAAAAAAABRAAAAAAAAAAMAAAAAAAAAgwAAAAAAAABhAAAAAAAAAJMAAAAAAAAAQwAAAAAAAADBAAAAAAAAAAMAAAAAAAAAYQAAAAAAAACpAAAAAAAAACMAAAAAAAAAQwAAAAAAAAChAAAAAAAAAIMAAAAAAAAAAQAAAAAAAABBAAAAAAAAAIsAAAAAAAAAIwAAAAAAAAABAAAAAAAAAAMAAAAAAAAAYQAAAAAAAABzAAAAAAAAACMAAAAAAAAAAwAAAAAAAAADAAAAAAAAACMAAAAAAAAAIQAAAAAAAACZAAAAAAAAA8L8AAAAAAAAUQAAAAAAAAABAAAAAAAAAAMAAAAAAAAAcQAAAAAAAAADAAAAAAAAACEAAAAAAAAAAwAAAAAAAABRAAAAAAAAA8D8AAAAAAAAYQAAAAAAAACZAAAAAAAAACMAAAAAAAAAIwAAAAAAAACTAAAAAAAAAFEAAAAAAAAAsQAAAAAAAAADAAAAAAAAAEEAAAAAAAAAxwAAAAAAAADlAAAAAAAAACEAAAAAAAAAkwAAAAAAAACpAAAAAAAAAEEAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAGMAAAAAAAAAiQAAAAAAAACbAAAAAAAAACEAAAAAAAAAAwAAAAAAAABRAAAAAAAAAAAAAAAAAAAAYQAAAAAAAAAjAAAAAAAAAP0AAAAAAAAAcwAAAAAAAABhAAAAAAAAAAEAAAAAAAAAQwAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAAAAAACrAAAAAAAAAIMAAAAAAAAAAQAAAAAAAABTAAAAAAAAAAEAAAAAAAAAAwAAAAAAAABDAAAAAAAAAEMAAAAAAAAAqQAAAAAAAACBAAAAAAAAAEEAAAAAAAAAYwAAAAAAAAAjAAAAAAAAAMkAAAAAAAAAiwAAAAAAAABjAAAAAAAAAJEAAAAAAAAAIQAAAAAAAADBAAAAAAAAAAEAAAAAAAAAAwAAAAAAAAABAAAAAAAAAKsAAAAAAAAAAwAAAAAAAAABAAAAAAAAACEAAAAAAAAAgwAAAAAAAAABAAAAAAAAAKEAAAAAAAAAowAAAAAAAAADAAAAAAAAAIsAAAAAAAAAAAAAAAAAAAPA/AAAAAAAAIsAAAAAAAAA3wAAAAAAAABRAAAAAAAAAEEAAAAAAAAAoQAAAAAAAAABAAAAAAAAAGEAAAAAAAAAAAAAAAAAAAPA/AAAAAAAAAAAAAAAAAAA3QAAAAAAAAAAAAAAAAAAAKEAAAAAAAAAcwAAAAAAAAAAA", + "dtype": "f8", + "shape": "31, 9" + } + } + ], + "layout": { + "coloraxis": { + "colorbar": { + "title": { + "text": "Inventory Discrepancy" + } + }, + "colorscale": [ + [ + 0, + "rgb(103,0,31)" + ], + [ + 0.1, + "rgb(178,24,43)" + ], + [ + 0.2, + "rgb(214,96,77)" + ], + [ + 0.3, + "rgb(244,165,130)" + ], + [ + 0.4, + "rgb(253,219,199)" + ], + [ + 0.5, + "rgb(247,247,247)" + ], + [ + 0.6, + "rgb(209,229,240)" + ], + [ + 0.7, + "rgb(146,197,222)" + ], + [ + 0.8, + "rgb(67,147,195)" + ], + [ + 0.9, + "rgb(33,102,172)" + ], + [ + 1, + "rgb(5,48,97)" + ] + ] + }, + "font": { + "color": "black" + }, + "height": 600, + "margin": { + "t": 60 + }, + "paper_bgcolor": "white", + "plot_bgcolor": "black", + "template": { + "data": { + "bar": [ + { + "error_x": { + "color": "#2a3f5f" + }, + "error_y": { + "color": "#2a3f5f" + }, + "marker": { + "line": { + "color": "#E5ECF6", + "width": 0.5 + }, + "pattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + } + }, + "type": "bar" + } + ], + "barpolar": [ + { + "marker": { + "line": { + "color": "#E5ECF6", + "width": 0.5 + }, + "pattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + } + }, + "type": "barpolar" + } + ], + "carpet": [ + { + "aaxis": { + "endlinecolor": "#2a3f5f", + "gridcolor": "white", + "linecolor": "white", + "minorgridcolor": "white", + "startlinecolor": "#2a3f5f" + }, + "baxis": { + "endlinecolor": "#2a3f5f", + "gridcolor": "white", + "linecolor": "white", + "minorgridcolor": "white", + "startlinecolor": "#2a3f5f" + }, + "type": "carpet" + } + ], + "choropleth": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "type": "choropleth" + } + ], + "contour": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "contour" + } + ], + "contourcarpet": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "type": "contourcarpet" + } + ], + "heatmap": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "heatmap" + } + ], + "histogram": [ + { + "marker": { + "pattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + } + }, + "type": "histogram" + } + ], + "histogram2d": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "histogram2d" + } + ], + "histogram2dcontour": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "histogram2dcontour" + } + ], + "mesh3d": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "type": "mesh3d" + } + ], + "parcoords": [ + { + "line": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "parcoords" + } + ], + "pie": [ + { + "automargin": true, + "type": "pie" + } + ], + "scatter": [ + { + "fillpattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + }, + "type": "scatter" + } + ], + "scatter3d": [ + { + "line": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatter3d" + } + ], + "scattercarpet": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattercarpet" + } + ], + "scattergeo": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattergeo" + } + ], + "scattergl": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattergl" + } + ], + "scattermap": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattermap" + } + ], + "scattermapbox": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattermapbox" + } + ], + "scatterpolar": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatterpolar" + } + ], + "scatterpolargl": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatterpolargl" + } + ], + "scatterternary": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatterternary" + } + ], + "surface": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "surface" + } + ], + "table": [ + { + "cells": { + "fill": { + "color": "#EBF0F8" + }, + "line": { + "color": "white" + } + }, + "header": { + "fill": { + "color": "#C8D4E3" + }, + "line": { + "color": "white" + } + }, + "type": "table" + } + ] + }, + "layout": { + "annotationdefaults": { + "arrowcolor": "#2a3f5f", + "arrowhead": 0, + "arrowwidth": 1 + }, + "autotypenumbers": "strict", + "coloraxis": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "colorscale": { + "diverging": [ + [ + 0, + "#8e0152" + ], + [ + 0.1, + "#c51b7d" + ], + [ + 0.2, + "#de77ae" + ], + [ + 0.3, + "#f1b6da" + ], + [ + 0.4, + "#fde0ef" + ], + [ + 0.5, + "#f7f7f7" + ], + [ + 0.6, + "#e6f5d0" + ], + [ + 0.7, + "#b8e186" + ], + [ + 0.8, + "#7fbc41" + ], + [ + 0.9, + "#4d9221" + ], + [ + 1, + "#276419" + ] + ], + "sequential": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "sequentialminus": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ] + }, + "colorway": [ + "#636efa", + "#EF553B", + "#00cc96", + "#ab63fa", + "#FFA15A", + "#19d3f3", + "#FF6692", + "#B6E880", + "#FF97FF", + "#FECB52" + ], + "font": { + "color": "#2a3f5f" + }, + "geo": { + "bgcolor": "white", + "lakecolor": "white", + "landcolor": "#E5ECF6", + "showlakes": true, + "showland": true, + "subunitcolor": "white" + }, + "hoverlabel": { + "align": "left" + }, + "hovermode": "closest", + "mapbox": { + "style": "light" + }, + "paper_bgcolor": "white", + "plot_bgcolor": "#E5ECF6", + "polar": { + "angularaxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + }, + "bgcolor": "#E5ECF6", + "radialaxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + } + }, + "scene": { + "xaxis": { + "backgroundcolor": "#E5ECF6", + "gridcolor": "white", + "gridwidth": 2, + "linecolor": "white", + "showbackground": true, + "ticks": "", + "zerolinecolor": "white" + }, + "yaxis": { + "backgroundcolor": "#E5ECF6", + "gridcolor": "white", + "gridwidth": 2, + "linecolor": "white", + "showbackground": true, + "ticks": "", + "zerolinecolor": "white" + }, + "zaxis": { + "backgroundcolor": "#E5ECF6", + "gridcolor": "white", + "gridwidth": 2, + "linecolor": "white", + "showbackground": true, + "ticks": "", + "zerolinecolor": "white" + } + }, + "shapedefaults": { + "line": { + "color": "#2a3f5f" + } + }, + "ternary": { + "aaxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + }, + "baxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + }, + "bgcolor": "#E5ECF6", + "caxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + } + }, + "title": { + "x": 0.05 + }, + "xaxis": { + "automargin": true, + "gridcolor": "white", + "linecolor": "white", + "ticks": "", + "title": { + "standoff": 15 + }, + "zerolinecolor": "white", + "zerolinewidth": 2 + }, + "yaxis": { + "automargin": true, + "gridcolor": "white", + "linecolor": "white", + "ticks": "", + "title": { + "standoff": 15 + }, + "zerolinecolor": "white", + "zerolinewidth": 2 + } + } + }, + "title": { + "text": "Inventory Discrepancy/day Heatmap" + }, + "width": 700, + "xaxis": { + "anchor": "y", + "constrain": "domain", + "domain": [ + 0, + 1 + ], + "scaleanchor": "y", + "title": { + "text": "Month" + } + }, + "yaxis": { + "anchor": "x", + "autorange": false, + "constrain": "domain", + "domain": [ + 0, + 1 + ], + "range": [ + 1, + 31 + ], + "title": { + "text": "Day of Month" + } + } + } + } + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "\n", + "# Create the heatmap\n", + "Heat_fig = px.imshow(\n", + " heatmap_data.values,\n", + " labels=dict(x=\"Month\", y=\"Day\", color=\"Inventory Discrepancy\"),\n", + " x=heatmap_data.columns,\n", + " y=heatmap_data.index,\n", + " color_continuous_scale=\"RdBu\", # Changed to Reds as Inventory Discrepancy are positive now\n", + " text_auto=True # Display values in the cells\n", + ")\n", + "\n", + "Heat_fig.update_layout(\n", + " title=\"Inventory Discrepancy/day Heatmap\",\n", + " xaxis_title=\"Month\",\n", + " yaxis_title=\"Day of Month\",\n", + "\n", + " yaxis=dict(\n", + " range=[1, 31], # Explicitly reverse the order (assuming max day is 31)\n", + " autorange=False # Disable automatic range adjustment\n", + " ), # Keep day labels in correct order\n", + " \n", + " width=700, # Set width\n", + " height=600, # Set height\n", + " plot_bgcolor=\"black\", # Set plot background to black\n", + " paper_bgcolor=\"white\", # Set entire figure background to black\n", + " font=dict(color=\"black\") # Set text color to white for contrast\n", + " \n", + ")\n", + "\n", + "# To display the figure\n", + "\n", + "Heat_fig" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#made a calnder as heatmap, and found :\n", + "\n", + "at (25/07) 31 unexpected item found \n", + "\n", + "at (30/05) & 03/08 highest missing record at -23 item " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### by weekday (Bar_fig)" + ] + }, + { + "cell_type": "code", + "execution_count": 93, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
DateTimeItem IDCategoryResponsible StaffInventory DiscrepancyMonthDateTimeDayWeekday
02024-05-29EveningITM006CTG001Robert Tabone-4May2024-05-2929Wednesday
12024-08-23AfternoonITM004CTG003Simon Fenech-5August2024-08-2323Friday
22024-05-12EveningITM001CTG001Jean-Pierre Ellul0May2024-05-1212Sunday
32024-03-27EveningITM003CTG001Andrew Cauchi-4March2024-03-2727Wednesday
42024-09-24EveningITM002CTG002Robert Tabone2September2024-09-2424Tuesday
\n", + "
" + ], + "text/plain": [ + " Date Time Item ID Category Responsible Staff \\\n", + "0 2024-05-29 Evening ITM006 CTG001 Robert Tabone \n", + "1 2024-08-23 Afternoon ITM004 CTG003 Simon Fenech \n", + "2 2024-05-12 Evening ITM001 CTG001 Jean-Pierre Ellul \n", + "3 2024-03-27 Evening ITM003 CTG001 Andrew Cauchi \n", + "4 2024-09-24 Evening ITM002 CTG002 Robert Tabone \n", + "\n", + " Inventory Discrepancy Month DateTime Day Weekday \n", + "0 -4 May 2024-05-29 29 Wednesday \n", + "1 -5 August 2024-08-23 23 Friday \n", + "2 0 May 2024-05-12 12 Sunday \n", + "3 -4 March 2024-03-27 27 Wednesday \n", + "4 2 September 2024-09-24 24 Tuesday " + ] + }, + "execution_count": 93, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Extract weekday name\n", + "df[\"Weekday\"] = df[\"Date\"].dt.day_name()\n", + "# Group by weekday and sum Inventory Discrepancy\n", + "df_grouped = df.groupby(\"Weekday\")[\"Inventory Discrepancy\"].sum().reset_index()\n", + "# Define weekday order\n", + "weekday_order = [\"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"Sunday\"]\n", + "# Create a category type with our custom order\n", + "df_grouped[\"Weekday\"] = pd.Categorical(df_grouped[\"Weekday\"], categories=weekday_order, ordered=True)\n", + "\n", + "# Sort by our ordered category\n", + "df_grouped = df_grouped.sort_values(\"Weekday\")\n", + "\n", + "# # Create color sequence to match your original\n", + "# colors = [\"skyblue\", \"orange\", \"green\", \"red\", \"purple\", \"pink\", \"brown\"]\n", + "\n", + "df.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 94, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.plotly.v1+json": { + "config": { + "plotlyServerURL": "https://plot.ly" + }, + "data": [ + { + "hovertemplate": "Day of the Week=%{x}
Total Inventory Discrepancy=%{marker.color}", + "legendgroup": "", + "marker": { + "color": { + "bdata": "DKJQ2TT1Kg==", + "dtype": "i1" + }, + "coloraxis": "coloraxis", + "pattern": { + "shape": "" + } + }, + "name": "", + "orientation": "v", + "showlegend": false, + "textposition": "auto", + "type": "bar", + "x": [ + "Monday", + "Tuesday", + "Wednesday", + "Thursday", + "Friday", + "Saturday", + "Sunday" + ], + "xaxis": "x", + "y": { + "bdata": "DKJQ2TT1Kg==", + "dtype": "i1" + }, + "yaxis": "y" + } + ], + "layout": { + "barmode": "relative", + "coloraxis": { + "colorbar": { + "title": { + "text": "Total Inventory Discrepancy" + } + }, + "colorscale": [ + [ + 0, + "red" + ], + [ + 1, + "blue" + ] + ] + }, + "font": { + "color": "white" + }, + "legend": { + "tracegroupgap": 0 + }, + "paper_bgcolor": "black", + "plot_bgcolor": "black", + "template": { + "data": { + "bar": [ + { + "error_x": { + "color": "#2a3f5f" + }, + "error_y": { + "color": "#2a3f5f" + }, + "marker": { + "line": { + "color": "#E5ECF6", + "width": 0.5 + }, + "pattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + } + }, + "type": "bar" + } + ], + "barpolar": [ + { + "marker": { + "line": { + "color": "#E5ECF6", + "width": 0.5 + }, + "pattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + } + }, + "type": "barpolar" + } + ], + "carpet": [ + { + "aaxis": { + "endlinecolor": "#2a3f5f", + "gridcolor": "white", + "linecolor": "white", + "minorgridcolor": "white", + "startlinecolor": "#2a3f5f" + }, + "baxis": { + "endlinecolor": "#2a3f5f", + "gridcolor": "white", + "linecolor": "white", + "minorgridcolor": "white", + "startlinecolor": "#2a3f5f" + }, + "type": "carpet" + } + ], + "choropleth": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "type": "choropleth" + } + ], + "contour": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "contour" + } + ], + "contourcarpet": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "type": "contourcarpet" + } + ], + "heatmap": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "heatmap" + } + ], + "histogram": [ + { + "marker": { + "pattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + } + }, + "type": "histogram" + } + ], + "histogram2d": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "histogram2d" + } + ], + "histogram2dcontour": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "histogram2dcontour" + } + ], + "mesh3d": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "type": "mesh3d" + } + ], + "parcoords": [ + { + "line": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "parcoords" + } + ], + "pie": [ + { + "automargin": true, + "type": "pie" + } + ], + "scatter": [ + { + "fillpattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + }, + "type": "scatter" + } + ], + "scatter3d": [ + { + "line": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatter3d" + } + ], + "scattercarpet": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattercarpet" + } + ], + "scattergeo": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattergeo" + } + ], + "scattergl": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattergl" + } + ], + "scattermap": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattermap" + } + ], + "scattermapbox": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattermapbox" + } + ], + "scatterpolar": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatterpolar" + } + ], + "scatterpolargl": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatterpolargl" + } + ], + "scatterternary": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatterternary" + } + ], + "surface": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "surface" + } + ], + "table": [ + { + "cells": { + "fill": { + "color": "#EBF0F8" + }, + "line": { + "color": "white" + } + }, + "header": { + "fill": { + "color": "#C8D4E3" + }, + "line": { + "color": "white" + } + }, + "type": "table" + } + ] + }, + "layout": { + "annotationdefaults": { + "arrowcolor": "#2a3f5f", + "arrowhead": 0, + "arrowwidth": 1 + }, + "autotypenumbers": "strict", + "coloraxis": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "colorscale": { + "diverging": [ + [ + 0, + "#8e0152" + ], + [ + 0.1, + "#c51b7d" + ], + [ + 0.2, + "#de77ae" + ], + [ + 0.3, + "#f1b6da" + ], + [ + 0.4, + "#fde0ef" + ], + [ + 0.5, + "#f7f7f7" + ], + [ + 0.6, + "#e6f5d0" + ], + [ + 0.7, + "#b8e186" + ], + [ + 0.8, + "#7fbc41" + ], + [ + 0.9, + "#4d9221" + ], + [ + 1, + "#276419" + ] + ], + "sequential": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "sequentialminus": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ] + }, + "colorway": [ + "#636efa", + "#EF553B", + "#00cc96", + "#ab63fa", + "#FFA15A", + "#19d3f3", + "#FF6692", + "#B6E880", + "#FF97FF", + "#FECB52" + ], + "font": { + "color": "#2a3f5f" + }, + "geo": { + "bgcolor": "white", + "lakecolor": "white", + "landcolor": "#E5ECF6", + "showlakes": true, + "showland": true, + "subunitcolor": "white" + }, + "hoverlabel": { + "align": "left" + }, + "hovermode": "closest", + "mapbox": { + "style": "light" + }, + "paper_bgcolor": "white", + "plot_bgcolor": "#E5ECF6", + "polar": { + "angularaxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + }, + "bgcolor": "#E5ECF6", + "radialaxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + } + }, + "scene": { + "xaxis": { + "backgroundcolor": "#E5ECF6", + "gridcolor": "white", + "gridwidth": 2, + "linecolor": "white", + "showbackground": true, + "ticks": "", + "zerolinecolor": "white" + }, + "yaxis": { + "backgroundcolor": "#E5ECF6", + "gridcolor": "white", + "gridwidth": 2, + "linecolor": "white", + "showbackground": true, + "ticks": "", + "zerolinecolor": "white" + }, + "zaxis": { + "backgroundcolor": "#E5ECF6", + "gridcolor": "white", + "gridwidth": 2, + "linecolor": "white", + "showbackground": true, + "ticks": "", + "zerolinecolor": "white" + } + }, + "shapedefaults": { + "line": { + "color": "#2a3f5f" + } + }, + "ternary": { + "aaxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + }, + "baxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + }, + "bgcolor": "#E5ECF6", + "caxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + } + }, + "title": { + "x": 0.05 + }, + "xaxis": { + "automargin": true, + "gridcolor": "white", + "linecolor": "white", + "ticks": "", + "title": { + "standoff": 15 + }, + "zerolinecolor": "white", + "zerolinewidth": 2 + }, + "yaxis": { + "automargin": true, + "gridcolor": "white", + "linecolor": "white", + "ticks": "", + "title": { + "standoff": 15 + }, + "zerolinecolor": "white", + "zerolinewidth": 2 + } + } + }, + "title": { + "text": "Inventory Discrepancy by Day of the Week" + }, + "xaxis": { + "anchor": "y", + "domain": [ + 0, + 1 + ], + "title": { + "text": "Day of the Week" + } + }, + "yaxis": { + "anchor": "x", + "domain": [ + 0, + 1 + ], + "gridcolor": "rgba(255,255,255,0.2)", + "gridwidth": 1, + "showgrid": true, + "title": { + "text": "Total Inventory Discrepancy" + } + } + } + } + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "# Create the bar chart\n", + "Bar_fig = px.bar(\n", + " df_grouped,\n", + " x=\"Weekday\",\n", + " y=\"Inventory Discrepancy\",\n", + " title=\"Inventory Discrepancy by Day of the Week\",\n", + " color=\"Inventory Discrepancy\", # Color by value\n", + " color_continuous_scale=['red', 'blue'], # Red for negative, blue for positive\n", + " labels={\"Weekday\": \"Day of the Week\", \"Inventory Discrepancy\": \"Total Inventory Discrepancy\"}\n", + ")\n", + "\n", + "# Update layout for dark background\n", + "Bar_fig.update_layout(\n", + " plot_bgcolor=\"black\", # Set plot background to black\n", + " paper_bgcolor=\"black\", # Set entire figure background to black\n", + " font=dict(color=\"white\") # Set text color to white for contrast\n", + ")\n", + "\n", + "# Add grid lines\n", + "Bar_fig.update_yaxes(showgrid=True, gridwidth=1, gridcolor='rgba(255,255,255,0.2)')\n", + "\n", + "component0 = pn.panel(Bar_fig)\n", + "# Display the figure\n", + "Bar_fig\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "allover the week tuesdays were for losing items . about 94 item were missed " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### staff sum of recorded stocks allover the year (Bar2_fig)" + ] + }, + { + "cell_type": "code", + "execution_count": 95, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Inventory Discrepancy
Responsible Staff
Aaron Vella8
Andrew Cauchi28
Franklin Attard-39
Jean-Pierre Ellul-11
Robert Tabone31
Simon Fenech25
\n", + "
" + ], + "text/plain": [ + " Inventory Discrepancy\n", + "Responsible Staff \n", + "Aaron Vella 8\n", + "Andrew Cauchi 28\n", + "Franklin Attard -39\n", + "Jean-Pierre Ellul -11\n", + "Robert Tabone 31\n", + "Simon Fenech 25" + ] + }, + "execution_count": 95, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#Inventory Discrepancy per staff\n", + "df_miss_perstaff=df.groupby(\"Responsible Staff\").agg({\n", + " 'Inventory Discrepancy': 'sum'\n", + "})\n", + "df_miss_perstaff.head(10)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "franklin & jean were responsible for most missing recordes ( 39 , 11)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### shifts and responsible staff (Line_fig)" + ] + }, + { + "cell_type": "code", + "execution_count": 96, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
TimeAfternoonEveningMorningTotal Shifts
Responsible Staff
Aaron Vella103107104314
Andrew Cauchi11010696312
Franklin Attard11598106319
Jean-Pierre Ellul106140122368
Robert Tabone106124123353
Simon Fenech104102128334
\n", + "
" + ], + "text/plain": [ + "Time Afternoon Evening Morning Total Shifts\n", + "Responsible Staff \n", + "Aaron Vella 103 107 104 314\n", + "Andrew Cauchi 110 106 96 312\n", + "Franklin Attard 115 98 106 319\n", + "Jean-Pierre Ellul 106 140 122 368\n", + "Robert Tabone 106 124 123 353\n", + "Simon Fenech 104 102 128 334" + ] + }, + "execution_count": 96, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#staff per shift\n", + "df_staff_shifts = df.groupby([\"Responsible Staff\", \"Time\"]).size().unstack(fill_value=0)\n", + "df_staff_shifts[\"Total Shifts\"] = df_staff_shifts.sum(axis=1)\n", + "df_staff_shifts.head(10)" + ] + }, + { + "cell_type": "code", + "execution_count": 97, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.plotly.v1+json": { + "config": { + "plotlyServerURL": "https://plot.ly" + }, + "data": [ + { + "hovertemplate": "%{x} Shift
Aaron Vella: %{y}", + "line": { + "color": "blue", + "width": 2 + }, + "marker": { + "color": "blue", + "size": 8 + }, + "mode": "lines+markers", + "name": "Aaron Vella", + "type": "scatter", + "x": [ + "Morning", + "Afternoon", + "Evening" + ], + "y": [ + 104, + 103, + 107 + ] + }, + { + "hovertemplate": "%{x} Shift
Andrew Cauchi: %{y}", + "line": { + "color": "red", + "width": 2 + }, + "marker": { + "color": "red", + "size": 8 + }, + "mode": "lines+markers", + "name": "Andrew Cauchi", + "type": "scatter", + "x": [ + "Morning", + "Afternoon", + "Evening" + ], + "y": [ + 96, + 110, + 106 + ] + }, + { + "hovertemplate": "%{x} Shift
Franklin Attard: %{y}", + "line": { + "color": "green", + "width": 2 + }, + "marker": { + "color": "green", + "size": 8 + }, + "mode": "lines+markers", + "name": "Franklin Attard", + "type": "scatter", + "x": [ + "Morning", + "Afternoon", + "Evening" + ], + "y": [ + 106, + 115, + 98 + ] + }, + { + "hovertemplate": "%{x} Shift
Jean-Pierre Ellul: %{y}", + "line": { + "color": "purple", + "width": 2 + }, + "marker": { + "color": "purple", + "size": 8 + }, + "mode": "lines+markers", + "name": "Jean-Pierre Ellul", + "type": "scatter", + "x": [ + "Morning", + "Afternoon", + "Evening" + ], + "y": [ + 122, + 106, + 140 + ] + }, + { + "hovertemplate": "%{x} Shift
Robert Tabone: %{y}", + "line": { + "color": "orange", + "width": 2 + }, + "marker": { + "color": "orange", + "size": 8 + }, + "mode": "lines+markers", + "name": "Robert Tabone", + "type": "scatter", + "x": [ + "Morning", + "Afternoon", + "Evening" + ], + "y": [ + 123, + 106, + 124 + ] + }, + { + "hovertemplate": "%{x} Shift
Simon Fenech: %{y}", + "line": { + "color": "brown", + "width": 2 + }, + "marker": { + "color": "brown", + "size": 8 + }, + "mode": "lines+markers", + "name": "Simon Fenech", + "type": "scatter", + "x": [ + "Morning", + "Afternoon", + "Evening" + ], + "y": [ + 128, + 104, + 102 + ] + } + ], + "layout": { + "height": 600, + "hovermode": "closest", + "legend": { + "title": { + "text": "Staff Members" + } + }, + "template": { + "data": { + "bar": [ + { + "error_x": { + "color": "#2a3f5f" + }, + "error_y": { + "color": "#2a3f5f" + }, + "marker": { + "line": { + "color": "#E5ECF6", + "width": 0.5 + }, + "pattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + } + }, + "type": "bar" + } + ], + "barpolar": [ + { + "marker": { + "line": { + "color": "#E5ECF6", + "width": 0.5 + }, + "pattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + } + }, + "type": "barpolar" + } + ], + "carpet": [ + { + "aaxis": { + "endlinecolor": "#2a3f5f", + "gridcolor": "white", + "linecolor": "white", + "minorgridcolor": "white", + "startlinecolor": "#2a3f5f" + }, + "baxis": { + "endlinecolor": "#2a3f5f", + "gridcolor": "white", + "linecolor": "white", + "minorgridcolor": "white", + "startlinecolor": "#2a3f5f" + }, + "type": "carpet" + } + ], + "choropleth": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "type": "choropleth" + } + ], + "contour": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "contour" + } + ], + "contourcarpet": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "type": "contourcarpet" + } + ], + "heatmap": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "heatmap" + } + ], + "histogram": [ + { + "marker": { + "pattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + } + }, + "type": "histogram" + } + ], + "histogram2d": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "histogram2d" + } + ], + "histogram2dcontour": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "histogram2dcontour" + } + ], + "mesh3d": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "type": "mesh3d" + } + ], + "parcoords": [ + { + "line": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "parcoords" + } + ], + "pie": [ + { + "automargin": true, + "type": "pie" + } + ], + "scatter": [ + { + "fillpattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + }, + "type": "scatter" + } + ], + "scatter3d": [ + { + "line": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatter3d" + } + ], + "scattercarpet": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattercarpet" + } + ], + "scattergeo": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattergeo" + } + ], + "scattergl": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattergl" + } + ], + "scattermap": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattermap" + } + ], + "scattermapbox": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattermapbox" + } + ], + "scatterpolar": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatterpolar" + } + ], + "scatterpolargl": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatterpolargl" + } + ], + "scatterternary": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatterternary" + } + ], + "surface": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "surface" + } + ], + "table": [ + { + "cells": { + "fill": { + "color": "#EBF0F8" + }, + "line": { + "color": "white" + } + }, + "header": { + "fill": { + "color": "#C8D4E3" + }, + "line": { + "color": "white" + } + }, + "type": "table" + } + ] + }, + "layout": { + "annotationdefaults": { + "arrowcolor": "#2a3f5f", + "arrowhead": 0, + "arrowwidth": 1 + }, + "autotypenumbers": "strict", + "coloraxis": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "colorscale": { + "diverging": [ + [ + 0, + "#8e0152" + ], + [ + 0.1, + "#c51b7d" + ], + [ + 0.2, + "#de77ae" + ], + [ + 0.3, + "#f1b6da" + ], + [ + 0.4, + "#fde0ef" + ], + [ + 0.5, + "#f7f7f7" + ], + [ + 0.6, + "#e6f5d0" + ], + [ + 0.7, + "#b8e186" + ], + [ + 0.8, + "#7fbc41" + ], + [ + 0.9, + "#4d9221" + ], + [ + 1, + "#276419" + ] + ], + "sequential": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "sequentialminus": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ] + }, + "colorway": [ + "#636efa", + "#EF553B", + "#00cc96", + "#ab63fa", + "#FFA15A", + "#19d3f3", + "#FF6692", + "#B6E880", + "#FF97FF", + "#FECB52" + ], + "font": { + "color": "#2a3f5f" + }, + "geo": { + "bgcolor": "white", + "lakecolor": "white", + "landcolor": "#E5ECF6", + "showlakes": true, + "showland": true, + "subunitcolor": "white" + }, + "hoverlabel": { + "align": "left" + }, + "hovermode": "closest", + "mapbox": { + "style": "light" + }, + "paper_bgcolor": "white", + "plot_bgcolor": "#E5ECF6", + "polar": { + "angularaxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + }, + "bgcolor": "#E5ECF6", + "radialaxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + } + }, + "scene": { + "xaxis": { + "backgroundcolor": "#E5ECF6", + "gridcolor": "white", + "gridwidth": 2, + "linecolor": "white", + "showbackground": true, + "ticks": "", + "zerolinecolor": "white" + }, + "yaxis": { + "backgroundcolor": "#E5ECF6", + "gridcolor": "white", + "gridwidth": 2, + "linecolor": "white", + "showbackground": true, + "ticks": "", + "zerolinecolor": "white" + }, + "zaxis": { + "backgroundcolor": "#E5ECF6", + "gridcolor": "white", + "gridwidth": 2, + "linecolor": "white", + "showbackground": true, + "ticks": "", + "zerolinecolor": "white" + } + }, + "shapedefaults": { + "line": { + "color": "#2a3f5f" + } + }, + "ternary": { + "aaxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + }, + "baxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + }, + "bgcolor": "#E5ECF6", + "caxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + } + }, + "title": { + "x": 0.05 + }, + "xaxis": { + "automargin": true, + "gridcolor": "white", + "linecolor": "white", + "ticks": "", + "title": { + "standoff": 15 + }, + "zerolinecolor": "white", + "zerolinewidth": 2 + }, + "yaxis": { + "automargin": true, + "gridcolor": "white", + "linecolor": "white", + "ticks": "", + "title": { + "standoff": 15 + }, + "zerolinecolor": "white", + "zerolinewidth": 2 + } + } + }, + "title": { + "text": "Shift Distribution Across Staff Members" + }, + "width": 800, + "xaxis": { + "gridcolor": "rgba(0,0,0,0.1)", + "gridwidth": 1, + "showgrid": true, + "title": { + "text": "Shifts" + } + }, + "yaxis": { + "gridcolor": "rgba(0,0,0,0.1)", + "gridwidth": 1, + "showgrid": true, + "title": { + "text": "Shift Distribution" + } + } + } + } + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "\n", + "# Data\n", + "staff = [\"Aaron Vella\", \"Andrew Cauchi\", \"Franklin Attard\", \"Jean-Pierre Ellul\", \"Robert Tabone\", \"Simon Fenech\"]\n", + "shifts = [\"Morning\", \"Afternoon\", \"Evening\"]\n", + "morning = [104, 96, 106, 122, 123, 128]\n", + "afternoon = [103, 110, 115, 106, 106, 104]\n", + "evening = [107, 106, 98, 140, 124, 102]\n", + "\n", + "# Define custom colors for each staff member\n", + "colors = ['blue', 'red', 'green', 'purple', 'orange', 'brown']\n", + "\n", + "# Create figure with specified name\n", + "Line_fig = go.Figure()\n", + "\n", + "# Add traces for each staff member with specific colors\n", + "for i, staff_name in enumerate(staff):\n", + " y_values = [morning[i], afternoon[i], evening[i]]\n", + " Line_fig.add_trace(go.Scatter(\n", + " x=shifts,\n", + " y=y_values,\n", + " mode='lines+markers',\n", + " name=staff_name,\n", + " line=dict(color=colors[i], width=2),\n", + " marker=dict(color=colors[i], size=8),\n", + " hovertemplate='%{x} Shift
' + \n", + " f'{staff_name}: ' + '%{y}'\n", + " ))\n", + "\n", + "# Update layout\n", + "Line_fig.update_layout(\n", + " title=\"Shift Distribution Across Staff Members\",\n", + " xaxis_title=\"Shifts\",\n", + " yaxis_title=\"Shift Distribution\",\n", + " legend_title=\"Staff Members\",\n", + " height=600,\n", + " width=800,\n", + " hovermode=\"closest\"\n", + ")\n", + "\n", + "# Add grid lines for better readability\n", + "Line_fig.update_xaxes(showgrid=True, gridwidth=1, gridcolor='rgba(0,0,0,0.1)')\n", + "Line_fig.update_yaxes(showgrid=True, gridwidth=1, gridcolor='rgba(0,0,0,0.1)')\n", + "\n", + "# Show the figure\n", + "Line_fig" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### final stocks of Items" + ] + }, + { + "cell_type": "code", + "execution_count": 98, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\S\\AppData\\Local\\Temp\\ipykernel_3408\\3132821364.py:1: FutureWarning:\n", + "\n", + "The provided callable is currently using SeriesGroupBy.sum. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string \"sum\" instead.\n", + "\n" + ] + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Inventory Discrepancy
Item IDCategory
ITM001CTG00116
ITM002CTG002-71
ITM003CTG00135
ITM004CTG00335
ITM005CTG004-42
ITM006CTG00169
\n", + "
" + ], + "text/plain": [ + " Inventory Discrepancy\n", + "Item ID Category \n", + "ITM001 CTG001 16\n", + "ITM002 CTG002 -71\n", + "ITM003 CTG001 35\n", + "ITM004 CTG003 35\n", + "ITM005 CTG004 -42\n", + "ITM006 CTG001 69" + ] + }, + "execution_count": 98, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_stocks = df.groupby([\"Item ID\", \"Category\"])[\"Inventory Discrepancy\"].agg(sum)\n", + "pd.DataFrame(df_stocks).head(10)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "ITM002 & ITM005 are the missed itmes : (Yoga Mat: 71 missing , foam rollers: 42 missing) " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## the interactive bar chart (fig)" + ] + }, + { + "cell_type": "code", + "execution_count": 99, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
TimeMonthResponsible StaffCategoryInventory Discrepancy
0EveningMayRobert TaboneCTG001-4
1AfternoonAugustSimon FenechCTG003-5
2EveningMayJean-Pierre EllulCTG0010
3EveningMarchAndrew CauchiCTG001-4
4EveningSeptemberRobert TaboneCTG0022
\n", + "
" + ], + "text/plain": [ + " Time Month Responsible Staff Category Inventory Discrepancy\n", + "0 Evening May Robert Tabone CTG001 -4\n", + "1 Afternoon August Simon Fenech CTG003 -5\n", + "2 Evening May Jean-Pierre Ellul CTG001 0\n", + "3 Evening March Andrew Cauchi CTG001 -4\n", + "4 Evening September Robert Tabone CTG002 2" + ] + }, + "execution_count": 99, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#make a df to customize\n", + "activ_df = pd.DataFrame(df[[\"Time\", \"Month\",\"Responsible Staff\",\"Category\",\"Inventory Discrepancy\"]])\n", + "activ_df.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 100, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "6f0b46edbc0d4e2e964a0304096251cd", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "BokehModel(combine_events=True, render_bundle={'docs_json': {'45a36b19-d5a7-41f8-881d-3e1239c3249f': {'version…" + ] + }, + "execution_count": 100, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Create a vertical radio button group\n", + "list_dropdown = pn.widgets.RadioButtonGroup(\n", + " name=\"Select Data on X axis\",\n", + " options=[\"Date\", \"Month\", \"Time\", \"Responsible Staff\", \"Category\", \"Item ID\" , \"Weekday\"],\n", + " description=\"select data type to calculate stock for!\",\n", + " button_style='outline'\n", + ")\n", + "\n", + "# Wrap in a Panel component (optional, but can help with layout)\n", + "component1 = pn.panel(list_dropdown)\n", + "list_dropdown" + ] + }, + { + "cell_type": "code", + "execution_count": 246, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.plotly.v1+json": { + "config": { + "plotlyServerURL": "https://plot.ly" + }, + "data": [ + { + "hovertemplate": "Month=%{x}
Inventory Discrepancy=%{marker.color}", + "legendgroup": "", + "marker": { + "color": { + "bdata": "1fP160Q1MdcB", + "dtype": "i1" + }, + "coloraxis": "coloraxis", + "pattern": { + "shape": "" + } + }, + "name": "", + "orientation": "v", + "showlegend": false, + "textposition": "auto", + "type": "bar", + "x": [ + "January", + "February", + "March", + "April", + "May", + "June", + "July", + "August", + "September" + ], + "xaxis": "x", + "y": { + "bdata": "1fP160Q1MdcB", + "dtype": "i1" + }, + "yaxis": "y" + } + ], + "layout": { + "barmode": "relative", + "coloraxis": { + "colorbar": { + "title": { + "text": "Inventory Discrepancy" + } + }, + "colorscale": [ + [ + 0, + "red" + ], + [ + 1, + "teal" + ] + ] + }, + "font": { + "color": "black" + }, + "height": 500, + "legend": { + "tracegroupgap": 0 + }, + "paper_bgcolor": "#f8f8f8", + "plot_bgcolor": "#f8f8f8", + "template": { + "data": { + "bar": [ + { + "error_x": { + "color": "#2a3f5f" + }, + "error_y": { + "color": "#2a3f5f" + }, + "marker": { + "line": { + "color": "#E5ECF6", + "width": 0.5 + }, + "pattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + } + }, + "type": "bar" + } + ], + "barpolar": [ + { + "marker": { + "line": { + "color": "#E5ECF6", + "width": 0.5 + }, + "pattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + } + }, + "type": "barpolar" + } + ], + "carpet": [ + { + "aaxis": { + "endlinecolor": "#2a3f5f", + "gridcolor": "white", + "linecolor": "white", + "minorgridcolor": "white", + "startlinecolor": "#2a3f5f" + }, + "baxis": { + "endlinecolor": "#2a3f5f", + "gridcolor": "white", + "linecolor": "white", + "minorgridcolor": "white", + "startlinecolor": "#2a3f5f" + }, + "type": "carpet" + } + ], + "choropleth": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "type": "choropleth" + } + ], + "contour": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "contour" + } + ], + "contourcarpet": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "type": "contourcarpet" + } + ], + "heatmap": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "heatmap" + } + ], + "histogram": [ + { + "marker": { + "pattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + } + }, + "type": "histogram" + } + ], + "histogram2d": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "histogram2d" + } + ], + "histogram2dcontour": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "histogram2dcontour" + } + ], + "mesh3d": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "type": "mesh3d" + } + ], + "parcoords": [ + { + "line": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "parcoords" + } + ], + "pie": [ + { + "automargin": true, + "type": "pie" + } + ], + "scatter": [ + { + "fillpattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + }, + "type": "scatter" + } + ], + "scatter3d": [ + { + "line": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatter3d" + } + ], + "scattercarpet": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattercarpet" + } + ], + "scattergeo": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattergeo" + } + ], + "scattergl": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattergl" + } + ], + "scattermap": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattermap" + } + ], + "scattermapbox": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattermapbox" + } + ], + "scatterpolar": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatterpolar" + } + ], + "scatterpolargl": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatterpolargl" + } + ], + "scatterternary": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatterternary" + } + ], + "surface": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "surface" + } + ], + "table": [ + { + "cells": { + "fill": { + "color": "#EBF0F8" + }, + "line": { + "color": "white" + } + }, + "header": { + "fill": { + "color": "#C8D4E3" + }, + "line": { + "color": "white" + } + }, + "type": "table" + } + ] + }, + "layout": { + "annotationdefaults": { + "arrowcolor": "#2a3f5f", + "arrowhead": 0, + "arrowwidth": 1 + }, + "autotypenumbers": "strict", + "coloraxis": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "colorscale": { + "diverging": [ + [ + 0, + "#8e0152" + ], + [ + 0.1, + "#c51b7d" + ], + [ + 0.2, + "#de77ae" + ], + [ + 0.3, + "#f1b6da" + ], + [ + 0.4, + "#fde0ef" + ], + [ + 0.5, + "#f7f7f7" + ], + [ + 0.6, + "#e6f5d0" + ], + [ + 0.7, + "#b8e186" + ], + [ + 0.8, + "#7fbc41" + ], + [ + 0.9, + "#4d9221" + ], + [ + 1, + "#276419" + ] + ], + "sequential": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "sequentialminus": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ] + }, + "colorway": [ + "#636efa", + "#EF553B", + "#00cc96", + "#ab63fa", + "#FFA15A", + "#19d3f3", + "#FF6692", + "#B6E880", + "#FF97FF", + "#FECB52" + ], + "font": { + "color": "#2a3f5f" + }, + "geo": { + "bgcolor": "white", + "lakecolor": "white", + "landcolor": "#E5ECF6", + "showlakes": true, + "showland": true, + "subunitcolor": "white" + }, + "hoverlabel": { + "align": "left" + }, + "hovermode": "closest", + "mapbox": { + "style": "light" + }, + "paper_bgcolor": "white", + "plot_bgcolor": "#E5ECF6", + "polar": { + "angularaxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + }, + "bgcolor": "#E5ECF6", + "radialaxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + } + }, + "scene": { + "xaxis": { + "backgroundcolor": "#E5ECF6", + "gridcolor": "white", + "gridwidth": 2, + "linecolor": "white", + "showbackground": true, + "ticks": "", + "zerolinecolor": "white" + }, + "yaxis": { + "backgroundcolor": "#E5ECF6", + "gridcolor": "white", + "gridwidth": 2, + "linecolor": "white", + "showbackground": true, + "ticks": "", + "zerolinecolor": "white" + }, + "zaxis": { + "backgroundcolor": "#E5ECF6", + "gridcolor": "white", + "gridwidth": 2, + "linecolor": "white", + "showbackground": true, + "ticks": "", + "zerolinecolor": "white" + } + }, + "shapedefaults": { + "line": { + "color": "#2a3f5f" + } + }, + "ternary": { + "aaxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + }, + "baxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + }, + "bgcolor": "#E5ECF6", + "caxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + } + }, + "title": { + "x": 0.05 + }, + "xaxis": { + "automargin": true, + "gridcolor": "white", + "linecolor": "white", + "ticks": "", + "title": { + "standoff": 15 + }, + "zerolinecolor": "white", + "zerolinewidth": 2 + }, + "yaxis": { + "automargin": true, + "gridcolor": "white", + "linecolor": "white", + "ticks": "", + "title": { + "standoff": 15 + }, + "zerolinecolor": "white", + "zerolinewidth": 2 + } + } + }, + "title": { + "text": "Inventory Discrepancy by Month" + }, + "width": 1200, + "xaxis": { + "anchor": "y", + "domain": [ + 0, + 1 + ], + "gridcolor": "lightgray", + "showgrid": true, + "title": { + "text": "Month" + } + }, + "yaxis": { + "anchor": "x", + "domain": [ + 0, + 1 + ], + "gridcolor": "black", + "title": { + "text": "Total Inventory Discrepancy" + } + } + } + } + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "\n", + "@pn.depends(list_dropdown)\n", + "def inter_bar(list_dropdown):\n", + " # Aggregate data for plotting\n", + " grouped_df = df.groupby(list_dropdown)['Inventory Discrepancy'].sum().reset_index()\n", + " \n", + " # Ensure 'Month' column is ordered correctly if the dropdown is \"Month\"\n", + " if list_dropdown == \"Month\":\n", + " grouped_df[\"Month\"] = pd.Categorical(grouped_df[\"Month\"], categories=month_order, ordered=True)\n", + " grouped_df = grouped_df.sort_values(\"Month\")\n", + "\n", + " # Set title dynamically\n", + " tit = \"Missing/overstock by item ID\" if list_dropdown == \"item ID\" else f'Inventory Discrepancy by {list_dropdown}'\n", + "\n", + " # Create the figure using Plotly Express\n", + " fig = px.bar(\n", + " grouped_df,\n", + " x=list_dropdown,\n", + " y=\"Inventory Discrepancy\",\n", + " title=tit,\n", + " color=\"Inventory Discrepancy\", # Color by category\n", + " color_continuous_scale=['red', ACCENT], # Adjust color scale\n", + " )\n", + " # Improve layout\n", + " fig.update_layout(\n", + " xaxis_title=list_dropdown,\n", + " yaxis_title=\"Total Inventory Discrepancy\",\n", + " plot_bgcolor=\"#f8f8f8\", \n", + " paper_bgcolor=\"#f8f8f8\", \n", + " font=dict(color=\"black\"), \n", + " xaxis=dict(gridcolor='lightgray', showgrid=True),\n", + " yaxis=dict(gridcolor='black'),\n", + " width=1200, \n", + " height=500,\n", + " )\n", + " \n", + " return fig\n", + "\n", + "component2 = pn.panel(inter_bar) # Assign to Panel\n", + "\n", + "inter_bar(\"Month\") # Show ordered months\n", + "\n", + " \n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## creating KPIs cards " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "total actual stock= 94489\n", + "\n", + "total expected stock= 94447\n", + "\n", + "total overstock= 42 (.044% of the stock)\n", + "\n", + "ITM002(Yoga Mat) lost 71 pieces , ITM005(Foam Roller) lost 42 piece, totlal= 113\n", + "\n", + "the over stock items (ITM001: 16 , ITM003: 35 , ITM004: 35 , ITM006: 69), total= 155" + ] + }, + { + "cell_type": "code", + "execution_count": 245, + "metadata": {}, + "outputs": [], + "source": [ + "ACCENT = \"teal\"\n", + "\n", + "styles = {\n", + " \"box-shadow\": \"rgba(50, 50, 93, 0.25) 0px 6px 12px -2px, rgba(0, 0, 0, 0.3) 0px 3px 7px -3px\",\n", + " \"border-radius\": \"10px\",\n", + " \"padding\": \"10px\",\n", + " \"background\": \"#DCEFF0\",\n", + " 'box-shadow': \"3px 3px 6px rgba(0,0,0,0.3)\",\n", + " \"width\": \"385px\",\n", + " \"height\": \"220px\" \n", + " } # a dict to use later in the cards \n" + ] + }, + { + "cell_type": "code", + "execution_count": 345, + "metadata": {}, + "outputs": [], + "source": [ + "# KPIs cards\n", + "cards= pn.FlexBox(\n", + "\n", + "\n", + "\n", + " #'Highest miss/day\n", + " pn.indicators.Number(name='The worst-performing day
(03.Aug & 30.May)📉',\n", + " value=23, \n", + " format='{value}'\n", + " ' items',\n", + " colors=[(1, 'black')],\n", + " styles=styles,\n", + " ),\n", + "\n", + " pn.indicators.Number(\n", + " name='Franklin Attard
the biggest Loser',\n", + " value=39,\n", + " # Embed HTML to style the units separately:\n", + " format='{value}'\n", + " ' items',\n", + " colors=[(0, ACCENT)]\n", + " ,styles=styles\n", + " ),\n", + "\n", + " pn.indicators.Number(\n", + " name='Morning shift had the
hieghest missing rate',\n", + " value=84,\n", + " # Embed HTML to style the units separately:\n", + " format='{value}'\n", + " ' items',\n", + " colors=[(0, ACCENT)]\n", + " ,styles=styles\n", + " )\n", + ")\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 239, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "c1a9a63c491643ae9fce2c6354d3f970", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "BokehModel(combine_events=True, render_bundle={'docs_json': {'1183480e-5217-4646-99d1-1ec3fbe4428d': {'version…" + ] + }, + "execution_count": 239, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cards" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### making cards of stock discrepancy" + ] + }, + { + "cell_type": "code", + "execution_count": 240, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "\n", + "# Data for missing and overstocked items\n", + "missing_items = {\n", + " \"Yoga Mat\": 71,\n", + " \"Foam Roller\": 42\n", + "}\n", + "overstock_items = {\n", + " \"Dumbbells\": 16,\n", + " \"Resistance Band\": 35,\n", + " \"Jump Rope\": 35,\n", + " \"Kettlebell\": 69\n", + "}\n", + "\n", + "# Convert to DataFrame\n", + "df_missing = pd.DataFrame(missing_items.items(), columns=[\"Item\", \"Quantity Lost\"])\n", + "df_overstock = pd.DataFrame(overstock_items.items(), columns=[\"Item\", \"Quantity Overstocked\"])\n" + ] + }, + { + "cell_type": "code", + "execution_count": 241, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "# Create bar plots\n", + "fig_missing = px.bar(\n", + " df_missing, \n", + " x=\"Item\", \n", + " y=\"Quantity Lost\", \n", + " title=\"Missing Items(max:71, sum:113)\", \n", + " color=\"Quantity Lost\",\n", + " color_continuous_scale=[(0, \"lightcoral\"), (0.5, \"red\"), (1, \"darkred\")]\n", + "\n", + ")\n", + "\n", + "\n", + "\n", + "fig_overstock = px.bar(\n", + " df_overstock, \n", + " x=\"Item\", \n", + " y=\"Quantity Overstocked\", \n", + " title=\"Overstocked Items(max:69, sum:155)\", \n", + " color=\"Quantity Overstocked\",\n", + " color_continuous_scale=\"blues\"\n", + ")\n", + "\n", + "# Improve layout\n", + "fig_missing.update_layout(paper_bgcolor=\"#DCEFF0\", plot_bgcolor=\"#DCEFF0\", width=295, height=295, coloraxis_showscale=False,title_font=dict(size=16))\n", + "fig_overstock.update_layout(paper_bgcolor=\"#DCEFF0\", plot_bgcolor=\"#DCEFF0\", width=295, height=295,coloraxis_showscale=False,title_font=dict(size=14) )\n", + "\n", + "component3=pn.panel(fig_missing)\n", + "component4=pn.panel(fig_overstock)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 242, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "# Convert to DataFrame\n", + "df_missing = pd.DataFrame(missing_items.items(), columns=[\"Item\", \"Quantity Lost\"])\n", + "df_overstock = pd.DataFrame(overstock_items.items(), columns=[\"Item\", \"Quantity Overstocked\"])\n", + "\n", + "# Create bar plots\n", + "fig_missing = px.bar(\n", + " df_missing, \n", + " x=\"Item\", \n", + " y=\"Quantity Lost\", \n", + " title=\"Missing Items(max:71, sum:113)\", \n", + " color=\"Quantity Lost\",\n", + " color_continuous_scale=[(0, \"lightcoral\"), (0.5, \"red\"), (1, \"darkred\")]\n", + ")\n", + "\n", + "\n", + "missing_items_indicator = pn.indicators.Number(\n", + " name=\"Missing Items\", # Title\n", + " value=113, # Number displayed\n", + " format=\"{:.0f}\", # No decimal places\n", + " colors=[(50, \"red\")], # Customize color if needed\n", + " font_size=\"20pt\" # Adjust font size\n", + ")\n", + "\n", + "\n", + "fig_overstock = px.bar(\n", + " df_overstock, \n", + " x=\"Item\", \n", + " y=\"Quantity Overstocked\", \n", + " title=\"Overstocked Items(max:69, sum:155)\", \n", + " color=\"Quantity Overstocked\",\n", + " color_continuous_scale=\"blues\"\n", + ")\n", + "\n", + "# Improve layout\n", + "fig_missing.update_layout(\n", + " paper_bgcolor=\"#DCEFF0\",\n", + " plot_bgcolor=\"#DCEFF0\",\n", + " width=600,\n", + " height=295,\n", + " coloraxis_showscale=False,\n", + " title_font=dict(size=28, color=\"#8B0000\") # Set title color to red\n", + ")\n", + "\n", + "fig_overstock.update_layout(\n", + " paper_bgcolor=\"#DCEFF0\",\n", + " plot_bgcolor=\"#DCEFF0\",\n", + " width=600,\n", + " height=295,\n", + " coloraxis_showscale=False,\n", + " title_font=dict(size=28, color=\"teal\") # Set title color to blue\n", + ")\n", + "\n", + "\n", + "component3=pn.panel(fig_missing)\n", + "component4=pn.panel(fig_overstock)\n", + "comp5=pn.panel(missing_items_indicator)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Dashboard layout" + ] + }, + { + "cell_type": "code", + "execution_count": 381, + "metadata": {}, + "outputs": [], + "source": [ + "styles2 = {\n", + " \"box-shadow\": \"rgba(50, 50, 93, 0.25) 0px 6px 12px -2px, rgba(0, 0, 0, 0.3) 0px 3px 7px -3px\",\n", + " \"border-radius\": \"10px\",\n", + " \"padding\": \"10px\",\n", + " \"background\": \"#DADADA\",\n", + " 'box-shadow': \"3px 3px 6px rgba(0,0,0,0.3)\",\n", + " \"width\": \"280px\",\n", + " \"height\": \"80px\" \n", + " } \n", + "sidebar_card1 = pn.indicators.Number(\n", + " name=(\"Total records: 2000\"),\n", + " styles=styles2\n", + " \n", + ")\n", + "\n", + "sidebar_card2 = pn.indicators.Number(\n", + " name=(\"Start date: 01-01-2024 To 30-09-2024\"),\n", + " styles=styles2\n", + ")\n", + "\n", + "insight1 = pn.indicators.Number(\n", + " name=\"More managment on Morinig shift is essential \",\n", + " styles={\"background\": \"#6AB187\", \"border-radius\": \"10px\", \"padding\": \"10px\", \"width\": \"300\" , \"height\":\"120px\"}\n", + ")\n", + "\n", + "insight2 = pn.indicators.Number(\n", + " name=\"light items must be moved in more watched ereas \",\n", + " styles={\"background\": \"#6AB187\", \"border-radius\": \"10px\", \"padding\": \"10px\", \"width\": \"300\" , \"height\":\"120px\"}\n", + ")\n", + "\n", + "insight3 = pn.indicators.Number(\n", + " name=\"need better rocording system to overcome the overstocking issue\",\n", + " styles={\"background\": \"#6AB187\", \"border-radius\": \"10px\", \"padding\": \"10px\", \"width\": \"300\" , \"height\":\"120px\"}\n", + ")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 389, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "<>:12: SyntaxWarning:\n", + "\n", + "invalid escape sequence '\\K'\n", + "\n", + "C:\\Users\\S\\AppData\\Local\\Temp\\ipykernel_3408\\1352288665.py:12: SyntaxWarning:\n", + "\n", + "invalid escape sequence '\\K'\n", + "\n" + ] + }, + { + "data": {}, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.holoviews_exec.v0+json": "", + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " Panel App\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n", + "\n", + "\n", + " \n", + "\n", + " \n", + " \n", + " \n", + " \n", + "\n", + " \n", + " \n", + "
\n", + " \n", + "\n", + "
\n", + "
\n", + "
    \n", + "
    \n", + "
    \n", + "
    \n", + "
    \n", + "
    \n", + "
    \n", + "
    \n", + "
\n", + "
\n", + "\n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + " \n", + " \n", + "
\n", + "
\n", + "
\n", + "
\n", + " ×\n", + "
\n", + "
\n", + "
\n", + "
\n", + "\n", + "\n", + "\n", + "
\n", + "
\n", + "
\n", + "
\n", + "\n", + "\n", + "
\n", + "\n", + " \n", + " \n", + " \n", + " \n", + "" + ], + "text/plain": [ + "EditableTemplate\n", + " [editor] TemplateEditor()\n", + " [js_area] HTML(None, height=0, margin=0, sizing_mode='fixed', width=0)\n", + " [actions] TemplateActions()\n", + " [browser_info] BrowserInfo()\n", + " [busy_indicator] LoadingSpinner(height=20, width=20)\n", + " [nav-1787242643232] Markdown(str)\n", + " [nav-1787242642752] Image(str, align='center', width=290)\n", + " [nav-1787095402928] Number(name='Total records: 2000', styles={'box-shadow': '3px 3px 6p...})\n", + " [nav-1787221463104] Number(name='Start date: 0..., styles={'box-shadow': '3px 3px 6p...})\n", + " [nav-1787221462384] Number(name='More managment o..., styles={'background': '#6AB187', ...})\n", + " [nav-1787221467664] Number(name='light items m..., styles={'background': '#6AB187', ...})\n", + " [nav-1787221465024] Number(name='need better r..., styles={'background': '#6AB187', ...})\n", + " [main-1787243512336] Column\n", + " [0] Row(sizing_mode='stretch_width')\n", + " [0] Plotly(Figure)\n", + " [1] Plotly(Figure)\n", + " [1] Row(sizing_mode='stretch_width')\n", + " [0] FlexBox(objects=[Number(colors=[(1, ...], sizing_mode='stretch_width')\n", + " [2] Column\n", + " [0] Row(sizing_mode='stretch_width')\n", + " [0] ParamFunction(function, _pane=Plotly, defer_load=False)\n", + " [1] Row(sizing_mode='stretch_width')\n", + " [0] Spacer(width=200)\n", + " [1] RadioButtonGroup(button_style='outline', description='select data t..., name='Select Data on X axis', options=['Date', 'Month', ...], value='Date')" + ] + }, + "execution_count": 389, + "metadata": { + "application/vnd.holoviews_exec.v0+json": { + "id": "b34d95ec-4842-4ec3-b806-5b663f8750fb" + } + }, + "output_type": "execute_result" + } + ], + "source": [ + "import panel as pn\n", + "\n", + "# Create the template\n", + "template = pn.template.EditableTemplate(\n", + " title=\"PeakFit Inventory Analysis Interactive Dashboard\",\n", + " theme=\"default\",\n", + " header_background=\"#1C4E80\", # Header background color\n", + " \n", + " sidebar=[\n", + " pn.pane.Markdown(\"Inventory Infos & Insights\"), # Sidebar title\n", + " pn.pane.Image(\n", + " \"D:\\K_REPO\\Depi_freelanceYard\\images.png\",\n", + " width=290, # Adjust width as needed\n", + " align=\"center\"\n", + " ),\n", + " sidebar_card1,\n", + " sidebar_card2,\n", + " insight1,\n", + " insight2,\n", + " insight3\n", + " ],\n", + " sidebar_width=300, # Adjust sidebar width\n", + ")\n", + "\n", + "\n", + "\n", + "# Add main content\n", + "template.main.append(\n", + " pn.Column(\n", + " # Row 1: Charts\n", + " pn.Row(component3, component4, sizing_mode=\"stretch_width\"), \n", + "\n", + " # Row 2: KPI Cards\n", + " pn.Row(cards, sizing_mode=\"stretch_width\"), \n", + "\n", + " # Row 3: Stacked Components\n", + " pn.Column(\n", + " pn.Row(component2, sizing_mode=\"stretch_width\"), \n", + " pn.Row(pn.Spacer(width=200), component1, sizing_mode=\"stretch_width\"), \n", + " ),\n", + " )\n", + ")\n", + "\n", + "template.servable()\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.13.2" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}