# Retrieve data from the OH2 snapDB based on specific parameters

**URL:** <http://discussions.gridprotectionalliance.org/t/retrieve-data-from-the-oh2-snapdb-based-on-specific-parameters/1296>\
**Category:** openHistorian\
**Created:** [August 15, 2024, 5:13pm UTC](http://discussions.gridprotectionalliance.org/t/retrieve-data-from-the-oh2-snapdb-based-on-specific-parameters/1296 "2024-08-15T17:13:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Renan\_Pires](http://discussions.gridprotectionalliance.org/user_avatar/discussions.gridprotectionalliance.org/renan_pires/32/1088_2.png) [@Renan\_Pires](http://discussions.gridprotectionalliance.org/u/Renan_Pires)\
**Post date:** [August 15, 2024, 5:13pm UTC](http://discussions.gridprotectionalliance.org/t/retrieve-data-from-the-oh2-snapdb-based-on-specific-parameters/1296/1 "2024-08-15T17:13:35Z")

</div>

Hello, Team,

I hope you’re all doing well.

We’re currently working on a Python API that includes a function designed to receive a list of PMUs, organized by PPAs, along with a specified time range. The purpose of this function is to retrieve the relevant data and subsequently save it locally within a DataFrame.

Here’s an example of how this part of the code looks:

```auto
time_filter = timestampSeekFilter.CreateFromRange(start_time, end_time)
point_filter = pointIDMatchFilter.CreateFromList(point_ids)

reader = instance.Read(time_filter, point_filter)
key = historianKey()
value = historianValue()

df = pd.DataFrame(columns=['Hora UTC', 'Valor', 'PPA'])

while reader.Read(key, value):
        match = re.search(r'@ (.+)', key.ToString(metadata))
        horario= match.group(1)
        #print(value.AsQuality)
        new_row = pd.DataFrame({'Hora UTC': [horario], 'Valor': [value.ToString()], 'PPA': [key.ToString().split('@')[0].strip()]})
        df = pd.concat([df, new_row], ignore_index=True)

```

As you can see, we’re using `openHistorian.historianKey` and `openHistorian.historianValue` to retrieve data from snapDB.

I have two requests for support:

1. **Decimal Precision** :  
Is there a way to adjust the returned values to display with the maximum number of decimal places?  
To address this, I modified `openHistorian.historianValue >> function ToString()` to return more decimal places, and the same adjustment was made for `openHistorian.historianKey >> function ToString()`. However, I believe there may be a more optimized and less intrusive way to achieve this goal.

2. **Data Acquisition Rate** :  
I would like to acquire data at lower rates (also specifying this parameter in the function mentioned above). For example, for PMUs that store data at 120fps, I would prefer to acquire only at 10fps. In this case, we have applications that do not necessarily require all 120 phasors to yield reliable results.

I would appreciate any suggestions you may have on both points mentioned above.

---

<div class="post-metadata">

**Author:** ![ritchiecarroll](http://discussions.gridprotectionalliance.org/user_avatar/discussions.gridprotectionalliance.org/ritchiecarroll/32/2_2.png) [@ritchiecarroll](http://discussions.gridprotectionalliance.org/u/ritchiecarroll)\
**Post date:** [August 20, 2024, 12:39am UTC](http://discussions.gridprotectionalliance.org/t/retrieve-data-from-the-oh2-snapdb-based-on-specific-parameters/1296/2 "2024-08-20T00:39:58Z")

</div>

1. I suspect you can adjust the printed precision of `historianValue` using a string format expression, for example:

```py
value = historianValue()
value.AsSingle = 59.095468

print(f"Value with 4 decimals of precision = {value.AsSingle:.4f}")

```

1. You can change the resolution of data retrieval by adjusting parameters on the `timestampSeekFilter`, for example:

```py
def TestRead(instance: historianInstance, metadata: metadataCache, startTime: datetime, endTime: datetime, pointIDList: List[np.uint64]):
    # Set interval for 10 samples per second, i.e., 0.1 seconds plus window width of 0.001 seconds
    timeFilter = timestampSeekFilter.CreateFromRangeInterval(startTime, endTime, 0.1, 0.001)
    pointFilter = pointIDMatchFilter.CreateFromList(pointIDList)

    opStart = time()
    reader = instance.Read(timeFilter, pointFilter)
    count = 0
                
    key = historianKey()
    value = historianValue()

    while reader.Read(key, value):
        count += 1
        print(f" Point {key.ToString(metadata)} = {value.ToString()}")

    print(f"\r\nRead complete for {count:,} points in {(time() - opStart):.2f} seconds.\r\n")

```
