# Reporting Is Connected (Online) Filter

**URL:** <https://forum.inductiveautomation.com/t/reporting-is-connected-online-filter/39404>\
**Category:** Ignition\
**Created:** [October 6, 2020, 12:53am UTC](https://forum.inductiveautomation.com/t/reporting-is-connected-online-filter/39404 "2020-10-06T00:53:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dion.botha](https://avatars.discourse-cdn.com/v4/letter/d/46a35a/32.png) [@dion.botha](https://forum.inductiveautomation.com/u/dion.botha)\
**Post date:** [October 6, 2020, 12:53am UTC](https://forum.inductiveautomation.com/t/reporting-is-connected-online-filter/39404/1 "2020-10-06T00:53:10Z")

</div>

Hello,

I need to report the amount of time a machine is actually online between 2 timestamps. I tried to do this with a Tag Calculation Query on the ‘Is Connected’ Modbus OPC diagnostic tag using the ‘Duration On (Seconds)’ calculation. Unfortunately, the connection to the machine is unreliable and so the modbus ‘Is Connected’ tag goes up and down all the time. As a result, the ‘Duration On (Seconds)’ calculation is much less than it actually should be.

To get around this, I am trying to ‘filter’ the ‘Is Connected’ tag such that it needs to be off for a certain duration for me to actually count it as turned off.

This is what I came up with:

```auto
	onlineFilterSeconds = data['OnlineFilterSeconds']
	
	path = ['[default]Meissner Filtration Products/Production/ESRT01/_Diagnostics_/Is Connected']
	startTime = data['StartTime']
	endTime = data['EndTime']
	columnNames = ['is connected']
	dataset = system.tag.queryTagHistory(paths=path, startDate=startTime, endDate=endTime, columnNames=columnNames, noInterpolation=1, ignoreBadQuality = 1, timeout = 10000)
	
	#find first online timestamp
	if dataset.getValueAt(0, 'is connected') == 1:
		i = 1
	else:
		i = 2

	#delete every row pair that is less than onlineFilterSeconds
	while True:
		try:
			offlineTime = dataset.getValueAt(i, 't_stamp')
			onlineTime = dataset.getValueAt(i + 1, 't_stamp')
			if system.date.secondsBetween(offlineTime, onlineTime) < onlineFilterSeconds:
				dataset = system.dataset.deleteRow(dataset, i)
				dataset = system.dataset.deleteRow(dataset, i)
			else:
				i = i + 1
		except:
			break	
	data['FilteredOnline'] = dataset

```

If I place that code (with a little tweaking) on a button in a vision window it works but it is returning the original dataset in the reporting module preview…

Any ideas?

I have not tried generating a real report (without the designer report preview mode) - will try tomorrow.

---

<div class="post-metadata">

**Author:** ![dion.botha](https://avatars.discourse-cdn.com/v4/letter/d/46a35a/32.png) [@dion.botha](https://forum.inductiveautomation.com/u/dion.botha)\
**Post date:** [October 7, 2020, 2:11pm UTC](https://forum.inductiveautomation.com/t/reporting-is-connected-online-filter/39404/2 "2020-10-07T14:11:07Z")

</div>

Figured it out, I had the default value for my `OnlineFilterSeconds` report parameter set to `0` instead of something that would actually filter.
