Heyhou
I'm trying to add some 3D models (buildings) in JSON format to a Firebase from a Node.js server reading the data from a JSON file. I'm using the push() to add a key under buildings.
var buildingsRef = new Firebase('https://test.firebaseIO-demo.com/buildings');
buildingsRef.push({ ... });
Unfortunately, the push is very slow and it takes approx. 30 seconds to insert the JSON into Firebase. The JSON object looks like the following:
{
geometries: {
vertices: [...],
faces: [...],
normals: [....]
},
materials: {
},
object: {
},
metadata: {
}
}
The geometries object contains Arrays for vertices, faces, normals, uv's, etc.. These arrays may have up to 10'000 entries or more, depending on the complexity of the 3D-Model.
I'm not sure if the large JSON itself (file on disk is about 2Mb) or the Array representation is the cause for the slow insertion into Firebase. I suspect that it has something to do with how Firebase internally represents Arrays.
Is there any way to optimize this? I like to store the whole building under one key, so I can check in the frond end of my application if the building has been replaced (usually by the server-side). I don't need to modify the individual arrays, I just like to be able to swap out a building with a different one and let my front-end update accordingly.
Thanks for your help!
Related
I currently use junit5, wiremock and restassured for my integration tests. Karate looks very promising, yet I am struggling with the setup of data-driven tests a bit as I need to prepare a nested data structures which, in the current setup, looks like the following:
abstract class StationRequests(val stations: Collection<String>): ArgumentsProvider {
override fun provideArguments(context: ExtensionContext): java.util.stream.Stream<out Arguments>{
val now = LocalDateTime.now()
val samples = mutableListOf<Arguments>()
stations.forEach { station ->
Subscription.values().forEach { subscription ->
listOf(
*Device.values(),
null
).forEach { device ->
Stream.Protocol.values().forEach { protocol ->
listOf(
null,
now.minusMinutes(5),
now.minusHours(2),
now.minusDays(1)
).forEach { startTime ->
samples.add(
Arguments.of(
subscription, device, station, protocol, startTime
)
)
}
}
}
}
}
return java.util.stream.Stream.of(*samples.toTypedArray())
}
}
Is there any preferred way how to setup such nested data structures with karate? I initially thought about defining 5 different arrays with sample values for subscription, device, station, protocol and startTime and to combine and merge them into a single array which would be used in the Examples: section.
I did not succeed so far though and I am wondering if there is a better way to prepare such nested data driven tests?
I don't recommend nesting unless absolutely necessary. You may be able to "flatten" your permutations into a single table, something like this: https://github.com/intuit/karate/issues/661#issue-402624580
That said, look out for the alternate option to Examples: which just might work for your case: https://github.com/intuit/karate#data-driven-features
EDIT: In version 1.3.0, a new #setup life cycle was introduced that changes the example below a bit.
Here's a simple example:
Feature:
Scenario:
* def data = [{ rows: [{a: 1},{a: 2}] }, { rows: [{a: 3},{a: 4}] }]
* call read('called.feature#one') data
and this is: called.feature:
#ignore
Feature:
#one
Scenario:
* print 'one:', __loop
* call read('called.feature#two') rows
#two
Scenario:
* print 'two:', __loop
* print 'value of a:', a
This is how it looks like in the new HTML report (which is in 0.9.6.RC2 and may need more fine tuning) and it shows off how Karate can support "nesting" even in the report, which Cucumber cannot do. Maybe you can provide feedback and let us know if it is ready for release :)
I want to save small images in my room database and I have two issues:
How do I save an image in my database?
How do I save multiple images in my database?
I tried saving a bitmap in the way recommended by the developers page (https://developer.android.com/training/data-storage/room/defining-data)
#Parcelize
#Entity(tableName = "image_table")
data class ImgMod(
#PrimaryKey(autoGenerate = true)
var invoiceId: Long = 0L,
#ColumnInfo(name = "image")
var single_img: Bitmap?
): Parcelable
However, I receive the following error:
Cannot figure out how to save this field into database. You can consider adding a type converter for it.
Secondly, I would like to save multiple images in one database entry. But I receive the same error with the following snippets:
#ColumnInfo(name = "imageList")
var img_list: ArrayList<BitMap>
or decoded bitmap as a String
#ColumnInfo(name = "imageList")
var decoded_img_list: ArrayList<String>
I am sorry if this is a very basic question. But how do I have to configure the database/process the data to an image list?
Thank you in advance,
rot8
A very simple way to get images into the database (although I personally discourage it) would be to base-64 encode the bitmaps into a String and put it into a row of the database.
Take in account that bitmaps are very memory heavy; and base64 encoding something increases it's size some more so be careful when loading a bunch of images... I do also think Room and SQLite supports binary data as blobs, so you could just declare a column as ByteArray and it should just work.
What I've been doing in my projects is to write them into the internal or external storage of my app and then store the reference Uri as a String to later be able to retrieve the image from disk.
Something that I discourage even more is to stuff more than one value per row; having a list of stuff inside a coulmn in SQL is definetely not a pattern you should follow. Creating a "join" table should be simple enough or simply an extra column you could use to group them by should be easy enough, right?
#State var cardData: [Card] = [
Card(number: 1 ,start: "05.06.2020", end: "15.06.2020", days: 10, success: true)
]
I have cardData, and the user can add more Elements to this array. But I want that it will be saved. Like UserDefaults. Is it possible to Store this (cardData) to UserDefaults?
If not, how can I save it permanent?
Thank you so much!
there are multiple ways. on would be adding a .onChange modifier to your view (available on Xcode 12, not sure about 11):
.onChange(of: cardData) { newValue in
UserDefaults.standard.setValue(newValue, forKey: "Your_UserDefaults_Key")
}
I noticed you are using a custom type that you've made. in that case you first need to convert all your data to some Type that can be saved to UserDefaults (like string, using codable, see: https://www.hackingwithswift.com/example-code/system/how-to-load-and-save-a-struct-in-userdefaults-using-codable)
As someone mentioned, this might not be the best way of saving your data on a persistent storage. If you plan to save a lot of data, and you don't need all that data at all times (for example, most of the times you only need one of those all cards) you should not use UserDefaults, and use CoreData instead. Using UserDefaults is not efficient in the case i described, because you have to get all the data from the device's storage everytime (you can't ask to only get the one card you need using UserDefaults, but you can do that using CoreData). And also when saving data to the device's storage, you have to replace the whole old data with some new data (in CoreData you can simply just add one more card. you won't need to replace (all-current-cards) with (all-current-cards + 1-new-card) )
I'm working on my first Angular project and I've been thinking of the best way to word this question for a while now but I'm going to give this a shot.
I'm building an app that uses the Veralite (MiOS) to return device data in json format. The first request returns all of the devices on the system (example below).
"devices":[
{
"name":"Bedroom Light",
"altid":"4",
"id":6,
"category":2,
"subcategory":0,
"room":0,
"parent":1,
"status":"0",
"level":"0",
"state":-1,
"comment":""
},
{
"name":"Office Light",
"altid":"6",
"id":18,
"category":2,
"subcategory":0,
"room":0,
"parent":1,
"level":"0",
"status":"0",
"state":-1,
"comment":""
}
Once all of the devices are returned, my script begins long polling the vera engine. Once a change to a device is made the results of the long poll are returned, but the results only include the devices that were changed (example below).
"devices":[
{
"altid":"6",
"id":"18",
"subcategory":"0",
"room":"0",
"parent":"1",
"level":"20",
"status":"1",
"state":"4",
"comment":"Office Light: Transmit was ok"
}
What I am trying to wrap my head around, is the proper way to update the existing devices array with the newly updated data. Would I need to convert them to arrays, then loop through each array and try to match them by keys?
Hopefully I asked this as clearly as possible.
EDIT: Just to update this a bit for anyone that stumbles across this, specifically people interested in developing for the Veralite. The ID returned from the original request will be returned as an integer, but when long polling the engine, the ID will be returned as a string. So even though the selected answer is correct, you'll need to either parse the updated device ID as an integer (parseInt), or only use a == instead of a === when filtering the devices.
You can loop through the object fields just like you can loop through an array with Object.keys.
Conceptually something like:
Step 1) Find the updated product, by the field id:
var previousVersionDevice = $scope.devices.filter(function(item) {
return item.id === updateDevice.id; // Keep only the one existing device that matches id
})[0];
Step 2) Loop through the keys in the product and overwrite the previous values with the ones received.
Object.keys(updatedDevice).forEach(function(key) {
previousVersionDevice[key] = updatedDevice[key]; // Overwrite/add all from updated version
});
yes, you can loop through and find the matching device via some sort of unique key (assuming id is unique and won't change, you can use that).
I am working on a project where I process a URL and get an array (containing columns and rows) using beautifulsoup. Now I need to store this data in the datastore. I cannot find any reference on storing an array in the datastore.
A multivalued property is represented in the datastore api as a python list. If you can organize the data in list, you can define a part of your data model as
class MyData(ndb.Model):
array = ndb.StringProperty(repeated=True)
In the request handler, store the data like
data = MyData()
data.array = list_you_got_from_request
data.put()