Skip to content

Commit

Permalink
Extract some reused variables to consts (#393)
Browse files Browse the repository at this point in the history
Co-authored-by: Dzianis Papakul <denis.papakul@designit.com>
Co-authored-by: Tim Stirrat <tim.stirrat@gmail.com>
  • Loading branch information
3 people authored Apr 10, 2020
1 parent ff7fd7a commit 03c3275
Show file tree
Hide file tree
Showing 18 changed files with 63 additions and 48 deletions.
3 changes: 2 additions & 1 deletion app/Entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import AboutScreen from './views/About';
import ChooseProviderScreen from './views/ChooseProvider';

import { GetStoreData, SetStoreData } from './helpers/General';
import { PARTICIPATE } from './constants/storage';

const Stack = createStackNavigator();

Expand All @@ -36,7 +37,7 @@ class Entry extends Component {
}

componentDidMount() {
GetStoreData('PARTICIPATE')
GetStoreData(PARTICIPATE)
.then(isParticipating => {
console.log(isParticipating);
this.setState({
Expand Down
5 changes: 5 additions & 0 deletions app/constants/authorities.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const PUBLIC_DATA_URL =
'https://raw.githubusercontent.com/beoutbreakprepared/nCoV2019/master/latest_data/latestdata.csv';

export const AUTHORITIES_LIST_URL =
'https://raw.githubusercontent.com/tripleblindmarket/safe-places/develop/healthcare-authorities.yaml';
6 changes: 6 additions & 0 deletions app/constants/storage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const LOCATION_DATA = 'LOCATION_DATA';
export const CONTACT_DATA = 'CONTACT_DATA';
export const PARTICIPATE = 'PARTICIPATE';
export const MY_UUIDs = 'MY_UUIDs';
export const CROSSED_PATHS = 'CROSSED_PATHS';
export const LANG_OVERRIDE = 'LANG_OVERRIDE';
5 changes: 3 additions & 2 deletions app/helpers/GoogleData.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Import a Google JSon into the Database.
*/
import { GetStoreData, SetStoreData } from '../helpers/General';
import { LOCATION_DATA } from '../constants/storage';

function BuildLocalFormat(placeVisit) {
return (loc = {
Expand Down Expand Up @@ -52,7 +53,7 @@ function Merge(localDataJSON, googleDataJSON) {
}

export async function MergeJSONWithLocalData(googleDataJSON) {
GetStoreData('LOCATION_DATA').then(locationArray => {
GetStoreData(LOCATION_DATA).then(locationArray => {
let locationData;

if (locationArray !== null) {
Expand All @@ -64,6 +65,6 @@ export async function MergeJSONWithLocalData(googleDataJSON) {
Merge(locationData, googleDataJSON);

console.log('Saving on array');
SetStoreData('LOCATION_DATA', locationData);
SetStoreData(LOCATION_DATA, locationData);
});
}
5 changes: 3 additions & 2 deletions app/helpers/Intersect.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
*/

import { GetStoreData, SetStoreData } from '../helpers/General';
import { LOCATION_DATA, CROSSED_PATHS } from '../constants/storage';

export async function IntersectSet(concernLocationArray, completion) {
GetStoreData('LOCATION_DATA').then(locationArrayString => {
GetStoreData(LOCATION_DATA).then(locationArrayString => {
var locationArray;
if (locationArrayString !== null) {
locationArray = JSON.parse(locationArrayString);
Expand Down Expand Up @@ -95,7 +96,7 @@ export async function IntersectSet(concernLocationArray, completion) {

// TODO: Show in the UI!
console.log('Crossing results: ', dayBin);
SetStoreData('CROSSED_PATHS', dayBin); // TODO: Store per authority?
SetStoreData(CROSSED_PATHS, dayBin); // TODO: Store per authority?
completion(dayBin);
});
}
Expand Down
5 changes: 5 additions & 0 deletions app/helpers/authorities.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const PUBLIC_DATA_URL =
'https://raw.githubusercontent.com/beoutbreakprepared/nCoV2019/master/latest_data/latestdata.csv';

export const AUTHORITIES_LIST_URL =
'https://raw.githubusercontent.com/tripleblindmarket/safe-places/develop/healthcare-authorities.yaml';
3 changes: 2 additions & 1 deletion app/locales/languages.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import i18next from 'i18next';
import { getLanguages } from 'react-native-i18n';
import { GetStoreData } from '../helpers/General';
import { LANG_OVERRIDE } from '../constants/storage';

// Refer this for checking the codes and creating new folders https://developer.chrome.com/webstore/i18n

Expand All @@ -25,7 +26,7 @@ export function findUserLang(callback) {
userLang = languages[0].split('-')[0]; // ['en-US' will become 'en']

// If the user specified a language override, use it instead
GetStoreData('LANG_OVERRIDE').then(res => {
GetStoreData(LANG_OVERRIDE).then(res => {
if (typeof res === 'string') {
console.log('Found user language override:');
console.log(res);
Expand Down
11 changes: 6 additions & 5 deletions app/services/BroadcastingService.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import UUIDGenerator from 'react-native-uuid-generator';
import AndroidBLEAdvertiserModule from 'react-native-ble-advertiser';
import { NativeEventEmitter, NativeModules } from 'react-native';
import { isPlatformAndroid, nowStr } from '../Util';
import { CONTACT_DATA, MY_UUIDs } from '../constants/storage';

var currentUUID = null;
var onDeviceFound = null;
Expand Down Expand Up @@ -52,7 +53,7 @@ function saveContact(contact) {
// Persist this contact data in our local storage of time/uuid values
//console.log('[Bluetooth]', nowStr(), currentUUID, 'New Device Found', contact['uuid']);
if (isNewContact(contact)) {
GetStoreData('CONTACT_DATA', false).then(contactArray => {
GetStoreData(CONTACT_DATA, false).then(contactArray => {
if (!contactArray) {
contactArray = [];
}
Expand All @@ -78,15 +79,15 @@ function saveContact(contact) {
curated.length,
);

SetStoreData('CONTACT_DATA', curated);
SetStoreData(CONTACT_DATA, curated);
});
}
}

function saveMyUUID(me) {
// Persist this contact data in our local storage of time/lat/lon values

GetStoreData('MY_UUIDs', false).then(myUUIDArray => {
GetStoreData(MY_UUIDs, false).then(myUUIDArray => {
if (!myUUIDArray) {
myUUIDArray = [];
}
Expand All @@ -113,12 +114,12 @@ function saveMyUUID(me) {
);
curated.push(uuid_time);

SetStoreData('MY_UUIDs', curated);
SetStoreData(MY_UUIDs, curated);
});
}

function loadLastUUIDAndBroadcast() {
GetStoreData('MY_UUIDs', false).then(myUUIDArray => {
GetStoreData(MY_UUIDs, false).then(myUUIDArray => {
if (!myUUIDArray) {
console.log(
'[Bluetooth]',
Expand Down
24 changes: 12 additions & 12 deletions app/services/LocationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import PushNotificationIOS from '@react-native-community/push-notification-ios';
import PushNotification from 'react-native-push-notification';
import { isPlatformAndroid } from '../Util';
import languages from '../locales/languages';
import { LOCATION_DATA, PARTICIPATE } from '../constants/storage';

let isBackgroundGeolocationConfigured = false;

Expand All @@ -17,12 +18,11 @@ export class LocationData {
this.minLocationSaveInterval = Math.floor(this.locationInterval * 0.8); // Minimum time between location information saves. 60000*4 = 4 minutes

// Maximum time that we will backfill for missing data
this.maxBackfillTime = 60000 * 60 * 8 // Time (in milliseconds). 60000 * 60 * 8 = 8 hours

this.maxBackfillTime = 60000 * 60 * 8; // Time (in milliseconds). 60000 * 60 * 8 = 8 hours
}

getLocationData() {
return GetStoreData('LOCATION_DATA').then(locationArrayString => {
return GetStoreData(LOCATION_DATA).then(locationArrayString => {
let locationArray = [];
if (locationArrayString !== null) {
locationArray = JSON.parse(locationArrayString);
Expand Down Expand Up @@ -55,7 +55,6 @@ export class LocationData {
saveLocation(location) {
// Persist this location data in our local storage of time/lat/lon values
this.getLocationData().then(locationArray => {

// Always work in UTC, not the local time in the locationData
let unixtimeUTC = Math.floor(location['time']);
let unixtimeUTC_28daysAgo = unixtimeUTC - 60 * 60 * 24 * 1000 * 28;
Expand All @@ -81,7 +80,7 @@ export class LocationData {

// Backfill the stationary points, if available
// The assumption is that if we see a gap in the data, the
// best guess is that the person was in that location for
// best guess is that the person was in that location for
// the entire time. This makes it easier for a health authority
// person to have a set of locations over time, and they can manually
// redact the time frames that aren't correct.
Expand All @@ -93,7 +92,7 @@ export class LocationData {
// To protect ourselves, we won't backfill more than the
// maxBackfillTime
let lastRecordedTime = lastLocationArray['time'];
if ((unixtimeUTC - lastRecordedTime) > this.maxBackfillTime) {
if (unixtimeUTC - lastRecordedTime > this.maxBackfillTime) {
lastRecordedTime = unixtimeUTC - this.maxBackfillTime;
}

Expand All @@ -105,9 +104,9 @@ export class LocationData {
let lat_lon_time = {
latitude: lastLocationArray['latitude'],
longitude: lastLocationArray['longitude'],
time: newTS
time: newTS,
};
console.log('[INFO] backfill location:',lat_lon_time);
console.log('[INFO] backfill location:', lat_lon_time);
curated.push(lat_lon_time);
}
}
Expand All @@ -117,12 +116,12 @@ export class LocationData {
let lat_lon_time = {
latitude: location['latitude'],
longitude: location['longitude'],
time: unixtimeUTC
time: unixtimeUTC,
};
curated.push(lat_lon_time);
console.log('[INFO] saved location:',lat_lon_time);
console.log('[INFO] saved location:', lat_lon_time);

SetStoreData('LOCATION_DATA', curated);
SetStoreData(LOCATION_DATA, curated);
});
}
}
Expand Down Expand Up @@ -353,8 +352,9 @@ export default class LocationServices {
});
BackgroundGeolocation.removeAllListeners();
BackgroundGeolocation.stop();

isBackgroundGeolocationConfigured = false;
SetStoreData('PARTICIPATE', 'false').then(() => {
SetStoreData(PARTICIPATE, 'false').then(() => {
// nav.navigate('LocationTrackingScreen', {});
});
}
Expand Down
6 changes: 2 additions & 4 deletions app/views/ChooseProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ import closeIcon from './../assets/images/closeIcon.png';
import saveIcon from './../assets/images/saveIcon.png';
import languages from '../locales/languages';
import NavigationBarWrapper from '../components/NavigationBarWrapper';

const authoritiesListURL =
'https://raw.githubusercontent.com/tripleblindmarket/safe-places/develop/healthcare-authorities.yaml';
import { AUTHORITIES_LIST_URL } from '../constants/authorities';

const width = Dimensions.get('window').width;

Expand Down Expand Up @@ -88,7 +86,7 @@ class ChooseProviderScreen extends Component {
// this is much more performant.
fileCache: true,
})
.fetch('GET', authoritiesListURL, {
.fetch('GET', AUTHORITIES_LIST_URL, {
//some headers ..
})
.then(result => {
Expand Down
2 changes: 0 additions & 2 deletions app/views/Export.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
View,
Text,
Image,
Dimensions,
TouchableOpacity,
BackHandler,
StatusBar,
Expand Down Expand Up @@ -33,7 +32,6 @@ import { SvgXml } from 'react-native-svg';
import close from './../assets/svgs/close';
import exportIcon from './../assets/svgs/export';

const width = Dimensions.get('window').width;
const base64 = RNFetchBlob.base64;

function ExportScreen(props) {
Expand Down
9 changes: 5 additions & 4 deletions app/views/LocationTracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import StateNoContact from './../assets/svgs/stateNoContact';
import StateUnknown from './../assets/svgs/stateUnknown';
import SettingsGear from './../assets/svgs/settingsGear';
import fontFamily from '../constants/fonts';
import { PARTICIPATE, CROSSED_PATHS } from '../constants/storage';

const StateEnum = {
UNKNOWN: 0,
Expand Down Expand Up @@ -131,7 +132,7 @@ class LocationTracking extends Component {
// already set on 12h timer, but run when this screen opens too
this.intersect_tick();

GetStoreData('CROSSED_PATHS').then(dayBin => {
GetStoreData(CROSSED_PATHS).then(dayBin => {
if (dayBin === null) {
console.log("Can't find crossed paths");
this.setState({ currentState: StateEnum.NO_CONTACT });
Expand All @@ -146,7 +147,7 @@ class LocationTracking extends Component {
componentDidMount() {
AppState.addEventListener('change', this._handleAppStateChange);
BackHandler.addEventListener('hardwareBackPress', this.handleBackPress);
GetStoreData('PARTICIPATE')
GetStoreData(PARTICIPATE)
.then(isParticipating => {
if (isParticipating === 'true') {
this.setState({
Expand Down Expand Up @@ -294,8 +295,8 @@ class LocationTracking extends Component {
}

willParticipate = () => {
SetStoreData('PARTICIPATE', 'true').then(() => {
// Turn off bluetooth for v1
SetStoreData(PARTICIPATE, 'true').then(() => {
// Turn of bluetooth for v1
//BroadcastingServices.start();
});
// Check and see if they actually authorized in the system dialog.
Expand Down
3 changes: 0 additions & 3 deletions app/views/MapLocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React, { Component } from 'react';
import {
View,
Text,
Dimensions,
StyleSheet,
ImageBackground,
StatusBar,
Expand Down Expand Up @@ -33,8 +32,6 @@ import { SvgXml } from 'react-native-svg';
import fontFamily from '../constants/fonts';
import LocationServices, { LocationData } from '../services/LocationService';

const width = Dimensions.get('window').width;

const InitialRegion = {
latitude: 35.692863,
longitude: -98.090517,
Expand Down
3 changes: 2 additions & 1 deletion app/views/Notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
} from 'victory-native';
import Colors from '../constants/colors';
import NavigationBarWrapper from '../components/NavigationBarWrapper';
import { CROSSED_PATHS } from '../constants/storage';

const width = Dimensions.get('window').width;
const height = Dimensions.get('window').height;
Expand Down Expand Up @@ -84,7 +85,7 @@ class NotificationScreen extends Component {
resetState() {}

getInitialState = async () => {
GetStoreData('CROSSED_PATHS').then(dayBin => {
GetStoreData(CROSSED_PATHS).then(dayBin => {
console.log(dayBin);

/* DEBUGGING TOOL -- handy for creating faux data
Expand Down
10 changes: 5 additions & 5 deletions app/views/Overlap.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import backArrow from '../assets/images/backArrow.png';
import languages from '../locales/languages';
import CustomCircle from '../helpers/customCircle';
import fontFamily from '../constants/fonts';
import { PUBLIC_DATA_URL } from '../constants/authorities';
import { LOCATION_DATA } from '../constants/storage';

const width = Dimensions.get('window').width;

Expand All @@ -36,8 +38,6 @@ const base64 = RNFetchBlob.base64;
// The dataset is now hosted on Github due to the high demand for it. The
// first Google Doc holding data (https://docs.google.com/spreadsheets/d/1itaohdPiAeniCXNlntNztZ_oRvjh0HsGuJXUJWET008/edit#gid=0)
// points to this souce but no longer holds the actual data.
const public_data =
'https://raw.githubusercontent.com/beoutbreakprepared/nCoV2019/master/latest_data/latestdata.csv';
const show_button_text = languages.t('label.show_overlap');
const overlap_true_button_text = languages.t(
'label.overlap_found_button_label',
Expand Down Expand Up @@ -93,7 +93,7 @@ function OverlapScreen() {
}

async function populateMarkers() {
GetStoreData('LOCATION_DATA').then(locationArrayString => {
GetStoreData(LOCATION_DATA).then(locationArrayString => {
var locationArray = JSON.parse(locationArrayString);
if (locationArray !== null) {
var markers = [];
Expand Down Expand Up @@ -125,7 +125,7 @@ function OverlapScreen() {

async function getInitialState() {
try {
GetStoreData('LOCATION_DATA').then(locationArrayString => {
GetStoreData(LOCATION_DATA).then(locationArrayString => {
const locationArray = JSON.parse(locationArrayString);
if (locationArray !== null) {
const { latitude, longitude } = locationArray.slice(-1)[0];
Expand Down Expand Up @@ -168,7 +168,7 @@ function OverlapScreen() {
// this is much more performant.
fileCache: true,
})
.fetch('GET', public_data, {})
.fetch('GET', PUBLIC_DATA_URL, {})
.then(res => {
// the temp file path
console.log('The file saved to ', res.path());
Expand Down
Loading

0 comments on commit 03c3275

Please sign in to comment.