Hi all!
The TL;DR is I need to translate or map some numeric data to a readable string using lookup tables stored on Firebase.
I have a functional Ionic V3 app which integrates firebase.
I have some data that is being stored and accessed in this format:
Message in Raw Format:
Key1: number;
Key2 :number;
I then have two conversion tables which are key-value pairs of each key to a plain string translation (possibly supporting multiple languages in future)
ie.
Key1 Lookup:
0: "Thing A",
1: "Thing B",
2: "Thing C"
Key2 Lookup:
0: "OK",
1: "Bad",
2: "Worse"
The first lookup table has ~3500 items and will require modification in the future as new features are added. The second has only ~20 or so and is likely static.
I’d like to store these tables on Firebase and use them to translate the stored data to readable text in the app.
I have a working implementation using a local dictionary/map and an pipe (thispipe) handling the translations.
<ion-col> {{ (item?.key1) | thispipe}} </ion-col>
I’d like to utliise the firebase stored key:values instead of a local dictionary to keep app size down and improve maintainability, and I think it would be neater to handle the translations inside the pipe(map) in my data service - similar to this:
//The following code is working nicely, but utilised a local/hardcoded lookupTable
private getReadableFromDataSub(): Observable<DeviceDataReadable> {
return this.afdb.list('somelocation').valueChanges().pipe(
map(x => new DisplayPacket(x, this.lookupMap))
//this translates the raw data to human readable using a local lookupMap
);
}
//note this is local, I want to use firebase data or sync'ed local data
private setupLookup() {
this.lookupMap.set("92", {name:"Engine Percent Load At Current Speed", unit: "%"});
this.lookupMap.set("100", {name:"Engine Oil Pressure", unit: "kPa"});
this.lookupMap.set("158", {name:"Keyswitch Battery Potential ", unit: "V"});
this.lookupMap.set("171", {name:"Ambient Air Temp", unit: "°C"});
this.lookupMap.set("190", {name:"Engine Speed", unit: "RPM"});
this.lookupMap.set("sig", {name:"Cell Signal", unit: "bars"});
}
I’d appreciate any advice! Hopefully I’ve made it somewhat clear what I’m after!
Kind Regards,
Alex