This commit is contained in:
Alexander Munch-Hansen 2019-04-06 18:48:51 +02:00
commit 7147e1734b
11 changed files with 126 additions and 7 deletions

View file

@ -0,0 +1,5 @@
.float-btn-container
{
margin-top: 35%;
margin-left: 20%;
}

View file

@ -1,3 +1,11 @@
<StackLayout>
<ns-locationButton></ns-locationButton>
<AbsoluteLayout>
<ns-side-drawer></ns-side-drawer>
<StackLayout class="float-btn-container">
<ns-my-button (tap)=onTap($event) text="Nightr"></ns-my-button>
</StackLayout>
<ns-locationButton></ns-locationButton>
</AbsoluteLayout>

View file

@ -1,9 +1,41 @@
import { Component } from "@angular/core";
import * as dialogs from "tns-core-modules/ui/dialogs";
import { MyHttpPostService } from './services/my-http-post-service'
import { TouchGestureEventData, GestureEventData } from 'tns-core-modules/ui/gestures'
import { isEnabled, enableLocationRequest, getCurrentLocation, watchLocation, distance, clearWatch } from "nativescript-geolocation";
@Component({
selector: "ns-app",
moduleId: module.id,
templateUrl: "./app.component.html"
templateUrl: "./app.component.html",
styleUrls: ['./app.component.css'],
providers: [MyHttpPostService]
})
export class AppComponent { }
export class AppComponent {
public user: string = "";
public pass: string = "";
returnMessage: string = "";
constructor(private myHttpPostSerivce: MyHttpPostService) { }
public onTap(args: GestureEventData): any {
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;
});
}
}

View file

@ -2,6 +2,8 @@ import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core";
import { NativeScriptModule } from "nativescript-angular/nativescript.module";
import { AppComponent } from "./app.component";
import { MyButtonComponent } from './component/my-button/my-button.component';
import { NativeScriptHttpClientModule } from "nativescript-angular/http-client";
import { MyLocationButtonComponent } from './component/locationButton/locationButton.component';
// Uncomment and add to NgModule imports if you need to use two-way binding
@ -16,10 +18,12 @@ import { MyLocationButtonComponent } from './component/locationButton/locationBu
],
imports: [
NativeScriptModule,
NativeScriptHttpClientModule,
],
declarations: [
AppComponent,
MyLocationButtonComponent,
MyButtonComponent,
],
providers: [],
schemas: [

View file

@ -0,0 +1,8 @@
.myButtonComponent {
background-color: #30bcff;
border-radius: 100;
width: 200;
height: 200;
text-align: center;
vertical-align: middle;
}

View file

@ -0,0 +1,3 @@
<StackLayout>
<Button [text]="text" class="btn btn-primary myButtonComponent" (tap)="onTap($event)"></Button>
</StackLayout>

View file

@ -0,0 +1,23 @@
import { Component, Input, OnInit, Output, EventEmitter } from '@angular/core';
import { TouchGestureEventData, GestureEventData } from 'tns-core-modules/ui/gestures'
@Component({
selector: 'ns-my-button',
templateUrl: './my-button.component.html',
styleUrls: ['./my-button.component.css'],
moduleId: module.id,
})
export class MyButtonComponent implements OnInit {
@Output() tap: EventEmitter<GestureEventData> = new EventEmitter<GestureEventData>();
@Input() text: string;
constructor() { }
ngOnInit() {
}
public onTap(args: GestureEventData): any {
this.tap.emit(args);
}
}

View file

@ -0,0 +1,9 @@
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class MyHttpGetService {
constructor() { }
}

View file

@ -0,0 +1,24 @@
import { Injectable } from "@angular/core";
import { HttpClient, HttpHeaders } from "@angular/common/http";
@Injectable({
providedIn: 'root'
})
export class MyHttpPostService {
private serverUrl = "https://nightr.caspervk.net";
constructor(private http: HttpClient) { }
postData(data: any) {
console.log('logged data is', data);
let options = this.createRequestOptions();
return this.http.post(this.serverUrl, { data }, { headers: options });
}
private createRequestOptions() {
let headers = new HttpHeaders({
"Content-Type": "application/json"
});
return headers;
}
}

View file

@ -11,4 +11,4 @@ var app_module_1 = require("./app/app.module");
// so we provide a wrapper platform object, platformNativeScriptDynamic,
// that sets up a NativeScript application and can bootstrap the Angular framework.
platform_1.platformNativeScriptDynamic().bootstrapModule(app_module_1.AppModule);
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9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mF0aXZlc2NyaXB0LWFuZ3VsYXIvcGxhdGZvcm1cIjtcclxuXHJcbmltcG9ydCB7IEFwcE1vZHVsZSB9IGZyb20gXCIuL2FwcC9hcHAubW9kdWxlXCI7XHJcblxyXG4vLyBBIHRyYWRpdGlvbmFsIE5hdGl2ZVNjcmlwdCBhcHBsaWNhdGlvbiBzdGFydHMgYnkgaW5pdGlhbGl6aW5nIGdsb2JhbCBvYmplY3RzLFxyXG4vLyBzZXR0aW5nIHVwIGdsb2JhbCBDU1MgcnVsZXMsIGNyZWF0aW5nLCBhbmQgbmF2aWdhdGluZyB0byB0aGUgbWFpbiBwYWdlLlxyXG4vLyBBbmd1bGFyIGFwcGxpY2F0aW9ucyBuZWVkIHRvIHRha2UgY2FyZSBvZiB0aGVpciBvd24gaW5pdGlhbGl6YXRpb246XHJcbi8vIG1vZHVsZXMsIGNvbXBvbmVudHMsIGRpcmVjdGl2ZXMsIHJvdXRlcywgREkgcHJvdmlkZXJzLlxyXG4vLyBBIE5hdGl2ZVNjcmlwdCBBbmd1bGFyIGFwcCBuZWVkcyB0byBtYWtlIGJvdGggcGFyYWRpZ21zIHdvcmsgdG9nZXRoZXIsXHJcbi8vIHNvIHdlIHByb3ZpZGUgYSB3cmFwcGVyIHBsYXRmb3JtIG9iamVjdCwgcGxhdGZvcm1OYXRpdmVTY3JpcHREeW5hbWljLFxyXG4vLyB0aGF0IHNldHMgdXAgYSBOYXRpdmVTY3JpcHQgYXBwbGljYXRpb24gYW5kIGNhbiBib290c3RyYXAgdGhlIEFuZ3VsYXIgZnJhbWV3b3JrLlxyXG5wbGF0Zm9ybU5hdGl2ZVNjcmlwdER5bmFtaWMoKS5ib290c3RyYXBNb2R1bGUoQXBwTW9kdWxlKTtcclxuIl19

View file

@ -1,4 +1,5 @@
import inspect
import json
import statistics
import timeit
from dataclasses import asdict
@ -7,7 +8,7 @@ from logging import DEBUG
from typing import List
import requests_cache
from flask import Flask, jsonify, logging
from flask import Flask, jsonify, logging, request
from .strategies import miloStrats, iss, cars_in_traffic, tide_strat, upstairs_neighbour
from .util import Context
@ -33,8 +34,10 @@ strategies = {
@app.route("/", methods=["GET", "POST"])
def probabilities():
phone_data = {} # TODO: get from POST request
phone_data = request.get_json(force=True)
context = Context(**phone_data)
logger.debug("phone_data:\n%s", json.dumps(phone_data, indent=2))
logger.debug("Context: %s", context)
predictions: List[dict] = []
for name, strategy in strategies.items():