From 2b702c4ee83586926aeefadf039529b678e204b6 Mon Sep 17 00:00:00 2001 From: Umit <60366307+umitozmen@users.noreply.github.com> Date: Sun, 8 Nov 2020 21:04:27 +0000 Subject: [PATCH] Fixture UCL-RITS/rse-classwork-2020#92 --- .vscode/settings.json | 3 ++ .../test_times.cpython-38-pytest-6.1.2.pyc | Bin 2256 -> 1266 bytes .../__pycache__/times.cpython-37.pyc | Bin 0 -> 1332 bytes .../__pycache__/times.cpython-38.pyc | Bin 1482 -> 1328 bytes week05-testing/fixture.yaml | 20 ++++++++ week05-testing/test_times.py | 46 +++++++++--------- week05-testing/times.py | 38 ++++++++------- 7 files changed, 65 insertions(+), 42 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 week05-testing/__pycache__/times.cpython-37.pyc create mode 100644 week05-testing/fixture.yaml diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..44f9878 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "C:\\Users\\umitozm\\AppData\\Local\\Programs\\Python\\Python37-32\\python.exe" +} \ No newline at end of file diff --git a/week05-testing/__pycache__/test_times.cpython-38-pytest-6.1.2.pyc b/week05-testing/__pycache__/test_times.cpython-38-pytest-6.1.2.pyc index 0afc867fb93421cc84a24d71269143fa8405f29d..9a1f52ce52692e3afb6480fe66ddfc1841e2c8f3 100644 GIT binary patch delta 464 zcmZ8bOG^VW7)kkNkckpj%O7E-9YlGsN3jqNH z1~D%-;+%qotvXkwYM87ny<>wMn?Rf=6;Lv z9wC2|TOSwJ8*r%~L2$xpLPBcptYI-iNy82uiXN7@ja-;(c%j$Ghk0Y8i68ph;gM~kSnFJuz8BlM-yx2-Qk(iZZZT~1cZmGXSKGGD3A zRLW})%WLKG9pfV~26wS5U_KfOP+hBHfWVRtGIrbXPWdJCnu&+6Hn03ZF$b9%|v*8_UA`e3$w zxELt^hrTkiK7(30P_uZi1ZvJ0s(}jp-pqRDUJjJBp=4>{y3CcEi)!j!6+LiL3j&59 zDyUUaEaGzcs1z$Dq&7RO1PYBSK|TxZZ?q4!P&$fbIv(xBNfJrXme?P$6loFM(RQbv z=z3G7ZqfpTO7BJLMXQr=1C44)YdcP&W(Mov08!*4ubJU& ziH{CA>j5Hv&DlO*$2KpAW)}`F_zfFzHo(u!v0)F47@T7l3~F%k7{t{8!|s=#punO+ zH%#=Ye?@a3edVPo9Re8gnl6g6nUeSvjQIAsVeQaK0r zU?TOdTHX{jy&q-!EM$!djk_Slfvjt2_<kyT8!rm?kO2sAb=rvtJSN&){q1 QzqaR6M%aJM_APJXf9j(uRR910 diff --git a/week05-testing/__pycache__/times.cpython-37.pyc b/week05-testing/__pycache__/times.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7a0549aa323681c3c82f474ba60feadc1b823f54 GIT binary patch literal 1332 zcmZuwO>Y}F5GA=ET5s(%ZH!t#i(n7cK|o|U0(x-`H)vfTht?Oj2|~zSte2Fu)k-Uq zRO}esOKrf;p@*J(v2X2P+G|hw3psU$w&Nfz7aVeCIm0)PGvBVP#018l{I7Hx67ml! zx5I+e-fxih6#2`f1?&GZF1>d5z9U&7gTt-3a?F8$r^c0&dE7F zXF~uZg0sl@7QA-IDXjq(ScnZ!18A+?lTSJ?dYx&nBa+V3&CZXToxPK9ej3X}&O}lT z69ZdQOl6|7*+?eiOedyF@(L{4s3JGzt0Ws5sglBIFlEZDD+c-Gm@W=fBA5?g>Zc$^ z#FG6dHNC(rsihZy8YD&Rg8WX`$n772`~UnMvOn0N59nE!@|Ko)H51z1*=0>6G9wW% zUqUHlX)-Xg^^JxWU9X{{SsP{Z^gx;;DQ9Uh1MDxeQm49EcJNd5OZDI6?brF{;AbtB z9xSGXsZOQ?rDZQKGp&y*HR<&?`Wpj?GTHd5XQVd8Y&1Y;y*_{SHr^@=ZGfoxHkOe_ z8bWsR&_#D-u5Xo94mWSZ=Jx12*03(HM)uJ6OAwB=F9xipHM8^*n7X2tU9ayLq5t!o zKvD!xHN=a%p2DKz%w!ES2WknFYk?TmM<7;UUV|mwKp_n0K1cT^ewLLB`Mpw=;wz>y zS()DO-vlnFZph<17I_3!73Vvi}S?^=kk4 z2May2zXMuOht{*xH-VsbomBtGUo9ELMa z>pQK_y|Oyu{{y^2 h-`vsXe!h2ys}}bH(blvQi&Ac*i$-Q6FJ6v5{TCCfJc$4R literal 0 HcmV?d00001 diff --git a/week05-testing/__pycache__/times.cpython-38.pyc b/week05-testing/__pycache__/times.cpython-38.pyc index 70a599317bbbd8e6dc6ebbeed9da45fae2c50a60..48b8b132f9ba983b67b6dfebfb3f9919d71e34dc 100644 GIT binary patch delta 396 zcmWlU&q~8U5XN^l*(6PyQfl-drR>2=P`rvDsMu2x5B@s@MMF1jL;r8~ps>M%eSwmj zURu2LDEJmWLLb4WaIzos&2PWU%>0(W-Rhm^xdh*5xPBU0i)v%9i9bOE3`t0YEev7K zAq2sMH76kza6A|B~Mg}Q6$yj&jI)VZhlVJ;N^exYsV7v%tj dI>-j*0hJV+gn|vp3f?KKk$WB8o8WKo;!oHgBi0Oiv7z6qeoa@uS3ko)ThXh2KLlRCcfL&)Y8ef8#(Xkh zu!IcE6(fwizzmHt`T{aCJrghsgDE88a{ndD<;Us0QR;H*VmF-?@wAT1+!Z!J;fV{TdUXf9ivO}bs_kl`da%pMi^0m0maPvuNHQj)dOnpHY;FmA3Wn-zhLn2 zh8k*wM`qb5PhK6VI`-0wBW1@9&LIVdtjlw1v?DLP;;QGh@4ch+A%{%i2ks|gt=wr< z7Hcuf&lsljBv|WC+THNp>P$XfY#$uYs#8}?jz1K(%&W;^QC5W=w4NdcKn{Te)D&Wf z_AV>`h0rW0-d%`CT)c;dJUoZD<2DHMu#pbfC|j1$C_C`<8NK>~2q%N#N#H33dy`)# z)U{vhysCJ@iC$&$&UJg6uk4T^>uo%)KFRw}Zn08dWdM|&M; end_time_s: - raise ValueError("Start time is later than end time") - + if(start_time_s>=end_time_s): + raise ValueError('The end of the time range has to come strictly after its start.') d = (end_time_s - start_time_s).total_seconds() / number_of_intervals + gap_between_intervals_s * (1 / number_of_intervals - 1) sec_range = [(start_time_s + datetime.timedelta(seconds=i * d + i * gap_between_intervals_s), start_time_s + datetime.timedelta(seconds=(i + 1) * d + i * gap_between_intervals_s)) for i in range(number_of_intervals)] return [(ta.strftime("%Y-%m-%d %H:%M:%S"), tb.strftime("%Y-%m-%d %H:%M:%S")) for ta, tb in sec_range] -def compute_overlap_helper(tuple1, tuple2): - start1, end1 = tuple1 - start2, end2 = tuple2 - if(start1 >= end2 or start2 >= end1): - return tuple() - else: - low = max(start1, start2) - high = min(end1, end2) - return((low, high)) def compute_overlap_time(range1, range2): overlap_time = [] - for tuple1 in range1: - for tuple2 in range2: - if(overlap := compute_overlap_helper(tuple1, tuple2)): - overlap_time.append((overlap)) - return(overlap_time) \ No newline at end of file + for start1, end1 in range1: + for start2, end2 in range2: + # both ranges need to start before the other ends, otherwise there is no overlap! + if start1 <= end2 and start2 <= end1: + low = max(start1, start2) + high = min(end1, end2) + if high == low: + continue + overlap_time.append((low, high)) + return overlap_time + +""" + if __name__ == "__main__": + large = time_range("2010-01-12 10:00:00", "2010-01-12 12:00:00") + short = time_range("2010-01-12 10:30:00", "2010-01-12 10:45:00", 2, 60) + print(compute_overlap_time(large, short)) +""" \ No newline at end of file