removeWhere in list of files - flutter

I have a File which contains all the names of all the files I've created and I decode it into a Map which then has the following formate:
{"fileList.json":"false",
"testwert_0_.json":"false",
"jakob_0_.json":"false",
"jakobjokoobus_0_.json":"true",
"jakobjokoobussss_0_.json":"false",
"jakobjokoobusssssss_0_.json":"true"}
Now I would like to delete all the entries from the map, which have the value set to "true".
It should be a simple problem, but I just can't wrap my head around the map.removeWhere() function.
Could someone please help me with this?

This should do it:
// assumes your map is declared by 'm'
m.removeWhere((k, v) => v == "true");
The function is called for each key-value pair. You remove the ones with value "true".
For other handy methods available for Maps and Objects in Dart this article is worth a read.

Related

How do I add a new Map entry to a Map without overwriting the entire Map?

In my Firestore database, I have a document with a Map called 'Videos'.
In it, I add another Map into it that includes my video data.
So it looks like this:
Videos (Map) :
2022-Oct-03-14:24 (Map):
Title: Hi
Now what I want to do is, add another Map to the Videos with a different date.
How do I do this in Flutter?
Currently, I am doing:
db.collection('Collection').doc('Document').update({
'Videos': {
'2022-Oct-03-14:55': {
'Title': 'Ok'
}
}
});
But what this does is, it overrides the entire Videos map and assigns this new map I give, so the old Map with the Title Hi gets deleted. How do I insert new maps?
While Alex's answer is correct if you had an array field, you only have map fields. In that case, you can use . notation to updates/write only the nested field:
db.collection('Collection').doc('Document').update({
'Videos.2022-Oct-03-14:55.Title': 'Ok'
});
Also see the Firebase documentation on updating a field in a nested object.
For adding a new object inside the Videos map, you have two options available. The first one would be to use the . (dot) notation, as #FrankvanPuffelen mentioned in his answer, which will work perfectly fine. This means that it will indeed create the Videos field if it doesn't exist, and it will add the 2022-Oct-03-14:55 subfield inside it if that doesn't exist, and then the Title you put in there. However, since it's an update operation, this solution will work only if the document already exists, otherwise, it will fail.
If you need to create the Videos field inside a document that doesn't already exist, then you should consider using the set() function with merge true. However, this solution doesn't work using the . notation. So for that, I recommend you check my answer in the following post:
Problem with the initial creation of a map structure within a document in firestore
The second solution would be to read the document/map first. It's not mandatory but it will help you check the existence of an existing object. Why, because those objects are maps, and when it comes to maps, if you add a record that has the same key, then it replaces the old value with the new one. So I recommend you have to check that first.
So in order to perform the addition operation, you have to:
Read to read the document.
Get the Videos map in memory.
Check if a video already exists.
Add the new map inside the Videos.
Write the document back to Firestore.
If you'll have a map with the exact same key as a previous key, then the data will be overwritten, meaning that you'll don't see any change in the key, but only in the value if it's different.

jasper: listing all key-values pairs of a collection

In jasper I have to print a collection without knowing in advance the keys, because they are programmatic and can change over time. Let me do an example of this list:
formData[0]={addictions=1, workout=0, allergies=1, selfSufficiency=0}
formData[1]={gastricNose=1, weightChange=1, diet=XXXX}
[...]
formData[12]={dailyAmount=12, latestDate={type=date, value=1542582000000}, ostomy=1, ostomyType=AA, ostomyBag=BB}
How can I print a list of all these keys/values so that they get all listed properly like this? I can already print these objects raw in a list but they obviously look pretty much like the example I wrote above, while instead I need jasper to cycle through each of the elements by itself and retrieve the keys and the value for each element.
This is what I'm trying to print:
addictions: 1
workout: 0
[...]
gastricNose: 1
weightChange: 1
[...]
dailyAmount: 12
latestDate: 18/11/2018
[...]
In all posts I've looked into I'm required to know at least the name of the keys, but in my case I can't. And I cannot modify the data source structure either (for instance formatting the collection to be {key:"addictions",value:"1"} can't do that).
Thanks for your hints

Mirth channel XML : how to read value from inside of an element

How to read a list of values from Mirth Channel XML's <mapping> element? I can use msg to read one value. But what if there are list of values? Example:
<patient>
<name>names</name>
<patient>
If there is one value fornames defined, then simply performing <mapping>msg['patient']['name']</mapping> will return the value. But how to get only values if the names return more than one name? How to iterate and display in the same XML? I am doing Mirth for the first time and any help is appreciated.
I understand your question in this way.. so you mean if you receive the XML in this fashion
<patient>
<name>names</name>
<name>name1</name>
</patient>
then how to iterate and fetch only 'name' tags value. If my understanding is correct then place the below code in your source transformer.
var nameLen = msg['name'].length();
for(i=0;i<nameLen;i++){
// Your Mapping Logic
logger.debug(msg['name'][i].toString());
}

dataFrame keying using pandas groupby method

I new to pandas and trying to learn how to work with it. Im having a problem when trying to use an example I saw in one of wes videos and notebooks on my data. I have a csv file that looks like this:
filePath,vp,score
E:\Audio\7168965711_5601_4.wav,Cust_9709495726,-2
E:\Audio\7168965711_5601_4.wav,Cust_9708568031,-80
E:\Audio\7168965711_5601_4.wav,Cust_9702445777,-2
E:\Audio\7168965711_5601_4.wav,Cust_7023544759,-35
E:\Audio\7168965711_5601_4.wav,Cust_9702229339,-77
E:\Audio\7168965711_5601_4.wav,Cust_9513243289,25
E:\Audio\7168965711_5601_4.wav,Cust_2102513187,18
E:\Audio\7168965711_5601_4.wav,Cust_6625625104,-56
E:\Audio\7168965711_5601_4.wav,Cust_6073165338,-40
E:\Audio\7168965711_5601_4.wav,Cust_5105831247,-30
E:\Audio\7168965711_5601_4.wav,Cust_9513082770,-55
E:\Audio\7168965711_5601_4.wav,Cust_5753907026,-79
E:\Audio\7168965711_5601_4.wav,Cust_7403410322,11
E:\Audio\7168965711_5601_4.wav,Cust_4062144116,-70
I loading it to a data frame and the group it by "filePath" and "vp", the code is:
res = df.groupby(['filePath','vp']).size()
res.index
and the output is:
[E:\Audio\7168965711_5601_4.wav Cust_2102513187,
Cust_4062144116, Cust_5105831247,
Cust_5753907026, Cust_6073165338,
Cust_6625625104, Cust_7023544759,
Cust_7403410322, Cust_9513082770,
Cust_9513243289, Cust_9702229339,
Cust_9702445777, Cust_9708568031,
Cust_9709495726]
Now Im trying to approach the index like a dict, as i saw in examples, but when im doing
res['Cust_4062144116']
I get an error:
KeyError: 'Cust_4062144116'
I do succeed to get a result when im putting the filepath, but as i understand and saw in previouse examples i should be able to use the vp keys as well, isnt is so?
Sorry if its a trivial one, i just cant understand why it is working in one example but not in the other.
Rutger you are not correct. It is possible to "partial" index a multiIndex series. I simply did it the wrong way.
The index first level is the file name (e.g. E:\Audio\7168965711_5601_4.wav above) and the second level is vp. Meaning, for each file name i have multiple vps.
Now, this is correct:
res['E:\Audio\7168965711_5601_4.wav]
and will return:
Cust_2102513187 2
Cust_4062144116 8
....
but trying to index by the inner index (the Cust_ indexes) will fail.
You groupby two columns and therefore get a MultiIndex in return. This means you also have to slice using those to columns, not with a single index value.
Your .size() on the groupby object converts it into a Series. If you force it in a DataFrame you can use the .xs method to slice a single level:
res = pd.DataFrame(df.groupby(['filePath','vp']).size())
res.xs('Cust_4062144116', level=1)
That works. If you want to keep it as a series, boolean indexing can help, something like:
res[res.index.get_level_values(1) == 'Cust_4062144116']
The last option is a bit less readable, but sometimes also more flexibile, you could test for multiple values at once for example:
res[res.index.get_level_values(1).isin(['Cust_4062144116', 'Cust_6073165338'])]

SWI-Prolog cgi_get_form(Arguments) saving and handling arguments web form

I'm looking for a way of saving and after handling the arguments of a web form in SWI-Prolog when I submit the form and I call the same program to generate another form and so on. Always calling the same prolog program from one form to the next one.
The CGI SWI-Prolog library saves these arguments as a list of Name(Value) terms, i.e [Name(Value)].
if I pass the arguments like a hidden argument inside the form (TotalArguments is a list):
format('"<"input type="hidden" id="nameofform1" name="nameofform1" value="~w" />~n', TotalArguments),
I need to get rid of the id or name that concatenates on my resultant list on TotalArguments when I append it. Any idea of how to do this so that the final list looks like [nameofform1(value1), nameofform2(value2),...]?
I could also write this list of arguments and append it into a file, and consult it every time the program is called again, but this will load them always and I only need to load the arguments needed in the specific step and form handled at the moment. Because otherwise this file could contain undesirable info after some executions. Any thoughts on how to do it this way?
Any other suggestions for this kind of problem?
Edit with my solution using hidden form
I've solved it by creating:
extract_value([],_).
extract_value([A0|__ ], Valor) :-
A0 =.. [_, Value],
Valor is Value.
and then doing:
extract_value(Arguments, Value),
and submiting the hidden value of the form like:
format('<"input type="hidden" id="nameofform1" name="nameofform1" value="~w"/>~n', [Value]),
and appending it in the next form so that it looks how I wanted:
[nameofform2(value2),nameofform1(value1)]
It's a bit unclear to me what exactly you need here, but to remove the first element of a list that unifies with a given element (especially if you know for certain that the list contains such an element), use selectkchk/3. For example:
selectchk(id(_), List0, List1),
selectchk(name(_), List1, List)
in order to obtain List, which is List0 without the elements id(_) and name(_). Kind of implicit in your question, as I understand it, seems to be how to create a term like "form1(Value)" given the terms name(form1) and Value. You can do this for example with =../2. You can create a term T with functor N and arguments Args with
T =.. [N|Args]
It does not seem necessary to write anything to files here, I would simply pass the info through forms just as you outline.