Select to view content in your preferred language

Python / SQL / Model Builder help!

1456
11
10-13-2022 05:58 AM
StephenSmith8847
Emerging Contributor

Hi all,

I'm hoping someone can help me. I'm trying to follow this guide:

Previously had help from some community members and managed to get the whole flow running, however the space time cube wasn't changing dates when the parameter date changed, so i've now tried to upgrade the model and i think i have it all correct.

StephenSmith8847_0-1665665426153.png

 This is what the model now looks like. Report Date is set and can be changed (once the tool is complete) by the inputter. The calculate value then creates the start date output (which then feeds into the select layer by attribute) we then recently added another calculate value to confirm the end date range. 

Starting Report Date Python expression: datetime.datetime.strptime('%ReportDate%', '%d/%m/%Y') - datetime.timedelta(days = 365)  (Data type is set to Date)

End Report Date Python expression: datetime.datetime.strptime('%ReportDate%', '%d/%m/%Y') (Data type set to Date)

So if the Parameter ReportDate is set to 01/06/2021, the output of the Starting Report Date is 01/06/2020 and the output for the End Report Date is 01/06/2021 which is perfect and is what we want to happen as that gives us a year period, which will change dynamically based on the ReportDate.

This then feeds into the Select Laybe by attribute, the SQL expression is: 

(Date >= timestamp '%Starting Report Date%') AND (Date <= timestamp '%End Report Date%')

E.g from the input layer, please create a new layer that has the dates greater than or equal to the start date or less than or equal to end date. (I have had to select remove from current selection otherwise it has another error. I would ideally like to choose select from new layer but that throws up a bigger fault.

The error with all the above set, is as follows:

Traceback (most recent call last):
  File "<string>", line 1766, in execute
  File "c:\program files\arcgis\pro\Resources\ArcToolbox\Scripts\SSCubeObject.py", line 295, in obtainData
    self.__obtainData()
  File "c:\program files\arcgis\pro\Resources\ArcToolbox\Scripts\SSCubeObject.py", line 374, in __obtainData
    self.__parseTimeInfo()
  File "c:\program files\arcgis\pro\Resources\ArcToolbox\Scripts\SSCubeObject.py", line 495, in __parseTimeInfo
    self.timeAlignment, timeBreaks = TUTILS.createTimeBreaks(timeData, breakTimeSize, 
  File "c:\program files\arcgis\pro\Resources\ArcToolbox\Scripts\SSTimeUtilities.py", line 379, in createTimeBreaks
    if refTime <= dataStartTime:
TypeError: '<=' not supported between instances of 'str' and 'datetime.datetime'
Failed to execute (Create Space Time Cube By Aggregating Points).

 

0 Kudos
11 Replies
by Anonymous User
Not applicable

If dataStartTime is a datetime object, what is the data type of the variable refTime?

Edit to add:

The error message provides that it is the 'str' and the dataStartTime  is a datetime:

 if refTime <= dataStartTime:
TypeError: '<=' not supported between instances of 'str' and 'datetime.datetime'

so refTime is the variable you should be looking at to solve this.

0 Kudos
StephenSmith8847
Emerging Contributor

Hi,

 

It only gets selected when we get to the Space time cube inputs, but its the name of one of my fields in my dataset which will be a feature class. 

 

I think i need to create 2x more calculate values, to convert the date time object back into date time strings to then feed that into the select layer by attribute.

0 Kudos