From 6c2cf9c4608e3717630246ff389aba83501299b8 Mon Sep 17 00:00:00 2001 From: Ren Juan Date: Sat, 28 Aug 2021 02:34:15 +0000 Subject: [PATCH] 2.0.4 --- Ejectable/GT2.tsx | 40 +++++++++---- Ejectable/components/EndScreenInfo.tsx | 3 +- Ejectable/components/ScreenInfo.tsx | 51 +++++++++++++---- Ejectable/package-lock.json | 8 +++ Ejectable/package.json | 1 + Ejectable/screens/SettingsScreen.tsx | 79 +++++++++++++++++++------- Ejectable/screens/TripScreen.tsx | 2 +- 7 files changed, 139 insertions(+), 45 deletions(-) diff --git a/Ejectable/GT2.tsx b/Ejectable/GT2.tsx index e6ecb66b..346bc465 100644 --- a/Ejectable/GT2.tsx +++ b/Ejectable/GT2.tsx @@ -59,11 +59,26 @@ interface expoGeoObj { } public get_glcoords() { - this.glCoords['lat'] = this.mLatitude; - this.glCoords['lon'] = this.mLongitude; + this.glCoords['lat'] = this.mLatitude; + this.glCoords['lon'] = this.mLongitude; } + public set_glcoords(lat:number,lon:number) { + this.glCoords['lat'] = lat; + this.glCoords['lon'] = lon; + } + + public roundTo(precision:number) { + var lat = this.mLatitude * Math.pow(10,precision); + var lon = this.mLongitude * Math.pow(10,precision); + lat = (Math.round(lat)) / Math.pow(10,precision); + lon = (Math.round(lon)) / Math.pow(10, precision); + this.set_glcoords(lat,lon); + } + public distanceTo(otherPoint:Coordinate) : number { + this.roundTo(Trips.sensitivity) + otherPoint.roundTo(Trips.sensitivity); return geolib.getPreciseDistance(this.glCoords,otherPoint.glCoords,geoLibAccuracy); } @@ -136,6 +151,7 @@ export class GT2 { displayInterval:number = displayBeat * heartbeat; public distance:number = 0.0; co2Rate:number = 250.0; + sensitivity:number = 3; z:number = 0.0; public v:number = 0.0; public inProgress:boolean = false; @@ -152,7 +168,9 @@ export class GT2 { public deltaLoc(lastFix:any) { - var t:number = 0.0; + var t:number = 0.0; + var lat:number = 0.0; + var lon:number = 0.0; lastFix = JSON.stringify(lastFix); let expoFix:expoGeoObj = JSON.parse(lastFix); @@ -165,18 +183,18 @@ export class GT2 { } - this.trip.loc.set(expoFix.coords['latitude'],expoFix.coords['longitude']); + lat = expoFix.coords['latitude']; lon = expoFix.coords['longitude']; - if (Trips.startPoint.mLatitude == 0.0) - Trips.startPoint.set(this.trip.loc.mLatitude,this.trip.loc.mLongitude); + this.trip.loc.set(lat,lon); + + if (Trips.startPoint.mLatitude == 0.0) Trips.startPoint.set(lat,lon); t = expoFix.coords['accuracy']; if (t < minExpoAccuracy ) return; - if (this.trip.lastFix.mLatitude == 0.0) - this.trip.lastFix.set(this.trip.loc.mLatitude,this.trip.loc.mLongitude); + if (this.trip.lastFix.mLatitude == 0.0) this.trip.lastFix.set(lat,lon); else - {this.trip.ds += this.trip.lastFix.distanceTo(this.trip.loc); - this.trip.lastFix.set(this.trip.loc.mLatitude,this.trip.loc.mLongitude); + {this.trip.ds += this.trip.lastFix.distanceTo(this.trip.loc); + this.trip.lastFix.set(lat,lon); if (debug > 10) console.log('delta ' + this.trip.ds); } @@ -188,7 +206,6 @@ export class GT2 { this.trip.stop(); this.inProgress = false; - if (this.distance < 250) this.distance = 0; this.trip.CO2 = ( this.distance / 1000 ) * this.co2Rate; this.nTrips++; @@ -243,6 +260,7 @@ export class GT2 { 'Destination: ' + 'lat: ' + this.trip.loc.mLatitude.toFixed(8) + ' long: ' + this.trip.loc.mLongitude.toFixed(8) + '\n' + 'CO2: ' + this.trip.CO2.toFixed(1) + ' grams ' + this.CO2Effect + '\n\n' + + 'CO2 Rate / Sensitivity: ' + this.co2Rate + " / " + this.sensitivity + '\n' + 'Distance covered while consuming fuel: ' + preferredUnits.toFixed(2) + ' ' + this.units ); } diff --git a/Ejectable/components/EndScreenInfo.tsx b/Ejectable/components/EndScreenInfo.tsx index 336a9a78..12f10c6b 100644 --- a/Ejectable/components/EndScreenInfo.tsx +++ b/Ejectable/components/EndScreenInfo.tsx @@ -19,9 +19,10 @@ export default function EndScreenInfo({ path }: { path: string }) { - Min trip is 250 meters. + {'Min trip for carbon accounting\n is 250 meters.'} diff --git a/Ejectable/components/ScreenInfo.tsx b/Ejectable/components/ScreenInfo.tsx index 585ea170..6dde4932 100644 --- a/Ejectable/components/ScreenInfo.tsx +++ b/Ejectable/components/ScreenInfo.tsx @@ -1,19 +1,17 @@ -import * as WebBrowser from 'expo-web-browser'; import React from 'react'; import { StyleSheet, TouchableOpacity } from 'react-native'; - -import Colors from '../constants/Colors'; -import { MonoText } from './StyledText'; import { Text, View } from './Themed'; +import * as Device from 'expo-device'; +import { withSafeAreaInsets } from 'react-native-safe-area-context'; export default function ScreenInfo() { return ( - {'Switch dark: km, light: mi\nset fuel, or CO2 g per km'} + {'Switch dark: km, light: mi'} ); @@ -30,6 +28,31 @@ export function ScreenInfo2() { ); } +export function ScreenInfo4() { + return ( + + + {'higher sensitivity may cause spurious motion at rest'} + + + ); +} + +export function ScreenInfo5() { + return ( + + + {'set CO2 rate or use fuel type buttons below'} + + + ); +} export function ScreenInfo3() { return ( @@ -38,20 +61,19 @@ export function ScreenInfo3() { style={styles.titleText} lightColor="rgba(0,0,0,0.8)" darkColor="rgba(255,255,255,0.8)"> - Green Travel Calculator v. 2.0.0 + Green Travel Calculator v. 2.0.4 - expo version + expo {Device.osName == 'iOS' ? 'iOS ' : 'android '} version - Spurious motion from expo location when at rest, addressed at end of trip and - as good or better than 2011 app on 2.1.0. + {'\nNote: accuracy depends on sensitivity setting, your device, and carrier.'} ); @@ -67,12 +89,21 @@ const styles = StyleSheet.create({ marginHorizontal: 50, marginVertical: 20, }, + sensitive: { + fontWeight: 'bold', + fontSize: 10, + }, titleText: { color: 'white', fontSize: 17, lineHeight: 24, textAlign: 'center', }, + switchText: { + fontSize: 10, + lineHeight: 24, + textAlign: 'center', + }, settingsText: { fontSize: 17, lineHeight: 24, diff --git a/Ejectable/package-lock.json b/Ejectable/package-lock.json index 3d33b1b3..1dff51b5 100644 --- a/Ejectable/package-lock.json +++ b/Ejectable/package-lock.json @@ -6039,6 +6039,14 @@ } } }, + "expo-device": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/expo-device/-/expo-device-3.3.0.tgz", + "integrity": "sha512-kZ6HZpxGp3T3GrgbpW4VSFvH6SQZVD/dwPN+I3tlRPezaZ3LUj64kSZDKLgOi1H/9VCuUQdxjItoVZZuIWTX1A==", + "requires": { + "ua-parser-js": "^0.7.19" + } + }, "expo-error-recovery": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/expo-error-recovery/-/expo-error-recovery-2.2.0.tgz", diff --git a/Ejectable/package.json b/Ejectable/package.json index 1d2a396f..b5d6d327 100644 --- a/Ejectable/package.json +++ b/Ejectable/package.json @@ -20,6 +20,7 @@ "expo": "~42.0.1", "expo-asset": "~8.3.2", "expo-constants": "~11.0.1", + "expo-device": "^3.3.0", "expo-font": "~9.2.1", "expo-linking": "~2.3.1", "expo-location": "~12.1.2", diff --git a/Ejectable/screens/SettingsScreen.tsx b/Ejectable/screens/SettingsScreen.tsx index f283e468..0592c3ad 100644 --- a/Ejectable/screens/SettingsScreen.tsx +++ b/Ejectable/screens/SettingsScreen.tsx @@ -2,30 +2,48 @@ import * as React from 'react'; import { Alert, Button, StyleSheet, Switch, TextInput } from 'react-native'; import { Text, View } from '../components/Themed'; import { useState } from 'react'; -import ScreenInfo from '../components/ScreenInfo'; +import ScreenInfo, { ScreenInfo4, ScreenInfo5 } from '../components/ScreenInfo'; import { Trips } from '../GT2'; import { RootTabScreenProps } from '../types'; + export default function SettingsScreen( { navigation }: RootTabScreenProps<'Settings'>) { - const [number, onChangeNumber] = React.useState(""); + const [rate, setRate] = useState("255"); + const [sens, setSens] = useState("3"); const [isKM, setMiles] = useState(false); const toggleUnits = () => { setMiles(previousState => !previousState) Trips.units = isKM ? "km" : "mi"; }; - return ( Model Settings - - + {'\nset custom CO2 rate or use buttons below'} + + { setRate(rate); Trips.co2Rate = Number(rate);} } + value={rate} + placeholder={Trips.co2Rate.toString()} + keyboardType="numeric" + /> + + {'\nsensitivity'} + + { setSens(sens); + var s = Number(sens); + if (s < 3 || s > 7) Alert.alert("Sensitivity must be greater than 2 and less than 8"); + else Trips.sensitivity = Number(sens); }} + value={sens} + placeholder={Trips.sensitivity.toString()} + keyboardType="numeric" + /> + +