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-checkbox": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/nativescript-checkbox/-/nativescript-checkbox-3.0.3.tgz",
"integrity": "sha1-H5oC4BvPi9fSd79IW8CvMa3jdcs="
},
"nativescript-dev-typescript": {
"version": "0.9.0",
"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",
"nativescript-angular": "~7.2.0",
"nativescript-camera": "^4.4.0",
"nativescript-checkbox": "^3.0.3",
"nativescript-geolocation": "^5.0.0",
"nativescript-powerinfo": "^1.0.7",
"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 { 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
@ -32,9 +30,7 @@ import { ResultPageComponent } from './result-page/result-page.component';
],
declarations: [
AppComponent,
MyLocationButtonComponent,
MyButtonComponent,
CameraButtonComponent,
ResultPageComponent,
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">
<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">
<ns-my-button (tap)=onTap($event) text="Nightr"></ns-my-button>
</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>
</ScrollView>

View File

@ -1,12 +1,12 @@
import { Component, OnInit } from "@angular/core";
import * as dialogs from "tns-core-modules/ui/dialogs";
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 { MyHttpPostService } from '../services/my-http-post-service';
@Component({
selector: "home-page",
moduleId: module.id,
@ -15,29 +15,44 @@ import { MyHttpPostService } from '../services/my-http-post-service';
providers: [MyHttpPostService]
})
export class HomePageComponent implements OnInit {
returnMessage: string = "";
myReturnJSON: Object;
locationData: Location;
myPicture: String;
image: any;
flat_earth: boolean;
in_australia: boolean;
changeYes: boolean;
public toggleFlatEarthState = "Is the earth flat?";
public toggleIsAustraliaState = "Are you in Australia?";
isEarthFlat: boolean;
inAustralia: boolean;
constructor(private routerExtensions: RouterExtensions,
) { }
ngOnInit(): void {
}
public changeGenderMale(){
if(this.changeYes == true)
this.changeYes = false;
else
this.changeYes = true;
public toggleFlatEarth(args) {
let firstSwitch = <Switch>args.object;
if (firstSwitch.checked) {
this.isEarthFlat = 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 {
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-size: 30px;
padding: 5px;
font-size: 35px;
color: white;
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 {
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 height="20%" class="title-container">
<Label text="{{night}}"></Label>
<Label text="{{percentage}}" textWrap="true"></Label>
<StackLayout height="45%" class="title-container">
<Label text="{{itis}}" class="h3"></Label>
<Label text="{{night}}" class="h1"></Label>
<Label text="{{percentage}}" textWrap="true" class="h2"></Label>
<Label text="{{hereswhy}}" class="h3"></Label>
</StackLayout>
<ScrollView height='80%'>
<ScrollView height='55%'>
<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">
@ -16,3 +17,4 @@
</ListView>
</ScrollView>
</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 { MyHttpPostService } from '../services/my-http-post-service'
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 { MyCameraService } from '../services/my-camera-service';
import { RouterExtensions } from 'nativescript-angular/router';
import { Location } from 'nativescript-geolocation';
import * as appSettings from "tns-core-modules/application-settings";
class Reason {
constructor(public str: string, public causestring: string) {
@ -18,9 +19,11 @@ class Reason {
templateUrl: './result-page.component.html',
styleUrls: ['./result-page.component.css'],
moduleId: module.id,
providers: [MyHttpPostService]
})
export class ResultPageComponent implements OnInit {
returnMessage: string = "";
isBusy: boolean;
myReturnJSON: Object;
locationData: Location;
myPicture: String;
@ -28,9 +31,12 @@ export class ResultPageComponent implements OnInit {
flat_earth: boolean;
in_australia: boolean;
night: string = "";
percentage: string = "";
percentage: string = "Calculating...";
hereswhy: string = "";
itis: string = "";
reasons: Array<Reason>;
JSONObject;
public reasons: Array<Reason>;
constructor(private myHttpPostSerivce: MyHttpPostService,
private routerExtensions: RouterExtensions,
@ -39,10 +45,11 @@ export class ResultPageComponent implements OnInit {
private cameraService: MyCameraService,){ }
ngOnInit(): Promise<void> {
this.isBusy = true;
this.reasons = new Array<Reason>();
return this.cameraService.takePicture().
then(picture => {
this.image = JSON.stringify(picture);
//console.log('this is picture in json', JSON.stringify(picture));
this.getLocation();
})
}
@ -50,7 +57,6 @@ export class ResultPageComponent implements OnInit {
public getLocation(): any {
this.geoLocationService.getLocation().then(location => {
this.locationData = location;
//console.log('this is locationData', this.locationData);
this.submit();
}).catch(error => {
});
@ -60,30 +66,34 @@ public submit(): void {
}
private makePostRequest(): void {
this.isBusy = true;
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 => {
//console.log('This is res', res);
this.JSONObject = res;
this.isBusy = false;
this.addToArray();
//console.log('THis is myreturnJSON', this.myReturnJSON);
});
}
public addToArray(): void {
if (this.JSONObject.night) {
this.night = "It is night";
this.night = "NIGHT";
} 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++) {
var causestring = ""
for (let j = 0; j < this.JSONObject.predictions[i].reasons.length; j++) {
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));
}
}

View File

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

View File

@ -1,4 +1,5 @@
import base64
import random
from dataclasses import dataclass, field
from pathlib import Path
from typing import List, Dict
@ -9,7 +10,7 @@ import numpy as np
@dataclass
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
image: np.ndarray = None