Get card data with nfc_manager? - flutter

I'm using the nfc_manager package to scan my transportation card. I've found similar apps on the playstore that were able to get transaction history, card serial number and other details from the app. However, using the nfc_manager package, I've only been able to obtain isodep and nfcB data. Below is the printed outputs of the isodep and nfcb data.
{identifier: [123, 123,123,123], hiLayerResponse: [], historicalBytes: null, isExtendedLengthApduSupported: true, maxTransceiveLength: 12312, timeout: 123}
{identifier: [123,123,123,123], applicationData: [0, 0, 0, 0], maxTransceiveLength: 123, protocolInfo: [123,123,123]}
(the values were changed to 123 because I'm not sure if the data is sensitive)
How do I go about obtaining data such as transportation history and all that from the data I have here? Or is that a limitation of the package?
here is the code used:
NfcManager.instance.startSession(onDiscovered: (NfcTag tag) async {
print(tag.data['isodep']);
print(tag.data['nfcb']);
IsoDep isoDep = IsoDep.from(tag);
print(isoDep.historicalBytes);
});
Thank you for your help!

Related

REST API get multiple records using id

We have the records in the below format :
[
{
id: 1,
name : 'Chris',
class : 'x',
year : 3,
},
{
id: 2,
name : 'John',
class : 'y',
year : 4,
}
]
I want to fetch multiple records based on id with a single api call.
This could be achieved either by passing multiple ids in a get call or using a post call to post the list of ids.
Get call with multiple ids
GET https://api.com/school/names?id=1,2,3
Post with multiple ids
POST https://api.com/school/names?action=get
request body :
{
id1: 1,
id2: 2,
id3: 3
}
We don't have issue with the url length as we will not cross the 2048 characters limit.
I see that many public apis use both of the above approaches, I have a feeling that using a POST call to fetch data is against the REST principle.
Could some one suggest what is the best approach for this scenario and the advantage of the approach compared to the other one.

Firebase Realtime DB query returns both a list and a map when using startAfter

I have the following piece of code, that is simplified for the purpose of illustration:
List<Name> _nameList = [];
_getNameList() {
String dbPath = “names/“;
var startAfter = _nameList.length - 1;
final db = FirebaseDatabase.instance
.ref()
.child(dbPath)
.orderByKey()
.startAfter(startAfter.toString())
.limitToFirst(4);
final nameFuture = db.once();
nameFuture.then((event) {
List<Name> nameList = [];
print(event.snapshot.value);
if (event.snapshot.value != null) {
for (var item in (event.snapshot.value as List<Object?>)) {
if (item != null) {
Name d = Name.fromRTDB(item);
nameList.add(d);
}
}
}
if (nameList.isNotEmpty) {
setState(() {
_nameList.addAll(nameList);
});
}
});
}
It initially reads the first 4 Name objects from Firebase Realtime DB. And whenever it is called, I expect it to read the very next 4 Name objects and attach them to the _nameList as stated in the code.
IMPORTANT to note that keys to each Name object in the Realtime DB are as 0, 1, 2, 3, 4, and so on. If I am not totally wrong, this actually should make the life easier when using startAfter.
As you may recognize, I print out the values coming from DB, as print(event.snapshot.value);.
The first read works perfectly fine, where startAfter is set to "-1". Example output from print(event.snapshot.value);:
[{name: "John"}, {name: "Johanna"}, {name: "Maria"}, {name: "Steve"}]
Problem 1
When I run the function again, where the startAfter is now 3, I see the following output:
[null, null, null, null, {name: "Michael"}, {name: "Maradona"}, {name: "Pelle"}, {name: "Messi"}]
I expect the list to have the size of 4 but it includes 8 items. And the first 4 are null. Why do I have 8 items in the returned list, and why are the first 4 null?
Problem 2
When I run the function for the 3rd time, where the startAfter is now 7, I get the following output this time:
{10: {name: "Jordan"}, 8: {name: "James"}, 9: {name: "Rambo"}, 11: {name: "Brian"}}
While the first 2 calls returned lists, the 3rd call returned a map.
Why does it all of a sudden return a map in the 3rd call?
And I make the call with orderByKey() but the returned keys in the map are not in order; why?
Problem 1: When I run the function again, where the startAfter is now 3, I see the following output:
[null, null, null, null, {name: "Michael"}, {name: "Maradona"}, {name: "Pelle"}, {name: "Messi"}]
This is the expected behavior for the Realtime Database API. When it sees a bunch of (sufficiently) sequential numeric keys, it assumed that data was originally an array and returns the data as an array. Since your array doesn't have items at indexes [0-3] those indexes show us as null.
This so-called array coercion depends very much on the data, but typically stops happening once there are too many (I don't recall the exact value for that) missing values at the start of the array, which I think is what may be causing the other problem.
The solution is to not use sequential numeric keys in your Realtime Database data, but either use the push() function to generate keys (recommended) or to prefix the numbers with a short string, e.g. "key_3", "key_4", etc.
Also see: Best Practices: Arrays in Firebase.

Advice on structuring data for scalability with large number of nested objects

Looking for advice on how best to structure data in MongoDB, particularly for scalability - worried about having an array of potentially thousands of objects within each user object.
I am building a language learning app with a built in flashcard system. I want users to 'unlock' new vocabulary for each level, which automatically gets added to their flashcards, so when you unlock level 4, all the vocabulary attached to level 4 gets added to your flashcards.
For the flashcards themselves, I want a changable 'due date', so that you get prompted to do certain cards at a certain date - if you're familiar with spaced repition, that's the plan. So when you get a card, you can say how well you know it and, for example, if you know it well you won't get it for another week, but if you get it wrong you'll get it again the next day.
I'm using MongoDB for the backend, but am a little unsure about how best to structure my data. Currently, I have two objects: one for the cards, and one for the users.
The cards object looks like this, so there's a nested object for each flashcard, with a unique ID, the level the word appears in, and then the word in both languages.
const CardsList = [
{
id: 1,
level: 1,
gd: "sgìth",
en: "tired",
},
{
id: 2,
level: 2,
gd: "ceist",
en: "question",
},
];
Then each user has an object like the below, with various user data, and a nested array of objects for the cards - with the id of every card they've unlocked, and the date at which that card is next due.
{
id: 1,
name: "gordon",
level: 2,
cards: [
{ id: 1, date: "07/12/2021" },
{ id: 2, date: "09/12/2021" },
],
},
{
id: 2,
name: "mike",
level: 1,
cards: [
{ id: 1, date: "08/12/2021" },
{ id: 2, date: "07/12/2021" },
],
},
This works fine, but I'm a bit concerned about the scalability of it.
The plan is to have about two or three thousand words in total, and so if I had, say, fifty users complete the app, then that would mean fifty user objects, each with as much as three thousand objects in that nested cards array.
Is that going to be a problem? Would it be a problem if I had a thousand (or more) users, instead of 50? Is there a more sensible way of structuring the data that I'm not spotting?

Return Height from Google Fit Rest API

Trying to get the latest height captured on Google Fit by a user for a web app. Using the https://developers.google.com/fit/rest/ I got the below.
const scopes = [
'https://www.googleapis.com/auth/plus.me',
'https://www.googleapis.com/auth/fitness.body.read'
];
const fitness = google.fitness('v1');
const gfHeight = await fitness.users.dataSources.get({
userId: 'me',
dataSourceId: '',
datasetId: '',
});
console.log(gfHeight.data);
Returns the log below which is just details of the data source:
...
{dataStreamId: 'raw:com.google.weight:com.google.android.apps.fitness:user_input',
dataStreamName: 'user_input',
type: 'raw',
dataType: { name: 'com.google.height', field: [[Object]] },
application: { packageName: 'com.google.android.apps.fitness' },
dataQualityStandard: []
}]}
On adding the datasets to datasource it returns a 404 so not sure how to structure the request to get an object containing the height.
const gfHeight = await fitness.users.dataSources.datasets.get...
Try the tutorial here which uses the Fit API data-types as reference.
get body height
Endpoint:
https://www.googleapis.com/fitness/v1/users/me/dataSources/derived:com.google.height:com.google.android.gms:merge_height/datasets/-
Alternative: /users/me/dataSources/raw:com.google.height:com.google.android.apps.fitness:user_input/datasets/-
Reference: https://developers.google.com/fit/rest/v1/data-types
description
This description relates to the primary endpoint above, for merged data points. This endpoint returns all of the body height data points that were synced to the Google Fit platform from devices connected to Google Fit. The body height values are returned as floating point numbers with a unit of meters. Each datapoint has a start datetime (startTimeNanos) and end datetime (endTimeNanos) and although they are likely the same, we will need to check that before creating the data point. The nanos values are unix epoch nanoseconds that are aligned to UTC.

Mongodb random sample selection but unique and different every time I ask for a new sample

I have Mongo Database, and I want to select a random sample of users, which I found a solution for in different places (including here).
Now, the hard part: How to get a unique and random set of users every time I make a request to mongo that doesn't correlate to the random sample I received in the (at least) last request.
Thanks!
One idea is to store the used up samples in an array and do your random query with the addition of the not-in-array-elements condition $nin. Below is sample code for demonstrating $nin, which you can edit and play around with on my Saturn Fiddle.
// Welcome to SaturnAPI!
// Start collaborating with MongoDB fiddles and accomplish more.
// Start your code below these comments.
// Create a new collection
var Posts = new Mongo.Collection(null);
//Insert some data
Posts.insert({
number: 1,
author: "Saturn Sam",
message: "Hello!"
});
Posts.insert({
number: 2,
author: "Saturn Sam2",
message: "Hello!"
});
Posts.insert({
number: 3,
author: "Saturn Sam3",
message: "Hello!"
});
// Returns all records
// Posts.find({}).fetch()
// Returns all records with `number` not equal to `2` or `1`
Posts.find({number: {$nin: [2, 1]}}).fetch()