From e94199b7fd322da720f07299743d46b08cf70620 Mon Sep 17 00:00:00 2001 From: Christian Date: Sat, 6 Apr 2019 17:52:50 +0200 Subject: [PATCH 1/2] Added button and location --- client/Nightr/src/app/app.component.html | 2 +- client/Nightr/src/app/app.component.ts | 1 + client/Nightr/src/app/app.module.ts | 4 +-- .../locationButton.component.css} | 0 .../locationButton.component.html | 4 +++ .../locationButton.component.ts | 25 +++++++++++++ .../app/my-button/my-button.component.html | 3 -- .../src/app/my-button/my-button.component.ts | 16 --------- .../app/services/my-geo-location.service.ts | 35 +++++++++++++++++++ client/Nightr/src/main.js | 2 +- 10 files changed, 69 insertions(+), 23 deletions(-) rename client/Nightr/src/app/{my-button/my-button.component.css => component/locationButton/locationButton.component.css} (100%) create mode 100644 client/Nightr/src/app/component/locationButton/locationButton.component.html create mode 100644 client/Nightr/src/app/component/locationButton/locationButton.component.ts delete mode 100644 client/Nightr/src/app/my-button/my-button.component.html delete mode 100644 client/Nightr/src/app/my-button/my-button.component.ts create mode 100644 client/Nightr/src/app/services/my-geo-location.service.ts diff --git a/client/Nightr/src/app/app.component.html b/client/Nightr/src/app/app.component.html index 6dea362..7bf993d 100644 --- a/client/Nightr/src/app/app.component.html +++ b/client/Nightr/src/app/app.component.html @@ -1,3 +1,3 @@ - + diff --git a/client/Nightr/src/app/app.component.ts b/client/Nightr/src/app/app.component.ts index d88b2fe..0bb10d0 100644 --- a/client/Nightr/src/app/app.component.ts +++ b/client/Nightr/src/app/app.component.ts @@ -1,4 +1,5 @@ import { Component } from "@angular/core"; +import { isEnabled, enableLocationRequest, getCurrentLocation, watchLocation, distance, clearWatch } from "nativescript-geolocation"; @Component({ selector: "ns-app", diff --git a/client/Nightr/src/app/app.module.ts b/client/Nightr/src/app/app.module.ts index d5d8d40..132e264 100644 --- a/client/Nightr/src/app/app.module.ts +++ b/client/Nightr/src/app/app.module.ts @@ -2,7 +2,7 @@ import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core"; import { NativeScriptModule } from "nativescript-angular/nativescript.module"; import { AppComponent } from "./app.component"; -import { MyButtonComponent } from './my-button/my-button.component'; +import { MyLocationButtonComponent } from './component/locationButton/locationButton.component'; // Uncomment and add to NgModule imports if you need to use two-way binding // import { NativeScriptFormsModule } from "nativescript-angular/forms"; @@ -19,7 +19,7 @@ import { MyButtonComponent } from './my-button/my-button.component'; ], declarations: [ AppComponent, - MyButtonComponent, + MyLocationButtonComponent, ], providers: [], schemas: [ diff --git a/client/Nightr/src/app/my-button/my-button.component.css b/client/Nightr/src/app/component/locationButton/locationButton.component.css similarity index 100% rename from client/Nightr/src/app/my-button/my-button.component.css rename to client/Nightr/src/app/component/locationButton/locationButton.component.css diff --git a/client/Nightr/src/app/component/locationButton/locationButton.component.html b/client/Nightr/src/app/component/locationButton/locationButton.component.html new file mode 100644 index 0000000..5088fab --- /dev/null +++ b/client/Nightr/src/app/component/locationButton/locationButton.component.html @@ -0,0 +1,4 @@ + + + + diff --git a/client/Nightr/src/app/component/locationButton/locationButton.component.ts b/client/Nightr/src/app/component/locationButton/locationButton.component.ts new file mode 100644 index 0000000..8495420 --- /dev/null +++ b/client/Nightr/src/app/component/locationButton/locationButton.component.ts @@ -0,0 +1,25 @@ +import { Component, OnInit } from '@angular/core'; +import { MyGeoLocationService} from '../../services/my-geo-location.service'; +@Component({ + selector: 'ns-locationButton', + templateUrl: './locationButton.component.html', + styleUrls: ['./locationButton.component.css'], + moduleId: module.id, +}) +export class MyLocationButtonComponent implements OnInit { + title = "Click to get location!"; + lat = "start"; + geoLocationService = new MyGeoLocationService(); + + constructor() { + } + ngOnInit() { + } + + onTap() { + this.geoLocationService.getLocation().then(location => { + this.lat = ""+location.latitude; + }).catch(error => { + }); + } +} diff --git a/client/Nightr/src/app/my-button/my-button.component.html b/client/Nightr/src/app/my-button/my-button.component.html deleted file mode 100644 index 59259f8..0000000 --- a/client/Nightr/src/app/my-button/my-button.component.html +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/client/Nightr/src/app/my-button/my-button.component.ts b/client/Nightr/src/app/my-button/my-button.component.ts deleted file mode 100644 index d18c116..0000000 --- a/client/Nightr/src/app/my-button/my-button.component.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { Component, OnInit } from '@angular/core'; - -@Component({ - selector: 'ns-my-button', - templateUrl: './my-button.component.html', - styleUrls: ['./my-button.component.css'], - moduleId: module.id, -}) -export class MyButtonComponent implements OnInit { - - constructor() { } - - ngOnInit() { - } - -} diff --git a/client/Nightr/src/app/services/my-geo-location.service.ts b/client/Nightr/src/app/services/my-geo-location.service.ts new file mode 100644 index 0000000..4de390a --- /dev/null +++ b/client/Nightr/src/app/services/my-geo-location.service.ts @@ -0,0 +1,35 @@ +import { Injectable } from '@angular/core'; +import { isEnabled, enableLocationRequest, getCurrentLocation, watchLocation, distance, clearWatch, Location } from "nativescript-geolocation"; +import { stringify } from '@angular/core/src/render3/util'; + +@Injectable({ + providedIn: 'root' +}) +export class MyGeoLocationService { + loc: Location; + constructor() { + } + + getLocation(): Promise { + this.isLocationEnabled(); + var result = getCurrentLocation({ + desiredAccuracy: 3, + timeout: 5000 + }); + return result; + } + + private isLocationEnabled() { + isEnabled().then(function (isEnabled) { + if (!isEnabled) { + enableLocationRequest().then(function () { + }, function (e) { + alert("Error: " + (e.message || e)); + }); + } + }, function (e) { + alert("Error: " + (e.message || e)); + }); + + } +} diff --git a/client/Nightr/src/main.js b/client/Nightr/src/main.js index faf70ce..d07591d 100644 --- a/client/Nightr/src/main.js +++ b/client/Nightr/src/main.js @@ -11,4 +11,4 @@ var app_module_1 = require("./app/app.module"); // so we provide a wrapper platform object, platformNativeScriptDynamic, // that sets up a NativeScript application and can bootstrap the Angular framework. platform_1.platformNativeScriptDynamic().bootstrapModule(app_module_1.AppModule); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWFpbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIm1haW4udHMiXSwibmFtZXMiOltdLCJ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ydCB7IEFwcE1vZHVsZSB9IGZyb20gXCIuL2FwcC9hcHAubW9kdWxlXCI7XG5cbi8vIEEgdHJhZGl0aW9uYWwgTmF0aXZlU2NyaXB0IGFwcGxpY2F0aW9uIHN0YXJ0cyBieSBpbml0aWFsaXppbmcgZ2xvYmFsIG9iamVjdHMsXG4vLyBzZXR0aW5nIHVwIGdsb2JhbCBDU1MgcnVsZXMsIGNyZWF0aW5nLCBhbmQgbmF2aWdhdGluZyB0byB0aGUgbWFpbiBwYWdlLlxuLy8gQW5ndWxhciBhcHBsaWNhdGlvbnMgbmVlZCB0byB0YWtlIGNhcmUgb2YgdGhlaXIgb3duIGluaXRpYWxpemF0aW9uOlxuLy8gbW9kdWxlcywgY29tcG9uZW50cywgZGlyZWN0aXZlcywgcm91dGVzLCBESSBwcm92aWRlcnMuXG4vLyBBIE5hdGl2ZVNjcmlwdCBBbmd1bGFyIGFwcCBuZWVkcyB0byBtYWtlIGJvdGggcGFyYWRpZ21zIHdvcmsgdG9nZXRoZXIsXG4vLyBzbyB3ZSBwcm92aWRlIGEgd3JhcHBlciBwbGF0Zm9ybSBvYmplY3QsIHBsYXRmb3JtTmF0aXZlU2NyaXB0RHluYW1pYyxcbi8vIHRoYXQgc2V0cyB1cCBhIE5hdGl2ZVNjcmlwdCBhcHBsaWNhdGlvbiBhbmQgY2FuIGJvb3RzdHJhcCB0aGUgQW5ndWxhciBmcmFtZXdvcmsuXG5wbGF0Zm9ybU5hdGl2ZVNjcmlwdER5bmFtaWMoKS5ib290c3RyYXBNb2R1bGUoQXBwTW9kdWxlKTtcbiJdfQ== \ No newline at end of file From d4bb45b84d0573fe231121d7dad4872240bdfa75 Mon Sep 17 00:00:00 2001 From: "Casper V. Kristensen" Date: Sat, 6 Apr 2019 17:56:13 +0200 Subject: [PATCH 2/2] Log execution times. --- server/nightr/app.py | 8 +++++++- server/nightr/strategies/upstairs_neighbour.py | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/server/nightr/app.py b/server/nightr/app.py index 00c41ef..3f8b923 100644 --- a/server/nightr/app.py +++ b/server/nightr/app.py @@ -1,7 +1,9 @@ import inspect import statistics +import timeit from dataclasses import asdict from datetime import timedelta +from logging import DEBUG from typing import List import requests_cache @@ -12,6 +14,7 @@ from .util import Context app = Flask(__name__) logger = logging.create_logger(app) +logger.setLevel(DEBUG) requests_cache.install_cache("requests_cache", expire_after=timedelta(minutes=10)) @@ -36,7 +39,10 @@ def probabilities(): predictions: List[dict] = [] for name, strategy in strategies.items(): try: + start = timeit.default_timer() prediction = strategy(context) + stop = timeit.default_timer() + logger.debug("Execution time for %s: %ss", name, stop - start) except Exception as e: logger.warning("Strategy '%s' failed:", name) logger.exception(e) @@ -79,7 +85,7 @@ def probabilities(): def main(): - app.run(host='0.0.0.0') + app.run(host='0.0.0.0', debug=True) if __name__ == '__main__': diff --git a/server/nightr/strategies/upstairs_neighbour.py b/server/nightr/strategies/upstairs_neighbour.py index 4b528b6..63ff206 100644 --- a/server/nightr/strategies/upstairs_neighbour.py +++ b/server/nightr/strategies/upstairs_neighbour.py @@ -6,7 +6,7 @@ from ..util import Prediction, Context def update(): - requests.post('https://euw.op.gg/summoner/ajax/renew.json/', data = {'summonerId': 34009256}) + requests.post('https://euw.op.gg/summoner/ajax/renew.json/', data={'summonerId': 34009256}) def check_games(context: Context) -> Prediction: