This commit is contained in:
Ren Juan 2021-08-28 02:34:15 +00:00
parent 43d1dc5216
commit 6c2cf9c460
7 changed files with 139 additions and 45 deletions

View File

@ -59,11 +59,26 @@ interface expoGeoObj {
} }
public get_glcoords() { public get_glcoords() {
this.glCoords['lat'] = this.mLatitude; this.glCoords['lat'] = this.mLatitude;
this.glCoords['lon'] = this.mLongitude; 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 { public distanceTo(otherPoint:Coordinate) : number {
this.roundTo(Trips.sensitivity)
otherPoint.roundTo(Trips.sensitivity);
return geolib.getPreciseDistance(this.glCoords,otherPoint.glCoords,geoLibAccuracy); return geolib.getPreciseDistance(this.glCoords,otherPoint.glCoords,geoLibAccuracy);
} }
@ -136,6 +151,7 @@ export class GT2 {
displayInterval:number = displayBeat * heartbeat; displayInterval:number = displayBeat * heartbeat;
public distance:number = 0.0; public distance:number = 0.0;
co2Rate:number = 250.0; co2Rate:number = 250.0;
sensitivity:number = 3;
z:number = 0.0; z:number = 0.0;
public v:number = 0.0; public v:number = 0.0;
public inProgress:boolean = false; public inProgress:boolean = false;
@ -152,7 +168,9 @@ export class GT2 {
public deltaLoc(lastFix:any) { 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); lastFix = JSON.stringify(lastFix);
let expoFix:expoGeoObj = JSON.parse(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) this.trip.loc.set(lat,lon);
Trips.startPoint.set(this.trip.loc.mLatitude,this.trip.loc.mLongitude);
if (Trips.startPoint.mLatitude == 0.0) Trips.startPoint.set(lat,lon);
t = expoFix.coords['accuracy']; if (t < minExpoAccuracy ) return; t = expoFix.coords['accuracy']; if (t < minExpoAccuracy ) return;
if (this.trip.lastFix.mLatitude == 0.0) if (this.trip.lastFix.mLatitude == 0.0) this.trip.lastFix.set(lat,lon);
this.trip.lastFix.set(this.trip.loc.mLatitude,this.trip.loc.mLongitude);
else else
{this.trip.ds += this.trip.lastFix.distanceTo(this.trip.loc); {this.trip.ds += this.trip.lastFix.distanceTo(this.trip.loc);
this.trip.lastFix.set(this.trip.loc.mLatitude,this.trip.loc.mLongitude); this.trip.lastFix.set(lat,lon);
if (debug > 10) console.log('delta ' + this.trip.ds); if (debug > 10) console.log('delta ' + this.trip.ds);
} }
@ -188,7 +206,6 @@ export class GT2 {
this.trip.stop(); this.trip.stop();
this.inProgress = false; this.inProgress = false;
if (this.distance < 250) this.distance = 0;
this.trip.CO2 = ( this.distance / 1000 ) * this.co2Rate; this.trip.CO2 = ( this.distance / 1000 ) * this.co2Rate;
this.nTrips++; this.nTrips++;
@ -243,6 +260,7 @@ export class GT2 {
'Destination: ' + 'lat: ' + this.trip.loc.mLatitude.toFixed(8) + 'Destination: ' + 'lat: ' + this.trip.loc.mLatitude.toFixed(8) +
' long: ' + this.trip.loc.mLongitude.toFixed(8) + '\n' + ' long: ' + this.trip.loc.mLongitude.toFixed(8) + '\n' +
'CO2: ' + this.trip.CO2.toFixed(1) + ' grams ' + this.CO2Effect + '\n\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 ); 'Distance covered while consuming fuel: ' + preferredUnits.toFixed(2) + ' ' + this.units );
} }

View File

@ -19,9 +19,10 @@ export default function EndScreenInfo({ path }: { path: string }) {
</Text> </Text>
<TripSummary/> <TripSummary/>
<Text <Text
style = {styles.helpLinkText}
lightColor="rgba(0,0,0,0.8)" lightColor="rgba(0,0,0,0.8)"
darkColor="rgba(255,255,255,0.8)"> darkColor="rgba(255,255,255,0.8)">
Min trip is 250 meters. {'Min trip for carbon accounting\n is 250 meters.'}
</Text> </Text>
</View> </View>

View File

@ -1,19 +1,17 @@
import * as WebBrowser from 'expo-web-browser';
import React from 'react'; import React from 'react';
import { StyleSheet, TouchableOpacity } from 'react-native'; import { StyleSheet, TouchableOpacity } from 'react-native';
import Colors from '../constants/Colors';
import { MonoText } from './StyledText';
import { Text, View } from './Themed'; import { Text, View } from './Themed';
import * as Device from 'expo-device';
import { withSafeAreaInsets } from 'react-native-safe-area-context';
export default function ScreenInfo() { export default function ScreenInfo() {
return ( return (
<View style={styles.settingsContainer}> <View style={styles.settingsContainer}>
<Text <Text
style={styles.settingsText} style={styles.switchText}
lightColor="rgba(0,0,0,0.8)" lightColor="rgba(0,0,0,0.8)"
darkColor="rgba(255,255,255,0.8)"> darkColor="rgba(255,255,255,0.8)">
{'Switch dark: km, light: mi\nset fuel, or CO2 g per km'} {'Switch dark: km, light: mi'}
</Text> </Text>
</View> </View>
); );
@ -30,6 +28,31 @@ export function ScreenInfo2() {
</View> </View>
); );
} }
export function ScreenInfo4() {
return (
<View style={styles.settingsContainer}>
<Text
style={styles.sensitive}
lightColor="rgba(0,0,0,0.8)"
darkColor="rgba(255,255,255,0.8)">
{'higher sensitivity may cause spurious motion at rest'}
</Text>
</View>
);
}
export function ScreenInfo5() {
return (
<View style={styles.settingsContainer}>
<Text
style={styles.sensitive}
lightColor="rgba(0,0,0,0.8)"
darkColor="rgba(255,255,255,0.8)">
{'set CO2 rate or use fuel type buttons below'}
</Text>
</View>
);
}
export function ScreenInfo3() { export function ScreenInfo3() {
return ( return (
@ -38,20 +61,19 @@ export function ScreenInfo3() {
style={styles.titleText} style={styles.titleText}
lightColor="rgba(0,0,0,0.8)" lightColor="rgba(0,0,0,0.8)"
darkColor="rgba(255,255,255,0.8)"> darkColor="rgba(255,255,255,0.8)">
Green Travel Calculator v. 2.0.0 Green Travel Calculator v. 2.0.4
</Text> </Text>
<Text <Text
style={styles.versionText} style={styles.versionText}
lightColor="rgba(0,0,0,0.8)" lightColor="rgba(0,0,0,0.8)"
darkColor="rgba(255,255,255,0.8)"> darkColor="rgba(255,255,255,0.8)">
expo version expo {Device.osName == 'iOS' ? 'iOS ' : 'android '} version
</Text> </Text>
<Text <Text
style={styles.cautionText} style={styles.cautionText}
lightColor="rgba(0,0,0,0.8)" lightColor="rgba(0,0,0,0.8)"
darkColor="rgba(255,255,255,0.8)"> darkColor="rgba(255,255,255,0.8)">
Spurious motion from expo location when at rest, addressed at end of trip and {'\nNote: accuracy depends on sensitivity setting, your device, and carrier.'}
as good or better than 2011 app on 2.1.0.
</Text> </Text>
</View> </View>
); );
@ -67,12 +89,21 @@ const styles = StyleSheet.create({
marginHorizontal: 50, marginHorizontal: 50,
marginVertical: 20, marginVertical: 20,
}, },
sensitive: {
fontWeight: 'bold',
fontSize: 10,
},
titleText: { titleText: {
color: 'white', color: 'white',
fontSize: 17, fontSize: 17,
lineHeight: 24, lineHeight: 24,
textAlign: 'center', textAlign: 'center',
}, },
switchText: {
fontSize: 10,
lineHeight: 24,
textAlign: 'center',
},
settingsText: { settingsText: {
fontSize: 17, fontSize: 17,
lineHeight: 24, lineHeight: 24,

View File

@ -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": { "expo-error-recovery": {
"version": "2.2.0", "version": "2.2.0",
"resolved": "https://registry.npmjs.org/expo-error-recovery/-/expo-error-recovery-2.2.0.tgz", "resolved": "https://registry.npmjs.org/expo-error-recovery/-/expo-error-recovery-2.2.0.tgz",

View File

@ -20,6 +20,7 @@
"expo": "~42.0.1", "expo": "~42.0.1",
"expo-asset": "~8.3.2", "expo-asset": "~8.3.2",
"expo-constants": "~11.0.1", "expo-constants": "~11.0.1",
"expo-device": "^3.3.0",
"expo-font": "~9.2.1", "expo-font": "~9.2.1",
"expo-linking": "~2.3.1", "expo-linking": "~2.3.1",
"expo-location": "~12.1.2", "expo-location": "~12.1.2",

View File

@ -2,30 +2,48 @@ import * as React from 'react';
import { Alert, Button, StyleSheet, Switch, TextInput } from 'react-native'; import { Alert, Button, StyleSheet, Switch, TextInput } from 'react-native';
import { Text, View } from '../components/Themed'; import { Text, View } from '../components/Themed';
import { useState } from 'react'; import { useState } from 'react';
import ScreenInfo from '../components/ScreenInfo'; import ScreenInfo, { ScreenInfo4, ScreenInfo5 } from '../components/ScreenInfo';
import { Trips } from '../GT2'; import { Trips } from '../GT2';
import { RootTabScreenProps } from '../types'; import { RootTabScreenProps } from '../types';
export default function SettingsScreen( { navigation }: RootTabScreenProps<'Settings'>) { 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 [isKM, setMiles] = useState(false);
const toggleUnits = () => { setMiles(previousState => !previousState) const toggleUnits = () => { setMiles(previousState => !previousState)
Trips.units = isKM ? "km" : "mi"; Trips.units = isKM ? "km" : "mi";
}; };
return ( return (
<View style={styles.container}> <View style={styles.container}>
<Text style={styles.title}>Model Settings</Text> <Text style={styles.title}>Model Settings</Text>
<View style={styles.separator} lightColor="#eee" darkColor="rgba(255,255,255,0.1)" /> <View style={styles.separator} lightColor="#eee" darkColor="rgba(255,255,255,0.1)" />
<ScreenInfo /> <Text style={styles.caption}>{'\nset custom CO2 rate or use buttons below'}</Text>
<Switch <View style={styles.inputs}>
style={styles.switch} <TextInput
trackColor={{ false: "#767577", true: "#81b0ff" }} style={styles.input}
thumbColor={true ? "#f5dd4b" : "#f4f3f4"} returnKeyType={'done'}
ios_backgroundColor="#3e3e3e" onChangeText={rate => { setRate(rate); Trips.co2Rate = Number(rate);} }
onValueChange={toggleUnits} value={rate}
value={isKM} placeholder={Trips.co2Rate.toString()}
keyboardType="numeric"
/> />
</View>
<Text style={styles.caption}>{'\nsensitivity'}</Text>
<View style={styles.inputs}>
<TextInput
style={styles.input}
returnKeyType={'done'}
onChangeText={sens => { 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"
/>
</View>
<ScreenInfo4/>
<View style={styles.controls} > <View style={styles.controls} >
<Button <Button
title="Jet" title="Jet"
@ -52,13 +70,14 @@ export default function SettingsScreen( { navigation }: RootTabScreenProps<'Sett
} }
/> />
</View> </View>
<TextInput <ScreenInfo />
style={styles.input} <Switch
returnKeyType={'done'} style={styles.switch}
onChangeText={onChangeNumber} trackColor={{ false: "#767577", true: "#81b0ff" }}
value={number} thumbColor={true ? "#f5dd4b" : "#f4f3f4"}
placeholder={Trips.co2Rate.toString()} ios_backgroundColor="#3e3e3e"
keyboardType="numeric" onValueChange={toggleUnits}
value={isKM}
/> />
</View> </View>
); );
@ -66,6 +85,10 @@ export default function SettingsScreen( { navigation }: RootTabScreenProps<'Sett
const styles = StyleSheet.create({ const styles = StyleSheet.create({
caption: {
fontSize: 10,
justifyContent: 'center',
},
switch: { switch: {
marginVertical: 20, marginVertical: 20,
}, },
@ -75,17 +98,23 @@ const styles = StyleSheet.create({
justifyContent: 'center', justifyContent: 'center',
}, },
controls: { controls: {
marginVertical: 20, marginVertical: 5,
width: "80%", width: "80%",
flexDirection: 'row', flexDirection: 'row',
justifyContent: "space-between", justifyContent: "space-between",
}, },
inputs: {
marginVertical: 5,
width: "80%",
flexDirection: 'row',
justifyContent: "center",
},
title: { title: {
fontSize: 20, fontSize: 20,
fontWeight: 'bold', fontWeight: 'bold',
}, },
separator: { separator: {
marginVertical: 10, marginVertical: 2,
height: 1, height: 1,
width: '80%', width: '80%',
}, },
@ -95,4 +124,10 @@ const styles = StyleSheet.create({
borderWidth: 1, borderWidth: 1,
padding: 10, padding: 10,
}, },
input2: {
height: 40,
margin: 30,
borderWidth: 1,
padding: 10,
},
}); });

View File

@ -71,7 +71,7 @@ export default function TripScreen( { navigation }: RootTabScreenProps<'Trip'>)
title={sButtonText} title={sButtonText}
onPress={() => { onPress={() => {
if (!getAdvised()) { if (!getAdvised()) {
Alert.alert("2.0.0 foreground only, 2.1 first production."); Alert.alert("2.0.n runs in foreground only.");
setAdvised(); setAdvised();
} }
if (!Trips.inProgress) {startTrip(); if (!Trips.inProgress) {startTrip();