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() {
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 );
}

View File

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

View File

@ -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 (
<View style={styles.settingsContainer}>
<Text
style={styles.settingsText}
style={styles.switchText}
lightColor="rgba(0,0,0,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>
</View>
);
@ -30,6 +28,31 @@ export function ScreenInfo2() {
</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() {
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
</Text>
<Text
style={styles.versionText}
lightColor="rgba(0,0,0,0.8)"
darkColor="rgba(255,255,255,0.8)">
expo version
expo {Device.osName == 'iOS' ? 'iOS ' : 'android '} version
</Text>
<Text
style={styles.cautionText}
lightColor="rgba(0,0,0,0.8)"
darkColor="rgba(255,255,255,0.8)">
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.'}
</Text>
</View>
);
@ -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,

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": {
"version": "2.2.0",
"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-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",

View File

@ -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 (
<View style={styles.container}>
<Text style={styles.title}>Model Settings</Text>
<View style={styles.separator} lightColor="#eee" darkColor="rgba(255,255,255,0.1)" />
<ScreenInfo />
<Switch
style={styles.switch}
trackColor={{ false: "#767577", true: "#81b0ff" }}
thumbColor={true ? "#f5dd4b" : "#f4f3f4"}
ios_backgroundColor="#3e3e3e"
onValueChange={toggleUnits}
value={isKM}
/>
<Text style={styles.caption}>{'\nset custom CO2 rate or use buttons below'}</Text>
<View style={styles.inputs}>
<TextInput
style={styles.input}
returnKeyType={'done'}
onChangeText={rate => { setRate(rate); Trips.co2Rate = Number(rate);} }
value={rate}
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} >
<Button
title="Jet"
@ -52,20 +70,25 @@ export default function SettingsScreen( { navigation }: RootTabScreenProps<'Sett
}
/>
</View>
<TextInput
style={styles.input}
returnKeyType={'done'}
onChangeText={onChangeNumber}
value={number}
placeholder={Trips.co2Rate.toString()}
keyboardType="numeric"
/>
<ScreenInfo />
<Switch
style={styles.switch}
trackColor={{ false: "#767577", true: "#81b0ff" }}
thumbColor={true ? "#f5dd4b" : "#f4f3f4"}
ios_backgroundColor="#3e3e3e"
onValueChange={toggleUnits}
value={isKM}
/>
</View>
);
}
const styles = StyleSheet.create({
caption: {
fontSize: 10,
justifyContent: 'center',
},
switch: {
marginVertical: 20,
},
@ -75,17 +98,23 @@ const styles = StyleSheet.create({
justifyContent: 'center',
},
controls: {
marginVertical: 20,
marginVertical: 5,
width: "80%",
flexDirection: 'row',
justifyContent: "space-between",
},
inputs: {
marginVertical: 5,
width: "80%",
flexDirection: 'row',
justifyContent: "center",
},
title: {
fontSize: 20,
fontWeight: 'bold',
},
separator: {
marginVertical: 10,
marginVertical: 2,
height: 1,
width: '80%',
},
@ -95,4 +124,10 @@ const styles = StyleSheet.create({
borderWidth: 1,
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}
onPress={() => {
if (!getAdvised()) {
Alert.alert("2.0.0 foreground only, 2.1 first production.");
Alert.alert("2.0.n runs in foreground only.");
setAdvised();
}
if (!Trips.inProgress) {startTrip();