# Convert historical status (string) data to integers

**URL:** <https://forum.inductiveautomation.com/t/convert-historical-status-string-data-to-integers/98473>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [November 11, 2024, 5:19pm UTC](https://forum.inductiveautomation.com/t/convert-historical-status-string-data-to-integers/98473 "2024-11-11T17:19:38Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Seth\_Johnson](https://avatars.discourse-cdn.com/v4/letter/s/c57346/32.png) [@Seth\_Johnson](https://forum.inductiveautomation.com/u/Seth_Johnson)\
**Post date:** [November 11, 2024, 5:19pm UTC](https://forum.inductiveautomation.com/t/convert-historical-status-string-data-to-integers/98473/1 "2024-11-11T17:19:38Z")

</div>

Can I take a table of historical string values denoting run status (eg R, Q, S, etc) and convert them to integers?

I figured it would be as easy as mapping a transform in the tag history binding eg R = 1, fallback = 0, but it seems to treat the dataset like a single data point... any help is appreciated.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/b/6b1a644da15de81c405b25e7b32acaaf8ada0264.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/a/aaa0e76c72aca493dee9bd24f67f084f539546dc.png)

---

<div class="post-metadata">

**Author:** ![sydney.bosworth](https://avatars.discourse-cdn.com/v4/letter/s/aca169/32.png) [@sydney.bosworth](https://forum.inductiveautomation.com/u/sydney.bosworth)\
**Post date:** [November 11, 2024, 5:37pm UTC](https://forum.inductiveautomation.com/t/convert-historical-status-string-data-to-integers/98473/2 "2024-11-11T17:37:30Z")

</div>

Are you just displaying it in a table? If so, you could look into using a view for that column and do your convert in the view.  
There may be a way to do the map like you are wanting, I just have never messed with it/seen it done. Aside from the good ole loop thru the dataset and changing...but I'd see that as least efficient most likely.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [November 11, 2024, 5:54pm UTC](https://forum.inductiveautomation.com/t/convert-historical-status-string-data-to-integers/98473/3 "2024-11-11T17:54:55Z")

</div>

You could do it in a transform, but there is an efficiency hit:

```python
mapDict = {'Q' : 4,
           'R' : 1,
		   'S' : 2
		  }

headers = list(value.columnNames)

# dict.get() can return a default value if the key is not found in the dictionary.
data = [[value.getValueAt(row,0), mapDict.get(value.getValueAt(row,1), 0)] for row in xrange(value.rowCount)]

return system.dataset.toDataSet(headers, data)

```

But, you may want to consider putting the raw data in a custom prop and use @pturmel's [Integration Toolkit module](https://forum.inductiveautomation.com/t/automation-professionals-integration-toolkit-module/74934) to do the transform as an expression. Much more performant.

---

<div class="post-metadata">

**Author:** ![Seth\_Johnson](https://avatars.discourse-cdn.com/v4/letter/s/c57346/32.png) [@Seth\_Johnson](https://forum.inductiveautomation.com/u/Seth_Johnson)\
**Post date:** [November 11, 2024, 6:11pm UTC](https://forum.inductiveautomation.com/t/convert-historical-status-string-data-to-integers/98473/4 "2024-11-11T18:11:47Z")

</div>

I'm not too worried about performance, this data is updated once a minute and it's just a proof of concept. The dataset is created in the tag binding - I'm not sure how to transform it via code or even how to reference it, so I would need a bit of help there.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/f/8feb0ee4856e41b2e7d1b706a9b56af6cfb54419.png)

Thanks for the replies so far!

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [November 11, 2024, 6:27pm UTC](https://forum.inductiveautomation.com/t/convert-historical-status-string-data-to-integers/98473/5 "2024-11-11T18:27:42Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/c/1c7884e2c3b53efe440716edd86c6f5d4540a395.png)

Try using a script transform using the sample code I posted. You will need to adjust the dictionary to your specific needs.

'value' in a transform is whatever the result is of the step before it-- in this case, a dataset.

---

<div class="post-metadata">

**Author:** ![Seth\_Johnson](https://avatars.discourse-cdn.com/v4/letter/s/c57346/32.png) [@Seth\_Johnson](https://forum.inductiveautomation.com/u/Seth_Johnson)\
**Post date:** [November 11, 2024, 6:38pm UTC](https://forum.inductiveautomation.com/t/convert-historical-status-string-data-to-integers/98473/6 "2024-11-11T18:38:06Z")

</div>

> [@JordanCClark](#):
>
> `data = [[value.getValueAt(row,0), mapDict.get(value.getValueAt(row,1), 0)] for row in xrange(value.rowCount)]`

Thank you, I'm on the right track now. I appreciate the explanation.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/4/04c760599130b674cc98bfcf6c06c224bf6f13b0.png)

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [November 11, 2024, 8:19pm UTC](https://forum.inductiveautomation.com/t/convert-historical-status-string-data-to-integers/98473/7 "2024-11-11T20:19:26Z")

</div>

Add your two columns to the `columns` property of the table, then configure the `t_stamp` column's `render` property to `datetime`, so you get something readable.  
Also, it seems kinda weird to convert the status to a boolean when there are more than 2 different possible values.  
I'd probably keep the original value, and add a new column, or some particular row styling (maybe a background color) to indicate whether the status is R or something else.  
But I don't know your use case, so don't blindly listen to me.

---

<div class="post-metadata">

**Author:** ![Seth\_Johnson](https://avatars.discourse-cdn.com/v4/letter/s/c57346/32.png) [@Seth\_Johnson](https://forum.inductiveautomation.com/u/Seth_Johnson)\
**Post date:** [November 11, 2024, 8:27pm UTC](https://forum.inductiveautomation.com/t/convert-historical-status-string-data-to-integers/98473/8 "2024-11-11T20:27:10Z")

</div>

Converting status strings to integers so I can use them graphically in a time series output - not using the table itself, it was just helpful to understand the dataset.
