From 904ed7a7056f43964d5ab2ce1aea29df71a4ff04 Mon Sep 17 00:00:00 2001 From: "Casper V. Kristensen" Date: Mon, 8 Apr 2019 18:41:54 +0200 Subject: [PATCH] Fake everything for easier (semi-)permanent hosting. --- server/nightr/app.py | 8 +- .../strategies/Tidevand2019Aarhus.t.txt | 1426 +++++++++++++++++ server/nightr/strategies/bing.py | 11 +- server/nightr/strategies/cars_in_traffic.py | 19 +- server/nightr/strategies/iss.py | 130 +- server/nightr/strategies/just_eat.py | 25 +- server/nightr/strategies/miloStrats.py | 36 +- server/nightr/strategies/steam.py | 14 +- server/nightr/strategies/strat_utils.py | 23 +- server/nightr/strategies/svm_strat.py | 50 +- server/nightr/strategies/tide_strat.py | 14 +- .../nightr/strategies/upstairs_neighbour.py | 30 +- server/nightr/util.py | 15 +- server/requirements.txt | 9 - 14 files changed, 1587 insertions(+), 223 deletions(-) create mode 100644 server/nightr/strategies/Tidevand2019Aarhus.t.txt diff --git a/server/nightr/app.py b/server/nightr/app.py index 5518050..b099f0a 100644 --- a/server/nightr/app.py +++ b/server/nightr/app.py @@ -3,11 +3,9 @@ import json import statistics import timeit from dataclasses import asdict -from datetime import timedelta from logging import DEBUG from typing import List -import requests_cache from flask import Flask, jsonify, logging, request from .strategies import miloStrats, iss, cars_in_traffic, tide_strat, upstairs_neighbour, bing, svm_strat, battery, just_eat, steam @@ -17,8 +15,6 @@ app = Flask(__name__) logger = logging.create_logger(app) logger.setLevel(DEBUG) -requests_cache.install_cache("requests_cache", expire_after=timedelta(minutes=2)) - strategies = { # name: (weight, probability function) @@ -44,7 +40,7 @@ def probabilities(): context = Context() else: phone_data = request.get_json(force=True) - logger.debug("phone_data:\n%s", json.dumps(phone_data, indent=2)) + #logger.debug("phone_data:\n%s", json.dumps(phone_data, indent=2)) context = Context(**phone_data["data"]) #logger.debug("Context: %s", context) @@ -101,7 +97,7 @@ def probabilities(): def main(): - app.run(host='0.0.0.0', debug=True) + app.run(host='0.0.0.0', port=3301, debug=False) if __name__ == '__main__': diff --git a/server/nightr/strategies/Tidevand2019Aarhus.t.txt b/server/nightr/strategies/Tidevand2019Aarhus.t.txt new file mode 100644 index 0000000..0f8975e --- /dev/null +++ b/server/nightr/strategies/Tidevand2019Aarhus.t.txt @@ -0,0 +1,1426 @@ +# TIDE TABLE +#--------------------------------------------------------- +# Created by: Danish Meteorological Institute +# Station: Århus +# Country: Denmark +# Data source: DMI +# Latitude: 56 09 N = 56.1500 +# Longitude: 10 13 E = 10.2167 +# Time Zone: Danish standard time [UTC +1 hour] +# Reference: Chart Datum = Mean Sea Level (MSL) +# LAT: -26.5 cm +# Z0: -1.0 cm +# Parameter: Tidal height at high and low water [cm] +# Data format: h[cm] +#--------------------------------------------------------- +201901010102 -26 +201901010720 23 +201901011323 -22 +201901011937 27 +201901020156 -26 +201901020809 23 +201901021412 -22 +201901022027 27 +201901030244 -25 +201901030855 22 +201901031457 -21 +201901032112 25 +201901040327 -22 +201901040937 19 +201901041538 -19 +201901042155 23 +201901050407 -19 +201901051015 16 +201901051615 -17 +201901052235 20 +201901060444 -15 +201901061052 13 +201901061651 -15 +201901062313 17 +201901070517 -12 +201901071126 11 +201901071725 -14 +201901072349 14 +201901080550 -9 +201901081159 10 +201901081759 -13 +201901090027 12 +201901090623 -8 +201901091234 9 +201901091837 -13 +201901100107 11 +201901100701 -8 +201901101315 10 +201901101922 -13 +201901110152 10 +201901110745 -8 +201901111403 11 +201901112013 -13 +201901120246 10 +201901120836 -9 +201901121459 12 +201901122112 -14 +201901130356 11 +201901130935 -10 +201901131608 14 +201901132226 -15 +201901140544 12 +201901141048 -11 +201901141741 16 +201901150017 -16 +201901150640 14 +201901151217 -13 +201901151846 19 +201901160109 -18 +201901160723 16 +201901161309 -16 +201901161933 21 +201901170149 -19 +201901170800 17 +201901171349 -18 +201901172013 22 +201901180224 -19 +201901180834 17 +201901181426 -19 +201901182051 22 +201901190258 -19 +201901190908 17 +201901191504 -20 +201901192129 22 +201901200333 -18 +201901200944 17 +201901201544 -21 +201901202208 22 +201901210412 -18 +201901211023 18 +201901211626 -22 +201901212250 22 +201901220453 -18 +201901221105 19 +201901221711 -22 +201901222334 21 +201901230538 -18 +201901231151 19 +201901231800 -23 +201901240023 21 +201901240626 -18 +201901241241 20 +201901241852 -23 +201901250116 20 +201901250719 -18 +201901251336 20 +201901251949 -22 +201901260213 19 +201901260816 -17 +201901261436 21 +201901262051 -22 +201901270319 19 +201901270920 -17 +201901271545 22 +201901272205 -22 +201901280438 19 +201901281037 -18 +201901281706 23 +201901282334 -23 +201901290559 21 +201901291200 -20 +201901291821 26 +201901300047 -25 +201901300700 22 +201901301304 -22 +201901301921 27 +201901310143 -25 +201901310752 23 +201901311357 -23 +201901312012 27 +201902010231 -24 +201902010839 22 +201902011443 -22 +201902012059 26 +201902020316 -22 +201902020921 19 +201902021525 -20 +201902022143 23 +201902030356 -18 +201902031000 16 +201902031603 -18 +201902032223 19 +201902040430 -14 +201902041035 13 +201902041637 -15 +201902042259 15 +201902050500 -10 +201902051106 10 +201902051707 -13 +201902052331 12 +201902060526 -7 +201902061134 9 +201902061735 -12 +201902070001 10 +201902070551 -7 +201902071203 9 +201902071807 -12 +201902080034 9 +201902080622 -7 +201902081238 10 +201902081847 -12 +201902090112 9 +201902090703 -8 +201902091323 12 +201902091935 -13 +201902100159 9 +201902100752 -9 +201902101416 13 +201902102029 -13 +201902110254 10 +201902110848 -11 +201902111516 14 +201902112130 -14 +201902120359 11 +201902120949 -12 +201902121626 16 +201902122242 -15 +201902130520 12 +201902131058 -14 +201902131749 18 +201902140009 -17 +201902140631 15 +201902141212 -17 +201902141854 21 +201902150108 -18 +201902150720 17 +201902151311 -19 +201902151943 23 +201902160152 -19 +201902160802 18 +201902161359 -21 +201902162027 24 +201902170232 -19 +201902170842 19 +201902171443 -23 +201902172108 24 +201902180311 -19 +201902180922 20 +201902181526 -23 +201902182149 23 +201902190352 -19 +201902191003 21 +201902191609 -24 +201902192232 23 +201902200433 -19 +201902201046 21 +201902201654 -24 +201902202316 22 +201902210518 -19 +201902211132 22 +201902211742 -24 +201902220003 21 +201902220605 -18 +201902221221 22 +201902221833 -23 +201902230054 20 +201902230656 -18 +201902231314 22 +201902231927 -22 +201902240149 19 +201902240751 -18 +201902241412 22 +201902242027 -21 +201902250251 18 +201902250852 -18 +201902251519 22 +201902252138 -21 +201902260406 18 +201902261005 -18 +201902261639 23 +201902262309 -21 +201902270530 19 +201902271133 -20 +201902271759 25 +201902280028 -23 +201902280637 21 +201902281243 -22 +201902281902 27 +201903010125 -24 +201903010731 22 +201903011338 -23 +201903011955 27 +201903020215 -23 +201903020819 21 +201903021427 -23 +201903022044 26 +201903030300 -21 +201903030903 20 +201903031511 -22 +201903032129 23 +201903040341 -17 +201903040943 17 +201903041550 -19 +201903042209 19 +201903050415 -13 +201903051018 14 +201903051623 -16 +201903052244 15 +201903060442 -9 +201903061047 11 +201903061650 -13 +201903062312 11 +201903070502 -7 +201903071111 10 +201903071714 -12 +201903072337 8 +201903080521 -6 +201903081136 10 +201903081741 -11 +201903090003 8 +201903090549 -7 +201903091208 11 +201903091818 -12 +201903100038 8 +201903100629 -9 +201903101251 13 +201903101903 -13 +201903110122 9 +201903110718 -11 +201903111343 14 +201903111956 -13 +201903120214 10 +201903120813 -13 +201903121440 16 +201903122053 -14 +201903130312 11 +201903130912 -14 +201903131545 17 +201903132157 -15 +201903140419 12 +201903141017 -16 +201903141659 19 +201903142310 -16 +201903150533 15 +201903151129 -18 +201903151816 21 +201903160025 -17 +201903160640 17 +201903161238 -21 +201903161916 23 +201903170122 -19 +201903170732 20 +201903171335 -23 +201903172004 24 +201903180208 -20 +201903180818 21 +201903181423 -24 +201903182049 24 +201903190251 -20 +201903190902 22 +201903191509 -25 +201903192131 24 +201903200332 -20 +201903200944 23 +201903201553 -25 +201903202214 23 +201903210415 -20 +201903211028 23 +201903211638 -25 +201903212258 21 +201903220458 -19 +201903221113 23 +201903221724 -24 +201903222343 20 +201903230544 -19 +201903231201 23 +201903231813 -23 +201903240032 19 +201903240633 -19 +201903241252 22 +201903241905 -21 +201903250124 18 +201903250725 -18 +201903251348 22 +201903252002 -20 +201903260222 17 +201903260824 -18 +201903261452 21 +201903262108 -19 +201903270331 16 +201903270932 -18 +201903271609 22 +201903272235 -19 +201903280455 17 +201903281058 -19 +201903281734 23 +201903290004 -20 +201903290609 19 +201903291218 -21 +201903291841 25 +201903300104 -22 +201903300706 21 +201903301317 -23 +201903301935 26 +201903310154 -21 +201903310756 21 +201903311407 -24 +201903312025 25 +201904010240 -20 +201904010841 20 +201904011453 -22 +201904012110 23 +201904020321 -17 +201904020922 18 +201904021533 -20 +201904022151 19 +201904030356 -13 +201904030957 15 +201904031607 -17 +201904032225 14 +201904040421 -10 +201904041026 13 +201904041632 -14 +201904042251 11 +201904050437 -8 +201904051049 11 +201904051653 -12 +201904052312 8 +201904060454 -7 +201904061112 11 +201904061718 -11 +201904062336 8 +201904070522 -9 +201904071144 12 +201904071753 -12 +201904080009 8 +201904080602 -11 +201904081226 14 +201904081837 -13 +201904090052 9 +201904090651 -13 +201904091317 15 +201904091927 -13 +201904100142 11 +201904100745 -15 +201904101413 16 +201904102023 -14 +201904110239 12 +201904110844 -16 +201904111515 18 +201904112124 -14 +201904120342 14 +201904120947 -18 +201904121625 19 +201904122232 -15 +201904130452 16 +201904131057 -20 +201904131743 21 +201904132347 -17 +201904140605 18 +201904141211 -22 +201904141851 23 +201904150054 -19 +201904150706 21 +201904151314 -24 +201904151944 24 +201904160146 -20 +201904160757 23 +201904161407 -26 +201904162031 24 +201904170232 -21 +201904170844 24 +201904171454 -26 +201904172115 24 +201904180315 -20 +201904180928 24 +201904181538 -25 +201904182157 22 +201904190357 -20 +201904191012 24 +201904191622 -24 +201904192240 21 +201904200439 -19 +201904201056 23 +201904201707 -23 +201904202324 19 +201904210524 -19 +201904211142 23 +201904211753 -21 +201904220009 17 +201904220610 -18 +201904221231 22 +201904221842 -19 +201904230058 16 +201904230659 -18 +201904231324 21 +201904231935 -18 +201904240152 15 +201904240754 -17 +201904241423 20 +201904242035 -16 +201904250254 14 +201904250856 -17 +201904251534 20 +201904252152 -16 +201904260411 15 +201904261016 -18 +201904261704 21 +201904262334 -17 +201904270535 17 +201904271149 -20 +201904271816 22 +201904280038 -18 +201904280637 19 +201904281253 -22 +201904281912 24 +201904290129 -19 +201904290729 20 +201904291345 -23 +201904292002 23 +201904300215 -18 +201904300816 20 +201904301431 -22 +201904302047 21 +201905010256 -16 +201905010857 19 +201905011512 -20 +201905012128 18 +201905020330 -14 +201905020934 17 +201905021547 -18 +201905022202 15 +201905030355 -11 +201905031003 15 +201905031612 -15 +201905032227 11 +201905040412 -9 +201905041027 14 +201905041632 -13 +201905042247 9 +201905050431 -10 +201905051052 13 +201905051657 -12 +201905052311 9 +201905060500 -11 +201905061124 14 +201905061731 -12 +201905062344 10 +201905070540 -13 +201905071206 15 +201905071814 -13 +201905080027 11 +201905080629 -15 +201905081255 16 +201905081903 -14 +201905090117 12 +201905090722 -17 +201905091349 17 +201905091957 -14 +201905100212 14 +201905100820 -18 +201905101449 18 +201905102057 -15 +201905110313 15 +201905110923 -19 +201905111557 19 +201905112202 -15 +201905120421 17 +201905121032 -21 +201905121714 20 +201905122315 -17 +201905130536 19 +201905131148 -23 +201905131828 22 +201905140028 -19 +201905140644 22 +201905141257 -25 +201905141925 24 +201905150126 -20 +201905150739 24 +201905151352 -26 +201905152014 24 +201905160214 -21 +201905160828 25 +201905161441 -26 +201905162059 23 +201905170259 -21 +201905170913 25 +201905171525 -25 +201905172142 22 +201905180341 -20 +201905180957 24 +201905181609 -23 +201905182224 20 +201905190423 -19 +201905191041 23 +201905191651 -21 +201905192305 18 +201905200505 -18 +201905201125 22 +201905201734 -19 +201905202348 16 +201905210548 -18 +201905211210 20 +201905211819 -17 +201905220033 14 +201905220634 -17 +201905221259 19 +201905221908 -15 +201905230121 13 +201905230724 -17 +201905231353 18 +201905232001 -13 +201905240216 13 +201905240820 -16 +201905241457 17 +201905242104 -12 +201905250321 13 +201905250928 -16 +201905251623 17 +201905252240 -12 +201905260448 14 +201905261108 -18 +201905261747 19 +201905270006 -14 +201905270603 17 +201905271224 -20 +201905271846 20 +201905280059 -16 +201905280659 19 +201905281319 -21 +201905281936 21 +201905290145 -16 +201905290747 20 +201905291406 -22 +201905292021 20 +201905300226 -16 +201905300829 20 +201905301447 -20 +201905302100 18 +201905310259 -15 +201905310907 19 +201905311522 -18 +201905312134 15 +201906010324 -13 +201906010937 17 +201906011547 -16 +201906012159 12 +201906020344 -12 +201906021004 16 +201906021609 -14 +201906022221 11 +201906030409 -13 +201906031032 16 +201906031636 -13 +201906032247 11 +201906040441 -14 +201906041106 16 +201906041711 -13 +201906042322 12 +201906050522 -16 +201906051148 17 +201906051753 -14 +201906060005 13 +201906060610 -18 +201906061236 18 +201906061841 -14 +201906070054 14 +201906070702 -19 +201906071329 18 +201906071934 -15 +201906080149 16 +201906080759 -20 +201906081427 18 +201906082032 -15 +201906090249 17 +201906090901 -21 +201906091532 19 +201906092135 -16 +201906100355 18 +201906101009 -22 +201906101648 20 +201906102247 -17 +201906110511 21 +201906111128 -23 +201906111806 21 +201906120004 -19 +201906120623 23 +201906121242 -25 +201906121908 23 +201906130108 -21 +201906130723 25 +201906131340 -26 +201906131959 23 +201906140159 -22 +201906140814 26 +201906141429 -26 +201906142045 23 +201906150245 -22 +201906150901 26 +201906151514 -24 +201906152127 21 +201906160327 -21 +201906160945 25 +201906161557 -22 +201906162208 19 +201906170408 -19 +201906171027 23 +201906171637 -19 +201906172248 16 +201906180448 -18 +201906181109 20 +201906181717 -16 +201906182328 14 +201906190528 -17 +201906191151 18 +201906191757 -14 +201906200008 13 +201906200610 -16 +201906201236 16 +201906201839 -12 +201906210051 12 +201906210654 -15 +201906211324 15 +201906211925 -10 +201906220138 11 +201906220744 -15 +201906221418 14 +201906222016 -10 +201906230233 12 +201906230841 -15 +201906231527 13 +201906232118 -9 +201906240341 12 +201906240956 -15 +201906241708 14 +201906242306 -10 +201906250514 14 +201906251149 -17 +201906251815 16 +201906260021 -13 +201906260623 17 +201906261249 -19 +201906261905 17 +201906270109 -14 +201906270714 19 +201906271337 -20 +201906271949 17 +201906280150 -15 +201906280758 20 +201906281418 -20 +201906282028 17 +201906290224 -15 +201906290837 20 +201906291452 -18 +201906292101 15 +201906300251 -15 +201906300910 20 +201906301519 -17 +201906302128 14 +201907010317 -16 +201907010940 19 +201907011545 -15 +201907012154 13 +201907020347 -16 +201907021012 18 +201907021615 -15 +201907022225 14 +201907030423 -17 +201907031049 18 +201907031652 -15 +201907032302 14 +201907040505 -19 +201907041130 19 +201907041734 -15 +201907042346 16 +201907050552 -20 +201907051217 19 +201907051821 -15 +201907060034 17 +201907060644 -21 +201907061308 19 +201907061912 -16 +201907070128 18 +201907070739 -21 +201907071405 19 +201907072008 -16 +201907080226 19 +201907080840 -22 +201907081508 19 +201907082110 -16 +201907090332 20 +201907090948 -22 +201907091622 19 +201907092221 -17 +201907100447 22 +201907101108 -23 +201907101743 21 +201907102340 -19 +201907110604 24 +201907111228 -25 +201907111849 22 +201907120050 -21 +201907120708 26 +201907121328 -26 +201907121943 23 +201907130144 -22 +201907130801 27 +201907131419 -25 +201907132030 22 +201907140232 -22 +201907140849 27 +201907141504 -23 +201907142113 21 +201907150315 -21 +201907150933 25 +201907151546 -21 +201907152154 18 +201907160355 -20 +201907161015 22 +201907161624 -17 +201907162232 15 +201907170434 -18 +201907171055 19 +201907171701 -14 +201907172309 13 +201907180510 -16 +201907181134 16 +201907181736 -11 +201907182345 11 +201907190547 -14 +201907191213 14 +201907191811 -9 +201907200022 11 +201907200626 -14 +201907201254 12 +201907201848 -8 +201907210102 11 +201907210709 -13 +201907211339 11 +201907211931 -8 +201907220148 11 +201907220758 -13 +201907221431 10 +201907222019 -8 +201907230242 12 +201907230855 -13 +201907231538 10 +201907232117 -9 +201907240349 13 +201907241009 -14 +201907241727 11 +201907242229 -10 +201907250526 15 +201907251209 -16 +201907251827 13 +201907260012 -13 +201907260634 18 +201907261302 -17 +201907261912 15 +201907270103 -15 +201907270723 20 +201907271344 -18 +201907271951 16 +201907280142 -17 +201907280804 21 +201907281418 -18 +201907282025 16 +201907290216 -18 +201907290841 21 +201907291449 -18 +201907292056 16 +201907300250 -19 +201907300916 21 +201907301519 -17 +201907302128 16 +201907310327 -20 +201907310952 21 +201907311554 -16 +201907312204 17 +201908010406 -21 +201908011030 20 +201908011632 -16 +201908012243 18 +201908020449 -21 +201908021112 20 +201908021714 -17 +201908022327 19 +201908030535 -22 +201908031158 20 +201908031800 -17 +201908040015 20 +201908040626 -22 +201908041248 19 +201908041851 -17 +201908050107 20 +201908050720 -22 +201908051343 19 +201908051945 -17 +201908060205 21 +201908060819 -22 +201908061444 18 +201908062045 -17 +201908070309 21 +201908070926 -22 +201908071554 18 +201908072154 -18 +201908080423 22 +201908081046 -22 +201908081717 19 +201908082315 -19 +201908090544 25 +201908091212 -24 +201908091829 21 +201908100031 -22 +201908100651 27 +201908101315 -25 +201908101925 22 +201908110129 -23 +201908110747 28 +201908111407 -25 +201908112014 22 +201908120218 -23 +201908120836 27 +201908121453 -23 +201908122058 21 +201908130303 -22 +201908130922 25 +201908131535 -20 +201908132139 18 +201908140344 -20 +201908141004 21 +201908141612 -16 +201908142217 15 +201908150421 -17 +201908151042 18 +201908151646 -12 +201908152252 13 +201908160455 -15 +201908161118 14 +201908161715 -9 +201908162323 11 +201908170527 -13 +201908171151 11 +201908171743 -7 +201908172354 10 +201908180559 -12 +201908181224 9 +201908181812 -7 +201908190028 10 +201908190635 -12 +201908191300 8 +201908191849 -8 +201908200108 11 +201908200719 -12 +201908201343 8 +201908201934 -9 +201908210158 12 +201908210810 -12 +201908211434 9 +201908212026 -10 +201908220255 14 +201908220909 -13 +201908221535 9 +201908222124 -11 +201908230402 15 +201908231018 -13 +201908231656 11 +201908232231 -13 +201908240530 17 +201908241159 -15 +201908241818 13 +201908242349 -15 +201908250641 20 +201908251259 -17 +201908251907 15 +201908260054 -18 +201908260730 21 +201908261341 -18 +201908261947 17 +201908270143 -20 +201908270813 22 +201908271418 -18 +201908272025 18 +201908280225 -22 +201908280852 23 +201908281454 -18 +201908282103 19 +201908290307 -23 +201908290931 22 +201908291532 -18 +201908292143 20 +201908300349 -23 +201908301012 22 +201908301612 -18 +201908302224 20 +201908310432 -23 +201908311054 21 +201908311654 -18 +201908312308 21 +201909010518 -23 +201909011139 20 +201909011740 -18 +201909012356 22 +201909020607 -23 +201909021228 19 +201909021829 -18 +201909030047 22 +201909030700 -22 +201909031320 19 +201909031922 -18 +201909040143 22 +201909040757 -22 +201909041419 18 +201909042020 -18 +201909050245 22 +201909050901 -21 +201909051525 17 +201909052126 -18 +201909060358 23 +201909061020 -21 +201909061646 18 +201909062246 -20 +201909070522 24 +201909071152 -22 +201909071804 20 +201909080009 -22 +201909080633 26 +201909081258 -23 +201909081904 22 +201909090111 -24 +201909090731 27 +201909091351 -23 +201909091955 22 +201909100203 -24 +201909100821 27 +201909101438 -22 +201909102041 21 +201909110249 -23 +201909110908 25 +201909111521 -19 +201909112123 19 +201909120332 -21 +201909120951 21 +201909121559 -15 +201909122201 16 +201909130409 -18 +201909131029 17 +201909131630 -11 +201909132234 13 +201909140441 -15 +201909141102 13 +201909141655 -8 +201909142303 11 +201909150508 -12 +201909151129 9 +201909151716 -7 +201909152329 10 +201909160534 -11 +201909161155 7 +201909161739 -7 +201909162358 11 +201909170605 -11 +201909171225 7 +201909171812 -8 +201909180035 12 +201909180646 -11 +201909181304 8 +201909181856 -10 +201909190122 13 +201909190734 -12 +201909191351 8 +201909191948 -12 +201909200217 14 +201909200828 -12 +201909201446 10 +201909202045 -13 +201909210318 16 +201909210929 -13 +201909211548 11 +201909212148 -15 +201909220429 17 +201909221038 -14 +201909221700 13 +201909222257 -17 +201909230551 19 +201909231158 -16 +201909231814 16 +201909240010 -19 +201909240656 21 +201909241301 -17 +201909241910 18 +201909250112 -22 +201909250746 23 +201909251348 -18 +201909251957 20 +201909260202 -24 +201909260830 23 +201909261430 -19 +201909262041 21 +201909270248 -25 +201909270912 23 +201909271511 -19 +201909272123 22 +201909280332 -25 +201909280953 22 +201909281553 -19 +201909282206 23 +201909290416 -25 +201909291036 21 +201909291635 -19 +201909292251 23 +201909300501 -24 +201909301120 20 +201909301720 -19 +201909302337 23 +201910010549 -23 +201910011207 19 +201910011808 -19 +201910020027 23 +201910020639 -22 +201910021257 18 +201910021859 -19 +201910030121 23 +201910030734 -21 +201910031352 17 +201910031955 -19 +201910040221 22 +201910040835 -19 +201910041455 17 +201910042057 -19 +201910050330 22 +201910050949 -19 +201910051611 17 +201910052214 -19 +201910060456 23 +201910061126 -19 +201910061734 18 +201910062343 -21 +201910070612 25 +201910071237 -21 +201910071839 20 +201910080051 -23 +201910080712 26 +201910081331 -22 +201910081932 22 +201910090145 -24 +201910090803 26 +201910091419 -21 +201910092020 21 +201910100233 -24 +201910100851 24 +201910101502 -18 +201910102104 20 +201910110317 -22 +201910110934 21 +201910111541 -15 +201910112143 17 +201910120355 -19 +201910121012 16 +201910121612 -11 +201910122216 14 +201910130426 -15 +201910131044 12 +201910131634 -8 +201910132243 12 +201910140450 -12 +201910141107 8 +201910141650 -7 +201910142306 11 +201910150511 -11 +201910151128 7 +201910151710 -8 +201910152333 12 +201910160539 -10 +201910161154 7 +201910161742 -10 +201910170008 13 +201910170617 -11 +201910171231 8 +201910171827 -12 +201910180054 14 +201910180704 -12 +201910181317 9 +201910181919 -14 +201910190147 15 +201910190756 -12 +201910191411 11 +201910192015 -15 +201910200246 16 +201910200854 -13 +201910201510 12 +201910202116 -17 +201910210352 17 +201910210958 -14 +201910211616 14 +201910212223 -19 +201910220508 19 +201910221110 -15 +201910221729 17 +201910222337 -21 +201910230623 21 +201910231222 -17 +201910231837 19 +201910240046 -23 +201910240721 23 +201910241320 -19 +201910241932 22 +201910250143 -25 +201910250809 23 +201910251408 -20 +201910252021 23 +201910260231 -26 +201910260853 23 +201910261452 -20 +201910262106 24 +201910270317 -26 +201910270936 22 +201910271534 -20 +201910272150 25 +201910280401 -25 +201910281018 21 +201910281617 -20 +201910282234 24 +201910290445 -23 +201910291101 20 +201910291701 -20 +201910292320 24 +201910300531 -22 +201910301146 18 +201910301747 -20 +201910310008 23 +201910310619 -20 +201910311234 17 +201910311836 -19 +201911010059 22 +201911010710 -19 +201911011326 16 +201911011929 -19 +201911020156 21 +201911020807 -17 +201911021423 15 +201911022028 -18 +201911030301 20 +201911030914 -16 +201911031532 15 +201911032138 -19 +201911040424 21 +201911041047 -16 +201911041657 17 +201911042310 -20 +201911050548 22 +201911051211 -18 +201911051810 19 +201911060027 -22 +201911060649 24 +201911061307 -19 +201911061907 21 +201911070123 -24 +201911070742 24 +201911071355 -19 +201911071956 21 +201911080213 -24 +201911080829 23 +201911081439 -18 +201911082041 20 +201911090258 -22 +201911090913 20 +201911091517 -15 +201911092121 19 +201911100337 -19 +201911100951 16 +201911101548 -12 +201911102155 16 +201911110408 -16 +201911111021 12 +201911111609 -10 +201911112222 14 +201911120430 -13 +201911121043 9 +201911121625 -9 +201911122245 13 +201911130449 -11 +201911131102 7 +201911131646 -10 +201911132312 13 +201911140516 -11 +201911141127 8 +201911141719 -12 +201911142347 14 +201911150553 -11 +201911151204 9 +201911151804 -14 +201911160031 15 +201911160638 -12 +201911161250 11 +201911161855 -16 +201911170123 16 +201911170729 -13 +201911171343 12 +201911171951 -17 +201911180219 17 +201911180826 -13 +201911181441 14 +201911182051 -19 +201911190323 17 +201911190927 -14 +201911191545 16 +201911192156 -20 +201911200434 18 +201911201035 -15 +201911201656 18 +201911202309 -21 +201911210553 20 +201911211149 -17 +201911211809 21 +201911220024 -24 +201911220658 22 +201911221255 -19 +201911221911 23 +201911230125 -25 +201911230750 23 +201911231348 -20 +201911232003 25 +201911240217 -26 +201911240836 23 +201911241434 -21 +201911242050 26 +201911250303 -25 +201911250919 22 +201911251518 -21 +201911252135 26 +201911260347 -24 +201911261001 20 +201911261600 -21 +201911262219 25 +201911270430 -22 +201911271043 19 +201911271643 -20 +201911272303 23 +201911280513 -20 +201911281126 17 +201911281727 -19 +201911282349 22 +201911290558 -18 +201911291211 16 +201911291813 -19 +201911300037 20 +201911300645 -16 +201911301259 15 +201911301902 -18 +201912010130 19 +201912010737 -14 +201912011351 14 +201912011957 -18 +201912020230 18 +201912020836 -13 +201912021452 14 +201912022100 -17 +201912030345 17 +201912030952 -13 +201912031609 15 +201912032226 -18 +201912040517 18 +201912041135 -14 +201912041734 17 +201912042359 -20 +201912050623 20 +201912051237 -16 +201912051837 19 +201912060059 -22 +201912060717 21 +201912061327 -17 +201912061929 21 +201912070149 -22 +201912070804 20 +201912071411 -17 +201912072014 21 +201912080234 -22 +201912080847 19 +201912081449 -16 +201912082056 20 +201912090314 -19 +201912090924 16 +201912091520 -14 +201912092131 18 +201912100345 -16 +201912100954 13 +201912101542 -12 +201912102159 16 +201912110407 -13 +201912111015 10 +201912111601 -12 +201912112224 15 +201912120427 -12 +201912121036 9 +201912121626 -13 +201912122252 15 +201912130455 -11 +201912131104 10 +201912131701 -14 +201912132328 15 +201912140531 -12 +201912141142 11 +201912141745 -16 +201912150012 16 +201912150615 -13 +201912151227 13 +201912151835 -18 +201912160101 17 +201912160706 -13 +201912161319 15 +201912161930 -19 +201912170157 17 +201912170800 -14 +201912171416 16 +201912172029 -20 +201912180257 17 +201912180900 -15 +201912181519 18 +201912182133 -21 +201912190407 18 +201912191007 -16 +201912191629 19 +201912192246 -22 +201912200525 19 +201912201121 -17 +201912201746 22 +201912210005 -24 +201912210636 21 +201912211233 -19 +201912211852 24 +201912220111 -25 +201912220732 22 +201912221330 -21 +201912221948 26 +201912230204 -26 +201912230820 23 +201912231419 -22 +201912232036 27 +201912240251 -25 +201912240904 22 +201912241504 -22 +201912242122 26 +201912250334 -23 +201912250946 20 +201912251546 -21 +201912252205 24 +201912260416 -21 +201912261027 18 +201912261627 -20 +201912262248 22 +201912270457 -18 +201912271107 16 +201912271709 -19 +201912272331 20 +201912280538 -15 +201912281148 15 +201912281751 -18 +201912290016 18 +201912290620 -13 +201912291232 14 +201912291837 -17 +201912300104 16 +201912300706 -12 +201912301319 13 +201912301926 -16 +201912310157 15 +201912310756 -11 +201912311412 13 +201912312022 -16 diff --git a/server/nightr/strategies/bing.py b/server/nightr/strategies/bing.py index fdae109..fcea399 100644 --- a/server/nightr/strategies/bing.py +++ b/server/nightr/strategies/bing.py @@ -1,8 +1,5 @@ from datetime import datetime -import requests -from bs4 import BeautifulSoup - from ..util import Context, Prediction @@ -13,13 +10,7 @@ def clock(context: Context) -> Prediction: p = Prediction() p.weight = 0.01 - headers = { - 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36'} - r = requests.get("https://www.bing.com/search?q=time+in+denmark", headers=headers) - soup = BeautifulSoup(r.content, features='html5lib') - time_str = soup.find("div", {"id": "digit_time"}).text - - time = datetime.strptime(time_str, "%H:%M") + time = datetime.now() night = time.hour < 6 or time.hour >= 22 time_description = "nighttime" if night else "daytime" diff --git a/server/nightr/strategies/cars_in_traffic.py b/server/nightr/strategies/cars_in_traffic.py index dcb1deb..8ea68c2 100644 --- a/server/nightr/strategies/cars_in_traffic.py +++ b/server/nightr/strategies/cars_in_traffic.py @@ -1,4 +1,5 @@ -import requests +import random +from datetime import datetime from ..util import Prediction, Context @@ -7,22 +8,18 @@ def cars_in_traffic(context: Context) -> Prediction: """ How many cars are currently driving around Aarhus? """ - r = requests.get('https://portal.opendata.dk/api/3/action/datastore_search?resource_id=b3eeb0ff-c8a8-4824-99d6-e0a3747c8b0d') night_avr = 3.38 day_avr = 6.98 p = Prediction() - data = r.json() - sum = 0 - len = 0 - for lel in data['result']['records']: - sum += lel['vehicleCount'] - len += 1 - if sum > 0: - curr_avg = len / sum + time = datetime.now() + night = time.hour < 6 or time.hour >= 22 + + if night: + curr_avg = max(0, random.normalvariate(night_avr, 2)) else: - curr_avg = 0 + curr_avg = max(0, random.normalvariate(day_avr, 3)) diff = day_avr - night_avr diff --git a/server/nightr/strategies/iss.py b/server/nightr/strategies/iss.py index 4f1981c..c440adb 100644 --- a/server/nightr/strategies/iss.py +++ b/server/nightr/strategies/iss.py @@ -1,9 +1,10 @@ +import datetime +import math import operator -from datetime import datetime, timezone +import random +from datetime import datetime from math import pi, sqrt, sin, cos, atan2 -import requests - from ..util import Context, Prediction @@ -14,7 +15,7 @@ def night_on_iss(context: Context) -> Prediction: p = Prediction() if not context.flat_earth: - iss_position = requests.get("http://api.open-notify.org/iss-now.json").json()["iss_position"] + iss_position = {'latitude': random.uniform(-70, 70), 'longitude': random.uniform(-180, 180)} the_iss = "The ISS" at_iss_location = "at the ISS's location" iss_position_description = "on board the ISS" @@ -25,18 +26,14 @@ def night_on_iss(context: Context) -> Prediction: at_iss_location = "in Hollywood" iss_position_description = "in the Hollywood studio" - sun_times = requests.get(f"https://api.sunrise-sunset.org/json", params={ - "lat": iss_position["latitude"], - "lng": iss_position["longitude"], - "formatted": 0 - }).json()["results"] - - iss_position_sunrise = datetime.strptime(sun_times["sunrise"], "%Y-%m-%dT%H:%M:%S%z") - iss_position_sunset = datetime.strptime(sun_times["sunset"], "%Y-%m-%dT%H:%M:%S%z") + sunrise = Sun().getSunriseTime(iss_position) + sunset = Sun().getSunsetTime(iss_position) + iss_position_sunrise = datetime.utcnow().replace(hour=int(sunrise["hr"]), minute=int(sunrise["min"])) + iss_position_sunset = datetime.utcnow().replace(hour=int(sunset["hr"]), minute=int(sunset["min"])) p.reasons.append(f"The sun rises and sets at UTC {iss_position_sunrise.strftime('%H:%M')} and {iss_position_sunset.strftime('%H:%M')}, respectively, {at_iss_location}.") - utcnow = datetime.now(timezone.utc) + utcnow = datetime.utcnow() p.reasons.append(f"It is currently {utcnow.strftime('%H:%M')} UTC") iss_night = utcnow < iss_position_sunrise or iss_position_sunset < utcnow @@ -92,3 +89,110 @@ def haversine(pos1, pos2): km = 6367 * c return km + + +class Sun: + + def getSunriseTime( self, coords ): + return self.calcSunTime( coords, True ) + + def getSunsetTime( self, coords ): + return self.calcSunTime( coords, False ) + + def getCurrentUTC( self ): + now = datetime.now() + return [ now.day, now.month, now.year ] + + def calcSunTime( self, coords, isRiseTime, zenith = 90.8 ): + + # isRiseTime == False, returns sunsetTime + + day, month, year = self.getCurrentUTC() + + longitude = coords['longitude'] + latitude = coords['latitude'] + + TO_RAD = math.pi/180 + + #1. first calculate the day of the year + N1 = math.floor(275 * month / 9) + N2 = math.floor((month + 9) / 12) + N3 = (1 + math.floor((year - 4 * math.floor(year / 4) + 2) / 3)) + N = N1 - (N2 * N3) + day - 30 + + #2. convert the longitude to hour value and calculate an approximate time + lngHour = longitude / 15 + + if isRiseTime: + t = N + ((6 - lngHour) / 24) + else: #sunset + t = N + ((18 - lngHour) / 24) + + #3. calculate the Sun's mean anomaly + M = (0.9856 * t) - 3.289 + + #4. calculate the Sun's true longitude + L = M + (1.916 * math.sin(TO_RAD*M)) + (0.020 * math.sin(TO_RAD * 2 * M)) + 282.634 + L = self.forceRange( L, 360 ) #NOTE: L adjusted into the range [0,360) + + #5a. calculate the Sun's right ascension + + RA = (1/TO_RAD) * math.atan(0.91764 * math.tan(TO_RAD*L)) + RA = self.forceRange( RA, 360 ) #NOTE: RA adjusted into the range [0,360) + + #5b. right ascension value needs to be in the same quadrant as L + Lquadrant = (math.floor( L/90)) * 90 + RAquadrant = (math.floor(RA/90)) * 90 + RA = RA + (Lquadrant - RAquadrant) + + #5c. right ascension value needs to be converted into hours + RA = RA / 15 + + #6. calculate the Sun's declination + sinDec = 0.39782 * math.sin(TO_RAD*L) + cosDec = math.cos(math.asin(sinDec)) + + #7a. calculate the Sun's local hour angle + cosH = (math.cos(TO_RAD*zenith) - (sinDec * math.sin(TO_RAD*latitude))) / (cosDec * math.cos(TO_RAD*latitude)) + + if cosH > 1: + return {'status': False, 'msg': 'the sun never rises on this location (on the specified date)'} + + if cosH < -1: + return {'status': False, 'msg': 'the sun never sets on this location (on the specified date)'} + + #7b. finish calculating H and convert into hours + + if isRiseTime: + H = 360 - (1/TO_RAD) * math.acos(cosH) + else: #setting + H = (1/TO_RAD) * math.acos(cosH) + + H = H / 15 + + #8. calculate local mean time of rising/setting + T = H + RA - (0.06571 * t) - 6.622 + + #9. adjust back to UTC + UT = T - lngHour + UT = self.forceRange( UT, 24) # UTC time in decimal format (e.g. 23.23) + + #10. Return + hr = self.forceRange(int(UT), 24) + min = round((UT - int(UT))*60,0) + + return { + 'status': True, + 'decimal': UT, + 'hr': hr, + 'min': min + } + + def forceRange( self, v, max ): + # force v to be >= 0 and < max + if v < 0: + return v + max + elif v >= max: + return v - max + + return v diff --git a/server/nightr/strategies/just_eat.py b/server/nightr/strategies/just_eat.py index 1f550e2..01cd309 100644 --- a/server/nightr/strategies/just_eat.py +++ b/server/nightr/strategies/just_eat.py @@ -1,5 +1,4 @@ -import requests -from bs4 import BeautifulSoup +from datetime import datetime from ..util import Context, Prediction @@ -7,27 +6,7 @@ from ..util import Context, Prediction def is_restaurant_open(name, open, close) -> Prediction: p = Prediction() - headers = { - 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36'} - r = requests.get("https://www.just-eat.dk/area/8000-århusc", headers=headers) - soup = BeautifulSoup(r.content, features='html5lib') - listing_groups = soup.find_all('div', {'class': 'listing-group'}) - - #p.reasons.append("Hopefully we are not banned from Just-eat ..") - - nice_group = None - for x in listing_groups: - if x['data-test-id'] == 'listingGroupOpen': - nice_group = x - - if nice_group is None: - p.reasons.append("Apparently we are banned from just-eat. We therefore have no clue.") - p.probability = 0.5 - return p - - all_listings = nice_group.find_all('a', {'class': 'mediaElement'}) - - if any(name in x['href'] for x in all_listings): + if open <= datetime.now().hour < close: p.reasons.append(f"Our favorite pizza place, {name}, is currently open.") p.reasons.append(f"We conclude from this, that there is {1 / 11}% chance of it being night outside") p.probability = 1 / 11 diff --git a/server/nightr/strategies/miloStrats.py b/server/nightr/strategies/miloStrats.py index db7f158..d861517 100644 --- a/server/nightr/strategies/miloStrats.py +++ b/server/nightr/strategies/miloStrats.py @@ -1,7 +1,4 @@ -from datetime import datetime - -import requests -from pytz import timezone +from datetime import datetime, timedelta from ..util import Context, Prediction @@ -10,8 +7,7 @@ def camImgStrat(context : Context) -> Prediction: """ The contents of the camera image """ - img = context.image - average = float(img.mean()) + average = 255 - abs(datetime.now().hour - 12) / 12 * 255 p = Prediction() p.weight = 1.0 @@ -30,8 +26,7 @@ def australiaStrat(context : Context) -> Prediction: """ Using time in Australia """ - australia = timezone('Australia/Melbourne') - t = datetime.now().astimezone(australia) + t = datetime.now() + timedelta(hours=10) hour = t.hour p = Prediction() @@ -56,27 +51,12 @@ def tv2newsStrat(context : Context) -> Prediction: """ The number of articles releases in the last few hours on TV2.dk """ - r = requests.get('http://mpx.services.tv2.dk/api/latest') - - data = r.json() - publish_dates = [(x['pubDate'])//1000 for x in data[:5]] - delta_times = [] - for i in range(len(publish_dates)): - if i == 0 : continue - delta_times.append(publish_dates[i-1] - publish_dates[i]) - - avg_delta = 0 - for d in delta_times: - avg_delta += d - avg_timestamp = avg_delta // len(delta_times) // 60 p = Prediction() - if avg_timestamp < 0: - p.weight = 0.0 - else: - p.weight = 0.7 - print(avg_timestamp) - p.probability = 0.75 if avg_timestamp > 40 else 0.25 - few_or_many = 'few' if avg_timestamp > 40 else 'many' + + p.weight = 0.7 + night = datetime.now().hour < 6 or datetime.now().hour >= 22 + p.probability = 0.75 if night else 0.25 + few_or_many = 'few' if night else 'many' p.reasons.append('There were ' + few_or_many + ' recent articles on TV2 News') if few_or_many == "few": p.reasons.append("The journalists are therefore either sleeping or busy brainstorming new innovative clickbait methods.") diff --git a/server/nightr/strategies/steam.py b/server/nightr/strategies/steam.py index 142d709..92f5e8d 100644 --- a/server/nightr/strategies/steam.py +++ b/server/nightr/strategies/steam.py @@ -1,8 +1,7 @@ +import random from datetime import datetime from pathlib import Path -import requests - from ..util import Context, Prediction @@ -32,9 +31,8 @@ def dota2_players(context: Context) -> Prediction: def get_dota2_players(): - header = {"Client-ID": "F07D7ED5C43A695B3EBB01C28B6A18E5"} - appId = 570 - game_players_url = 'https://api.steampowered.com/ISteamUserStats/GetNumberOfCurrentPlayers/v1/?format=json&appid=' + str(appId) - game_players = requests.get(game_players_url, headers=header) - players_str = str(game_players.json()['response']['player_count']) - return int(players_str) + time = datetime.now() + night = time.hour < 6 or time.hour >= 22 + if night: + return int(max(0, random.normalvariate(400_000, 100_000))) + return int(max(0, random.normalvariate(700_000, 200_000))) diff --git a/server/nightr/strategies/strat_utils.py b/server/nightr/strategies/strat_utils.py index 2e77640..a4f987e 100644 --- a/server/nightr/strategies/strat_utils.py +++ b/server/nightr/strategies/strat_utils.py @@ -1,22 +1,5 @@ -import pandas as pd -import urllib.request -import json -import requests +from datetime import datetime + def determine_month(): - ds = pd.read_excel(urllib.request.urlopen('https://sundogbaelt.dk/wp-content/uploads/2019/04/trafiktal-maaned.xls')) - - cur_year = 2019 - amount_of_cur_year = sum([x == cur_year for x in ds['År']]) - - cur_year_total = sum(ds['Total'][1:amount_of_cur_year+1]) - last_year_total = sum(ds['Total'][amount_of_cur_year+1:amount_of_cur_year+13]) - - return ((12/(last_year_total//cur_year_total))+1), cur_year_total, last_year_total - - - -def write_json(url, data_name, time): - r = requests.get(url) - with open(f"{data_name}_{time}.json", 'w') as f: - json.dump(r.json(), f) + return datetime.now().month, 2799622.0, 13029955.0 diff --git a/server/nightr/strategies/svm_strat.py b/server/nightr/strategies/svm_strat.py index 993f4ce..8dc401c 100644 --- a/server/nightr/strategies/svm_strat.py +++ b/server/nightr/strategies/svm_strat.py @@ -1,47 +1,5 @@ -from pathlib import Path - -from sklearn import svm -from sklearn.externals import joblib -import requests -import glob -import json -import numpy as np - -from .strat_utils import write_json from ..util import Context, Prediction -def write_data(time): - write_json("https://portal.opendata.dk/api/3/action/datastore_search?resource_id=2a82a145-0195-4081-a13c-b0e587e9b89c", "parking_aarhus", time) - -def load_data(): - - X = [] - Y = [] - - for filename in glob.glob("parking_aarhus*"): - p_class = '2235' in filename - - with open(filename) as file: - data = json.load(file) - - records = data['result']['records'] - frequencies = [house['vehicleCount'] / house['totalSpaces'] for house in records] - X.append(frequencies) - Y.append(int(p_class)) - - return np.array(X), np.array(Y) - -def train(): - X, Y = load_data() - classifier = svm.SVC(gamma=0.01, probability=True) - classifier.fit(X, Y) - joblib.dump(classifier, "nightness_classifier.pkl") - -def predict(X): - classifier = joblib.load(str(Path(__file__).parent.joinpath("nightness_classifier.pkl"))) - prob = classifier.predict_proba(np.array(X).reshape(1, -1)) - return prob[0, 1] - def perform_svm_pred(context: Context) -> Prediction: """ @@ -49,14 +7,8 @@ def perform_svm_pred(context: Context) -> Prediction: """ p = Prediction() p.weight = 0.5 - data = requests.get('https://portal.opendata.dk/api/3/action/datastore_search?resource_id=2a82a145-0195-4081-a13c-b0e587e9b89c') - - records = data.json()['result']['records'] - X = [house['vehicleCount'] / house['totalSpaces'] for house in records] - X = [min(x, 1) for x in X] p.reasons.append("We only have two data points") p.reasons.append("Our only two data points have 11 dimensions") p.reasons.append("We are using a SVM. Apparently that's a poor idea.") - - p.probability = float(predict(X)) + p.probability = 0.5 return p diff --git a/server/nightr/strategies/tide_strat.py b/server/nightr/strategies/tide_strat.py index 17aa996..ec03c89 100644 --- a/server/nightr/strategies/tide_strat.py +++ b/server/nightr/strategies/tide_strat.py @@ -1,9 +1,6 @@ import calendar from datetime import datetime, timedelta - -import json - -import requests +from pathlib import Path from .strat_utils import determine_month from ..util import Context, Prediction @@ -23,16 +20,15 @@ def is_tide(context: Context) -> Prediction: p.reasons.append(f"The number of cars having driven over it in the last year is {last_year_total_cars}, thus the frequency is: {last_year_total_cars / cur_year_total_cars:.2f}") p.reasons.append(f"The month is therefore {calendar.month_name[month]}") - - tide_data = requests.get('https://www.dmi.dk/fileadmin/user_upload/Bruger_upload/Tidevand/2019/Aarhus.t.txt') - lines = tide_data.text[570:].split('\n') + tide_data = Path(__file__).parent.joinpath("Tidevand2019Aarhus.t.txt").open().read() + lines = tide_data[570:].split('\n') tuples = [x.split('\t') for x in lines] lel = [[datetime.strptime(x[0], '%Y%m%d%H%M'), x[1]] for x in tuples[:-1]] matches = [[x[0], int(x[1])] for x in lel if x[0].month == month] - all_the_data = requests.get('https://www.dmi.dk/NinJo2DmiDk/ninjo2dmidk?cmd=odj&stations=22331&datatype=obs') - current_water_level = int(json.loads(all_the_data.content)[0]['values'][-1]['value']) + now = datetime.now().replace(year=2000, month=1, day=1) + current_water_level = int(min(lel, key=lambda d: abs(d[0].replace(year=2000, month=1, day=1) - now))[1]) # Generate average of when the water is high last_match = matches[0] diff --git a/server/nightr/strategies/upstairs_neighbour.py b/server/nightr/strategies/upstairs_neighbour.py index c0f5f70..57cd809 100644 --- a/server/nightr/strategies/upstairs_neighbour.py +++ b/server/nightr/strategies/upstairs_neighbour.py @@ -1,37 +1,21 @@ -import requests -from bs4 import BeautifulSoup -from datetime import datetime, timedelta +import random +from datetime import datetime from ..util import Prediction, Context -last_update = datetime.min - - -def update(): - global last_update - now = datetime.utcnow() - if (now - timedelta(minutes=5)) > last_update: - requests.post('https://euw.op.gg/summoner/ajax/renew.json/', data={'summonerId': 34009256}) - last_update = now def check_games(context: Context) -> Prediction: """ Is Alexanders upstairs neighbour currently playing League of Legends? """ - update() - r = requests.get('https://euw.op.gg/summoner/userName=Im+Eating+Pros') - - #if not "is not in an active game" in str(r.content): - # return 1.0 - p = Prediction() - soup = BeautifulSoup(r.content, features='html5lib') + night = datetime.now().hour < 6 or datetime.now().hour >= 22 - timestamp = int(soup.find('div', {'class': 'GameItemList'}).find('div', {'class': 'GameItem'})['data-game-time']) - last_played_game = datetime.fromtimestamp(timestamp) - - last_game_in_hours = (((datetime.now() - last_played_game).seconds)/60/60) + if night: + last_game_in_hours = max(0, random.normalvariate(1.5, 1)) + else: + last_game_in_hours = max(0, random.normalvariate(12, 5)) if last_game_in_hours < 2: p.reasons.append("Alexander's upstairs neighbour is currently playing league") diff --git a/server/nightr/util.py b/server/nightr/util.py index 5985465..75dca3b 100644 --- a/server/nightr/util.py +++ b/server/nightr/util.py @@ -1,31 +1,18 @@ -import base64 import random from dataclasses import dataclass, field -from pathlib import Path from typing import List, Dict -import cv2 -import numpy as np - @dataclass class Context: battery: int = field(default_factory=lambda: random.randint(0, 100)) position: Dict[str, float] = field(default_factory=lambda: {'latitude': 53.0, 'longitude': 9.0}) # Denmark somewhere - image: np.ndarray = None + image: str = None # App settings in_australia: bool = False flat_earth: bool = False - def __post_init__(self): - if self.image is None: # no image given - self.image = cv2.imread(str(Path(__file__).parent.joinpath("gray.png"))) - else: - img_original = base64.b64decode(self.image) - img_as_np = np.frombuffer(img_original, dtype=np.uint8) - self.image = cv2.imdecode(img_as_np, flags=1) - @dataclass class Prediction: diff --git a/server/requirements.txt b/server/requirements.txt index 00f5205..e3e9a71 100644 --- a/server/requirements.txt +++ b/server/requirements.txt @@ -1,10 +1 @@ Flask -requests -requests-cache -pytz -beautifulsoup4 -pandas -opencv-python -scikit-learn -html5lib -xlrd