I am trying to get a histogram object that displays the distribution output of a timeMeasureEnd block, and have managed to get the histogram to display this output as a cumulative distribution and mean.
However, one objective of my model is to the measure the hourly average and distribution of the timeMeasureEnd block, and I am unable to make the histogram object reset on an hourly basis using an event block.
At present I have the following:
An event block called HourlyReset in cyclic mode using a 1h timeout based on model time, this element is functioning correctly.
I also have a histogram provisionally called chart, that is currently displaying timeMeasureEnd.distribution, this is also functioning correctly.
However, when I specify the action for the event block as chart.reset(); I get an error message:
Description: Type mismatch: cannot convert from TimeMeasureEnd to double. Location: Histogram Test/Main/data - Histogram Data
A second approach I tried was to have the timeMeasureEnd block write to a histogram data object, and have the event block reset a histogram data object but in this instance I get the same error message.
I am clearly missing something here, and I assume it is related to the agent object that is being injected into the system by the source block.
Any pointers in the right direction would be welcomed.
You can just call the resetStats() method of the timeMeasureEnd block. Just put code like timeMeasureEnd.resetStats() inside your event and the collected statistics inside this block and therefore the histogram will be reset every time you call this function.
Good luck (and please accept this answers if it solves your problem:))
Related
I'd like to measure the time from order placement (agent Order) to delivery to the shop.
There are some delays inbetween due to assembly of the goods. But after that I need to transport it to a defined port by trucks and vice versa in the country of destination.
I figuered I have to use sources (creates my good agents) and sinks (arrival of my good at destination) for timemeasuring. So I can use TimeMeasureStart and TimeMeasureEnd but I am having trouble with how I acutally implement this in my flowchart in AnyLogic.
Any thoughts?
Thanks in advance!
Benj
Create three parameters in your order agent: timeEnter, timeLeave, timeInSystem. When the order is created, set agent.timeEnter=time() and whenever you dispose of them, type
agent.timeLeave=time();
agent.timeInSystem=agent.timeLeave-agent.timeEnter;
You can add this value into a dataSet, for example.
You can use the time measure start and time measure end blocks.
You simply place the 'start' block where you want to start measuring and the 'end' block where you want to stop measuring and then refer to the associated start block inside the end block
The screenshot is from the how to model that can be found in the AnyLogic How to examples in the Software
Or check the link here https://anylogic.help/library-reference-guides/process-modeling-library/time-in-system.html#measuring-time-in-system
Say i have an application where a REST API updates the price of a product.I want to use a Micrometer Gauge to expose the new price as a metric. I'm having trouble understanding from Micrometer documentation how this should be accomplished.
The only toDoubleFunction that worked for me was to create a new method in my ProductService which returns it's price. This seems like an overhead for every piece of data i want to expose as a metric.
What am i missing here? why product.getPrice() isn't enough to update the Gauge?
Micrometer's Gauge would hold a reference to whatever it has to pull the value from. And that reference is a WeakReference by default.
For example:
StatsdGauge
DefaultGauge
This means that should your provided value get garbage collected, micrometer would have nothing to poll the value from.
I assume that when you call product.getPrice(); you never hold on to that value just passing it to something like meterRegistry.gauge("product.price",tags,value); Since after the completion of this block of code nothing holds a strong reference to that specific value it gets Garbage Collected (GC-ed).
You have couple solutions here: either build a Gauge using a builder and specifying the strongReference(true) or (better) make sure you hold your references and manage their values yourself.
Both are rather weird as you'll end up holding a lot of "Gauge sources" in memory.
Im using anylogic in order to build a model of randomly moving cars.
In that model i want to gather some information on the agents (Cars) using a varivable and an event block.
On the model i want the event to set the variable carsLane with the lane of the car that is currently on the road and to do so every 2 seconds.
The thing is that every time the event is suppose to take place i get "NullpointerException" error and it happen so on every method of Car that im trying to use using the Event.
The event is on the Main tab and the code im using on the action box:
carsLane=Car.getLaneIndex();
On the image you can see the formation of the blocks and the code on the event's action box
Am i using the event wrong or is it something else?
Thank you for any kind of help.
This will be confusing to you, but the Agent Car that you defined in the model is NOT or does not contain the agents that are created in the carSource module, so doing carLane=Car.anything will give you an error, since the Car agent is probably empty or is not in any Lane.
To solve this, you need to do a bunch of things (and I will assume that you generate cars in your carsource in a way that there will be a maximum of 1 car in the road... if there are more, you have to do something different.
First: create a new Car agent with a population of cars, let's call it thecar (use the agent from the agent palette... not the "car type") with an initial population of 0.
This agent will be an extension of the Car type you created:
Second: In the car source, add your cars to a custom population:
And also, your car source will generate cars of the type thecar:
third: In your event now you can do:
carsLane=thecars.get(0).getLaneIndex();
And I created the model for you... find it here:
https://ufile.io/5jkqu
I need to know the relative position of an object in a list. Lets say I need to know the position of a certain wine of all wines added to the database, based in the votes received by users. The app should be able to receive the ranking position as an object property when retrieving a "wine" class object.
This should be easy to do in the backend side but I've seen Cloud Code and it seems it only is able to execute code before or after saving or deleting, not before reading and giving response.
Any way to do this task?. Any workaround?.
Thanks.
I think you would have to write a Cloud function to perform this calculation for a particular wine.
https://www.parse.com/docs/cloud_code_guide#functions
This would be a function you would call manually. You would have to provide the "wine" object or objectId as a parameter and then get have your cloud function return the value you need. Keep in mind there are limitations on cloud functions. Read the documentation about time limits. You also don't want to make too many API calls every time you run this. It sounds like your computation could be fairly heavy if your dataset is large and you aren't caching at least some of the information.
I was wondering if there is a way how to perform actions in a function after it returning a value.
i.e there is a method which returns a string. Now after the string is returned I want the method to perform another action like checking whether a condition is met so it can send out a notification or something else. Is that somehow possible?
The thing is that I am using a framework called core plot to add some plots to my application. Unfortunately this framework does not have a didFinishAddingPlot method. So I have to manually program a mechanism which notifies me whenever the plot finished plotting. When the addPlot method is called another method is called which goes through an array of values and returns a value for a specific index to plot. My idea was to put in a "if (condition)" block to check if the index is equal to the count of my values array so I know that it is now fetching the last value. However it first needs to return the value before sending a message that it finished plotting. Otherwise the last value won't get passed.
As soon as a function hits a return statement the function stops running. You would need to perform whatever other action you want to do before you return.
So, you want to return a value from your function or method, which by definition returns control (as well as your answer) to the call site. On the face of it, it's not possible; you've returned control, so you're done.
But you could spawn a new Thread during your method execution, to (for example) perform some cleanup tasks later on.
Since you tagged the question as Cocoa, check out Apple's Threaded Programming Guide, which will teach you about NSThread, POSIX threads, and more.