From 57352c3763c09d21fb3a27d309f250b80ff00bc7 Mon Sep 17 00:00:00 2001 From: Whizel Date: Sat, 6 Apr 2019 20:39:28 +0200 Subject: [PATCH 01/10] Comitting before pulling Picture service --- .../src/app/services/my-battery-info.service.ts | 15 +++++++++++++++ .../src/app/services/my-http-post-service.ts | 1 - 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 client/Nightr/src/app/services/my-battery-info.service.ts diff --git a/client/Nightr/src/app/services/my-battery-info.service.ts b/client/Nightr/src/app/services/my-battery-info.service.ts new file mode 100644 index 0000000..c00a32d --- /dev/null +++ b/client/Nightr/src/app/services/my-battery-info.service.ts @@ -0,0 +1,15 @@ +import { Injectable } from '@angular/core'; +import * as power from 'nativescript-powerinfo' + +@Injectable({ + providedIn: 'root' +}) +export class MyBatteryInfoService { + + constructor() { } + public getPowerPercent (): number { + power.startPowerUpdates(function(Info) { + power.stopPowerUpdates(); + return Info.percentage; + }) +} diff --git a/client/Nightr/src/app/services/my-http-post-service.ts b/client/Nightr/src/app/services/my-http-post-service.ts index 8dca261..69202bf 100644 --- a/client/Nightr/src/app/services/my-http-post-service.ts +++ b/client/Nightr/src/app/services/my-http-post-service.ts @@ -10,7 +10,6 @@ export class MyHttpPostService { constructor(private http: HttpClient) { } postData(data: any) { - console.log('logged data is', data); let options = this.createRequestOptions(); return this.http.post(this.serverUrl, { data }, { headers: options }); } From 024ffe2a7f6652ebe005fced3221dd17d9197f0b Mon Sep 17 00:00:00 2001 From: Whizel Date: Sat, 6 Apr 2019 20:40:11 +0200 Subject: [PATCH 02/10] Comitting before pulling Picture service --- client/Nightr/src/app/app.component.html | 8 ++--- client/Nightr/src/app/app.component.ts | 33 ++++++++++++------- .../locationButton.component.html | 2 +- .../locationButton.component.ts | 8 +++-- 4 files changed, 33 insertions(+), 18 deletions(-) diff --git a/client/Nightr/src/app/app.component.html b/client/Nightr/src/app/app.component.html index 97b4fff..2ba3f44 100644 --- a/client/Nightr/src/app/app.component.html +++ b/client/Nightr/src/app/app.component.html @@ -1,11 +1,11 @@ - - - + - + + + diff --git a/client/Nightr/src/app/app.component.ts b/client/Nightr/src/app/app.component.ts index 0758a86..3359e3a 100644 --- a/client/Nightr/src/app/app.component.ts +++ b/client/Nightr/src/app/app.component.ts @@ -1,8 +1,11 @@ import { Component } from "@angular/core"; import * as dialogs from "tns-core-modules/ui/dialogs"; -import { MyHttpPostService } from './services/my-http-post-service' import { TouchGestureEventData, GestureEventData } from 'tns-core-modules/ui/gestures' -import { isEnabled, enableLocationRequest, getCurrentLocation, watchLocation, distance, clearWatch } from "nativescript-geolocation"; +import { Location } from "nativescript-geolocation"; + +import { MyHttpPostService } from './services/my-http-post-service' +import { MyGeoLocationService} from './services/my-geo-location.service'; +import { MyBatteryInfoService } from './services/my-battery-info.service'; @Component({ selector: "ns-app", @@ -12,30 +15,38 @@ import { isEnabled, enableLocationRequest, getCurrentLocation, watchLocation, di providers: [MyHttpPostService] }) export class AppComponent { - public user: string = ""; - public pass: string = ""; returnMessage: string = ""; + myReturnJSON: JSON; + locationData: Location; - constructor(private myHttpPostSerivce: MyHttpPostService) { } + constructor(private myHttpPostSerivce: MyHttpPostService, + private geoLocationService: MyGeoLocationService, + private batterInfoService: MyBatteryInfoService) { } public onTap(args: GestureEventData): any { - this.submit(); - dialogs.confirm("Should be result").then(result => { - console.log("Dialog result: " + result); + this.geoLocationService.getLocation().then(location => { + this.locationData = location; + console.log('this is locationData', this.locationData); + this.submit(); + }).catch(error => { }); } + public onLocationTap(args: GestureEventData): any { + console.log('This should be batterinfo', this.batterInfoService.getPowerPercent()); + } + public submit(): void { this.makePostRequest(); } private makePostRequest(): void { - console.log('Reached makepostRequest'); this.myHttpPostSerivce - .postData({ username: this.user, password: this.pass }) + .postData({ position: this.locationData }) .subscribe(res => { console.log('This is res', res); - this.returnMessage = (res).json.data.username; + this.myReturnJSON = (res).json.data.username; + console.log('THis is myreturnJSON', this.myReturnJSON); }); } } diff --git a/client/Nightr/src/app/component/locationButton/locationButton.component.html b/client/Nightr/src/app/component/locationButton/locationButton.component.html index 5088fab..9fe4bc3 100644 --- a/client/Nightr/src/app/component/locationButton/locationButton.component.html +++ b/client/Nightr/src/app/component/locationButton/locationButton.component.html @@ -1,4 +1,4 @@ - + diff --git a/client/Nightr/src/app/component/locationButton/locationButton.component.ts b/client/Nightr/src/app/component/locationButton/locationButton.component.ts index 8495420..d28c873 100644 --- a/client/Nightr/src/app/component/locationButton/locationButton.component.ts +++ b/client/Nightr/src/app/component/locationButton/locationButton.component.ts @@ -1,4 +1,5 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, EventEmitter, OnInit, Output } from '@angular/core'; +import { TouchGestureEventData, GestureEventData } from 'tns-core-modules/ui/gestures' import { MyGeoLocationService} from '../../services/my-geo-location.service'; @Component({ selector: 'ns-locationButton', @@ -11,12 +12,15 @@ export class MyLocationButtonComponent implements OnInit { lat = "start"; geoLocationService = new MyGeoLocationService(); + @Output() tap: EventEmitter = new EventEmitter(); + constructor() { } ngOnInit() { } - onTap() { + onTap(args: GestureEventData): any { + this.tap.emit(args); this.geoLocationService.getLocation().then(location => { this.lat = ""+location.latitude; }).catch(error => { From 55dfa63f1aeab2ac78b19b2a16a1d7f02cec0674 Mon Sep 17 00:00:00 2001 From: Whizel Date: Sat, 6 Apr 2019 20:40:36 +0200 Subject: [PATCH 03/10] Comitting before pulling Picture service --- client/Nightr/package-lock.json | 15 +++++++++++++++ client/Nightr/package.json | 1 + 2 files changed, 16 insertions(+) diff --git a/client/Nightr/package-lock.json b/client/Nightr/package-lock.json index 04b5e41..35b0d28 100644 --- a/client/Nightr/package-lock.json +++ b/client/Nightr/package-lock.json @@ -3991,6 +3991,21 @@ "resolved": "https://registry.npmjs.org/nativescript-permissions/-/nativescript-permissions-1.2.3.tgz", "integrity": "sha1-4+ZVRfmP5IjdVXj3/5DrrjCI5wA=" }, + "nativescript-powerinfo": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/nativescript-powerinfo/-/nativescript-powerinfo-1.0.7.tgz", + "integrity": "sha1-ZXIq2bQwxIR7lRJT5kUmt1zsGXo=", + "requires": { + "typescript": "^1.8.10" + }, + "dependencies": { + "typescript": { + "version": "1.8.10", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-1.8.10.tgz", + "integrity": "sha1-tHXW4N/wv1DyluXKbvn7tccyDx4=" + } + } + }, "nativescript-theme-core": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/nativescript-theme-core/-/nativescript-theme-core-1.0.4.tgz", diff --git a/client/Nightr/package.json b/client/Nightr/package.json index ddcc97a..aef7aa2 100644 --- a/client/Nightr/package.json +++ b/client/Nightr/package.json @@ -23,6 +23,7 @@ "@angular/router": "~7.2.0", "nativescript-angular": "~7.2.0", "nativescript-geolocation": "^5.0.0", + "nativescript-powerinfo": "^1.0.7", "nativescript-theme-core": "~1.0.4", "reflect-metadata": "~0.1.12", "rxjs": "~6.3.0", From f47982f0940877196676d2a33a3d7ede077b7790 Mon Sep 17 00:00:00 2001 From: Whizel Date: Sat, 6 Apr 2019 21:17:46 +0200 Subject: [PATCH 04/10] Camera is now working --- client/Nightr/src/app/app.component.ts | 25 ++++++++++++++----- .../app/services/my-battery-info.service.ts | 3 ++- client/Nightr/src/main.js | 2 +- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/client/Nightr/src/app/app.component.ts b/client/Nightr/src/app/app.component.ts index 3359e3a..ffe906e 100644 --- a/client/Nightr/src/app/app.component.ts +++ b/client/Nightr/src/app/app.component.ts @@ -6,6 +6,7 @@ import { Location } from "nativescript-geolocation"; import { MyHttpPostService } from './services/my-http-post-service' import { MyGeoLocationService} from './services/my-geo-location.service'; import { MyBatteryInfoService } from './services/my-battery-info.service'; +import { MyCameraService } from './services/my-camera-service' @Component({ selector: "ns-app", @@ -18,12 +19,24 @@ export class AppComponent { returnMessage: string = ""; myReturnJSON: JSON; locationData: Location; + myPicture: String; + image: any; constructor(private myHttpPostSerivce: MyHttpPostService, private geoLocationService: MyGeoLocationService, - private batterInfoService: MyBatteryInfoService) { } + private batterInfoService: MyBatteryInfoService, + private cameraService: MyCameraService) { } - public onTap(args: GestureEventData): any { + public onTap(args: GestureEventData): Promise { + return this.cameraService.takePicture(). + then(picture => { + this.image = JSON.stringify(picture); + console.log('this is picture in json', JSON.stringify(picture)); + this.getLocation(); + }) + } + + public getLocation(): any { this.geoLocationService.getLocation().then(location => { this.locationData = location; console.log('this is locationData', this.locationData); @@ -33,7 +46,7 @@ export class AppComponent { } public onLocationTap(args: GestureEventData): any { - console.log('This should be batterinfo', this.batterInfoService.getPowerPercent()); + //console.log('This should be batterinfo', this.batterInfoService.getPowerPercent()); } public submit(): void { @@ -42,11 +55,11 @@ export class AppComponent { private makePostRequest(): void { this.myHttpPostSerivce - .postData({ position: this.locationData }) + .postData({ position: this.locationData, image: this.image }) .subscribe(res => { - console.log('This is res', res); + //console.log('This is res', res); this.myReturnJSON = (res).json.data.username; - console.log('THis is myreturnJSON', this.myReturnJSON); + //console.log('THis is myreturnJSON', this.myReturnJSON); }); } } diff --git a/client/Nightr/src/app/services/my-battery-info.service.ts b/client/Nightr/src/app/services/my-battery-info.service.ts index c00a32d..21800ea 100644 --- a/client/Nightr/src/app/services/my-battery-info.service.ts +++ b/client/Nightr/src/app/services/my-battery-info.service.ts @@ -7,9 +7,10 @@ import * as power from 'nativescript-powerinfo' export class MyBatteryInfoService { constructor() { } - public getPowerPercent (): number { + /* public getPowerPercent (): number { power.startPowerUpdates(function(Info) { power.stopPowerUpdates(); return Info.percentage; }) + } */ } diff --git a/client/Nightr/src/main.js b/client/Nightr/src/main.js index d07591d..faf70ce 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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWFpbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIm1haW4udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSwwR0FBMEc7QUFDMUcsMERBQTRFO0FBRTVFLCtDQUE2QztBQUU3QyxnRkFBZ0Y7QUFDaEYsMEVBQTBFO0FBQzFFLHNFQUFzRTtBQUN0RSx5REFBeUQ7QUFDekQseUVBQXlFO0FBQ3pFLHdFQUF3RTtBQUN4RSxtRkFBbUY7QUFDbkYsc0NBQTJCLEVBQUUsQ0FBQyxlQUFlLENBQUMsc0JBQVMsQ0FBQyxDQUFDIiwic291cmNlc0NvbnRlbnQiOlsiLy8gdGhpcyBpbXBvcnQgc2hvdWxkIGJlIGZpcnN0IGluIG9yZGVyIHRvIGxvYWQgc29tZSByZXF1aXJlZCBzZXR0aW5ncyAobGlrZSBnbG9iYWxzIGFuZCByZWZsZWN0LW1ldGFkYXRhKVxuaW1wb3J0IHsgcGxhdGZvcm1OYXRpdmVTY3JpcHREeW5hbWljIH0gZnJvbSBcIm5hdGl2ZXNjcmlwdC1hbmd1bGFyL3BsYXRmb3JtXCI7XG5cbmltcG9ydCB7IEFwcE1vZHVsZSB9IGZyb20gXCIuL2FwcC9hcHAubW9kdWxlXCI7XG5cbi8vIEEgdHJhZGl0aW9uYWwgTmF0aXZlU2NyaXB0IGFwcGxpY2F0aW9uIHN0YXJ0cyBieSBpbml0aWFsaXppbmcgZ2xvYmFsIG9iamVjdHMsXG4vLyBzZXR0aW5nIHVwIGdsb2JhbCBDU1MgcnVsZXMsIGNyZWF0aW5nLCBhbmQgbmF2aWdhdGluZyB0byB0aGUgbWFpbiBwYWdlLlxuLy8gQW5ndWxhciBhcHBsaWNhdGlvbnMgbmVlZCB0byB0YWtlIGNhcmUgb2YgdGhlaXIgb3duIGluaXRpYWxpemF0aW9uOlxuLy8gbW9kdWxlcywgY29tcG9uZW50cywgZGlyZWN0aXZlcywgcm91dGVzLCBESSBwcm92aWRlcnMuXG4vLyBBIE5hdGl2ZVNjcmlwdCBBbmd1bGFyIGFwcCBuZWVkcyB0byBtYWtlIGJvdGggcGFyYWRpZ21zIHdvcmsgdG9nZXRoZXIsXG4vLyBzbyB3ZSBwcm92aWRlIGEgd3JhcHBlciBwbGF0Zm9ybSBvYmplY3QsIHBsYXRmb3JtTmF0aXZlU2NyaXB0RHluYW1pYyxcbi8vIHRoYXQgc2V0cyB1cCBhIE5hdGl2ZVNjcmlwdCBhcHBsaWNhdGlvbiBhbmQgY2FuIGJvb3RzdHJhcCB0aGUgQW5ndWxhciBmcmFtZXdvcmsuXG5wbGF0Zm9ybU5hdGl2ZVNjcmlwdER5bmFtaWMoKS5ib290c3RyYXBNb2R1bGUoQXBwTW9kdWxlKTtcbiJdfQ== \ No newline at end of file +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWFpbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIm1haW4udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSwwR0FBMEc7QUFDMUcsMERBQTRFO0FBRTVFLCtDQUE2QztBQUU3QyxnRkFBZ0Y7QUFDaEYsMEVBQTBFO0FBQzFFLHNFQUFzRTtBQUN0RSx5REFBeUQ7QUFDekQseUVBQXlFO0FBQ3pFLHdFQUF3RTtBQUN4RSxtRkFBbUY7QUFDbkYsc0NBQTJCLEVBQUUsQ0FBQyxlQUFlLENBQUMsc0JBQVMsQ0FBQyxDQUFDIiwic291cmNlc0NvbnRlbnQiOlsiLy8gdGhpcyBpbXBvcnQgc2hvdWxkIGJlIGZpcnN0IGluIG9yZGVyIHRvIGxvYWQgc29tZSByZXF1aXJlZCBzZXR0aW5ncyAobGlrZSBnbG9iYWxzIGFuZCByZWZsZWN0LW1ldGFkYXRhKVxyXG5pbXBvcnQgeyBwbGF0Zm9ybU5hdGl2ZVNjcmlwdER5bmFtaWMgfSBmcm9tIFwibmF0aXZlc2NyaXB0LWFuZ3VsYXIvcGxhdGZvcm1cIjtcclxuXHJcbmltcG9ydCB7IEFwcE1vZHVsZSB9IGZyb20gXCIuL2FwcC9hcHAubW9kdWxlXCI7XHJcblxyXG4vLyBBIHRyYWRpdGlvbmFsIE5hdGl2ZVNjcmlwdCBhcHBsaWNhdGlvbiBzdGFydHMgYnkgaW5pdGlhbGl6aW5nIGdsb2JhbCBvYmplY3RzLFxyXG4vLyBzZXR0aW5nIHVwIGdsb2JhbCBDU1MgcnVsZXMsIGNyZWF0aW5nLCBhbmQgbmF2aWdhdGluZyB0byB0aGUgbWFpbiBwYWdlLlxyXG4vLyBBbmd1bGFyIGFwcGxpY2F0aW9ucyBuZWVkIHRvIHRha2UgY2FyZSBvZiB0aGVpciBvd24gaW5pdGlhbGl6YXRpb246XHJcbi8vIG1vZHVsZXMsIGNvbXBvbmVudHMsIGRpcmVjdGl2ZXMsIHJvdXRlcywgREkgcHJvdmlkZXJzLlxyXG4vLyBBIE5hdGl2ZVNjcmlwdCBBbmd1bGFyIGFwcCBuZWVkcyB0byBtYWtlIGJvdGggcGFyYWRpZ21zIHdvcmsgdG9nZXRoZXIsXHJcbi8vIHNvIHdlIHByb3ZpZGUgYSB3cmFwcGVyIHBsYXRmb3JtIG9iamVjdCwgcGxhdGZvcm1OYXRpdmVTY3JpcHREeW5hbWljLFxyXG4vLyB0aGF0IHNldHMgdXAgYSBOYXRpdmVTY3JpcHQgYXBwbGljYXRpb24gYW5kIGNhbiBib290c3RyYXAgdGhlIEFuZ3VsYXIgZnJhbWV3b3JrLlxyXG5wbGF0Zm9ybU5hdGl2ZVNjcmlwdER5bmFtaWMoKS5ib290c3RyYXBNb2R1bGUoQXBwTW9kdWxlKTtcclxuIl19 \ No newline at end of file From 319c03067f6212af02ebbf8ef253d4ba85480f0c Mon Sep 17 00:00:00 2001 From: "Casper V. Kristensen" Date: Sat, 6 Apr 2019 23:00:08 +0200 Subject: [PATCH 05/10] Reasons and battery. --- server/nightr/app.py | 3 ++- server/nightr/strategies/battery.py | 21 +++++++++++++++++++ server/nightr/strategies/bing.py | 4 ++-- server/nightr/strategies/iss.py | 3 +-- server/nightr/strategies/just_eat.py | 8 ++++--- server/nightr/strategies/miloStrats.py | 11 ++++------ server/nightr/strategies/svm_strat.py | 6 +++--- .../nightr/strategies/upstairs_neighbour.py | 2 +- server/nightr/util.py | 4 ++-- 9 files changed, 41 insertions(+), 21 deletions(-) create mode 100644 server/nightr/strategies/battery.py diff --git a/server/nightr/app.py b/server/nightr/app.py index b7b4072..ad3ce8f 100644 --- a/server/nightr/app.py +++ b/server/nightr/app.py @@ -10,7 +10,7 @@ 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 +from .strategies import miloStrats, iss, cars_in_traffic, tide_strat, upstairs_neighbour, bing, battery from .util import Context app = Flask(__name__) @@ -30,6 +30,7 @@ strategies = { "tide": tide_strat.is_tide, "upstairs_neighbour": upstairs_neighbour.check_games, "bing": bing.clock, + "battery_level": battery.battery_level, } diff --git a/server/nightr/strategies/battery.py b/server/nightr/strategies/battery.py new file mode 100644 index 0000000..b301ee8 --- /dev/null +++ b/server/nightr/strategies/battery.py @@ -0,0 +1,21 @@ +from ..util import Context, Prediction + + +def battery_level(context: Context) -> Prediction: + """ + If the battery is low, it's probably bedtime soon. + """ + p = Prediction() + + if context.battery > 60: + p.reasons.append("Battery level's good, so it's probably still early in the day.") + elif context.battery > 30: + p.reasons.append("Battery level's getting low, so it's probably around dinnertime.") + elif context.battery > 10: + p.reasons.append("Your phone is dying, so it's bedtime soon?") + else: + p.reasons.append("Your phone's practically dead, so it's probably around four in the morning.") + + p.probability = 1 - (context.battery / 100) # night is inverse proportional to battery level + + return p diff --git a/server/nightr/strategies/bing.py b/server/nightr/strategies/bing.py index 13b64fd..6b61db5 100644 --- a/server/nightr/strategies/bing.py +++ b/server/nightr/strategies/bing.py @@ -11,7 +11,7 @@ def clock(context: Context) -> Prediction: It's nighttime if Bing says it's daytime. """ p = Prediction() - p.weight = 0.05 + p.weight = 0.02 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'} @@ -22,7 +22,7 @@ def clock(context: Context) -> Prediction: time = datetime.strptime(time_str, "%H:%M") night = time.hour < 6 or time.hour >= 22 - time_description = "" if night else "daytime" + time_description = "nighttime" if night else "daytime" time_description_oppersite = "daytime" if night else "nighttime" p.reasons.append(f"Bing says its {time_description}.") diff --git a/server/nightr/strategies/iss.py b/server/nightr/strategies/iss.py index 64b308a..bd759bc 100644 --- a/server/nightr/strategies/iss.py +++ b/server/nightr/strategies/iss.py @@ -1,5 +1,4 @@ import itertools -import logging from datetime import datetime from math import pi, sqrt, sin, cos, atan2 @@ -14,7 +13,7 @@ tf = TimezoneFinder(in_memory=True) def night_on_iss(context: Context) -> Prediction: """ - It is night if it is night on the ISS and it is currently orbiting above us. + It is night if it is night on the ISS and it is currently orbiting above us. http://www.isstracker.com/ """ p = Prediction() diff --git a/server/nightr/strategies/just_eat.py b/server/nightr/strategies/just_eat.py index 4376958..3bf29e8 100644 --- a/server/nightr/strategies/just_eat.py +++ b/server/nightr/strategies/just_eat.py @@ -17,7 +17,7 @@ def is_restaurant_open(name, open, close) -> Prediction: 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 ..") + #p.reasons.append("Hopefully we are not banned from Just-eat ..") nice_group = None for x in listing_groups: @@ -32,10 +32,12 @@ def is_restaurant_open(name, open, close) -> Prediction: all_listings = nice_group.find_all('a', {'class': 'mediaElement'}) if any(name in x['href'] for x in all_listings): - p.reasons.append(f"{name} is currently open. We conclude from this, that there is {1 / 11}% chance of it being night outside!") + 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 else: - p.reasons.append(f"{name} is not open. We can conclude from this, that there is {1 - (1/11)}% chance of it currently being night outside! ") + p.reasons.append(f"Our favorite pizza place, {name}, is closed.") + p.reasons.append(f"We can conclude from this, that there is {1 - (1/11)}% chance of it currently being night outside!") p.probability = 1 - (1 / 11) return p diff --git a/server/nightr/strategies/miloStrats.py b/server/nightr/strategies/miloStrats.py index 0b51e43..d061c3d 100644 --- a/server/nightr/strategies/miloStrats.py +++ b/server/nightr/strategies/miloStrats.py @@ -18,11 +18,11 @@ def camImgStrat(context : Context) -> Prediction: p.probability = 1 - round((average/255),3) if average < 128: p.weight = round(1 - (average/255), 3) - p.reasons.append('Image was dark') + p.reasons.append('Camera image was dark, so the sun has probably set.') else: p.weight = round(average / 255, 3) - p.reasons.append('Image was light') + p.reasons.append('Camera image was light, so the sun is still shining.') return p @@ -37,10 +37,10 @@ def australiaStrat(context : Context) -> Prediction: if hour > 22 or hour < 6: p.probability = 0.0 - p.reasons.append('It\'s night-time in Australia') + p.reasons.append('It\'s night-time in Australia, so it must be day-time here.') else: p.probability = 1.0 - p.reasons.append('It\'s day-time in Australia') + p.reasons.append('It\'s day-time in Australia, so it must be night-time here.') return p @@ -48,10 +48,7 @@ def tv2newsStrat(context : Context) -> Prediction: """ The number of articles releases in the last few hours on TV2.dk """ - - print('before') r = requests.get('http://mpx.services.tv2.dk/api/latest') - print('after') data = r.json() publish_dates = [(x['pubDate'])//1000 for x in data][:10] diff --git a/server/nightr/strategies/svm_strat.py b/server/nightr/strategies/svm_strat.py index 58a17f6..0af7835 100644 --- a/server/nightr/strategies/svm_strat.py +++ b/server/nightr/strategies/svm_strat.py @@ -50,9 +50,9 @@ def perform_svm_pred(context: Context) -> Prediction: 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("Since we only have two data points") - p.reasons.append("Since our only two data points have 11 dimensions") - p.reasons.append("Since we are using a SVM") + 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") p.probability = predict(X) return p diff --git a/server/nightr/strategies/upstairs_neighbour.py b/server/nightr/strategies/upstairs_neighbour.py index 25ce40f..c0f5f70 100644 --- a/server/nightr/strategies/upstairs_neighbour.py +++ b/server/nightr/strategies/upstairs_neighbour.py @@ -34,7 +34,7 @@ def check_games(context: Context) -> Prediction: last_game_in_hours = (((datetime.now() - last_played_game).seconds)/60/60) if last_game_in_hours < 2: - p.reasons.append("Alexanders upstairs neighbour is currently playing league") + p.reasons.append("Alexander's upstairs neighbour is currently playing league") p.probability = 0.8 else: last_game_in_hours = min(24.0, last_game_in_hours) diff --git a/server/nightr/util.py b/server/nightr/util.py index 6c70643..82725a1 100644 --- a/server/nightr/util.py +++ b/server/nightr/util.py @@ -9,8 +9,8 @@ import numpy as np @dataclass class Context: - battery: int = 100 - position: Dict[str, float] = field(default_factory=lambda: {'latitude': 53.0, 'longitude': 9.0}) + battery: int = 55 + position: Dict[str, float] = field(default_factory=lambda: {'latitude': 53.0, 'longitude': 9.0}) # Denmark somewhere image: np.ndarray = None # App settings From e1ae6d2d54cd91a5ff5a3eb17a48db7ab7dd6ecb Mon Sep 17 00:00:00 2001 From: Christian Date: Sat, 6 Apr 2019 23:11:23 +0200 Subject: [PATCH 06/10] Added routing through Angular --- client/Nightr/package-lock.json | 15 ++++++ client/Nightr/package.json | 1 + client/Nightr/src/app/app.component.html | 15 ++---- client/Nightr/src/app/app.component.ts | 35 +------------ client/Nightr/src/app/app.module.ts | 11 +++++ .../src/app/home-page/home-page.component.css | 5 ++ .../app/home-page/home-page.component.html | 14 ++++++ .../src/app/home-page/home-page.component.ts | 49 +++++++++++++++++++ .../app/result-page/result-page.component.css | 1 + .../result-page/result-page.component.html | 7 +++ .../app/result-page/result-page.component.ts | 21 ++++++++ 11 files changed, 128 insertions(+), 46 deletions(-) create mode 100644 client/Nightr/src/app/home-page/home-page.component.css create mode 100644 client/Nightr/src/app/home-page/home-page.component.html create mode 100644 client/Nightr/src/app/home-page/home-page.component.ts create mode 100644 client/Nightr/src/app/result-page/result-page.component.css create mode 100644 client/Nightr/src/app/result-page/result-page.component.html create mode 100644 client/Nightr/src/app/result-page/result-page.component.ts diff --git a/client/Nightr/package-lock.json b/client/Nightr/package-lock.json index 1469775..ec0d477 100644 --- a/client/Nightr/package-lock.json +++ b/client/Nightr/package-lock.json @@ -3999,6 +3999,21 @@ "resolved": "https://registry.npmjs.org/nativescript-permissions/-/nativescript-permissions-1.2.3.tgz", "integrity": "sha1-4+ZVRfmP5IjdVXj3/5DrrjCI5wA=" }, + "nativescript-powerinfo": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/nativescript-powerinfo/-/nativescript-powerinfo-1.0.7.tgz", + "integrity": "sha1-ZXIq2bQwxIR7lRJT5kUmt1zsGXo=", + "requires": { + "typescript": "^1.8.10" + }, + "dependencies": { + "typescript": { + "version": "1.8.10", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-1.8.10.tgz", + "integrity": "sha1-tHXW4N/wv1DyluXKbvn7tccyDx4=" + } + } + }, "nativescript-theme-core": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/nativescript-theme-core/-/nativescript-theme-core-1.0.4.tgz", diff --git a/client/Nightr/package.json b/client/Nightr/package.json index 36bf9c5..a534fa3 100644 --- a/client/Nightr/package.json +++ b/client/Nightr/package.json @@ -24,6 +24,7 @@ "nativescript-angular": "~7.2.0", "nativescript-camera": "^4.4.0", "nativescript-geolocation": "^5.0.0", + "nativescript-powerinfo": "^1.0.7", "nativescript-theme-core": "~1.0.4", "reflect-metadata": "~0.1.12", "rxjs": "~6.3.0", diff --git a/client/Nightr/src/app/app.component.html b/client/Nightr/src/app/app.component.html index 8de10bd..6a6bd89 100644 --- a/client/Nightr/src/app/app.component.html +++ b/client/Nightr/src/app/app.component.html @@ -1,12 +1,3 @@ - - - - - - - - - - - - + + + diff --git a/client/Nightr/src/app/app.component.ts b/client/Nightr/src/app/app.component.ts index 0758a86..8dead37 100644 --- a/client/Nightr/src/app/app.component.ts +++ b/client/Nightr/src/app/app.component.ts @@ -1,41 +1,8 @@ import { Component } from "@angular/core"; -import * as dialogs from "tns-core-modules/ui/dialogs"; -import { MyHttpPostService } from './services/my-http-post-service' -import { TouchGestureEventData, GestureEventData } from 'tns-core-modules/ui/gestures' -import { isEnabled, enableLocationRequest, getCurrentLocation, watchLocation, distance, clearWatch } from "nativescript-geolocation"; @Component({ selector: "ns-app", moduleId: module.id, templateUrl: "./app.component.html", - styleUrls: ['./app.component.css'], - providers: [MyHttpPostService] }) -export class AppComponent { - public user: string = ""; - public pass: string = ""; - returnMessage: string = ""; - - constructor(private myHttpPostSerivce: MyHttpPostService) { } - - public onTap(args: GestureEventData): any { - this.submit(); - dialogs.confirm("Should be result").then(result => { - console.log("Dialog result: " + result); - }); - } - - public submit(): void { - this.makePostRequest(); - } - - private makePostRequest(): void { - console.log('Reached makepostRequest'); - this.myHttpPostSerivce - .postData({ username: this.user, password: this.pass }) - .subscribe(res => { - console.log('This is res', res); - this.returnMessage = (res).json.data.username; - }); - } -} +export class AppComponent {} diff --git a/client/Nightr/src/app/app.module.ts b/client/Nightr/src/app/app.module.ts index 04ef01a..46046e5 100644 --- a/client/Nightr/src/app/app.module.ts +++ b/client/Nightr/src/app/app.module.ts @@ -1,11 +1,14 @@ import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core"; import { NativeScriptModule } from "nativescript-angular/nativescript.module"; +import { NativeScriptRouterModule } from "nativescript-angular/router"; import { AppComponent } from "./app.component"; +import { HomePageComponent } from "./home-page/home-page.component"; import { MyButtonComponent } from './component/my-button/my-button.component'; import { NativeScriptHttpClientModule } from "nativescript-angular/http-client"; import { MyLocationButtonComponent } from './component/locationButton/locationButton.component'; import { CameraButtonComponent } from './component/camera-button/camera-button.component'; +import { ResultPageComponent } from './result-page/result-page.component'; // Uncomment and add to NgModule imports if you need to use two-way binding // import { NativeScriptFormsModule } from "nativescript-angular/forms"; @@ -18,6 +21,12 @@ import { CameraButtonComponent } from './component/camera-button/camera-button.c AppComponent ], imports: [ + NativeScriptRouterModule, + NativeScriptRouterModule.forRoot([ + { path: "", redirectTo: "/home-page", pathMatch: "full" }, + { path: "home-page", component: HomePageComponent}, + { path: "result-page", component: ResultPageComponent} + ]), NativeScriptModule, NativeScriptHttpClientModule, ], @@ -26,6 +35,8 @@ import { CameraButtonComponent } from './component/camera-button/camera-button.c MyLocationButtonComponent, MyButtonComponent, CameraButtonComponent, + ResultPageComponent, + HomePageComponent, ], providers: [], schemas: [ diff --git a/client/Nightr/src/app/home-page/home-page.component.css b/client/Nightr/src/app/home-page/home-page.component.css new file mode 100644 index 0000000..18496f5 --- /dev/null +++ b/client/Nightr/src/app/home-page/home-page.component.css @@ -0,0 +1,5 @@ +.float-btn-container + { + margin-top: 35%; + margin-left: 20%; + } diff --git a/client/Nightr/src/app/home-page/home-page.component.html b/client/Nightr/src/app/home-page/home-page.component.html new file mode 100644 index 0000000..34a9045 --- /dev/null +++ b/client/Nightr/src/app/home-page/home-page.component.html @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/client/Nightr/src/app/home-page/home-page.component.ts b/client/Nightr/src/app/home-page/home-page.component.ts new file mode 100644 index 0000000..56b788d --- /dev/null +++ b/client/Nightr/src/app/home-page/home-page.component.ts @@ -0,0 +1,49 @@ +import { Component, OnInit } from "@angular/core"; +import * as dialogs from "tns-core-modules/ui/dialogs"; +import { MyHttpPostService } from '../services/my-http-post-service' +import { RouterExtensions } from "nativescript-angular/router"; +import { TouchGestureEventData, GestureEventData } from 'tns-core-modules/ui/gestures' +import { isEnabled, enableLocationRequest, getCurrentLocation, watchLocation, distance, clearWatch } from "nativescript-geolocation"; + +@Component({ + selector: "home-page", + moduleId: module.id, + templateUrl: './home-page.component.html', + styleUrls: ['./home-page.component.css'], + providers: [MyHttpPostService] +}) +export class HomePageComponent implements OnInit { + public user: string = ""; + public pass: string = ""; + returnMessage: string = ""; + + constructor(private myHttpPostSerivce: MyHttpPostService, private routerExtensions: RouterExtensions) { } + + public onTap(args: GestureEventData): any { + this.routerExtensions.navigateByUrl("/result-page"); + this.submit(); + dialogs.confirm("Should be result").then(result => { + console.log("Dialog result: " + result); + }); + } + + public submit(): void { + this.makePostRequest(); + } + + private makePostRequest(): void { + console.log('Reached makepostRequest'); + this.myHttpPostSerivce + .postData({ username: this.user, password: this.pass }) + .subscribe(res => { + console.log('This is res', res); + this.returnMessage = (res).json.data.username; + }); + } + + ngOnInit(): void { + } + goBack(): void { + this.routerExtensions.back(); + } +} diff --git a/client/Nightr/src/app/result-page/result-page.component.css b/client/Nightr/src/app/result-page/result-page.component.css new file mode 100644 index 0000000..bcd4764 --- /dev/null +++ b/client/Nightr/src/app/result-page/result-page.component.css @@ -0,0 +1 @@ +/* Add mobile styles for the component here. */ diff --git a/client/Nightr/src/app/result-page/result-page.component.html b/client/Nightr/src/app/result-page/result-page.component.html new file mode 100644 index 0000000..5a89837 --- /dev/null +++ b/client/Nightr/src/app/result-page/result-page.component.html @@ -0,0 +1,7 @@ + + + + + + + diff --git a/client/Nightr/src/app/result-page/result-page.component.ts b/client/Nightr/src/app/result-page/result-page.component.ts new file mode 100644 index 0000000..a764430 --- /dev/null +++ b/client/Nightr/src/app/result-page/result-page.component.ts @@ -0,0 +1,21 @@ +import { Component, OnInit } from '@angular/core'; +import { RouterExtensions } from 'nativescript-angular/router'; + +@Component({ + selector: 'result-page', + templateUrl: './result-page.component.html', + styleUrls: ['./result-page.component.css'], + moduleId: module.id, +}) +export class ResultPageComponent implements OnInit { + + constructor(private routerExtensions: RouterExtensions) { } + + ngOnInit(): void { + } + + goBack(): void { + this.routerExtensions.back(); + } + +} From 43f117e5184f74e7d82ae641b0af4a625f13c110 Mon Sep 17 00:00:00 2001 From: Whizel Date: Sat, 6 Apr 2019 23:29:16 +0200 Subject: [PATCH 07/10] commit before pull --- client/Nightr/src/app/app.component.ts | 4 ++-- .../app/services/my-battery-info.service.ts | 22 ++++++++++++------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/client/Nightr/src/app/app.component.ts b/client/Nightr/src/app/app.component.ts index ffe906e..954da50 100644 --- a/client/Nightr/src/app/app.component.ts +++ b/client/Nightr/src/app/app.component.ts @@ -31,7 +31,7 @@ export class AppComponent { return this.cameraService.takePicture(). then(picture => { this.image = JSON.stringify(picture); - console.log('this is picture in json', JSON.stringify(picture)); + //console.log('this is picture in json', JSON.stringify(picture)); this.getLocation(); }) } @@ -39,7 +39,7 @@ export class AppComponent { public getLocation(): any { this.geoLocationService.getLocation().then(location => { this.locationData = location; - console.log('this is locationData', this.locationData); + //console.log('this is locationData', this.locationData); this.submit(); }).catch(error => { }); diff --git a/client/Nightr/src/app/services/my-battery-info.service.ts b/client/Nightr/src/app/services/my-battery-info.service.ts index 21800ea..424327f 100644 --- a/client/Nightr/src/app/services/my-battery-info.service.ts +++ b/client/Nightr/src/app/services/my-battery-info.service.ts @@ -1,16 +1,22 @@ import { Injectable } from '@angular/core'; -import * as power from 'nativescript-powerinfo' +import { android as androidApp, ios as iosApp } from "tns-core-modules/application"; +import { ios as iosUtils } from "tns-core-modules/utils/utils"; @Injectable({ providedIn: 'root' }) export class MyBatteryInfoService { - constructor() { } - /* public getPowerPercent (): number { - power.startPowerUpdates(function(Info) { - power.stopPowerUpdates(); - return Info.percentage; - }) - } */ + public getBatteryLife() { + if (iosApp){ + iosUtils.getter(UIDevice, UIDevice.currentDevice).batteryMonitoringEnabled = true; + let battery = +(iosUtils.getter(UIDevice, UIDevice.currentDevice).batteryLevel * 100); + }else{ + androidApp.registerBroadcastReceiver(android.content.Intent.ACTION_BATTERY_CHANGED,(context: android.content.Context, intent: android.content.Intent) =>{ + let level = intent.getIntExtra(android.os.BatteryManager.EXTRA_LEVEL, -1); + let scale = intent.getIntExtra(android.os.BatteryManager.EXTRA_SCALE, -1); + let percent = (level / scale) * 100.0; + }); + } +} } From 9392ab2f9cdd7c1cce09debdd8b956c9cd8e2efa Mon Sep 17 00:00:00 2001 From: Whizel Date: Sat, 6 Apr 2019 23:29:38 +0200 Subject: [PATCH 08/10] commit before pull --- client/Nightr/package-lock.json | 6 ++++++ client/Nightr/package.json | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/client/Nightr/package-lock.json b/client/Nightr/package-lock.json index ec0d477..6091599 100644 --- a/client/Nightr/package-lock.json +++ b/client/Nightr/package-lock.json @@ -5876,6 +5876,12 @@ "resolved": "https://registry.npmjs.org/tns-core-modules-widgets/-/tns-core-modules-widgets-5.3.0.tgz", "integrity": "sha512-mR8Pof0NhMRhPYcshQ54WyPrlbrqmTgrwxALtF1485fbCAHblz/2DqU7yGmTgC5LNdV7yhNeHYouoYg3TYOZbA==" }, + "tns-platform-declarations": { + "version": "5.3.1", + "resolved": "https://registry.npmjs.org/tns-platform-declarations/-/tns-platform-declarations-5.3.1.tgz", + "integrity": "sha512-sTEx3eGOEqILzLTARIamuMlCL0fZ3REyVaCJ0n19Nq7OdjnQiTV6zGADl5yQ1mI4NLZVtAtLQgc90Qj9XYnMIw==", + "dev": true + }, "to-arraybuffer": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/to-arraybuffer/-/to-arraybuffer-1.0.1.tgz", diff --git a/client/Nightr/package.json b/client/Nightr/package.json index a534fa3..f583598 100644 --- a/client/Nightr/package.json +++ b/client/Nightr/package.json @@ -36,7 +36,8 @@ "@nativescript/schematics": "~0.5.0", "@ngtools/webpack": "~7.2.0", "nativescript-dev-typescript": "~0.9.0", - "nativescript-dev-webpack": "~0.21.0" + "nativescript-dev-webpack": "~0.21.0", + "tns-platform-declarations": "^5.3.1" }, "gitHead": "803cec054c44c99eaa59cdc267993e6346f6cb3a", "readme": "NativeScript Application" From 65a49dfb95fa3c57e22c9a2fa349cf0b29c39487 Mon Sep 17 00:00:00 2001 From: Alexander Munch-Hansen Date: Sun, 7 Apr 2019 00:01:06 +0200 Subject: [PATCH 09/10] pls --- server/nightr/app.py | 3 ++- server/nightr/strategies/parking_aarhus_2235.json | 1 + server/nightr/strategies/svm_strat.py | 2 -- 3 files changed, 3 insertions(+), 3 deletions(-) create mode 100644 server/nightr/strategies/parking_aarhus_2235.json diff --git a/server/nightr/app.py b/server/nightr/app.py index ad3ce8f..e0f5d75 100644 --- a/server/nightr/app.py +++ b/server/nightr/app.py @@ -10,7 +10,7 @@ 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, battery +from .strategies import miloStrats, iss, cars_in_traffic, tide_strat, upstairs_neighbour, bing, svm_strat, battery from .util import Context app = Flask(__name__) @@ -30,6 +30,7 @@ strategies = { "tide": tide_strat.is_tide, "upstairs_neighbour": upstairs_neighbour.check_games, "bing": bing.clock, + "svm_parking": svm_strat.perform_svm_pred, "battery_level": battery.battery_level, } diff --git a/server/nightr/strategies/parking_aarhus_2235.json b/server/nightr/strategies/parking_aarhus_2235.json new file mode 100644 index 0000000..00162db --- /dev/null +++ b/server/nightr/strategies/parking_aarhus_2235.json @@ -0,0 +1 @@ +{"help": "https://portal.opendata.dk/api/3/action/help_show?name=datastore_search", "success": true, "result": {"include_total": true, "resource_id": "2a82a145-0195-4081-a13c-b0e587e9b89c", "fields": [{"type": "int", "id": "_id"}, {"type": "text", "id": "date"}, {"type": "text", "id": "garageCode"}, {"type": "int4", "id": "totalSpaces"}, {"type": "int4", "id": "vehicleCount"}], "records_format": "objects", "records": [{"_id": 1, "date": "2019/04/06 22:30:01", "garageCode": "NORREPORT", "totalSpaces": 80, "vehicleCount": 61}, {"_id": 2, "date": "2019/04/06 22:30:01", "garageCode": "SCANDCENTER", "totalSpaces": 1240, "vehicleCount": 442}, {"_id": 6, "date": "2019/04/06 22:30:01", "garageCode": "SALLING", "totalSpaces": 700, "vehicleCount": 290}, {"_id": 7, "date": "2019/04/06 22:30:01", "garageCode": "DOKK1", "totalSpaces": 1000, "vehicleCount": 0}, {"_id": 8, "date": "2019/04/06 22:30:01", "garageCode": "Navitas", "totalSpaces": 449, "vehicleCount": 161}, {"_id": 9, "date": "2019/04/06 22:30:01", "garageCode": "NewBusgadehuset", "totalSpaces": 105, "vehicleCount": 99}, {"_id": 3, "date": "2019/04/06 22:30:01", "garageCode": "BRUUNS", "totalSpaces": 953, "vehicleCount": 598}, {"_id": 4, "date": "2019/04/06 22:30:01", "garageCode": "MAGASIN", "totalSpaces": 378, "vehicleCount": 65}, {"_id": 5, "date": "2019/04/06 22:30:01", "garageCode": "KALKVAERKSVEJ", "totalSpaces": 210, "vehicleCount": 278}, {"_id": 10, "date": "2019/04/06 22:30:01", "garageCode": "Urban Level 1", "totalSpaces": 319, "vehicleCount": 32}, {"_id": 11, "date": "2019/04/06 22:30:01", "garageCode": "Urban Level 2+3", "totalSpaces": 654, "vehicleCount": 66}], "_links": {"start": "/api/3/action/datastore_search?resource_id=2a82a145-0195-4081-a13c-b0e587e9b89c", "next": "/api/3/action/datastore_search?offset=100&resource_id=2a82a145-0195-4081-a13c-b0e587e9b89c"}, "total": 11}} \ No newline at end of file diff --git a/server/nightr/strategies/svm_strat.py b/server/nightr/strategies/svm_strat.py index 0af7835..81d1569 100644 --- a/server/nightr/strategies/svm_strat.py +++ b/server/nightr/strategies/svm_strat.py @@ -5,11 +5,9 @@ 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) From fa63cb9e065afd0da3210187cf3976a3c63fb870 Mon Sep 17 00:00:00 2001 From: Alexander Munch-Hansen Date: Sun, 7 Apr 2019 00:03:50 +0200 Subject: [PATCH 10/10] pls --- server/nightr/strategies/svm_strat.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/nightr/strategies/svm_strat.py b/server/nightr/strategies/svm_strat.py index 81d1569..90fa84f 100644 --- a/server/nightr/strategies/svm_strat.py +++ b/server/nightr/strategies/svm_strat.py @@ -1,3 +1,5 @@ +from pathlib import Path + from sklearn import svm from sklearn.externals import joblib import requests @@ -36,7 +38,7 @@ def train(): joblib.dump(classifier, "nightness_classifier.pkl") def predict(X): - classifier = joblib.load("nightness_classifier.pkl") + 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]