Skip to main content

Hey. Hey. I need some way to automate adding a time interval to a script in pythoncaller see attachment. I have a regular WS which I don't publish directly to the server, however it is not a problem to publish to the server, I have it available as well. It depends on whether the automation will be handled within some workspace or by some setting on the server, I don't know what your advice implies.

So I have a calendar created in postgress DB see attachment, where I have airac_start and airac_end values - this is the time interval. I need to add these values to a script in pythoncaller ( there are two in WS ). This addition would happen by pasting the source files somewhere on disk ( probably watching for a change in the contents of the folder would be like a trigger ), which would start the whole process and depending on what cycle should be running, the airac_start and airac_end values would be added to the script. Can anyone think of any way to automate this thing? The way I work now is that each cycle I have to open the script and manually edit the date and time.

Thank you very much.

One way to do this:

  • Upstream of the PythonCaller
  • Add a DateTimeStamper.
  • Add a FeatureReader to read the postgres table with the calender. In the FeatureReader, set merge attributes, so the timestamp created in the previous step is merged.
  • Now use a Tester to check which record datetimenow is in.
  • In the PythonCaller, use the attributes from the selected row from the table as input.

Hey, thanks for the answer.

Could you please elaborate on the steps? I'm probably not able to make the required function work. How do I get the script to be edited with the new time interval? Or how do I achieve that the correct time interval is selected from the database?

Thank you


Hey, thanks for the answer.

Could you please elaborate on the steps? I'm probably not able to make the required function work. How do I get the script to be edited with the new time interval? Or how do I achieve that the correct time interval is selected from the database?

Thank you

Certainly. You can use feature.getAttribute('<attributename>') to use attributes from features in your script in the PythonCaller. I am by no means a Python expert, but I attached a workspace demonstrating what I described above.

 

 


Hey. Hey,

aha, I think I understand the part where pythoncaller sets the airac_start and airac_end attribute values using GET. It will probably be more complicated, but I'll have to debug that somehow. However, I don't really know how to incorporate a database where I have a defined calendar and how to automate that the correct value for airac_start and airac_end attribute is reached with the database calendar. Or should I try to solve it through the featureMerger as you write?


Maybe it could be solved based on the cycles performed ( workpacs run ), using counter. And the database would select the airac_start and airac_end data of the cycle (attribute cycle ) that would correspond to the counter value. But it's probably less systemic than what you write. 

Do I understand correctly that in attributeCreator and attributeCreator_2 I would have to always add the date manually? The timestamp on attributeCreatoru_3 is certainly a good idea, but how to work to get the correct airac date from the database? I can think of one rule that might be applicable except for one month ( october ) - cycle number and month timestamp equals calendar month airac_end. So create some binding where the calendar month in timestamp must be the same month as the airac_end row? I don't know well, it all seems so complicated to me...an "over the wall" solution. What do you think?


That is how I would solve it, reading the data you need using a FeatureReader, select the row you need using a Tester and use that row as initiator for your PythonCaller and use the attributes in your script.


Maybe it could be solved based on the cycles performed ( workpacs run ), using counter. And the database would select the airac_start and airac_end data of the cycle (attribute cycle ) that would correspond to the counter value. But it's probably less systemic than what you write. 

Do I understand correctly that in attributeCreator and attributeCreator_2 I would have to always add the date manually? The timestamp on attributeCreatoru_3 is certainly a good idea, but how to work to get the correct airac date from the database? I can think of one rule that might be applicable except for one month ( october ) - cycle number and month timestamp equals calendar month airac_end. So create some binding where the calendar month in timestamp must be the same month as the airac_end row? I don't know well, it all seems so complicated to me...an "over the wall" solution. What do you think?

AttributeCreator and AttributeCreator_2 are in the sample workspace to simulate the data loaded from the agenda table in postgres, as I do not have you data. You need to replace those with a FeatureReader reading the postgres table.


Oh, I see...and the attributeCreator_3 function is to generate the current time, do I understand correctly? Sorry for the possibly stupid questions, but I've never used attributeCreator in this way.


I tried saving the WS as FMWT, my data should be cached.

 

Thank you


Oh, I see...and the attributeCreator_3 function is to generate the current time, do I understand correctly? Sorry for the possibly stupid questions, but I've never used attributeCreator in this way.

Correct. Can also be done in the Tester but this is more clear. And no stupid questions :)


I tried saving the WS as FMWT, my data should be cached.

 

Thank you

It is cached. I edited it as I think you need it to work. Now there are 2 rows for today’s date, but I guess that is just finetuning.


Great. This already makes sense to me, I can work this out and debug it, at least I hope so 🙂 I still didn't understand the individual attributeCreators there, now I understand.

Thanks a lot for the support.


Cheers 🙂 happy I could help.


Reply