Hello I have this code -
# Function to create SampleEvent entries
def create_sample_events(data):
# current_Ttime
current_time = datetime.datetime.now()
# Get IDs for ProductionEvent, ProductSample, Product, Sample, SampleSchedule for each row
for row in data:
pe_id = row['ProductionEventID']
ps_id = row['ProductSampleID']
p_id = row['ProductID']
s_id = row['SampleID']
ss_id = row['SampleScheduleID']
# Get the time for last sample taken for that ProductionEvent
last_sample_time_dataset = system.db.runNamedQuery("Scheduling/GetLastSampleEventTime",parameters={"productionEventID": pe_id})
last_sample_time = last_sample_time_dataset.getValueAt(0, 0)
# Get Interval and Offset for the SampleSchedule
intervalOffset = system.db.runNamedQuery("Scheduling/GetIntervalOffsetBySampleScheduleID",parameters = {"sampleScheduleID": ss_id})
# Get Interval value
sample_interval = intervalOffset.getValueAt(0,"Interval")
# If there is no last_sample_time use offset
if last_sample_time == None:
print("No last")
# If there is a last_sample_time
else:
# Calculate the next_sample_time by adding the interval to the last_sample_time
next_sample_time = system.date.addHours(last_sample_time, sample_interval)
I am running into an issue where if the last_sample_time takes place a day(s) before. The next sample_time will be set to day(s) earlier than it should be. I want the next_sample_time to be the last_sample_time but for the current date (or potentially the day after).