From 2690322023082275b8fefae533d2666c51fb301b Mon Sep 17 00:00:00 2001 From: "github-classroom[bot]" <66690702+github-classroom[bot]@users.noreply.github.com> Date: Sun, 27 Feb 2022 05:28:28 +0000 Subject: [PATCH 01/10] Setting up GitHub Classroom Feedback From 87fc25f7da2597080875fa5f58876804f2a9027a Mon Sep 17 00:00:00 2001 From: Aniruddh Bhaskaran Date: Mon, 28 Feb 2022 12:11:56 +0530 Subject: [PATCH 02/10] is_nan & alerts functionality & invalid_arg test --- __pycache__/statistics.cpython-38.pyc | Bin 0 -> 1740 bytes statistics.py | 56 +++++++++++++++++++++++++- statistics.test.py | 15 +++++-- 3 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 __pycache__/statistics.cpython-38.pyc diff --git a/__pycache__/statistics.cpython-38.pyc b/__pycache__/statistics.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..6b249d4f4eada91b5b79f65afd4c32a61a0df5e8 GIT binary patch literal 1740 zcmbVM&2Aev5GJ`?c_qkh+Vm$*(l$-opgLG8dg#e8VmN6oflxpW3J58->*ZEjYj-7+ zlv@e%$$o)8hF^)-p8N_u^&7^Dr2ZV*6=uXCIWyn<@zwTrgWt6uj zDaagvDW-VA`b-HGT(LfX!IV_t6;t7*=nF_SwFPMlQUEDZbx3tcQt=*ZHEv*obyH4% zw;y~mq9c&eV2YFVL2$tb>_S+!V3*wTQKVm6L2D&PLVv45Rl8yf{tP=8;_N3ISm|&2 zI}bbt8~U9Zao7`;RIJDBmW>vCAua_pgGB&bQP%~@`M?Eb@+(+gX+pRGQ(%Kq(F2+H zzy<*JW8;EbcFKPfXR^nxSxY!sCU)q8Dybld_ScT*I>dF){`jHu%4FJfk}B6zrG_WN z#EcT1RGshjc%YLKz6Twf8LM=Do>l2sWqWzGH<|6dOrUwJlhZ7jf z%r*842zvq|P8?Yp4J zDi`YUv{EiG(^AtNO;(*$d5R13eA1F`tD2T4h{(xNHZy&B4%;pyY-SaKSSFvdUg_CrwuT{8#)@9OqSTaBt!#YanJ1V{3}2lo)C zf3LNYs5u@U)V$`JzOj9nnN9;JEI(RPosK}}4j9HBRbSwVh|xXJ=3Pu_9aDci)R`H& zdP1#psI_SYntbaoi9I3qc8YyF`|5p#eLreU)cE{^bs%q3krIOCM~H|#qHnOk^Tz1` zTcDG7@uHmak<@Jkgr|4}cUc_Vt|iv~`D%q-Ka9uzjk=-EZiRkg*0A2kuKt{kZo{CN z(H|1q48v`w!z>*gR>~)E4>wE%#zcfcZ1Va2ji5Fzcj5O_GWm$uXT*F self.maxThresh: + + self.alertArrs[0].emailSent = True + self.alertArrs[1].ledGlows = True + +# print(calculateStats([])) +# print(calculateStats(["a", "b", "c", "d"])) # type error: unsupported operand types. test case? +# print(calculateStats("a string")) +# print(math.nan) + diff --git a/statistics.test.py b/statistics.test.py index cb914d6..232ebf0 100644 --- a/statistics.test.py +++ b/statistics.test.py @@ -1,3 +1,4 @@ +from cmath import isnan import unittest import statistics @@ -15,12 +16,20 @@ def test_avg_is_nan_for_empty_input(self): # nan (not-a-number), as defined in the math package # Design the assert here. # Use nan and isnan in https://docs.python.org/3/library/math.html + self.assertTrue(isnan(computedStats["avg"])) + self.assertTrue(isnan(computedStats["max"])) + self.assertTrue(isnan(computedStats["min"])) + + def test_invalid_arg_returns_None(self): + # tests if calculateStats returns None on receiving non-array argument for 'numbers' + computedStats = statistics.calculateStats("a string") + self.assertTrue(statistics.calculateStats, None) def test_raise_alerts_when_max_above_threshold(self): - emailAlert = EmailAlert() - ledAlert = LEDAlert() + emailAlert = statistics.EmailAlert() # added statistics module identifier for class instantiation + ledAlert = statistics.LEDAlert() maxThreshold = 10.5 - statsAlerter = StatsAlerter(maxThreshold, [emailAlert, ledAlert]) + statsAlerter = statistics.StatsAlerter(maxThreshold, [emailAlert, ledAlert]) statsAlerter.checkAndAlert([22.6, 12.5, 3.7]) self.assertTrue(emailAlert.emailSent) self.assertTrue(ledAlert.ledGlows) From 1235fade34aafc14d1fc9cf836a5c3e6da5f5d9c Mon Sep 17 00:00:00 2001 From: Aniruddh Bhaskaran Date: Mon, 28 Feb 2022 12:16:52 +0530 Subject: [PATCH 03/10] cleaning up + comments --- statistics.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/statistics.py b/statistics.py index dfe41a6..b00cb77 100644 --- a/statistics.py +++ b/statistics.py @@ -9,21 +9,23 @@ def calculateStats(numbers): if len(numbers) == 0: - vals = [math.nan for i in keys] + vals = [math.nan for i in keys] # is_nan test # print(vals) else: - vals = [ round((sum(numbers) / len(numbers)), 3), max(numbers), min(numbers) ] + vals = [ round((sum(numbers) / len(numbers)), 3), max(numbers), min(numbers) ] # min_max_report test else: - return + return # invalid_arg test stats = dict(zip(keys, vals)) return stats +# below: alerts tests + class EmailAlert: def __init__(self): @@ -50,8 +52,4 @@ def checkAndAlert(self, numbers): self.alertArrs[0].emailSent = True self.alertArrs[1].ledGlows = True -# print(calculateStats([])) -# print(calculateStats(["a", "b", "c", "d"])) # type error: unsupported operand types. test case? -# print(calculateStats("a string")) -# print(math.nan) From ca52461db90507e9f2de3e9c64acd1ec3a8e73c0 Mon Sep 17 00:00:00 2001 From: Aniruddh Bhaskaran Date: Sat, 5 Mar 2022 19:57:39 +0530 Subject: [PATCH 04/10] updated w.r.t. feedback --- statistics.py | 54 ++++++++++++--------------------------------------- 1 file changed, 12 insertions(+), 42 deletions(-) diff --git a/statistics.py b/statistics.py index b00cb77..cafd93a 100644 --- a/statistics.py +++ b/statistics.py @@ -2,54 +2,24 @@ def calculateStats(numbers): - keys = ["avg", "max", "min"] - vals = [] + stats = dict.fromkeys(["avg", "max", "min"]) - if type(numbers) is list: - if len(numbers) == 0: + if type(numbers) != list: - vals = [math.nan for i in keys] # is_nan test - # print(vals) + return None # invalid_arg test - else: - vals = [ round((sum(numbers) / len(numbers)), 3), max(numbers), min(numbers) ] # min_max_report test - - else: + if len(numbers) == 0: - return # invalid_arg test + for key in stats.keys(): + + stats[key] = math.nan # is_nan test - stats = dict(zip(keys, vals)) + else: + stats["avg"] = round((sum(numbers) / len(numbers)), 3) + stats["max"] = max(numbers) + stats["min"] = min(numbers) # min_max_report test + return stats - -# below: alerts tests - -class EmailAlert: - - def __init__(self): - self.emailSent = False # by default - -class LEDAlert: - - def __init__(self): - self.ledGlows = False # by default - -class StatsAlerter: - - def __init__(self, maxThresh, alertArrs): - - self.maxThresh = maxThresh - self.alertArrs = alertArrs - - def checkAndAlert(self, numbers): - - stats = calculateStats(numbers) - - if stats["max"] > self.maxThresh: - - self.alertArrs[0].emailSent = True - self.alertArrs[1].ledGlows = True - - From 4672a371a80e48158ee585007079964d258e2962 Mon Sep 17 00:00:00 2001 From: Aniruddh Bhaskaran Date: Sat, 5 Mar 2022 19:57:55 +0530 Subject: [PATCH 05/10] cache files updated --- __pycache__/alerts.cpython-38.pyc | Bin 0 -> 1331 bytes __pycache__/statistics.cpython-38.pyc | Bin 1740 -> 552 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 __pycache__/alerts.cpython-38.pyc diff --git a/__pycache__/alerts.cpython-38.pyc b/__pycache__/alerts.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5c988cad8139405c8391297f07198b59581dc116 GIT binary patch literal 1331 zcmbVLO>@&Q5S3&*aY7O(rNifqOFh#zH%<&grj%Yf8D`R6axtnU8n?DnRu0fkIME*h z$NVK-IrT4aVAxfXCM|FP&1k)Ad8PNBpAMSMI>Yg^czXC&F!r5_<>6uR5~q2FK{3TM z)@Qp+3FTcd<$V!-j+L(htOBeARuxsns*07Tc#lQlCHAszLUDQEdDFe`VWL@|E7li^ zD{;ZF)5A{R)^~E5W}Qq!nee4%%Bg=Fry&Z8k6DZedu$@QuOn`2nmT*BC@0+dMrZFP z4669$k6!!0XfSPAq%cxya5#|WM1m~ZZ(w)?GSAcEs9kDPDo8)*A{i>ZnHHO;XPbKx zJNH2z>!cjQSz8h?vvqoA!#GZhw2Wgq!VomZ&sP`dx902JiBBIFGS_iz>v5b9)hMI9 z5y$UGGMlbI4R>&OmqJMIXzu{0J0ujY{x5CAy`5M8q%4pdP}(rlYBw8xG(b3R;v?XV zIX)C&Wq!;;0-!&()JK|uBiF)=7U$%s{yVuRxca+sl#d2NOQL})w$UqPX&g-r2@#kN z%C9W6j>XtnXe`i3m>qM)A2Q6b#$34EBZEa=7s!8?6wsr!Tz=XgfHnhLbB5>u7+ZJ# za|b)YTo!py!6vv%VU>cTzTi*dt>84I1``!t;SGMiwoKwm#>BadzQaLmXl~;)8yHIV zm5=#1{#lIiQW5%NapJ?eB0gU1yJrwrW{j*yETXEd8x$-xWtteR zI*yzLO$zRUJf>`+;X=qexIoYhAq_=X1$qh($ literal 0 HcmV?d00001 diff --git a/__pycache__/statistics.cpython-38.pyc b/__pycache__/statistics.cpython-38.pyc index 6b249d4f4eada91b5b79f65afd4c32a61a0df5e8..1dbb421c651b75832303dd1a01fd16536a60eba7 100644 GIT binary patch literal 552 zcmYjPO=}cE5Uu{0WQ~)>uajN`PdTgu;&Bl{@gyOz24TTN?{vF6*_obAbxm+!a*97B zIePck^wm@Tf+wp-krce@s;+v~kM2G_JUjrllk*p=p90`lO75EE>*ZEjYj-7+ zlv@e%$$o)8hF^)-p8N_u^&7^Dr2ZV*6=uXCIWyn<@zwTrgWt6uj zDaagvDW-VA`b-HGT(LfX!IV_t6;t7*=nF_SwFPMlQUEDZbx3tcQt=*ZHEv*obyH4% zw;y~mq9c&eV2YFVL2$tb>_S+!V3*wTQKVm6L2D&PLVv45Rl8yf{tP=8;_N3ISm|&2 zI}bbt8~U9Zao7`;RIJDBmW>vCAua_pgGB&bQP%~@`M?Eb@+(+gX+pRGQ(%Kq(F2+H zzy<*JW8;EbcFKPfXR^nxSxY!sCU)q8Dybld_ScT*I>dF){`jHu%4FJfk}B6zrG_WN z#EcT1RGshjc%YLKz6Twf8LM=Do>l2sWqWzGH<|6dOrUwJlhZ7jf z%r*842zvq|P8?Yp4J zDi`YUv{EiG(^AtNO;(*$d5R13eA1F`tD2T4h{(xNHZy&B4%;pyY-SaKSSFvdUg_CrwuT{8#)@9OqSTaBt!#YanJ1V{3}2lo)C zf3LNYs5u@U)V$`JzOj9nnN9;JEI(RPosK}}4j9HBRbSwVh|xXJ=3Pu_9aDci)R`H& zdP1#psI_SYntbaoi9I3qc8YyF`|5p#eLreU)cE{^bs%q3krIOCM~H|#qHnOk^Tz1` zTcDG7@uHmak<@Jkgr|4}cUc_Vt|iv~`D%q-Ka9uzjk=-EZiRkg*0A2kuKt{kZo{CN z(H|1q48v`w!z>*gR>~)E4>wE%#zcfcZ1Va2ji5Fzcj5O_GWm$uXT*F Date: Sat, 5 Mar 2022 19:58:50 +0530 Subject: [PATCH 06/10] created alerts.py for alerting classes --- alerts.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 alerts.py diff --git a/alerts.py b/alerts.py new file mode 100644 index 0000000..6ba8d67 --- /dev/null +++ b/alerts.py @@ -0,0 +1,31 @@ +import statistics + +# below: alerts tests + +class EmailAlert: + + def __init__(self): + self.emailSent = False # by default + +class LEDAlert: + + def __init__(self): + self.ledGlows = False # by default + +class StatsAlerter: + + def __init__(self, maxThresh, alertArrs): + + self.maxThresh = maxThresh + self.alertArrs = alertArrs + self.emailAlert = self.alertArrs[0] + self.ledAlert = self.alertArrs[1] + + def checkAndAlert(self, numbers): + + stats = statistics.calculateStats(numbers) + + if stats["max"] > self.maxThresh: + + self.emailAlert.emailSent = True + self.ledAlert.ledGlows = True \ No newline at end of file From 098a98b089f8e319317d831451a36f5a67d6d28c Mon Sep 17 00:00:00 2001 From: Aniruddh Bhaskaran Date: Sat, 5 Mar 2022 19:59:16 +0530 Subject: [PATCH 07/10] updated imports from alerts.py --- statistics.test.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/statistics.test.py b/statistics.test.py index 232ebf0..87939b3 100644 --- a/statistics.test.py +++ b/statistics.test.py @@ -1,6 +1,7 @@ from cmath import isnan import unittest import statistics +import alerts class StatsTest(unittest.TestCase): def test_report_min_max_avg(self): @@ -26,10 +27,10 @@ def test_invalid_arg_returns_None(self): self.assertTrue(statistics.calculateStats, None) def test_raise_alerts_when_max_above_threshold(self): - emailAlert = statistics.EmailAlert() # added statistics module identifier for class instantiation - ledAlert = statistics.LEDAlert() + emailAlert = alerts.EmailAlert() # added statistics module identifier for class instantiation + ledAlert = alerts.LEDAlert() maxThreshold = 10.5 - statsAlerter = statistics.StatsAlerter(maxThreshold, [emailAlert, ledAlert]) + statsAlerter = alerts.StatsAlerter(maxThreshold, [emailAlert, ledAlert]) statsAlerter.checkAndAlert([22.6, 12.5, 3.7]) self.assertTrue(emailAlert.emailSent) self.assertTrue(ledAlert.ledGlows) From ef7a95d7ce9eafaead1c4af5493a7c85d94da14f Mon Sep 17 00:00:00 2001 From: Aniruddh Bhaskaran Date: Sun, 6 Mar 2022 19:58:09 +0530 Subject: [PATCH 08/10] create limit-size.yml --- .github/workflows/limit-size.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .github/workflows/limit-size.yml diff --git a/.github/workflows/limit-size.yml b/.github/workflows/limit-size.yml new file mode 100644 index 0000000..be15436 --- /dev/null +++ b/.github/workflows/limit-size.yml @@ -0,0 +1,16 @@ +name: Limit complexity + +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Install lizard + run: pip install lizard + + - name: Limit complexity + run: $HOME/.local/bin/lizard --CCN 3 \ No newline at end of file From b89b0fa6d75016e09f7f0a70200c012f6d1b23cb Mon Sep 17 00:00:00 2001 From: Aniruddh Bhaskaran Date: Mon, 7 Mar 2022 00:13:19 +0530 Subject: [PATCH 09/10] fixed bug in invalid arg test --- statistics.test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/statistics.test.py b/statistics.test.py index 87939b3..6babe61 100644 --- a/statistics.test.py +++ b/statistics.test.py @@ -24,7 +24,7 @@ def test_avg_is_nan_for_empty_input(self): def test_invalid_arg_returns_None(self): # tests if calculateStats returns None on receiving non-array argument for 'numbers' computedStats = statistics.calculateStats("a string") - self.assertTrue(statistics.calculateStats, None) + self.assertTrue((computedStats == None), None) def test_raise_alerts_when_max_above_threshold(self): emailAlert = alerts.EmailAlert() # added statistics module identifier for class instantiation From 841f1345da29df611d44240120f3c818350c6384 Mon Sep 17 00:00:00 2001 From: Aniruddh Bhaskaran Date: Mon, 7 Mar 2022 00:13:59 +0530 Subject: [PATCH 10/10] updated to reduce CCN to 3 --- __pycache__/statistics.cpython-38.pyc | Bin 552 -> 555 bytes statistics.py | 21 +++++++-------------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/__pycache__/statistics.cpython-38.pyc b/__pycache__/statistics.cpython-38.pyc index 1dbb421c651b75832303dd1a01fd16536a60eba7..209607bfec6e5bb47261aa286e6fb29b4232f1a8 100644 GIT binary patch delta 394 zcmYjNJ5B>Z47EM8`H__ZB?u`EMMOhG7tzqu1e)!Vcojl+H_?o@00mJj7l^n7i2G2? z4Y&oK2q7%JXZyXeHS)XtwCP=%_CR9=XS3}tJ$)H!!@yWT7BdxCQbq`D*uFw$7$-1F zzT?cz2m^VUV{CqdG`AGj3h$Hz1R0swER4{@9~P#e2A@&v78;afW!weBuSncQadSf7Z0#ETpamFhuVhDxLk8xt delta 391 zcmYLFu}T9$5S^XfGiSUDMy(V7OeKZd$|--L0G~}kQ_*JprHk%e6Q62&1EST!4fW@U7I4U zJyuFlV)GbAr^N|{w7xQ~ zoyz)_oXpa~so!zlp$8|6PT>MG92eS2JI;;2!6=4?Oe)1V@218kfu#;vC)xN8rvBO% y*{v5^{~o|i8KL5gu%>oJBqB81egm3_%Zi)2XaBIptqYs^P>-|p%spj% diff --git a/statistics.py b/statistics.py index cafd93a..fe03d04 100644 --- a/statistics.py +++ b/statistics.py @@ -1,25 +1,18 @@ import math +from turtle import st def calculateStats(numbers): - stats = dict.fromkeys(["avg", "max", "min"]) + stats = dict(zip(["avg", "max", "min"], [math.nan, math.nan, math.nan])) + if type(numbers) != list: - if type(numbers) != list: - - return None # invalid_arg test - - - if len(numbers) == 0: - - for key in stats.keys(): - - stats[key] = math.nan # is_nan test - - else: + return None + + if len(numbers) != 0: stats["avg"] = round((sum(numbers) / len(numbers)), 3) stats["max"] = max(numbers) stats["min"] = min(numbers) # min_max_report test - return stats + return stats \ No newline at end of file