Merge remote-tracking branch 'origin/master'
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 31 KiB |
After Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 31 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 31 KiB |
After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 54 KiB After Width: | Height: | Size: 31 KiB |
After Width: | Height: | Size: 54 KiB |
Before Width: | Height: | Size: 116 KiB After Width: | Height: | Size: 31 KiB |
After Width: | Height: | Size: 116 KiB |
Before Width: | Height: | Size: 193 KiB After Width: | Height: | Size: 31 KiB |
After Width: | Height: | Size: 193 KiB |
|
@ -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',
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 = (<any>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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,18 @@
|
|||
<ActionBar title="Result" class="action-bar"></ActionBar>
|
||||
|
||||
<ScrollView class="page">
|
||||
<AbsoluteLayout>
|
||||
<Button class="btn btn-primary" text="Home" [nsRouterLink]="['/home-page']"></Button>
|
||||
</AbsoluteLayout>
|
||||
<StackLayout class="page" height="100%">
|
||||
<StackLayout height="20%" class="title-container">
|
||||
<Label text="{{night}}"></Label>
|
||||
<Label text="{{percentage}}" textWrap="true"></Label>
|
||||
</StackLayout>
|
||||
<ScrollView height='80%'>
|
||||
<ListView [items]="reasons" class="list-group">
|
||||
<ng-template let-reason="item" let-i="index" let-odd="odd" let-even="even">
|
||||
<StackLayout orientation="vertical" class="list-group-item">
|
||||
<Label class="item-header" [text]="reason.str" width="100%" textWrap="true"></Label>
|
||||
<Label class="item-item" [text]="reason.causestring" width="100%" textWrap="true"></Label>
|
||||
</StackLayout>
|
||||
</ng-template>
|
||||
</ListView>
|
||||
</ScrollView>
|
||||
</StackLayout>
|
||||
|
|
|
@ -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<Reason>;
|
||||
|
||||
constructor(private routerExtensions: RouterExtensions) { }
|
||||
constructor(private myHttpPostSerivce: MyHttpPostService,
|
||||
private routerExtensions: RouterExtensions,
|
||||
private geoLocationService: MyGeoLocationService,
|
||||
private batterInfoService: MyBatteryInfoService,
|
||||
private cameraService: MyCameraService,){ }
|
||||
|
||||
ngOnInit(): void {
|
||||
ngOnInit(): Promise<void> {
|
||||
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 {
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
}
|
||||
}
|
||||
} */
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ export class MyCameraService {
|
|||
src.fromAsset(imageAsset).then(
|
||||
(source) => {
|
||||
resolve(source.toBase64String("png", 75));
|
||||
alert("Image uploaded");
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|