How to use contains with a list in dart - dart

Hi i have list of objects and i would like to check if a certain object is in the list
i have the following code
List<GladiatorOutput> gladiators = await Obstructionum.utDifficultas(principalisDirectory);
for (GladiatorOutput gladiator in gladiators) {
print(gladiator.toJson());
}
print(gladiatorToAttack.outputs[conf.index].toJson());
if (!gladiators.contains(gladiatorToAttack.outputs[conf.index])) {
return Response.forbidden(json.encode({
"code": 0,
"message": "Gladiator non inveni",
"english": "Gladiator not found"
}));
}
with the following output
{rationem: [{probationem: d24bb59f1b6d86fd0c6bb860faa204eb377289e9ad8ec4096a789fbf1bcf2ddf, interioreRationem: {publicaClavis: 043af38cfb7ff7cd65d73fe926cd3547aa143ab0041479ec19933a5732f3ad40aeb361b2ff64fa4d5ed79daefc569497c6d0c83cbc8748b6bbb51cbe2b5c264b30, nonce: 0, id: 6834a99b8b1880eaaf6eea1bf6d3475e3bc3b54de9c3b750a257a8b47fbbcf64}}], defensio: 6a}
{rationem: [{probationem: 0000eb7896fe02966d5690cfb5838d638f3b2e6761ea00bd09d735ba0911d58a, interioreRationem: {publicaClavis: 04282a6a6dbc6f3a255786db2ab4521f3b592a910262771b47d9b2847839413a9191c72c5dd8a7a3f4b7972c502062d600171464ee4c4db322966a5f3af089b02d, nonce: 155531, id: fcf1c5dac4d40b61b7e20ca078940d7d925e21f618ecdad300a45afba9a5d2b3}}], defensio: e8}
{rationem: [{probationem: 0000b7de2cf7b2e3c1c1849991d9ce3717c3cb536d42bac4fa7e603bd7c13231, interioreRationem: {publicaClavis: 049da1bcf3374b7aa543bc135134fd6cff416658447517a448b3cc929ce94fc151e6f3bde849d317b30484a03288cc48e92cdd168ff99838dfab900c32f3ff20d2, nonce: 65750, id: 3ebcb052e32663d89275591fd13dfffd33041b77aa216715d8f0cf96af968368}}], defensio: ef}
{rationem: [], defensio: cf}
{rationem: [], defensio: 75}
{rationem: [], defensio: 8e}
{rationem: [], defensio: b4}
{rationem: [], defensio: b4}
could someone tell me why contains is not giving true

it's hard to tell without knowing the contents of gladiators, maybe print gladiators, and see if gladiatorToAttack.outputs[conf.index] is there, however also, your question says you would like to check "if the object is in the list",
but !gladiators.contains(gladiatorToAttack.outputs[conf.index]) you're asking it in the code to check "if the object is NOT in the list", clarify please what exactly you wanna do

Related

Loop through a nested json object in OPA

I am very new to OPA and trying to loop through the below input data
input =
"data":{
"list":[
{"Name": "abc", "Status": "Done"},
{"Name": "def", "Status": "Done"},
{"Name": "ghi", "Status": "pending"},
{"Name": "jkl", "Status": ""},
{"Name": "mno", "Status": null},
]
}
and return two lists based on that input, one list that would return the names of all objects that has the status as 'Done' and another list with status not equal to 'Done', here is the rego code I was trying, I used somewhat python syntax to convey the code as I was not sure how the opa syntax would look like
package play
default done_list := []
default other_list := []
done_list {
some i
input.data.list[i].Status == "Done"
done_list.append(input.data.list[i].Name) #python syntax and looking for something similar in opa
}
other_list{
some j
input.data.list[j].Status != "Done"
other_list.append(input.data.list[j].Name)
}
#or maybe use a list comprehension like this?
#not even sure if this makes sense but ...
done_list = [x.Name | x := input.data.list[_]; x.Status = "Done"]
other_list = [x.Name | x := input.data.list[_]; x.Status != "Done"]
test_return{
"done_list": done_list,
"other_list": other_list
}
and the output I'm looking for is something like
{
"done_list": ["abc", "def"],
"other_list": ["ghi","jkl","mno"]
}
Any help is greatly appreciated. Thanks in advance.
I think you're best to use a list comprehension as you guessed :)
package play
doneStatus := "Done"
result := {
"done_list": [e |
item := input.data.list[_]
item.Status == doneStatus
e := item.Name
],
"other_list": [e |
item := input.data.list[_]
item.Status != doneStatus
e := item.Name
],
}
I've created a Rego playground which shows this: https://play.openpolicyagent.org/p/dBKUXFO3v2

Is there a way to use OCR to extract specific data from a CAD technical drawing?

I'm trying to use OCR to extract only the base dimensions of a CAD model, but there are other associative dimensions that I don't need (like angles, length from baseline to hole, etc). Here is an example of a technical drawing. (The numbers in red circles are the base dimensions, the rest in purple highlights are the ones to ignore.) How can I tell my program to extract only the base dimensions (the height, length, and width of a block before it goes through the CNC)?
The issue is that the drawings I get are not in a specific format, so I can't tell the OCR where the dimensions are. It has to figure out on its own contextually.
Should I train the program through machine learning by running several iterations and correcting it? If so, what methods are there? The only thing I can think of are Opencv cascade classifiers.
Or are there other methods to solving this problem?
Sorry for the long post. Thanks.
I feel you... it's a very tricky problem, and we spent the last 3 years finding a solution for it. Forgive me for mentioning the own solution, but it will certainly solve your problem: pip install werk24
from werk24 import Hook, W24AskVariantMeasures
from werk24.models.techread import W24TechreadMessage
from werk24.utils import w24_read_sync
from . import get_drawing_bytes # define your own
def recv_measures(message: W24TechreadMessage) -> None:
for cur_measure in message.payload_dict.get('measures'):
print(cur_measure)
if __name__ == "__main__":
# define what information you want to receive from the API
# and what shall be done when the info is available.
hooks = [Hook(ask=W24AskVariantMeasures(), function=recv_measures)]
# submit the request to the Werk24 API
w24_read_sync(get_drawing_bytes(), hooks)
In your example it will return for example the following measure
{
"position": <STRIPPED>
"label": {
"blurb": "ø30 H7 +0.0210/0",
"quantity": 1,
"size": {
"blurb": "30",
"size_type":" "DIAMETER",
"nominal_size": "30.0",
},
"unit": "MILLIMETER",
"size_tolerance": {
"toleration_type": "FIT_SIZE_ISO",
"blurb": "H7",
"deviation_lower": "0.0",
"deviation_upper": "0.0210",
"fundamental_deviation": "H",
"tolerance_grade": {
"grade":7,
"warnings":[]
},
"thread": null,
"chamfer": null,
"depth":null,
"test_dimension": null,
},
"warnings": [],
"confidence": 0.98810
}
or for a GD&T
{
"position": <STRIPPED>,
"frame": {
"blurb": "[⟂|0.05|A]",
"characteristic": "⟂",
"zone_shape": null,
"zone_value": {
"blurb": "0.05",
"width_min": 0.05,
"width_max": null,
"extend_quantity": null,
"extend_shape": null,
"extend": null,
"extend_angle": null
},
"zone_combinations": [],
"zone_offset": null,
"zone_constraint": null,
"feature_filter": null,
"feature_associated": null,
"feature_derived": null,
"reference_association": null,
"reference_parameter": null,
"material_condition": null,
"state": null,
"data": [
{
"blurb": "A"
}
]
}
}
Check the documentation on Werk24 for details.
Although a managed offering, Mixpeek is one free option:
pip install mixpeek
from mixpeek import Mixpeek
mix = Mixpeek(
api_key="my-api-key"
)
mix.upload(file_name="design_spec.dwg", file_path="s3://design_spec_1.dwg")
This /upload endpoint will extract the contents of your DWG file, then when you search for terms it will include the file_path so you can render it in your HTML.
Behind the scenes it uses the open source LibreDWG library to run a number of AutoCAD native commands such as DATAEXTRACTION.
Now you can search for a term and the relevant DWG file (in addition to the context in which it exists) will be returned:
mix.search(query="retainer", include_context=True)
[
{
"file_id": "6377c98b3c4f239f17663d79",
"filename": "design_spec.dwg",
"context": [
{
"texts": [
{
"type": "text",
"value": "DV-34-"
},
{
"type": "hit",
"value": "RETAINER"
},
{
"type": "text",
"value": "."
}
]
}
],
"importance": "100%",
"static_file_url": "s3://design_spec_1.dwg"
}
]
More documentation here: https://docs.mixpeek.com/

How to get the value from a List using Rest Assured?

I am trying to grab the first value of courseNumber for studenId=123 using Rest Assured.
When I using
.body("students.courseList.courseNumber[0]",equalTo(1000000000))
I am getting:
Expected: <1000000000>
Actual: [1000000000, 1000000001, 1000000002, 1000000003, ...........]
There are more than 10 courseList for studentId 123.
Also is it possible to use regex to grab a particular element from JSON Response or how do I get the path of an element when I have a few thousand lines of JSON Response.
Sample Response -
{
"students": [
{
"studentId": "ABC",
"studentName": "Abcd Abcd",
"courseDescription": "AAJSHKJASSJAK LASNLKASA KJk;;K K;;KK;K;KL;K;",
"creditRemaining": 100,
"classStartDate": "20191220"
},
{
"studentId": "123",
"studentName": "DEFG, VBNH",
"courseDescription": "AAJSHKJASSJAK LASNLKASA KJk;;K K;;KK;K;KL;K;",
"classSchedule": 2,
"classStartDate": "20191220",
"slotsRemaining": 10,
"courseList": [
{
"courseNumber": 1000000000,
"courseName": "Chemistry",
"courseInstructor": "HGJ IOUIOU"
"courseCity": "New York",
"courseLevel": 100,
"description": "GJKJLKJLafgdhgf ljkllklk klyiyy mnbbnkljlkj
yttiuyuyuyoyo
jhlkjkljkl"},
{
"courseNumber": 1000000001,
"courseName": "History",
"courseInstructor": "HGJ IOUIOU"
"courseCity": "New York",
"courseLevel": 100,
"description": "GJKJLKJLafgdhgf ljkllklk klyiyy mnbbnkljlkj yttiuyuyuyoyo
jhlkjkljkl"},
]
}
students.courseList.courseNumber[0][0] --> will give 1000000000
students.courseList.courseNumber[0][1] --> will give 1000000001

Array to JSON Array in Swift

I have two array of Integers and I like to send it to my mongodb database. When I send it to database in Alamofire as paramter and in code data_array 1 and 2 refers to Int arrays.
let parameters_post: Parameters = [
"sensor_id": "ecg_raw",
"member_id": "58d3f509e48f4ca90dd218e4",
"esignal": "3.5V",
"ts": "emre",
"value1" : data_array1,
"value2" : data_array2
]
Alamofire.request("https://api.mlab.com/api/1/databases/mysignal/collections/Cecgraw?apiKey=2ABdhQTy1GAWiwfvsKfJyeZVfrHeloQI", method: .post, parameters: parameters_post,encoding: JSONEncoding.default, headers: nil).responseData{ response in
print(response.request)
print(response.response)
print(response.result)
}
However, It is seen as like this in mongodb. I think which is incorrect;
{
"_id": {
"$oid": "58f9d0e7c2ef162ad3000cb6"
},
"sensor_id": "ecg_raw",
"member_id": "58d3f509e48f4ca90dd218e4",
"value2": [
[
240,
279,
555,
547,
504
]
],
"value1": [
[
135,
91,
101,
115,
106
]
],
"esignal": "3.5V",
"ts": "emre"
}
As per you said you want to send value for key value as [(Int, Int)]. But actually you are sending as [[(Int, Int)]], which means array of array of tuples(Hope you need to send as array of tuples).
Try to send list below,
let parameters_post: Parameters = [
"sensor_id": "ecg_raw",
"member_id": "58d3f509e48f4ca90dd218e4",
"esignal": "3.5V",
"ts": "emre",
"value" : data_array
]
Thanks.

swift - how to parse this JSON object

// Get the #1 app name from iTunes and SwiftyJSON
DataManager.getTopAppsDataFromItunesWithSuccess { (iTunesData) -> Void in
let json = JSON(data: iTunesData)
println(json)
how to access all the elements of["venues"]["pub city"]["venue"] ?
{
"venues":{
"cityuser":"Beirut",
"venue-usernewplace":{
"star":[
],
"idcat":[
],
"namecat":[
],
"name":[
],
"id":[
],
"phone":[
],
"address":[
],
"crossStreet":[
],
"lat":[
],
"lng":[
],
"cc":[
]
},
"placesofpeople":{
"star":"false",
"nameplace":"B0 18",
"idplace":"4b52670df964a520847b27e3",
"count":"4",
"cc":"LB",
"phone":"01580018",
"crossStreet":"Main Highway",
"lat":"33.898404713314",
"lng":"35.534128372291",
"address":"Karantina"
},
"pubcity":{
"venue":[
{
"id":"4fe75b17e4b032d653ce50fd",
"idcat":"4bf58dd8d48988d11e941735",
"name":"Cl\u00e9 Cafe-Lounge Bar",
"phone":"71200712",
"address":"Mohammed Abdel Baki Street, Clemenceau",
"crossStreet":"Hamra, Facing Najjar Hospital",
"lat":"33.897185328966",
"lng":"35.487202808518",
"cc":"LB",
"count":"0",
"namecat":"Cocktail Bar",
"star":"false"
},
{
"id":"4e3e7533fa76455375c56a33",
"idcat":"4bf58dd8d48988d11f941735",
"name":"Skybar",
"phone":"03939191",
"address":"Biel",
"crossStreet":"Downtown Beirut",
"lat":"33.90610643966",
"lng":"35.510663636771",
"cc":"LB",
"count":"0",
"namecat":"Nightclub",
"star":"false"
},
{
"id":"4b52670df964a520847b27e3",
"idcat":"4bf58dd8d48988d11f941735",
"name":"B 018",
"phone":"01580018",
"address":"Karantina",
"crossStreet":"Main Highway",
"lat":"33.898404713314",
"lng":"35.534128372291",
"cc":"LB",
"count":"0",
"namecat":"Nightclub",
"star":"false"
},
There's two methods I know of.
1 Post that wall of text into a JSON formatter which makes that blob more readable. In which case you can then inspect which keys you can pull out from it.
2 Check the documentation.
Using swiftyJson:
if let venues = json["venues"]["pubcity"]["venue"].array {
//venue is an array of the dictionaries.
for venue in venues {
//just printing the name, but you have the whole dictioary of each venue here.
println(venue["name"].string!)
}
}

Resources