From 579b2436cb421b5e864c78e6c24cd10a54f80c95 Mon Sep 17 00:00:00 2001 From: Prasanth P <3108prasanthp@gmail.com> Date: Wed, 8 Mar 2023 10:20:26 +0530 Subject: [PATCH 1/2] Python Solution Files by Prasanth P --- .../__pycache__/codechallenge1.cpython-39.pyc | Bin 0 -> 1626 bytes .../__pycache__/codechallenge2.cpython-39.pyc | Bin 0 -> 1826 bytes Solution-Prasanth/codechallenge1.py | 61 +++++++++++++++ Solution-Prasanth/codechallenge2.py | 71 ++++++++++++++++++ 4 files changed, 132 insertions(+) create mode 100644 Solution-Prasanth/__pycache__/codechallenge1.cpython-39.pyc create mode 100644 Solution-Prasanth/__pycache__/codechallenge2.cpython-39.pyc create mode 100644 Solution-Prasanth/codechallenge1.py create mode 100644 Solution-Prasanth/codechallenge2.py diff --git a/Solution-Prasanth/__pycache__/codechallenge1.cpython-39.pyc b/Solution-Prasanth/__pycache__/codechallenge1.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..0813918c319e423dd247211aaf482496f2c41e55 GIT binary patch literal 1626 zcmbVMOK%)S5bmD$&OQ^CfCY!)gjPacA}%OcD2X=&6Ulb4!(p^&G;Fumv!0i`do6jj z!vS+ZNJ#tx>|_1}ch21U2&epooT%=xH+IA!%8a^R{iv_2x+-qBeFWd%hc@}eL+D?n zT>mUk?!(|e0U?Os6or`LbAuQcI5fdxrdDQ$cIJdm=7ugt)TZ7U4jWSx`Y@WbF>4Wv z*i%fL-wfgs?`H(_?Mr*(((aR{ws*9>wOZdM9c}LtyoUze7k~q8F9w_UhR--2XPAbg_yT>lJEHeqlG6B0<^Gr;p4Zx0Nnf+QQOqn;zy0E;FspKRV6 zYoKEdbi9+(5lc?!ctrV;D9Z8EXAd8ZHNfaWnT+@7q{xZ7&RCJvmF}*Wr?NGrBD(UU z62}!PWUwYsY3=Up?cczyVAwD;?q4xN391154F8VVj{=<=7pTI*Jhztk0%OQ-1$nJZ zVpbNhDx27q1H%=zaAq#C*C1~r^!-1Tw}f1-A>j~r4K2MjbY!p*Xdo$VX&fQ;r|@1` z&fsLNH|iCjo5ZgySkbI4m3?!)P(E79V;@z{(yZL$(aja$MR`?TR;Mma@cf$XZ9IYR zHsC^}vw`Zng6wJ;FoE0!*#h1JZUb)ucYxml?gGEPfkXr1id0-df9Js1L!?jMO)$Bm zZ8algk7A0iS1g>9suth>|HSKQk2PbioF8uvM z#Az@AN77OrUi_s{*p#t?E&6b%Dw`mi1Nngl-|X#dCw~CYfzM2}&`o%xN=ka_eJY8m zB9Ts9mHbGzUe~2B>mE}rnfwiUg)q6e60yt~o4eR6IuyZgMHeL1(_5sM(aO>`&!TTzp z^|@cbnyYgENbT)~P8sJU=F%u3t&GMbf_}%|he>!)s^u}&9(0cC9_2+*9%nR)qzS3f xNz%R{L&aQB-A43nnDX$yh`f!gAoG-dsU9l70|WwS^sxuQw2Th+O&Fha@PDcLgB$<= literal 0 HcmV?d00001 diff --git a/Solution-Prasanth/__pycache__/codechallenge2.cpython-39.pyc b/Solution-Prasanth/__pycache__/codechallenge2.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4f1461ef5047c698016abfe27a3be571c690d927 GIT binary patch literal 1826 zcma)6OK%)S5bo}I?(D-3ERHQAG(;S-2fRQegdz)JY!jIv+ld_xqm4$xcH3_6&ci*u zmb{wbfDtz&{{!q}?)(Y+Ghy=ujQj_fD57|X0?hCgq2w9|25^j_8C!uB+kqWBfrAmVn0tYP+7Svo7us`pAk(b(`01BhJq<8i&v5wWrtt=gc1MKfTv*{M#G%F#J+$>0564076;}w%;P(o z>@XS)rT=&oC6dc?{~I22>GQ;Y^l;pK!cJG`qH%pA&85G`gpw_-Qwn94CehHp$zM3& zG4o~WZ?Yl0bWxd7j96fQtIIR6_eLV*bXeC6C`zc(t?Vev z07+$u2%1Jk=wW5$$5F;AgD0}G1nO!};LeIKaAKY)Xqu3KE&zX# z0$$mZK2+h8z|`oyXns*a4QQEawk1`7a66#=s$&RM*VSS_jkA&D$x%2#(E@J12NNPD zcH#H1IsMzDP41BQOdtFB1LA>f5hN|*l0`D18d&{Gs|^wxEX-`USiBE5$8LAx=707* z;egV#^NDwXzJXu&J{^RoE`DNn3(m}%)m^2#7}!~q&?v7+2I&_pq9Jr^u?#|ZuBu@R z)!cM0Cmq%e!z7AX7*+= int(purchase["Req. Quantity"]): + + cost = int(df["Cost Per KG"][j])*int(purchase["Req. Quantity"]) + + else: + + additional = int(df["Cost Per KG"][j]) + int(df["Additional Cost Per KG"][j]) + addtocost = ((int(purchase["Req. Quantity"])-int(df["Default Quantity Limit in KG"][j])) * additional) + cost = (int(df["Cost Per KG"][j]) * int(df["Default Quantity Limit in KG"][j])) + addtocost + + if cost < mincost: + mincost = int(cost) + mintime = int(df["Time to Deliver"][j]) + isavail = "true" + vendor = df["Vendor"][j] + + elif cost == mincost: + + if df["Time to Deliver"][j] < mintime: + + mintime = int(df["Time to Deliver"][j]) + isavail = "true" + vendor = df["Vendor"][j] + + result_dictionary["Purchase Id"] = purchase["Pur_id"] + result_dictionary["Item"] = purchase["item"] + result_dictionary["Quantity"] = purchase["Req. Quantity"] + result_dictionary["IsAvail"] = isavail + result_dictionary["Vendor"] = vendor + if mincost == 100000 and mintime == 1000: + total=0 + time=0 + else: + total=mincost + time=mintime + result_dictionary["Total cost"] = total + result_dictionary["Time"] = time + result.append(result_dictionary) + return result_dictionary,201 + return {"error": "Request must be JSON"}, 415 + +@app.route("/results", methods=["GET"]) +def get_result(): + return jsonify(result) \ No newline at end of file From dba3913e2e0a8a5d20943d4454f0c8a87bb82095 Mon Sep 17 00:00:00 2001 From: Prasanth P <3108prasanthp@gmail.com> Date: Wed, 8 Mar 2023 10:28:14 +0530 Subject: [PATCH 2/2] Uploades Python Solution files from Prasanth P --- Solution-Prasanth/codechallenge1.py | 13 +++++++++++++ Solution-Prasanth/codechallenge2.py | 16 ++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/Solution-Prasanth/codechallenge1.py b/Solution-Prasanth/codechallenge1.py index 3a9be56..f4fce76 100644 --- a/Solution-Prasanth/codechallenge1.py +++ b/Solution-Prasanth/codechallenge1.py @@ -1,3 +1,16 @@ +""" Problem Statement 1 + +- Given a list of purchases, each has an item and its quantity. +- Find the vendor for each purchase where cost is minimum (primary objective) and time-efficient (secondary objective). Do not assign multiple vendors to a single purchase. +- If a purchase is not possible, mark that purchase as not possible. +- Quantity will always be in KG. +- Use the data given in `vendors.csv`. + +**Input**: A CSV file `input.csv`. Each row contains the purchase id, item, and required quantity. + +**Expected Output**: A CSV file `output.csv`. Each row contains the purchase id, item, required quantity, indication if a purchase is possible (true/false), vendor, total cost, and delivery time. +""" + import pandas as pd df = pd.read_csv("C:/Users/3108p/code_challenge/vendors.csv") diff --git a/Solution-Prasanth/codechallenge2.py b/Solution-Prasanth/codechallenge2.py index f151adb..858dd67 100644 --- a/Solution-Prasanth/codechallenge2.py +++ b/Solution-Prasanth/codechallenge2.py @@ -1,3 +1,19 @@ +""" + +We have provided `vendor_capacities.csv` which contains vendor, item, cost, delivery time, quantity limit, and additional cost. + +- Given a list of purchases, each has an item and its quantity. +- Find the vendor for each purchase where cost is minimum (primary objective) and time-efficient (secondary objective). Do not assign multiple vendors to a single purchase. +- Consider the quantity limit and additional cost if a purchase quantity exceeds the quantity limit. If a purchase is not possible, mark that purchase impossible. +- Quantity will always be in KG. +- Use the data given in `vendor_capacities.csv`. + +**Input**: A CSV file input-capacities.csv. Each row contains the purchase id, item, and required quantity. + +**Expected Output**: Same as Problem statement 1. + +""" + import pandas as pd df = pd.read_csv("C:/Users/3108p/code_challenge/vendor-capacities.csv")