I have this TXT file:
{ input: [0,0], output: [0], id: 232362 }
{ input:[0,1], output: [1], id: 232363 }
I would like to convert it into array of objects in Typescript this way:
[
{ input: [0, 0], output: [0] },
{ input: [0, 1], output: [1] }
];
Could you help me, please?
I am a beginner, sorry.
Related
I'm trying to draw a polygon from a list of points with labels on each of the sides (borders) with the length of the sides?
Is there a simple way to get this happening?
Here's a snippet with what I've got at present. Note that I want to be able to use an arbitrary number of points, not just three if at all possible.
const board = JXG.JSXGraph.initBoard('jxgbox', {
boundingbox: [-5, 5, 5, -5],
axis: true
});
var points = [
[0, 0],
[0, 1],
[1, 0]
];
var pg = board.create('polygon', points, {
fixed: true,
hasInnerPoints: true,
vertices: {
visible: false
},
borders: {
names: ['a', 'b', 'c'],
withLabel: true
}
});
It is possible to set the label text of each border to be a function. This has to be done after the construction of the polygon. A possible solution would look like this:
const board = JXG.JSXGraph.initBoard('jxgbox', {
boundingbox: [-5, 5, 5, -5], axis:true
});
var points = [
[0, 0],
[0, 2],
[2, 0]
];
var pg = board.create('polygon', points, {
fixed: true,
hasInnerPoints: true,
vertices: {
visible: false
},
borders: {
names: ['a', 'b', 'c'],
label: { offset: [-10, 10] },
withLabel: true
}
});
// Overwrite the labels of the borders:
for (let i = 0; i < pg.borders.length; i++) {
pg.borders[i].label.setText( () => pg.borders[i].L().toFixed(2) );
}
See https://jsfiddle.net/h6knmgjc/ for a working example.
Below is the Input_dict for data analysis:
input_dict =
{
"C:\\arm64\\lib_apple.so": { "func-abc": [5,6,7,8], "func-123":[1,1,1,1] },
"C:\\arm64\\lib_banana.so": { "func-123": [2,3,4], "func-rt": [0,0] },
"C:\\armeabi\\lib_banana.so": { "func-123": [1,0,0], "func-rt": [1,5] },
"C:\\armeabi\\lib2.so": { "func-0": [1]},
"C:\\x86\\lib_apple.so": { "func-so": [5,6,7,8], "func-123": [2,2,1,1] },
"C:\\x86\\lib_banana.so": { "func-rt": [2,0] },
"C:\\x86\\lib2.so": { "func-0": [1,2,3]}
}
The aim is to compare the 'values' of functions with same name of different architectures(arm64,armeabi,x86).
In other words, I want to compare the "lists" of functions(with same name) in different libraries(.so) files.
For example: Comparing func-123: [2,3,4] with func-123: [1,0,0] from arm64\lib_banana.so and armeabi\lib_banana.so respectively.
One of the desired output could be:
{ lib_apple.so: { func-123: [arm64,[1,1,1,1]],[x86,[2,2,1,1]]}}
You can restructure your function data to order by their name first, then supported architectures. Afterwards, print out those functions that appear in multiple architectures:
from collections import defaultdict
from pathlib import PureWindowsPath
lib2func = {
r'C:\arm64\lib_apple.so': { 'func-abc': [5,6,7,8], 'func-123': [1,1,1,1] },
r'C:\arm64\lib_banana.so': { 'func-123': [2,3,4], 'func-rt': [0,0] },
r'C:\armeabi\lib_banana.so': { 'func-123': [1,0,0], 'func-rt': [1,5] },
r'C:\armeabi\lib.so': {},
r'C:\armeabi\lib2.so': { 'func-0': [1]},
r'C:\x86\lib_apple.so': { 'func-so': [5,6,7,8], 'func-123': [2,2,1,1] },
r'C:\x86\lib_banana.so': { 'func-rt': [2,0] },
r'C:\x86\lib2.so': { 'func-0': [1,2,3] },
}
# restructure
func2arch = defaultdict(dict)
for lib_path, functions in lib2func.items():
path = PureWindowsPath(lib_path)
lib = path.name
arch = path.parent.name
for func_name, func_val in functions.items():
func2arch[(lib, func_name)][arch] = func_val
# find functions defined for multiple architectures
for (lib, func_name), arch_data in func2arch.items():
if len(arch_data) < 2:
continue # skip functions that only appear once
print(lib, func_name, arch_data)
gives
lib_apple.so func-123 {'arm64': [1, 1, 1, 1], 'x86': [2, 2, 1, 1]}
lib_banana.so func-123 {'arm64': [2, 3, 4], 'armeabi': [1, 0, 0]}
lib_banana.so func-rt {'arm64': [0, 0], 'armeabi': [1, 5], 'x86': [2, 0]}
lib2.so func-0 {'armeabi': [1], 'x86': [1, 2, 3]}
The above code assumes that library/function name pairs are unique.
My issue is the following. I have a collection (territories) that have a geometry of type Polygon inside. The thing is that the polygons in my applications must be validated against this collection. Meaning that for a polygon to be valid, it must be COMPLETELY contained in at least one territory.
As $geoWithin is intented to work only in one direction. I try to do the following.
db.territories.insertMany([
{
_id: 1,
geometry: {
type: "Polygon",
coordinates: [
[
[0, 0],
[5, 0],
[5, 5],
[0, 5],
[0, 0]
]
]
}
}
])
const aggregation = [
{
$addFields: {
polygonToValidate: {
type: "Polygon",
coordinates: [[[2, 2], [4, 2], [4, 4], [2, 4], [2, 2]]]
},
territoryPolygon: "$geometry",
},
},
{
$match: {
polygonToValidate: {
$geoWithin: {
$geometry: "$territoryPolygon"
}
}
}
}
]
db.territories.aggregate(aggregation);
The polygon is valid as it is completely contained inside the territory polygon. But is not posible to reference the document field, neither the field added in the $addFields (territoryPolygon).
I need to update (in bulk) many entities.
Each entity has a field that its value is an array.
I want to concat a whole array to the existed array in mongo.
For example:
Assume we have the field 'myField', and (its value) the array saved in mongo is: [4, 5, 6]
I want to concat the array [1, 2, 3] to this field, so the result:
myField: [1, 2, 3, 4, 5, 6]
I tried some options:
pushAll - but it is no longer available.
usePushEach: true, in options - not working, still get the same error:
"Unknown modifier: $pushAll. Expected a valid update modifier or pipeline-style update specified as an array"
I read about concat - but it is not looks compatiable.
Thanks in advance!
you can use $addToSet to add the values to existing array and avoid the duplicates like so,
[
{
id: 1,
values: [
1,
2,
3
]
}
]
db.collection.update({
id: 1
},
{
"$addToSet": {
values: {
"$each": [
5,
7,
1,
44
]
}
}
})
https://mongoplayground.net/p/S3HfWajg9r_
I have an Object MyObject which has a List of ThatObjects where each ThatObject is a list of ThoseObjects.
MyObject {
List<ThatObject> thatObjects;
}
ThatObject {
List<ThoseObject> thoseObjects
}
If I have a handle to MyObject, is it possible to get a handle to all thoseObjects in one list joined to together? Without have to iterate and make the joined list myself?
Thanks
Given:
class MyObject {
List thatObjects
}
class ThatObject {
List thoseObjects
}
We can make a test object of:
def o = new MyObject( thatObjects:[ new ThatObject( thoseObjects:[ 1, 2 ] ),
new ThatObject( thoseObjects:[ 3, 4 ] ) ] )
Then a simple walk through the properties gives us:
assert o.thatObjects.thoseObjects == [ [1, 2], [3, 4] ]
And call flatten to get a single list:
assert o.thatObjects.thoseObjects.flatten() == [ 1, 2, 3, 4 ]
Or, you could use collectMany
assert o.thatObjects.collectMany { it.thoseObjects } == [ 1, 2, 3, 4 ]