how to firebase ml vision storing each line to a variable - firebase

I'm currently trying to learn flutter and implement OCR with firebase ml vision, but currently I want to store the text read to a variable, what's the suggested approach?
For example I have a paper with
NAME
INFORMATION
Can I read the first line and store as String variable name and second line as information? How should I implement my for loop here?
Let's say I already imported the libraries, and I'm stuck here.
for (TextBlock block in visionText.blocks) {
for(n=0; n<block.lines.length; n++ )
{
name =
info =
}
}
Thanks in advance

In your scenario, assuming both name and information take one line each, I would do it the first way:
for (TextBlock block in visionText.blocks) {
name = block.lines[0];
info = block.lines[1];
}

Related

Is there a way to loop dynamic links parameters to avoid repetition of values?

I'm using kotlin and I have implemented dynamic links to my app, and when ever the user clicks the link, it will retrieve specific data from Firebase depending on the link. I try to query the parameters of the link but I was unsuccessful so I had to get creative and use .endWith("") statement to assign each link a specific collection from Firebase. The problem is that the more links I use, the bigger the list will get and is not convinient for me. I know there has to be a more efficient way. Any suggestions? Thanks in advance.
val drinksCoffeeShopsFB = FirebaseFirestore.getInstance().collection("Drinks").document("CoffeeShops")
val foodFastFoodFB = FirebaseFirestore.getInstance().collection("Food").document("FastFood")
var deepLink: Uri? = null
val it = Firebase.dynamicLinks.getDynamicLink(intent).result
if (it != null) { deepLink = it.link }
when{
deepLink.toString().endsWith("DrinksCoffeeShops/1/")-> {drinksCoffeeShopsFB.collection("1").get()}
deepLink.toString().endsWith("DrinksCoffeeShops/2/")-> {drinksCoffeeShopsFB.collection("2").get()}
deepLink.toString().endsWith("DrinksCoffeeShops/3/")-> {drinksCoffeeShopsFB.collection("3").get()}
deepLink.toString().endsWith("DrinksCoffeeShops/4/")-> {drinksCoffeeShopsFB.collection("4").get()}
deepLink.toString().endsWith("DrinksCoffeeShops/5/")-> {drinksCoffeeShopsFB.collection("5").get()}
deepLink.toString().endsWith("DrinksCoffeeShops/6/")-> {drinksCoffeeShopsFB.collection("6").get()}
...
deepLink.toString().endsWith("FoodFastFood/1/")-> {foodFastFoodFB.collection("1").get()}
deepLink.toString().endsWith("FoodFastFood/2/")-> {foodFastFoodFB.collection("2").get()}
deepLink.toString().endsWith("FoodFastFood/3/")-> {foodFastFoodFB.collection("3").get()}
deepLink.toString().endsWith("FoodFastFood/4/")-> {foodFastFoodFB.collection("4").get()}
deepLink.toString().endsWith("FoodFastFood/5/")-> {foodFastFoodFB.collection("5").get()}
deepLink.toString().endsWith("FoodFastFood/6/")-> {foodFastFoodFB.collection("6").get()}
...
}
This is an example of the dynamic link being used to retrieve its parameters
https://myapp.page.link/DrinksCoffeeShops/2/
You can try something like this:
val id = link.removeSuffix("/").split('/').last() // This will give you the id present in the deepLink
if("DrinksCoffeeShops" in link)
drinksCoffeeShopsFB.collection(id).get()
if("FoodFastFood" in link)
foodFastFoodFB.collection(id).get()

Flutter : How to add element to map field inside firebase database?

I'm trying to find a way to add element to map field inside firebase database from my flutter code. The element as well is a map. So it's a nested map.
Future updateImageDate({
String token,
int rating,
int like,
int display_count,
//Map participants,
}) async {
return await pictureCollection.document(token).updateData({
'rating': rating,
'like': like,
'display_count': display_count,
//'participants': participants,
// I want to add only one element to this existing map field in firebase database.
// Although currently it's empty, I want to keep add new element every time I use this method.
// The element as well is a map. So it's a nested map.
});
}
Please help me! I'm looking forward to hearing from you. Thank you in advance. :D
To write to a map, use dot (.) notation. So:
pictureCollection.document(token).updateData({ 'path.to.field': 'new value' });

How to Set/Get "Last Saved on" Information for a baseline using Aspose.Tasks

I want to export data and create MsProject File using Aspose.Tasks. I am able to export data from my local db to project file successfully but while exporting Baseline information I am not able to find how to set "Last Saved on" information for the baseline. I am using below code to create and set baseline.
project.SetBaseline(BaselineType.Baseline, new Task[] { task });
var baselineType=BaselineType.Baseline;
TaskBaseline baseline = task.Baselines.FirstOrDefault(x =>
x.BaselineNumber.Equals(baselineType));
if (baseline != null)
{
if (!String.IsNullOrEmpty(baselineDto.Cost))
baseline.Cost = Convert.ToDecimal(baselineDto.Cost);
}
If Anyone has any idea how to Get/Set "Last Saved on" Information for a baseline, please share.
Thanks.
Bhupesh
I have observed your requirements and like to inform that we can only get Last Saved information using Aspose.Tasks. I have shared following sample code. This will help you to achieve your requirements.
var s = #"c:\test\baseline msp 2016.mpp"; Project p = new Project(s);
Console.WriteLine(p.GetBaselineSaveTime(BaselineType.Baseline));
Console.WriteLine(p.GetBaselineSaveTime(BaselineType.Baseline1));
Console.WriteLine(p.GetBaselineSaveTime(BaselineType.Baseline2));
I am working as Support developer/ Evangelist at Aspose.

How to add battery_cost_change multiple time with counter value in firebase in same user Message Which is LM2JKCacawaW7tlK4yK

is it possible to insert battery_cost_change: field multiple time with counter value in firebase in same user Message Which is LM2JKCacawaW7tlK4yK. like battery_cost_change1: ,battery_cost_change2:,battery_cost_change3: and so on And how these fields will be retrieve in android programmaticallyenter image description here
You may wish to consider the db structure for battery_cost_changes to hold multiple instances of battery_cost_change object.
Everytime you add a new battery_cost_change - you can push the object into the path .../LM2JKCacawaW7tlK4yK/battery_cost_changes. <pushId> is the random ID Firebase generates, when an object is pushed/added into the node.
{ LM2JKCacawaW7tlK4yK: {
....
battery_cost_changes: {
<pushId>: {
battery_cost_change: 6
},
<pushId>: {
battery_cost_change: 3
}
}
....
}
While retrieving the values, you can read the path .../LM2JKCacawaW7tlK4yK/battery_cost_changes and observe the values for an array of battery_change_cost objects. Please share more details, to explore a better or more suitable answer. However, I feel this is a generic idea to store multiple values under a node.

Firebase real time database, get values from different locations in one snapshot

I am working on using the Firebase database in a Unity project. I read that you want to structure your database as flat as possible for preformance so for a leaderboard I am structuring it like this
users
uid
name
uid
name
leaderboard
uid
score
uid
score
I want a class that can get this data and trigger a callback when it is done. I run this in my constructor.
root.Child("leaderboard").OrderByChild("score").LimitToLast(_leaderboardCount).ValueChanged += onValueChanged;
To trigger the callback with the data I wrote this.
void onValueChanged(object sender, ValueChangedEventArgs args)
{
int index = 0;
List<string> names = new List<string>();
foreach (DataSnapshot snapshot in args.Snapshot.Children)
{
root.Child("players").Child(snapshot.Key).GetValueAsync().ContinueWith(task =>
{
if (task.Result.Exists)
{
names.Add(task.Result.Child("name").Value.ToString());
index++;
if (index == args.Snapshot.ChildrenCount)
{
_callback(names);
}
}
});
}
}
I am wondering if there is a better way to do this that I am missing? I'm worried if the tasks finish out of order my leaderboard will be jumbled. Can I get the names and scores in one snapshot?
Thanks!
You can only load:
a single complete node
a subset of all child nodes matching a certain condition under a single node
It seems that what you are trying to do is get a subset of the child nodes from multiple roots, which isn't possible. It actually looks like you're trying to do a join, which on Firebase is something you have to do with client-side code.
Note that loading the subsequent nodes is often a lot more efficient than developers expect, since Firebase can usually pipeline the requests (everything goes over a single web socket connection). For more on this, see http://stackoverflow.com/questions/35931526/speed-up-fetching-posts-for-my-social-network-app-by-using-query-instead-of-obse/35932786#35932786.

Resources