merged
This commit is contained in:
commit
27935feeba
8
client/Nightr/package-lock.json
generated
8
client/Nightr/package-lock.json
generated
|
@ -3776,6 +3776,14 @@
|
||||||
"reflect-metadata": "^0.1.8"
|
"reflect-metadata": "^0.1.8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"nativescript-camera": {
|
||||||
|
"version": "4.4.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/nativescript-camera/-/nativescript-camera-4.4.0.tgz",
|
||||||
|
"integrity": "sha512-9Snw/IGjw8cVN1nOwkhQko/x/D2thcd6FZT98k9bstvCHwdBBdmLtGGcHCm4SN0k3MSgvbghs8iaARniZCKO0Q==",
|
||||||
|
"requires": {
|
||||||
|
"nativescript-permissions": "^1.2.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
"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",
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
"@angular/platform-browser-dynamic": "~7.2.0",
|
"@angular/platform-browser-dynamic": "~7.2.0",
|
||||||
"@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-geolocation": "^5.0.0",
|
"nativescript-geolocation": "^5.0.0",
|
||||||
"nativescript-theme-core": "~1.0.4",
|
"nativescript-theme-core": "~1.0.4",
|
||||||
"reflect-metadata": "~0.1.12",
|
"reflect-metadata": "~0.1.12",
|
||||||
|
|
|
@ -4,8 +4,9 @@
|
||||||
<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-locationButton></ns-locationButton>
|
||||||
|
<ns-camera-button></ns-camera-button>
|
||||||
|
</StackLayout>
|
||||||
</AbsoluteLayout>
|
</AbsoluteLayout>
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import { AppComponent } from "./app.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 { MyLocationButtonComponent } from './component/locationButton/locationButton.component';
|
||||||
|
import { CameraButtonComponent } from './component/camera-button/camera-button.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
|
||||||
// import { NativeScriptFormsModule } from "nativescript-angular/forms";
|
// import { NativeScriptFormsModule } from "nativescript-angular/forms";
|
||||||
|
@ -24,6 +25,7 @@ import { MyLocationButtonComponent } from './component/locationButton/locationBu
|
||||||
AppComponent,
|
AppComponent,
|
||||||
MyLocationButtonComponent,
|
MyLocationButtonComponent,
|
||||||
MyButtonComponent,
|
MyButtonComponent,
|
||||||
|
CameraButtonComponent,
|
||||||
],
|
],
|
||||||
providers: [],
|
providers: [],
|
||||||
schemas: [
|
schemas: [
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
/* Add mobile styles for the component here. */
|
|
@ -0,0 +1 @@
|
||||||
|
<Button text="camera-button works!" class="btn btn-primary" (tap)="onTap()"></Button>
|
|
@ -0,0 +1,25 @@
|
||||||
|
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',
|
||||||
|
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)}, () => {}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
35
client/Nightr/src/app/services/my-camera-service.ts
Normal file
35
client/Nightr/src/app/services/my-camera-service.ts
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import * as camera from 'nativescript-camera';
|
||||||
|
import { ImageSource } from 'tns-core-modules/image-source/image-source';
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class MyCameraService {
|
||||||
|
|
||||||
|
constructor() { }
|
||||||
|
|
||||||
|
takePicture(): Promise<string> {
|
||||||
|
var result = new Promise<string>((resolve, reject) => {
|
||||||
|
camera.requestPermissions().
|
||||||
|
then(
|
||||||
|
() => {
|
||||||
|
camera.takePicture().then(
|
||||||
|
(imageAsset) => {
|
||||||
|
var src = new ImageSource();
|
||||||
|
src.fromAsset(imageAsset).then(
|
||||||
|
(source) => {
|
||||||
|
resolve(source.toBase64String("png", 75));
|
||||||
|
alert("Image uploaded");
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
).catch((error) => alert(error.message));
|
||||||
|
}, () => {
|
||||||
|
alert("Request rejected");
|
||||||
|
}
|
||||||
|
).catch();
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,5 @@
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { isEnabled, enableLocationRequest, getCurrentLocation, watchLocation, distance, clearWatch, Location } from "nativescript-geolocation";
|
import { isEnabled, enableLocationRequest, getCurrentLocation, watchLocation, distance, clearWatch, Location } from "nativescript-geolocation";
|
||||||
import { stringify } from '@angular/core/src/render3/util';
|
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
|
|
|
@ -11,4 +11,4 @@ var app_module_1 = require("./app/app.module");
|
||||||
// so we provide a wrapper platform object, platformNativeScriptDynamic,
|
// so we provide a wrapper platform object, platformNativeScriptDynamic,
|
||||||
// that sets up a NativeScript application and can bootstrap the Angular framework.
|
// that sets up a NativeScript application and can bootstrap the Angular framework.
|
||||||
platform_1.platformNativeScriptDynamic().bootstrapModule(app_module_1.AppModule);
|
platform_1.platformNativeScriptDynamic().bootstrapModule(app_module_1.AppModule);
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWFpbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIm1haW4udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSwwR0FBMEc7QUFDMUcsMERBQTRFO0FBRTVFLCtDQUE2QztBQUU3QyxnRkFBZ0Y7QUFDaEYsMEVBQTBFO0FBQzFFLHNFQUFzRTtBQUN0RSx5REFBeUQ7QUFDekQseUVBQXlFO0FBQ3pFLHdFQUF3RTtBQUN4RSxtRkFBbUY7QUFDbkYsc0NBQTJCLEVBQUUsQ0FBQyxlQUFlLENBQUMsc0JBQVMsQ0FBQyxDQUFDIiwic291cmNlc0NvbnRlbnQiOlsiLy8gdGhpcyBpbXBvcnQgc2hvdWxkIGJlIGZpcnN0IGluIG9yZGVyIHRvIGxvYWQgc29tZSByZXF1aXJlZCBzZXR0aW5ncyAobGlrZSBnbG9iYW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0aXZlcywgcm91dGVzLCBESSBwcm92aWRlcnMuXG4vLyBBIE5hdGl2ZVNjcmlwdCBBbmd1bGFyIGFwcCBuZWVkcyB0byBtYWtlIGJvdGggcGFyYWRpZ21zIHdvcmsgdG9nZXRoZXIsXG4vLyBzbyB3ZSBwcm92aWRlIGEgd3JhcHBlciBwbGF0Zm9ybSBvYmplY3QsIHBsYXRmb3JtTmF0aXZlU2NyaXB0RHluYW1pYyxcbi8vIHRoYXQgc2V0cyB1cCBhIE5hdGl2ZVNjcmlwdCBhcHBsaWNhdGlvbiBhbmQgY2FuIGJvb3RzdHJhcCB0aGUgQW5ndWxhciBmcmFtZXdvcmsuXG5wbGF0Zm9ybU5hdGl2ZVNjcmlwdER5bmFtaWMoKS5ib290c3RyYXBNb2R1bGUoQXBwTW9kdWxlKTtcbiJdfQ==
|
|
@ -10,7 +10,7 @@ from typing import List
|
||||||
import requests_cache
|
import requests_cache
|
||||||
from flask import Flask, jsonify, logging, request
|
from flask import Flask, jsonify, logging, request
|
||||||
|
|
||||||
from .strategies import miloStrats, iss, cars_in_traffic, tide_strat, upstairs_neighbour
|
from .strategies import miloStrats, iss, cars_in_traffic, tide_strat, upstairs_neighbour, bing
|
||||||
from .util import Context
|
from .util import Context
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
@ -29,6 +29,7 @@ strategies = {
|
||||||
"cars_in_traffic": cars_in_traffic.cars_in_traffic,
|
"cars_in_traffic": cars_in_traffic.cars_in_traffic,
|
||||||
"tide": tide_strat.is_tide,
|
"tide": tide_strat.is_tide,
|
||||||
"upstairs_neighbour": upstairs_neighbour.check_games,
|
"upstairs_neighbour": upstairs_neighbour.check_games,
|
||||||
|
"bing": bing.clock,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -77,13 +78,13 @@ def probabilities():
|
||||||
prediction["night"] = not prediction["night"]
|
prediction["night"] = not prediction["night"]
|
||||||
|
|
||||||
# Calculate contributions of predictions
|
# Calculate contributions of predictions
|
||||||
consensus_weight_sum = sum(p["weight"] for p in predictions if p["night"] == night)
|
weight_sum = sum(p["weight"] for p in predictions)
|
||||||
for prediction in predictions:
|
for prediction in predictions:
|
||||||
# If this prediction agrees with the consensus it contributed
|
prediction["contribution"] = prediction["weight"] / weight_sum
|
||||||
if prediction["night"] == night:
|
|
||||||
prediction["contribution"] = prediction["weight"] / consensus_weight_sum
|
# If this prediction disagrees with the consensus it contributed negatively
|
||||||
else:
|
if prediction["night"] != night:
|
||||||
prediction["contribution"] = 0.0
|
prediction["contribution"] *= -1
|
||||||
|
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"predictions": predictions,
|
"predictions": predictions,
|
||||||
|
|
34
server/nightr/strategies/bing.py
Normal file
34
server/nightr/strategies/bing.py
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
import requests
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
from ..util import Context, Prediction
|
||||||
|
|
||||||
|
|
||||||
|
def clock(context: Context) -> Prediction:
|
||||||
|
"""
|
||||||
|
It's nighttime if Bing says it's daytime.
|
||||||
|
"""
|
||||||
|
p = Prediction()
|
||||||
|
p.weight = 0.5
|
||||||
|
|
||||||
|
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'}
|
||||||
|
r = requests.get("https://www.bing.com/search?q=time+in+denmark", headers=headers)
|
||||||
|
soup = BeautifulSoup(r.content, features='html5lib')
|
||||||
|
time_str = soup.find("div", {"id": "digit_time"}).text
|
||||||
|
|
||||||
|
time = datetime.strptime(time_str, "%H:%M")
|
||||||
|
night = time.hour < 6 or time.hour >= 22
|
||||||
|
|
||||||
|
time_description = "" if night else "daytime"
|
||||||
|
time_description_oppersite = "daytime" if night else "nighttime"
|
||||||
|
|
||||||
|
p.reasons.append(f"Bing says its {time_description}.")
|
||||||
|
p.reasons.append(f"We don't really trust it.")
|
||||||
|
p.reasons.append(f"Let's guess its {time_description_oppersite}.")
|
||||||
|
|
||||||
|
p.probability = 1 - p.probability
|
||||||
|
|
||||||
|
return p
|
|
@ -48,7 +48,7 @@ def night_on_iss(context: Context) -> Prediction:
|
||||||
break
|
break
|
||||||
iss_time = datetime.now(pytz.timezone(iss_tz))
|
iss_time = datetime.now(pytz.timezone(iss_tz))
|
||||||
|
|
||||||
iss_night = 6 < iss_time.hour > 22
|
iss_night = iss_time.hour < 6 or iss_time.hour >= 22
|
||||||
|
|
||||||
# iss_night on_iss_time night
|
# iss_night on_iss_time night
|
||||||
# 0 0 1
|
# 0 0 1
|
||||||
|
|
|
@ -11,7 +11,7 @@ def camImgStrat(context : Context) -> Prediction:
|
||||||
The contents of the camera image
|
The contents of the camera image
|
||||||
"""
|
"""
|
||||||
img = context.image
|
img = context.image
|
||||||
average = img.mean(axis=0).mean(axis=0)
|
average = img.mean()
|
||||||
p = Prediction()
|
p = Prediction()
|
||||||
p.weight = 0.7
|
p.weight = 0.7
|
||||||
if average < 100:
|
if average < 100:
|
||||||
|
@ -40,7 +40,11 @@ def australiaStrat(context : Context) -> Prediction:
|
||||||
p.reasons.append('It\'s day-time in Australia')
|
p.reasons.append('It\'s day-time in Australia')
|
||||||
return p
|
return p
|
||||||
|
|
||||||
|
|
||||||
def tv2newsStrat(context : Context) -> Prediction:
|
def tv2newsStrat(context : Context) -> Prediction:
|
||||||
|
"""
|
||||||
|
The number of articles releases in the last few hours on TV2.dk
|
||||||
|
"""
|
||||||
r = requests.get('http://mpx.services.tv2.dk/api/latest')
|
r = requests.get('http://mpx.services.tv2.dk/api/latest')
|
||||||
data = r.json()
|
data = r.json()
|
||||||
publish_dates = [(x['pubDate'])//1000 for x in data][:10]
|
publish_dates = [(x['pubDate'])//1000 for x in data][:10]
|
||||||
|
@ -61,4 +65,3 @@ def tv2newsStrat(context : Context) -> Prediction:
|
||||||
p.probability = 1.0 if avg_timestamp > 50 else 0.0
|
p.probability = 1.0 if avg_timestamp > 50 else 0.0
|
||||||
p.reasons.append('There were ' + ('few' if avg_timestamp > 50 else 'many') + ' recent articles on TV2 News')
|
p.reasons.append('There were ' + ('few' if avg_timestamp > 50 else 'many') + ' recent articles on TV2 News')
|
||||||
return p
|
return p
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ import numpy as np
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Context:
|
class Context:
|
||||||
battery: float = 1.0
|
battery: int = 100
|
||||||
position: Dict[str, float] = field(default_factory=lambda: {'latitude': 53.0, 'longitude': 9.0})
|
position: Dict[str, float] = field(default_factory=lambda: {'latitude': 53.0, 'longitude': 9.0})
|
||||||
image: np.ndarray = None
|
image: np.ndarray = None
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue