Merge remote-tracking branch 'origin/master'

This commit is contained in:
Alexander Munch-Hansen 2019-04-07 04:49:04 +02:00
commit 1c6611e103
16 changed files with 115 additions and 121 deletions

View File

@ -3784,6 +3784,11 @@
"nativescript-permissions": "^1.2.3" "nativescript-permissions": "^1.2.3"
} }
}, },
"nativescript-checkbox": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/nativescript-checkbox/-/nativescript-checkbox-3.0.3.tgz",
"integrity": "sha1-H5oC4BvPi9fSd79IW8CvMa3jdcs="
},
"nativescript-dev-typescript": { "nativescript-dev-typescript": {
"version": "0.9.0", "version": "0.9.0",
"resolved": "https://registry.npmjs.org/nativescript-dev-typescript/-/nativescript-dev-typescript-0.9.0.tgz", "resolved": "https://registry.npmjs.org/nativescript-dev-typescript/-/nativescript-dev-typescript-0.9.0.tgz",

View File

@ -23,6 +23,7 @@
"@angular/router": "~7.2.0", "@angular/router": "~7.2.0",
"nativescript-angular": "~7.2.0", "nativescript-angular": "~7.2.0",
"nativescript-camera": "^4.4.0", "nativescript-camera": "^4.4.0",
"nativescript-checkbox": "^3.0.3",
"nativescript-geolocation": "^5.0.0", "nativescript-geolocation": "^5.0.0",
"nativescript-powerinfo": "^1.0.7", "nativescript-powerinfo": "^1.0.7",
"nativescript-theme-core": "~1.0.4", "nativescript-theme-core": "~1.0.4",

View File

@ -6,8 +6,6 @@ import { AppComponent } from "./app.component";
import { HomePageComponent } from "./home-page/home-page.component"; import { HomePageComponent } from "./home-page/home-page.component";
import { MyButtonComponent } from './component/my-button/my-button.component'; import { MyButtonComponent } from './component/my-button/my-button.component';
import { NativeScriptHttpClientModule } from "nativescript-angular/http-client"; 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'; import { ResultPageComponent } from './result-page/result-page.component';
// Uncomment and add to NgModule imports if you need to use two-way binding // Uncomment and add to NgModule imports if you need to use two-way binding
@ -32,9 +30,7 @@ import { ResultPageComponent } from './result-page/result-page.component';
], ],
declarations: [ declarations: [
AppComponent, AppComponent,
MyLocationButtonComponent,
MyButtonComponent, MyButtonComponent,
CameraButtonComponent,
ResultPageComponent, ResultPageComponent,
HomePageComponent, HomePageComponent,
], ],

View File

@ -1 +0,0 @@
/* Add mobile styles for the component here. */

View File

@ -1 +0,0 @@
<Button text="camera-button works!" class="btn btn-primary" (tap)="onTap()"></Button>

View File

@ -1,24 +0,0 @@
import { Component, OnInit } from '@angular/core';
import { MyCameraService } from '../../services/my-camera-service';
@Component({
selector: 'ns-camera-button',
templateUrl: './camera-button.component.html',
styleUrls: ['./camera-button.component.css'],
moduleId: module.id,
})
export class CameraButtonComponent implements OnInit {
camera:MyCameraService = new MyCameraService();
constructor() { }
ngOnInit() {
}
onTap() {
this.camera.takePicture().then(
(res) => {console.log(res)}, () => {}
);
}
}

View File

@ -1 +0,0 @@
/* Add mobile styles for the component here. */

View File

@ -1,4 +0,0 @@
<StackLayout>
<Button text="{{title}}" class="btn btn-primary" (tap)="onTap($event)"></Button>
<Label text="{{lat}}"></Label>
</StackLayout>

View File

@ -1,29 +0,0 @@
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',
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();
@Output() tap: EventEmitter<GestureEventData> = new EventEmitter<GestureEventData>();
constructor() {
}
ngOnInit() {
}
onTap(args: GestureEventData): any {
this.tap.emit(args);
this.geoLocationService.getLocation().then(location => {
this.lat = ""+location.latitude;
}).catch(error => {
});
}
}

View File

@ -1,14 +1,15 @@
<ActionBar title="Home" class="action-bar"></ActionBar> <ActionBar title="Nightr" class="action-bar"></ActionBar>
<ScrollView class="page"> <ScrollView class="page">
<AbsoluteLayout> <AbsoluteLayout>
<GridLayout rows="auto auto" columns="* *" class="m-5">
<Label class="h3 m-15" text="Is the Earth flat?" textWrap="true" row="0" col="0"></Label>
<Switch class="m-15" checked="false" (checkedChange)="toggleFlatEarth($event)" row="0" col="1"></Switch>
<Label class="h3 m-15" text="Are you in Australia?" textWrap="true" row="1" col="0"></Label>
<Switch class="m-15" checked="false" (checkedChange)="toggleIsAustralia($event)" row="1" col="1"></Switch>
</GridLayout>
<StackLayout class="float-btn-container"> <StackLayout class="float-btn-container">
<ns-my-button (tap)=onTap($event) text="Nightr"></ns-my-button> <ns-my-button (tap)=onTap($event) text="Nightr"></ns-my-button>
</StackLayout> </StackLayout>
<StackLayout>
<ns-locationButton></ns-locationButton>
<ns-camera-button></ns-camera-button>
<Button class="btn btn-primary" text="Result page" [nsRouterLink]="['/result-page']"></Button>
</StackLayout>
</AbsoluteLayout> </AbsoluteLayout>
</ScrollView> </ScrollView>

View File

@ -1,12 +1,12 @@
import { Component, OnInit } from "@angular/core"; import { Component, OnInit } from "@angular/core";
import * as dialogs from "tns-core-modules/ui/dialogs";
import { RouterExtensions } from "nativescript-angular/router"; import { RouterExtensions } from "nativescript-angular/router";
import { TouchGestureEventData, GestureEventData } from 'tns-core-modules/ui/gestures' import { GestureEventData } from 'tns-core-modules/ui/gestures'
import { Switch } from "tns-core-modules/ui/switch";
import * as appSettings from "tns-core-modules/application-settings";
import { isEnabled, enableLocationRequest, getCurrentLocation, watchLocation, distance, clearWatch, Location } from "nativescript-geolocation"; import { isEnabled, enableLocationRequest, getCurrentLocation, watchLocation, distance, clearWatch, Location } from "nativescript-geolocation";
import { MyHttpPostService } from '../services/my-http-post-service'; import { MyHttpPostService } from '../services/my-http-post-service';
@Component({ @Component({
selector: "home-page", selector: "home-page",
moduleId: module.id, moduleId: module.id,
@ -15,29 +15,44 @@ import { MyHttpPostService } from '../services/my-http-post-service';
providers: [MyHttpPostService] providers: [MyHttpPostService]
}) })
export class HomePageComponent implements OnInit { export class HomePageComponent implements OnInit {
returnMessage: string = ""; public toggleFlatEarthState = "Is the earth flat?";
myReturnJSON: Object; public toggleIsAustraliaState = "Are you in Australia?";
locationData: Location; isEarthFlat: boolean;
myPicture: String; inAustralia: boolean;
image: any;
flat_earth: boolean;
in_australia: boolean;
changeYes: boolean;
constructor(private routerExtensions: RouterExtensions, constructor(private routerExtensions: RouterExtensions,
) { } ) { }
ngOnInit(): void { ngOnInit(): void {
} }
public changeGenderMale(){ public toggleFlatEarth(args) {
if(this.changeYes == true) let firstSwitch = <Switch>args.object;
this.changeYes = false; if (firstSwitch.checked) {
else this.isEarthFlat = true;
this.changeYes = true; appSettings.setBoolean("applicationIsEarthFlat", true);
} } else {
this.isEarthFlat = false;
appSettings.setBoolean("applicationIsEarthFlat", false);
}
}
public toggleIsAustralia(args) {
let secondSwitch = <Switch>args.object;
if (secondSwitch.checked) {
this.inAustralia = true;
appSettings.setBoolean("applicationinAustralia", true);
} else {
this.inAustralia = false;
appSettings.setBoolean("applicationinAustralia", false);
}
}
public onTap(args: GestureEventData): void { public onTap(args: GestureEventData): void {
this.routerExtensions.navigateByUrl("/result-page"); let navigationExtras = {
queryParams: {
isEarthFlat: this.isEarthFlat,
inAustralia: this.inAustralia }
}
this.routerExtensions.navigateByUrl("/result-page"), navigationExtras;
} }
} }

View File

@ -1,11 +1,26 @@
.title-container .h2
{ {
font-family: sans-serif; font-family: sans-serif;
font-size: 30px; font-size: 35px;
padding: 5px;
color: white; color: white;
text-align: center; text-align: center;
} }
.h1
{
font-family: sans-serif;
font-size: 100px;
color: white;
text-align: center;
}
.h3
{
font-family: sans-serif;
font-style: italic;
font-size: 20px;
color: white;
text-align: center;
}
.page { .page {
background-color: lightskyblue; background-color: lightskyblue;
} }

View File

@ -1,11 +1,12 @@
<ActionBar title="Result" class="action-bar"></ActionBar> <ActionBar title="Nightr" class="action-bar"></ActionBar>
<StackLayout class="page" height="100%"> <StackLayout class="page" height="100%">
<StackLayout height="20%" class="title-container"> <StackLayout height="45%" class="title-container">
<Label text="{{night}}"></Label> <Label text="{{itis}}" class="h3"></Label>
<Label text="{{percentage}}" textWrap="true"></Label> <Label text="{{night}}" class="h1"></Label>
<Label text="{{percentage}}" textWrap="true" class="h2"></Label>
<Label text="{{hereswhy}}" class="h3"></Label>
</StackLayout> </StackLayout>
<ScrollView height='80%'> <ScrollView height='55%'>
<ListView [items]="reasons" class="list-group"> <ListView [items]="reasons" class="list-group">
<ng-template let-reason="item" let-i="index" let-odd="odd" let-even="even"> <ng-template let-reason="item" let-i="index" let-odd="odd" let-even="even">
<StackLayout orientation="vertical" class="list-group-item"> <StackLayout orientation="vertical" class="list-group-item">
@ -16,3 +17,4 @@
</ListView> </ListView>
</ScrollView> </ScrollView>
</StackLayout> </StackLayout>
<ActivityIndicator #activityIndicator [busy]="isBusy" originX ="0.5" originY="0.5" width="100" height="100" class="activity-indicator"></ActivityIndicator>

View File

@ -1,11 +1,12 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { MyHttpPostService } from '../services/my-http-post-service' import { MyHttpPostService } from '../services/my-http-post-service';
import { MyGeoLocationService} from '../services/my-geo-location.service'; import { MyGeoLocationService} from '../services/my-geo-location.service';
import { MyBatteryInfoService } from '../services/my-battery-info.service'; import { MyBatteryInfoService } from '../services/my-battery-info.service';
import { MyCameraService } from '../services/my-camera-service' import { MyCameraService } from '../services/my-camera-service';
import { RouterExtensions } from 'nativescript-angular/router'; import { RouterExtensions } from 'nativescript-angular/router';
import { Location } from 'nativescript-geolocation'; import { Location } from 'nativescript-geolocation';
import * as appSettings from "tns-core-modules/application-settings";
class Reason { class Reason {
constructor(public str: string, public causestring: string) { constructor(public str: string, public causestring: string) {
@ -18,9 +19,11 @@ class Reason {
templateUrl: './result-page.component.html', templateUrl: './result-page.component.html',
styleUrls: ['./result-page.component.css'], styleUrls: ['./result-page.component.css'],
moduleId: module.id, moduleId: module.id,
providers: [MyHttpPostService]
}) })
export class ResultPageComponent implements OnInit { export class ResultPageComponent implements OnInit {
returnMessage: string = ""; returnMessage: string = "";
isBusy: boolean;
myReturnJSON: Object; myReturnJSON: Object;
locationData: Location; locationData: Location;
myPicture: String; myPicture: String;
@ -28,21 +31,25 @@ export class ResultPageComponent implements OnInit {
flat_earth: boolean; flat_earth: boolean;
in_australia: boolean; in_australia: boolean;
night: string = ""; night: string = "";
percentage: string = ""; percentage: string = "Calculating...";
hereswhy: string = "";
itis: string = "";
reasons: Array<Reason>;
JSONObject; JSONObject;
public reasons: Array<Reason>;
constructor(private myHttpPostSerivce: MyHttpPostService, constructor(private myHttpPostSerivce: MyHttpPostService,
private routerExtensions: RouterExtensions, private routerExtensions: RouterExtensions,
private geoLocationService: MyGeoLocationService, private geoLocationService: MyGeoLocationService,
private batterInfoService: MyBatteryInfoService, private batterInfoService: MyBatteryInfoService,
private cameraService: MyCameraService,){ } private cameraService: MyCameraService,){ }
ngOnInit(): Promise<void> { ngOnInit(): Promise<void> {
this.isBusy = true;
this.reasons = new Array<Reason>();
return this.cameraService.takePicture(). return this.cameraService.takePicture().
then(picture => { then(picture => {
this.image = JSON.stringify(picture); this.image = JSON.stringify(picture);
//console.log('this is picture in json', JSON.stringify(picture));
this.getLocation(); this.getLocation();
}) })
} }
@ -50,7 +57,6 @@ export class ResultPageComponent implements OnInit {
public getLocation(): any { public getLocation(): any {
this.geoLocationService.getLocation().then(location => { this.geoLocationService.getLocation().then(location => {
this.locationData = location; this.locationData = location;
//console.log('this is locationData', this.locationData);
this.submit(); this.submit();
}).catch(error => { }).catch(error => {
}); });
@ -60,30 +66,34 @@ public submit(): void {
} }
private makePostRequest(): void { private makePostRequest(): void {
this.isBusy = true;
this.myHttpPostSerivce this.myHttpPostSerivce
.postData({ position: this.locationData, image: this.image, flat_earth: true, in_australia: true, }) .postData({ position: this.locationData, image: this.image,
flat_earth: appSettings.getBoolean("applicationIsEarthFlat", false),
in_australia: appSettings.getBoolean("applicationinAustralia", false), })
.subscribe(res => { .subscribe(res => {
//console.log('This is res', res);
this.JSONObject = res; this.JSONObject = res;
this.isBusy = false;
this.addToArray(); this.addToArray();
//console.log('THis is myreturnJSON', this.myReturnJSON);
}); });
} }
public addToArray(): void { public addToArray(): void {
if (this.JSONObject.night) { if (this.JSONObject.night) {
this.night = "It is night"; this.night = "NIGHT";
} else { } else {
this.night = "It is day"; this.night = "DAY";
} }
this.percentage = "At least we are "+Math.floor(this.JSONObject.weighted_probabilities_mean*100)+"% sure, here's why" this.percentage = "At least we are "+Math.floor(this.JSONObject.weighted_probabilities_mean*100)+"% sure"
for (let i = 0; i < this.JSONObject.predictions.length; i++) { for (let i = 0; i < this.JSONObject.predictions.length; i++) {
var causestring = "" var causestring = ""
for (let j = 0; j < this.JSONObject.predictions[i].reasons.length; j++) { for (let j = 0; j < this.JSONObject.predictions[i].reasons.length; j++) {
causestring = causestring + " - " + this.JSONObject.predictions[i].reasons[j] + "\n"; causestring = causestring + " - " + this.JSONObject.predictions[i].reasons[j] + "\n";
} }
this.itis = "It is"
this.hereswhy = "Here's why:"
this.reasons.push(new Reason(""+Math.round(this.JSONObject.predictions[i].contribution*100)+"% - " + this.JSONObject.predictions[i].name, causestring)); this.reasons.push(new Reason(""+Math.round(this.JSONObject.predictions[i].contribution*100)+"% - " + this.JSONObject.predictions[i].name, causestring));
} }
} }

View File

@ -35,12 +35,20 @@ def australiaStrat(context : Context) -> Prediction:
hour = t.hour hour = t.hour
p = Prediction() p = Prediction()
if hour > 22 or hour < 6: if context.in_australia:
p.probability = 0.0 if hour > 22 or hour < 6:
p.reasons.append('It\'s night-time in Australia, so it must be day-time here.') p.probability = 1.0
p.reasons.append('It\'s night-time in Australia, and that\'s where we\'re at.')
else:
p.probability = 0.0
p.reasons.append('It\'s day-time in Australia, and that\'s where we\'re at.')
else: else:
p.probability = 1.0 if hour > 22 or hour < 6:
p.reasons.append('It\'s day-time in Australia, so it must be night-time here.') p.probability = 0.0
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, so it must be night-time here.')
return p return p

View File

@ -1,4 +1,5 @@
import base64 import base64
import random
from dataclasses import dataclass, field from dataclasses import dataclass, field
from pathlib import Path from pathlib import Path
from typing import List, Dict from typing import List, Dict
@ -9,7 +10,7 @@ import numpy as np
@dataclass @dataclass
class Context: class Context:
battery: int = 55 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 position: Dict[str, float] = field(default_factory=lambda: {'latitude': 53.0, 'longitude': 9.0}) # Denmark somewhere
image: np.ndarray = None image: np.ndarray = None