From 7a991f697a45e158f6003fa0aea655d79fa69740 Mon Sep 17 00:00:00 2001 From: sessionm21 Date: Wed, 13 May 2020 01:29:40 +0100 Subject: [PATCH] calculate total distance traveled --- fgs/.model.py.swp | Bin 0 -> 12288 bytes fgs/.views.py.swo | Bin 0 -> 12288 bytes fgs/.views.py.swp | Bin 0 -> 12288 bytes fgs/__init__.pyc | Bin 0 -> 600 bytes fgs/__pycache__/__init__.cpython-37.pyc | Bin 0 -> 489 bytes fgs/__pycache__/jwt.cpython-37.pyc | Bin 0 -> 1212 bytes fgs/__pycache__/model.cpython-37.pyc | Bin 0 -> 2140 bytes fgs/__pycache__/views.cpython-37.pyc | Bin 0 -> 2634 bytes fgs/views.py | 24 ++++++++++++++++++++++++ 9 files changed, 24 insertions(+) create mode 100644 fgs/.model.py.swp create mode 100644 fgs/.views.py.swo create mode 100644 fgs/.views.py.swp create mode 100644 fgs/__init__.pyc create mode 100644 fgs/__pycache__/__init__.cpython-37.pyc create mode 100644 fgs/__pycache__/jwt.cpython-37.pyc create mode 100644 fgs/__pycache__/model.cpython-37.pyc create mode 100644 fgs/__pycache__/views.cpython-37.pyc diff --git a/fgs/.model.py.swp b/fgs/.model.py.swp new file mode 100644 index 0000000000000000000000000000000000000000..5cec15fa06816499350fa7d4165f78b150cb5c06 GIT binary patch literal 12288 zcmeI2y-yTD7>5Tf6csgMWwn0g_7XTiVq!=r{0N2+q6wgtT;_I%Wy0RhW_A`ljs6YB zLjMG{vC>8pEwxt@J2e(|VrOHbzhQR|j)PN-Hsqb;$=%Mq^YK3W&K9t>!7JmF&Y8*( zLp#XWhl>-l*T3#$yRI@8OWXPTrujmDz>QeqjgG;$V>yrry(sj+T#yXZl`q0d+<8pL z3F${NKnAv8poa~g8X7!)?5NXwXl4uJD3lD40Wv@a$N(8217v^R2KB$oaGC&5%02v?yWPl8i0Wv@a$N(821KY#^_Zj=Lo3ZEJNC^M`w|@gzKET)~ z@DaQQ_rVgF1}DJ@&<)=2XY3yE!7%6spL-a430{B);0Cw^j)3KTjJ*O+!4q%?R6#%Z zv6rzo;1PHT?g9=*!C}w~zVBh|9e4{KgIRD5oCe>p|7BqFcxH2fDDj< z?PtJ2i+PePDeXI>POMcdv}w43Fx8^J&q>x?l^L^xY}3M|I&x~BZp5bI%?ocKUUG|J z6%l!OJJT)O@!?#h=&#Q6WWLPo1iqMaR)#g#a&2f|b4%rs)z#W3!G`m-?UWlYod*OW zN_c48^6J8Clj^W+o@D##%?#GMTA8TWbxX$BtY52~S7BO@Tzs1{T1G*(ofL1hM!YUM z#YlU9T4orJj0l8=EiLO@H>wMwF*>bNQD$CbGrwEL7aMu@;_8q>4s|26O$Pih`|;_>1hPjI5_&nw<5FT*MC5 ziuM*4wg!uKixuCB&yq?_B7IRB$qG2XY>)Ht-ZB* literal 0 HcmV?d00001 diff --git a/fgs/.views.py.swo b/fgs/.views.py.swo new file mode 100644 index 0000000000000000000000000000000000000000..bd906466c42c8270a5c71bba04d541ca2a3c7da6 GIT binary patch literal 12288 zcmeI2!EYNy6vn4Opg>v>ATE{KX+hduaMlj=P+4`Gs+DMwD3M4DBDB`pJ9eht-P!Dp zlUh*_=N^#YzyS`>1L9BMfPgC!aN@=hAr2f6LP%UH!8f}*YddiqLocYBm45N=%$xUS zzV~LwO46!bz4Qt_=)Pjzuiw3t`ib-)wutac)f+LC)uVqm}>lX%&RF& zHds>abkphvXPc=TPaiYYq3JXV7zJiipf5WMrw)-9Us$X?bK*FC@`)?6jWbq80i%FX zz$jo8FbWt2i~>dhqrg3*fQ%22zpdhqrg3)faeqP-W(y{KZph4@Biv|0KYy)$amm#a0^7>4e&a63Dm(ca1{J?81~>R z@IH7G90NZdBIGvs1iTC00UO{PSON|>0_MS=^N0l!a2h-d=D@d)60!+G5P(bIA~*q_ z0(TxEWpEVC1EtqD;5LZB3a~&IoC7~W(@%lYb`4ly4*c=}^Z>Vjxr_ovfm{JvUI~-^ zB%(J`5%JEzUX2Bhq$@?!=WS^_v?CIlwNV~X-;-W5drGf4r1XIsF9__hmMMPKxGCKT zyT8Q@6Pq5Qa4;#-q_&x5xvRmW3hp(16=2sj*;tuP?%6ZHvkuWS_?PZyE*~lqpC!%K zz`lT*Th59S)yE_cnd`H(Z99(p7SYpCpB)~^d`MdaftNJ7-{8Ks8Yx}cphKtYeU=R1 zDRad;G#^WON-v9u)v4DKiL_7FPUg8Ox*PO-7Q@Yl4?`C*J3L9Tdx+1p$L1POrAP)g zrc@_OH#TK6Ve5UKFrO@WaqK3dFPUvs^9X76H1=Vg`)8`fK+DPJxI=NTE%^p(7NZIq zCC6wjsb@+pA5-w6HnZwf-!^+Z5FvwbDcvTSS@C1b;yw&>$1e9P)QY@NjV+qgQ-zje z#wX%pNi6d1vU_N#{I>=2+YG!^A{p7k&=B2|X7_x9cA1C=uI_ZNa;znigA2v7?4j36 zcI&vku=J~5WLc|vk!3e&Gxm_DdTBBouV+=5xUqdjZBWt?EH{zZ15s zGB>E_(7Tx*YNHvmbi&3BiY#vbr@dmuBDIF)HZIcc9aE%Sze{up=+7BSVdM>2F7p3a z53`lQ9(muQRv-W8oV}c|@w%>h%6_OOx}Cp;L$*&4yxJzeVc}nj9*a;2nddH(O}xHs z2j@^*`0%S@sI1`lP!{^|z!^p(A@fn~HP-Iog_EY6NSv*2oZ$&m%bjE%8uW@<#Lm-2 z^{GWQ^o`?=R!0#(TXu1PsX6FadS1IimIe)cT|mrKy4d}pi^T#8f z-Q49*rHzL%j_Dl-1nDFqr0II#1yDa6(88+IkJ@=(2PaTZH+L)gTX01$t&$)Axv?7} b*@3oxu4qIh=%%qVJ&Wz?F08*o{TBHLY#sP% literal 0 HcmV?d00001 diff --git a/fgs/.views.py.swp b/fgs/.views.py.swp new file mode 100644 index 0000000000000000000000000000000000000000..fdd4d701d88fc7af5da464486bb848384f23efd7 GIT binary patch literal 12288 zcmeI2&u`pB6vwBaK!FwzAaOvV(*(&j+ImykLs)fDP%6+4VLd-D{(<^oi}6H}B2+zL~L< zWMlcp<+tfdc$VOLmXO=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@nsLM*I+tdRYG>y$kE2#6>hkO8QEyO6;2?QZW>;f>f@XJ& zGie#-Z?j+4mp>ZG@S1jGsk#HQ{EIFS$20IbyjCJug136wpa547O-Dru6&yS literal 0 HcmV?d00001 diff --git a/fgs/__pycache__/__init__.cpython-37.pyc b/fgs/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..56e6bcb8a3391ddc10af408970f8c3dd83c9f5af GIT binary patch literal 489 zcmXw!O;6iE5QcZXwqr~}A*#fcTa_NV_X<_bhoKFjRdIS?4_&$0NpQ0MsMiFAYySuw z`8C}4+7o}FC&r;2Y3F@sb~KM>(CLH(<8gfUV@wJ8(-i;1Me`A#sW2&`s3sW|ls4Yc zPR0b=dZu0B0tN3k6~1!8y=y7&o*okLmx1z+3AoFhyHK_6X*pH__;ME*_&D8GJ1W$j zDcS1YKYfMDV$$1vLN4i1>z(Mttk8tG6>FgB1fPco3wvZO4nzknL@we@F3K2I06g+*Ewxn=la z!xxrBmUYxm;jL4+G1kip1zND>P5nTs16;jLf8X${A_HEgd<14y7bQ1Pt)b%ch2c`B id0I>PuH4w*7&lyN_|P0+x|rIuO#>&OuW8q5G@#GAb=3S2;ywv!|KR8?cVO~hU8f} z;p9dJ;zmJ!f?cLhkt#ogO^Q_NQ@P3vFERv#z&ywq4rjg@el{9q4A);@ee?Wx!Pwul zxn3NVCrIWwGRY(~tRTr7XnDa~QHVAu0$@_epb6Wkh}yV_{XT4xHZ4-rnT(pO9TWr9 zW0|~S#ZV1ZIvL7TX1E(kc*^p@6~4iaa^YgFeq1SI9n4)=9(USa0h)5|xIA{E?E4&C z@SRZ_Wq7K~-b~4X7ReClb0l*InPoLd*sz*cU_~8BF2$w5_kttGE9t_opFa5HAqGmz zX5Q(_p0s)BM15*qq?Xf8Doyz47@5nAnrdYy3$>;cjA~}TF?|b7@9vFHx>k+*YW#&V z3)}T$%3Z17wL3#K1l`>emU zVI6I_4AC!s%WP7oGMa;oFU7gASv{zS8zGasOs1FcW`rI)lU=)0?@G2v^vmlwui1ue z;1^6XV0Lej=|6y-yZR13ydrosm8%EHawxL*Ju|*bIe1b1gBS9BP5v%EQ6)CfXad%Srf(|iM5C5^ zLM2bZ_PSbH zoSvZ6bK|1Lsh6YjW-%__J}4b1oFSO`@zMJfai2`Ov`S89tL2n}QjX>xGR8AVU=N0n za1H@vp6)=#64dw5c6J{}YeIjg(n=maYPxCJn8%0z4~j6Q7%}JiBNX~$Vl>2f?hkx2 z!<*5DXf*^NgM-`pKKbr!@e5~7X%-%856c#2rX%#(ewwhwPt1 eivlHa1CQhpUR^cnG5u;o9ZKN9V=&~2i1@$V8W!mQ literal 0 HcmV?d00001 diff --git a/fgs/__pycache__/model.cpython-37.pyc b/fgs/__pycache__/model.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..9c4ae7159246accd1badea3ced58fa01828c2103 GIT binary patch literal 2140 zcma)7%Z}Vc6m_}%>~_zi6W$;p2#-c$`Ug-Hl8^{Rw2&qsx);n;w>z z1LqE!`W1#-oE6rT#f(|p=AFWh?S~e3xckE5u3#sf=bhL=#N$39ej9NS33!M|*hV}= zy1a)-uZ{S;b7&2tYldxxOxyhE8lE-I$S$uHnA?a5D`wn^ZP7V#&|J>A{nCy-(Yc~$ zf6n5d^+Whw_&wf%7jXw$x!Su|6-6o^W4m50^JywCl2dV^!~1EI{#fN@GamMJkR)X~ z6-lDINiwbYtRO#1lHX=&u^5py;F#rR(^C82myMVRsqLI=@34`1InfTy)c)P7Dnwdp zFU^|#Oz238B5m@jRL6O(dmI}lHSMhawB!w}YRo^kM#t4ujOu)JU#Qcjsz*x5Ga*M$ zCu#&tqBy88B(XzH1uy~IV-ao>-69bgUS#xlIIkhm1!>64oXzbunUwFBtfiEw4p)(0 zOSnrkw|*b~PV4W&-&?37-sb_*5K6*>97q@aWtf?q9OV3(G>O!NwG>&dz)?oppo@BX z>mHhVALf~LLXDx>XdN_%vp-y{Z;z4bu&ByO-pshr0r73T{!!XA0y!_lnJ9Ds@xeA`m`h^Oon7gNs?ZaJu(rD?mnob$S36^(&mDn1k!RJ6jj>10#OIpMLfo5EWqy4 zDuh^mL}n$ag-4hT|FompgCW`6WCPqJp2#+%Tk@ea-J$8fz`RC2kPdf@RF;*vj)WUh zq1rSx40-f8rOnfWLnLEX%+$A3DyB%5Dv@ttYbfSzbmL+41{}(dF?CH<9Gz9g3`K2H zANTRpq?7jXe@XfT?-PwCsYKF(B1!QrdR9l&&lq_fJ^0)eG4Mm8>xC6}xywEDJ?`@W zeI)v#D|*lEc!!4|r>mWxZ~!dn*s2Sv4O16XAgBWi^Vt}B?boSN=auBiajK5N-iMg5 z@vTO`(L^-Ka^e@5ph%DwyWFP@4>m_LGlD_tNffJUY^*Exj9uAt3tne#%~6wy!&@Xc zcaJi8Q8%$iK<|2Z0sURZ1ONa4 literal 0 HcmV?d00001 diff --git a/fgs/__pycache__/views.cpython-37.pyc b/fgs/__pycache__/views.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..92ac2d2f43bcd3871d6fa002a4635992ac41154e GIT binary patch literal 2634 zcmaJ@&u<$=6rP#=;kDy9u9LQD8=x(}>QdqgBtR$%736?8go+d@ty-*&XXC81>vd)~ zZ4#|d>9takI9A9$@;C5*aM&xSp1JkJ_hxM;jVdh7?AteQXWqQ;n{WK>{CtJsxB1Oq zzkXh3>>qlW{!AG6(2~E=NhW#7BJT1?xPsHW2#v^eO>G;Y^?*rJTA>}4+*0JYPE>Zw zQN^ub+>~}W7ggP=woBo>Tl4v7K{{hD%d+x}op87A^WK7-lhrPl^UsB>$p!7dpd;&J z?wj(0Y>*Gp4eedj-X(c);$76FBm+IvNNugYr^??qYKV$GFT9Gh#3-0%j2 zT*&Pv&#S$sX-udlUh+$1L=iR*2OX7a8bCj1T!cWrN^0s4@BF@}7=yx_> z^Hzt#r$3tiJG6w#DLK{@o5%Ct`(YU0x&Aa(p}g@YQ}Y-+?Ow06cH_uz4T4tUt0%r{ z?R1mYlfZwPtPYNH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? Uq>p;hFqg{?ubF5yv`Y^E4*`)^@&Et; literal 0 HcmV?d00001 diff --git a/fgs/views.py b/fgs/views.py index 4da57e1..37af82e 100644 --- a/fgs/views.py +++ b/fgs/views.py @@ -3,6 +3,7 @@ from .jwt import jwt_required from .model import * from flask import g, jsonify, request, abort from sqlalchemy import func +import geopy.distance @app.route('/') def index(): @@ -37,6 +38,29 @@ def collars(): return jsonify(active_collars) +@app.route('/collars/stats/distance') +@jwt_required +def collars_distance(): + active_collars = [] + for collar in Collar.query.filter_by(active=True).all(): + coords = DataPoint.query.filter_by(collar_id=collar.id).\ + order_by(DataPoint.datetime.desc()) + + distance_kilometers = 0 + coords_pairs = list(map(lambda e : (e.longitude, e.latitude), coords)) + + coord_last = coords_pairs.pop() + for coord in coords_pairs: + distance_kilometers += geopy.distance.VincentyDistance(coord_last,coord).km + coord_last = coord + + active_collars.append( + {'id': collar.id, 'name': collar.name, + 'distance': distance_kilometers } + ) + + return jsonify(active_collars) + @app.route('/collars//history') @jwt_required def collar_history(id):