date parameter updated with time Anylogic - date

I'm using Anylogic and I would like to assign a parameter of type date to each agent (agent is a customer), called DueDate, that represents deadline to his machine failure. My goal is to update value parameter and make it shorter as model time passes (because the failure date is coming). There is some function or code that I can use? I also want to assign a priority parameter to agent that increases when failure date is nearest, so that in queue a customer with a failure nearest is processed before agents with lower priority. How can I do?
Thanks at all

This question seems to contradict itself somewhat. The parameter described is a Due Date, therefore, by definition, should be fixed. Yet, parameter value should be updated as failure date is coming. Do you mean that there should be two parameters: 1) Due Date and 2) remaining time until Due Date? If so this can be achieve like this:
Due Date - if you want to set due date at 10 time units after model start, you can make a parameter (call it p_dueDate of type ) and use timeToDate(100.0) function (help entry).
Remaining time - create a function in the agent f_getRemainingTime() with this code:
return dateToTime(p_dueDate) - time();
where dateToTime() will convert the p_dueDate value back into a double value representing simulation's time units and time() returns current simulation time (also as a double value).
so, let's say for a model starting on 1st Jan with time units = days; offset of 10 will result in p_dueDate = 10th Jan and on 3rd of Jan f_getRemainingTime() will return 7.0.

Related

AnyLogic: Change parameter at certain times with events

I want to change the parameter parSize at certain times. For example, the parameter parSize should be equal to 50 at XX:XX o'clock and equal to 30 at YY:YY o'clock. This change of the parameter is repeated every day at the same time.
The time when the parameter should be changed can be entered manually by the end user before the simulation starts. The parameters for each time are stored separated by hour and minutes as int.
My approach is to trigger a cyclic event for each parameter change, which repeats every day at time XX:XX, YY:YY, etc.
Is there a better way to change parameters at a certain time of the day (repeated everyday)?
How can I trigger an event with my input int parameters (one for hour, one for minutes) of the time? So that occurrence date not set manually in the selection window, but by code and my end user input parameters?
Use a DynamicEvent object named MyDynamicEvent instead.
Give it 2 arguments of type double:
minsToDailyChange (in mins since midnight).
newValue
For each of the 7 changes per day, call create_MyDynamicEvent(0, SECOND, minsFromMidnightForThisChange, newValue) on the start of the model
In the action code, write:
set_parSize(newValue);
create_MyDynamicEvent(24, HOUR, minsFromMidnightForThisChange, newValue)
Now, you have 7 parallel DEs that manage themselves and will change the value every 24 hrs to the new value required.

How to count no of agents who have spent X days in the system in Anylogic

I am building invoice processing simulation model. invoice creation date is the source generation date . Every Invoice will have due date which varies. 31 days, 60 days, 90 days.
Any agent generated at resource I can add these days to the source generation date and get due date. Next step is at point I should know how many invoices are past due date .
e.g 10 invoices are between 1- 5 days, 15 invoices are between 6 to 20 days etc. I have created three variable in the agent population. Start time, end time and Due time
double DueTime= (time()-dateToTime (due_date));
This is calculating DueTime correctly.
Then in the main I am trying to compute the count of agent
int x_1_5= count( invoices, p -> p.DueTime >1 && p.DueTime<=5 );
age_1_5=String.valueOf(x_1_5);
This is giving me 0 as output.
Is there a way to do do this ?
You are only calculating your DueDate variable once at the start of the agent creation.
You need to turn it into a function getDueTime() that returns the double value when called. Just paste return (time()-dateToTime (due_date)); into the function and then in your counter call
int x_1_5= count( invoices, p -> p.getDueTime() >1 && p.getDueTime()<=5 );
Variables do not act like functions and vice versa.
Tried this approach. Created function in Invoice agent and then calling it on the main inside another function. But it is throwing error .

How to use a date in a logical condition in Dialogflow CX

I am brand new to Dialogflow CX and am having trouble figuring out how to use a date in a condition. I want to require that a birthdate be entered and be greater than 2000-01-01. I have tried
$intent.params.dob.resolved > 2005-01-01
with and without quotes, but it does not work (always false). I discovered that $intent.params.dob.original > "1/1/01" is resolved as True for all dates, so that is of no help.
Is there a way that works?
To achieve your described use case, you can utilize the condition route or conditional response to return a response according to the condition. Here is a condition you may use:
$intent.params.birthdate.resolved.year > 2000 OR
($intent.params.birthdate.resolved.year = 2000 AND
$intent.params.birthdate.resolved.month > 1) OR
($intent.params.birthdate.resolved.year = 2000 AND
$intent.params.birthdate.resolved.month = 1 AND
$intent.params.birthdate.resolved.day > 1)
Here are examples for your reference:
A. Using the condition in the Conditional Response
B. Using the condition as the Condition Route:
Please note that the birthdate parameter isn’t a string parameter. It is composed of year, month, and day sub-parameters so it is appropriate to utilize them for your use case. Also, note that dates are in ISO-8601 format. For more information, you can refer to the System Entities documentation.
Here are the following results using the condition defined in the conditional response:
When the user enters the same year but not January 1st
When the user enters an invalid date
When the user enters a previous date from 2000-01-01
When the user enters a valid date and latest from 2000-01-01
I guess $intent.params.dob.resolved returns a string, so you need to build a date object firstly, and then compare it with your date.
I encountered a similar problem a few weeks ago. Thing is, Dialogflow actually defaults to string parameters: this means that every value entered as a parameter will (by default) be a string, surrounded by "quotes".
To operate comparisons between dates you'd want to compare integers/numbers, and I think the best way to do so is to take advantage of date system entities.
For example, the system entity
#sys.date
allows you to match a date inserted by the user. Then the best part is, in your condition, you can even manage the date by referencing sub-parts. Here is an example:
if $intent.params.dob.year <= 2005 AND $intent.params.dob.month <= 04:
I'm sorry, you're too young to use this service!
endif
Also, on a side note, "intent parameters" actually become "session parameters" as soon as Dialogflow makes a step from the state in which the parameter was set to another page.
This means that if you set the parameter dob when the user says "I was born on the thirteen of July, 2004" and then you go on to a new page, that parameter will only be accessible as $session.params.dob (and session parameters don't have a "resolved value", they are resolved by default).
So, to recap. Make sure you're using the system date entity. Make conditions for all the parts of the date you need to verify (year, month, day) and try to use your parameter as a session parameter.
I hope at least some of what I wrote can help you, happy bot-building!

FormCalc Date function doesn't returns current system date

How do I get date function to return date according to current system date?
Right now, with the code snippet below, it always returns UK time, not the current system date.
<calculate>
<script>$ = concat( num2date(date(), DateFmt()), " ", num2Time(Time(), TimeFmt()) )</script>
Any help is appreciated!
It's probably not UK time exactly, but rather GMT (or UTC, to use a more precise term). The UK happens to be aligned to GMT in the winter, but in the summer it advances one hour to BST for daylight saving time.
Now, I've never used LiveCycle myself, but nonetheless, I've read through the somewhat minimal docs for LiveCycle FormCalc Date and Time Functions, and the spec, and it appears to me that a few critical mistakes were made.
The date and time functions return UTC-based values, but only the time-related functions have been made aware of the local time zone. That is, there are separate Num2Time and Num2GMTime functions, but there is only one Num2Date function.
The Num2Date function works in terms of whole integer days, and thus they are simply days since 1900-01-01. Therefore, the number being passed in to the function must already be representative of the desired time zone. However, the Date function only gets the current GMT date. There does not appear to be a function to get the current local date.
It's different on the time side, because of the millisecond precision involved. However, there's yet another flaw here. Despite the docs saying that the Time function returning "the number of milliseconds since the epoch", its actually returning only the number of milliseconds since midnight GMT. There is no day-over-day accumulation of milliseconds from the date part. The docs here are even lying in their sample code which says:
Returns the current system time as the number of milliseconds since the epoch.
Time() => 71533235 at precisely 3:52:15 P.M. on September 15th, 2003 to a user in the Eastern Standard Time (EST) zone.
If that was indeed the case (and ensuring to use their 1900-01-01 epoch), the value would actually include an additional 3272572800000 milliseconds representing the days between 1900-01-01 and 2003-09-15, bringing the total timestamp to 3272644333235. Additionally, there's a typo there, because the timestamp they give is 3:52:13, not 3:52:15. Clearly nobody paid close attention to these docs!
The real problem is that one cannot be certain that the number of milliseconds since midnight of the current day in the local time zone is the same on every day. If instead of getting the current time, you were working with past stored time values, you might be an hour off (+ or -) if the current offset is different due to daylight saving time. Example: Eastern time might be UTC-5 or UTC-4, but only the offset currently in effect will be used by the Num2Time function, even if the date you're working with is using the other offset.
So, in summary, the Date function is insufficient, leading to your observations, and the date/time functionality in general is poorly designed. Given the constraints of this API, I can't even recommend a workaround. There would have to be a LocalDate function of some kind to be used instead of the Date function, but it doesn't exist.
The only advice I can offer is that it appears (from my research, not experience) that LiveCycle can use either FormCalc or JavaScript. So - use JavaScript instead.

Jasperreports time series chart timePeriod Expression

I have dataset with 00:00:00,00:00:15...
how to set it to be the timePeriod Expression to show one day's time from 00:00:00 to 23:59:59
i put (Date)new SimpleDateFormat("HH:mm").parse($F{time}) into the timePeriod Expression
but the chart just show one time point
If you don't have gaps you can use Line chart like DeGriz's link to Tarnschaf's answer.
If you may have gaps or would like to summarise the data ensure you use <timeSeriesDatasettimePeriod="Second"> or perhaps timePeriod="Minute" otherwise it tends to default to something large like a year, hence one data point.
THE JASPERREPORTS ULTIMATE GUIDE: Time Period Expression
This expression returns a java.util.Date value from which the engine will extract the
corresponding time period depending on the value set for the timePeriod attribute
mentioned earlier in the Time Series dataset. For instance, if the chart is about yearly
data, the engine will extract only the year from the date value, or if you are gathering
monthly data, the engine will use only the month value from the date object returned by
this expression.
I think you may also be asking to set the Min and Max for the axis to exactly one day, for this I believe you can use <domainAxisMinValueExpression> and <domainAxisMaxValueExpression>