diff --git a/client/Nightr/App_Resources/Android/src/main/res/drawable-hdpi/logo.png b/client/Nightr/App_Resources/Android/src/main/res/drawable-hdpi/logo.png index 5218f4c..d2d2014 100644 Binary files a/client/Nightr/App_Resources/Android/src/main/res/drawable-hdpi/logo.png and b/client/Nightr/App_Resources/Android/src/main/res/drawable-hdpi/logo.png differ diff --git a/client/Nightr/App_Resources/Android/src/main/res/drawable-hdpi/logo_old.png b/client/Nightr/App_Resources/Android/src/main/res/drawable-hdpi/logo_old.png new file mode 100644 index 0000000..5218f4c Binary files /dev/null and b/client/Nightr/App_Resources/Android/src/main/res/drawable-hdpi/logo_old.png differ diff --git a/client/Nightr/App_Resources/Android/src/main/res/drawable-ldpi/logo.png b/client/Nightr/App_Resources/Android/src/main/res/drawable-ldpi/logo.png index b9e102a..d2d2014 100644 Binary files a/client/Nightr/App_Resources/Android/src/main/res/drawable-ldpi/logo.png and b/client/Nightr/App_Resources/Android/src/main/res/drawable-ldpi/logo.png differ diff --git a/client/Nightr/App_Resources/Android/src/main/res/drawable-mdpi/logo.png b/client/Nightr/App_Resources/Android/src/main/res/drawable-mdpi/logo.png index 6263387..d2d2014 100644 Binary files a/client/Nightr/App_Resources/Android/src/main/res/drawable-mdpi/logo.png and b/client/Nightr/App_Resources/Android/src/main/res/drawable-mdpi/logo.png differ diff --git a/client/Nightr/App_Resources/Android/src/main/res/drawable-mdpi/logo_old.png b/client/Nightr/App_Resources/Android/src/main/res/drawable-mdpi/logo_old.png new file mode 100644 index 0000000..6263387 Binary files /dev/null and b/client/Nightr/App_Resources/Android/src/main/res/drawable-mdpi/logo_old.png differ diff --git a/client/Nightr/App_Resources/Android/src/main/res/drawable-xhdpi/logo.png b/client/Nightr/App_Resources/Android/src/main/res/drawable-xhdpi/logo.png index ad8ee2f..d2d2014 100644 Binary files a/client/Nightr/App_Resources/Android/src/main/res/drawable-xhdpi/logo.png and b/client/Nightr/App_Resources/Android/src/main/res/drawable-xhdpi/logo.png differ diff --git a/client/Nightr/App_Resources/Android/src/main/res/drawable-xhdpi/logo_old.png b/client/Nightr/App_Resources/Android/src/main/res/drawable-xhdpi/logo_old.png new file mode 100644 index 0000000..ad8ee2f Binary files /dev/null and b/client/Nightr/App_Resources/Android/src/main/res/drawable-xhdpi/logo_old.png differ diff --git a/client/Nightr/App_Resources/Android/src/main/res/drawable-xxhdpi/logo.png b/client/Nightr/App_Resources/Android/src/main/res/drawable-xxhdpi/logo.png index 6683278..d2d2014 100644 Binary files a/client/Nightr/App_Resources/Android/src/main/res/drawable-xxhdpi/logo.png and b/client/Nightr/App_Resources/Android/src/main/res/drawable-xxhdpi/logo.png differ diff --git a/client/Nightr/App_Resources/Android/src/main/res/drawable-xxhdpi/logo_old.png b/client/Nightr/App_Resources/Android/src/main/res/drawable-xxhdpi/logo_old.png new file mode 100644 index 0000000..6683278 Binary files /dev/null and b/client/Nightr/App_Resources/Android/src/main/res/drawable-xxhdpi/logo_old.png differ diff --git a/client/Nightr/App_Resources/Android/src/main/res/drawable-xxxhdpi/logo.png b/client/Nightr/App_Resources/Android/src/main/res/drawable-xxxhdpi/logo.png index fa6331c..d2d2014 100644 Binary files a/client/Nightr/App_Resources/Android/src/main/res/drawable-xxxhdpi/logo.png and b/client/Nightr/App_Resources/Android/src/main/res/drawable-xxxhdpi/logo.png differ diff --git a/client/Nightr/App_Resources/Android/src/main/res/drawable-xxxhdpi/logo_old.png b/client/Nightr/App_Resources/Android/src/main/res/drawable-xxxhdpi/logo_old.png new file mode 100644 index 0000000..fa6331c Binary files /dev/null and b/client/Nightr/App_Resources/Android/src/main/res/drawable-xxxhdpi/logo_old.png differ diff --git a/client/Nightr/src/app/component/camera-button/camera-button.component.ts b/client/Nightr/src/app/component/camera-button/camera-button.component.ts index bd916ef..d3bd803 100644 --- a/client/Nightr/src/app/component/camera-button/camera-button.component.ts +++ b/client/Nightr/src/app/component/camera-button/camera-button.component.ts @@ -1,6 +1,5 @@ import { Component, OnInit } from '@angular/core'; import { MyCameraService } from '../../services/my-camera-service'; -import { Image } from 'tns-core-modules/ui/image' @Component({ selector: 'ns-camera-button', diff --git a/client/Nightr/src/app/home-page/home-page.component.css b/client/Nightr/src/app/home-page/home-page.component.css index 18496f5..6b0ca11 100644 --- a/client/Nightr/src/app/home-page/home-page.component.css +++ b/client/Nightr/src/app/home-page/home-page.component.css @@ -1,5 +1,16 @@ .float-btn-container { - margin-top: 35%; - margin-left: 20%; + width: 50%; + left: 90%; + top: 160%; } + + .font-awesome { + font-family: "fontawesome-webfont"; + font-size: 24; +} + +.radioBefore { + font-family: "fontawesome-webfont"; + font-size: 24; +} diff --git a/client/Nightr/src/app/home-page/home-page.component.ts b/client/Nightr/src/app/home-page/home-page.component.ts index 56b788d..329ff98 100644 --- a/client/Nightr/src/app/home-page/home-page.component.ts +++ b/client/Nightr/src/app/home-page/home-page.component.ts @@ -1,9 +1,11 @@ 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"; +import { isEnabled, enableLocationRequest, getCurrentLocation, watchLocation, distance, clearWatch, Location } from "nativescript-geolocation"; + +import { MyHttpPostService } from '../services/my-http-post-service'; + @Component({ selector: "home-page", @@ -13,37 +15,29 @@ import { isEnabled, enableLocationRequest, getCurrentLocation, watchLocation, di providers: [MyHttpPostService] }) export class HomePageComponent implements OnInit { - public user: string = ""; - public pass: string = ""; returnMessage: string = ""; + myReturnJSON: Object; + locationData: Location; + myPicture: String; + image: any; + flat_earth: boolean; + in_australia: boolean; + changeYes: boolean; - 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; - }); - } + constructor(private routerExtensions: RouterExtensions, + ) { } ngOnInit(): void { } - goBack(): void { - this.routerExtensions.back(); + + public changeGenderMale(){ + if(this.changeYes == true) + this.changeYes = false; + else + this.changeYes = true; + } + + public onTap(args: GestureEventData): void { + this.routerExtensions.navigateByUrl("/result-page"); } } diff --git a/client/Nightr/src/app/result-page/result-page.component.css b/client/Nightr/src/app/result-page/result-page.component.css index bcd4764..7b3ead4 100644 --- a/client/Nightr/src/app/result-page/result-page.component.css +++ b/client/Nightr/src/app/result-page/result-page.component.css @@ -1 +1,22 @@ -/* Add mobile styles for the component here. */ +.title-container + { + font-family: sans-serif; + font-size: 30px; + padding: 5px; + color: white; + text-align: center; + } +.page { + background-color: lightskyblue; +} +.item-item { + font-family: sans-serif; + color: white; + font-size: 20px; +} +.item-header { + font-family: sans-serif; + color: white; + font-size: 25px; + font-weight: 800; +} diff --git a/client/Nightr/src/app/result-page/result-page.component.html b/client/Nightr/src/app/result-page/result-page.component.html index 5a89837..7f4c484 100644 --- a/client/Nightr/src/app/result-page/result-page.component.html +++ b/client/Nightr/src/app/result-page/result-page.component.html @@ -1,7 +1,18 @@ - - - - - + + + + + + + + + + + + + + + + diff --git a/client/Nightr/src/app/result-page/result-page.component.ts b/client/Nightr/src/app/result-page/result-page.component.ts index a764430..f447ffb 100644 --- a/client/Nightr/src/app/result-page/result-page.component.ts +++ b/client/Nightr/src/app/result-page/result-page.component.ts @@ -1,5 +1,17 @@ import { Component, OnInit } from '@angular/core'; + +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' import { RouterExtensions } from 'nativescript-angular/router'; +import { Location } from 'nativescript-geolocation'; + +class Reason { + constructor(public str: string, public causestring: string) { + + } +} @Component({ selector: 'result-page', @@ -8,10 +20,72 @@ import { RouterExtensions } from 'nativescript-angular/router'; moduleId: module.id, }) export class ResultPageComponent implements OnInit { + returnMessage: string = ""; + myReturnJSON: Object; + locationData: Location; + myPicture: String; + image: any; + flat_earth: boolean; + in_australia: boolean; + night: string = ""; + percentage: string = ""; + JSONObject; + public reasons: Array; - constructor(private routerExtensions: RouterExtensions) { } + constructor(private myHttpPostSerivce: MyHttpPostService, + private routerExtensions: RouterExtensions, + private geoLocationService: MyGeoLocationService, + private batterInfoService: MyBatteryInfoService, + private cameraService: MyCameraService,){ } - ngOnInit(): void { + ngOnInit(): 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); + this.submit(); + }).catch(error => { + }); +} +public submit(): void { + this.makePostRequest(); +} + +private makePostRequest(): void { + this.myHttpPostSerivce + .postData({ position: this.locationData, image: this.image, flat_earth: true, in_australia: true, }) + .subscribe(res => { + //console.log('This is res', res); + this.JSONObject = res; + this.addToArray(); + //console.log('THis is myreturnJSON', this.myReturnJSON); + }); +} + +public addToArray(): void { + + if (this.JSONObject.night) { + this.night = "It is night"; + } else { + this.night = "It is day"; + } + + this.percentage = "At least we are "+Math.floor(this.JSONObject.weighted_probabilities_mean*100)+"% sure, here's why" + for (let i = 0; i < this.JSONObject.predictions.length; i++) { + var causestring = "" + for (let j = 0; j < this.JSONObject.predictions[i].reasons.length; j++) { + causestring = causestring + " - " + this.JSONObject.predictions[i].reasons[j] + "\n"; + } + this.reasons.push(new Reason(""+Math.round(this.JSONObject.predictions[i].contribution*100)+"% - " + this.JSONObject.predictions[i].name, causestring)); + } } goBack(): void { 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 424327f..2906c36 100644 --- a/client/Nightr/src/app/services/my-battery-info.service.ts +++ b/client/Nightr/src/app/services/my-battery-info.service.ts @@ -7,7 +7,7 @@ import { ios as iosUtils } from "tns-core-modules/utils/utils"; }) export class MyBatteryInfoService { - public getBatteryLife() { + /*public getBatteryLife() { if (iosApp){ iosUtils.getter(UIDevice, UIDevice.currentDevice).batteryMonitoringEnabled = true; let battery = +(iosUtils.getter(UIDevice, UIDevice.currentDevice).batteryLevel * 100); @@ -18,5 +18,5 @@ export class MyBatteryInfoService { let percent = (level / scale) * 100.0; }); } -} +} */ } diff --git a/client/Nightr/src/app/services/my-camera-service.ts b/client/Nightr/src/app/services/my-camera-service.ts index a6a4f14..96325ef 100644 --- a/client/Nightr/src/app/services/my-camera-service.ts +++ b/client/Nightr/src/app/services/my-camera-service.ts @@ -20,7 +20,6 @@ export class MyCameraService { src.fromAsset(imageAsset).then( (source) => { resolve(source.toBase64String("png", 75)); - alert("Image uploaded"); } ); } diff --git a/server/nightr/app.py b/server/nightr/app.py index e0f5d75..23bd1ae 100644 --- a/server/nightr/app.py +++ b/server/nightr/app.py @@ -10,28 +10,29 @@ 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 +from .strategies import miloStrats, iss, cars_in_traffic, tide_strat, upstairs_neighbour, bing, svm_strat, battery, just_eat 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)) +requests_cache.install_cache("requests_cache", expire_after=timedelta(minutes=2)) strategies = { # name: (weight, probability function) - "tv2news": miloStrats.tv2newsStrat, - "australia": miloStrats.australiaStrat, - "camera": miloStrats.camImgStrat, - "iss": iss.night_on_iss, - "cars_in_traffic": cars_in_traffic.cars_in_traffic, - "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, + "TV2 News": miloStrats.tv2newsStrat, + "Australia": miloStrats.australiaStrat, + "Camera Image": miloStrats.camImgStrat, + "The International Space Station": iss.night_on_iss, + "Nearby Traffic situation": cars_in_traffic.cars_in_traffic, + "Tidal Measurements": tide_strat.is_tide, + "Legends of Nighttime": upstairs_neighbour.check_games, + "Bing AI": bing.clock, + "ML Parking": svm_strat.perform_svm_pred, + "Phone Battery Level": battery.battery_level, + "Pizza Availability": just_eat.do_just_eat_strat, } @@ -87,6 +88,9 @@ def probabilities(): # If this prediction disagrees with the consensus it contributed negatively if prediction["night"] != night: prediction["contribution"] *= -1 + + predictions.sort(key=lambda p: (p["contribution"], p["probability"]), reverse=True) + return jsonify({ "predictions": predictions, "weighted_probabilities_mean": mean, diff --git a/server/nightr/strategies/iss.py b/server/nightr/strategies/iss.py index bd759bc..4972a43 100644 --- a/server/nightr/strategies/iss.py +++ b/server/nightr/strategies/iss.py @@ -40,11 +40,11 @@ def night_on_iss(context: Context) -> Prediction: side = "same" if on_iss_time else "other" p.reasons.append(f"{the_iss} is {int(distance)} km away, so we are on the {side} side of the earth.") for i in itertools.count(1): - iss_tz = tf.closest_timezone_at(lng=float(iss_position["longitude"]), - lat=float(iss_position["latitude"]), + iss_tz = tf.closest_timezone_at(lng=float(iss_position["longitude"]), lat=float(iss_position["latitude"]), delta_degree=i) if iss_tz is not None: break + iss_time = datetime.now(pytz.timezone(iss_tz)) iss_night = iss_time.hour < 6 or iss_time.hour >= 22 @@ -75,6 +75,9 @@ def haversine(pos1, pos2): lat2 = float(pos2["latitude"]) long2 = float(pos2["longitude"]) + lat1 = 0 # we're only interested in the distance in the longitude for the timezone calculation + lat2 = 0 + degree_to_rad = float(pi / 180.0) d_lat = (lat2 - lat1) * degree_to_rad diff --git a/server/nightr/strategies/just_eat.py b/server/nightr/strategies/just_eat.py index 9a314cd..634c9a1 100644 --- a/server/nightr/strategies/just_eat.py +++ b/server/nightr/strategies/just_eat.py @@ -1,12 +1,8 @@ import requests from bs4 import BeautifulSoup -from datetime import datetime, timedelta -import requests_cache from ..util import Context, Prediction -requests_cache.install_cache("requests_cache", expire_after=timedelta(minutes=10)) - def is_restaurant_open(name, open, close) -> Prediction: p = Prediction()