Solved

COGNITE CHARTS

  • 28 August 2023
  • 3 replies
  • 49 views

Badge +2

There is a requirement for me where the stakeholder wanted to download all the charts (120+) in one-GO for a specific date range and then validate them. There are some charts (out of 120+) that are using the timeseries objects with some calculations. (ta * tb) /1000 , (ta + tb + tc)/1000 , 141/(ta) - 131.5,……

 

I cannot go to each one of them manually and download them, but the customer wants to download them all in one and then validate as per their choice. 

 

Please advise

icon

Best answer by absqueued 29 August 2023, 12:46

View original

3 replies

HI @eashwar11,

Just checked on that for you. In Cognite Chart, you can grab each chart as a CSV, PNG, or just the Calculations rows. But, yeah, there's no feature to bulk download all charts at once.

Totally get why that'd be useful.

Out of curiosity, which format were you hoping to download them in?

Badge +2

 Thanks @absqueued . My customer is asking for a xls so that they can download all the charts in CDF. They only want the final output values (if there are some calculations attached in the chart) so that it can be validated offline. This must be specific for a particular time frame input by the user (start = date1, end = date2). 

 

Also, I am already creating a Cognite function and trying to work out this mechanism. This Cognite function can be executed manually by the client by providing the start and end and then they can derive the data. 

If you can take this design and incorporate it into the ‘Charts’ product in CDF, that would be great. 

Hope I am credited with this feature idea to recognize my contribution:) 


 

import pandas as pd
from cognite.client import CogniteClient
start=pd.Timestamp("2023-01-01")
end=pd.Timestamp("2023-01-07")

client = CogniteClient()
ts_names_list = client.time_series.list(limit=None,asset_subtree_ids=[785298418492686])

time_series_data_extids = ts_names_list.as_external_ids()

data_points = {ts: client.time_series.data.retrieve_dataframe(external_id=ts,start=start,end=end,) for ts in time_series_data_extids if not client.time_series.data.retrieve_dataframe(external_id=ts,start=start,end=end,).empty}

df_keys = list(data_points.keys())

combined_df = data_points[df_keys[0]]

# Iterate through the remaining DataFrames and merge them based on the common index
for key in df_keys[1:]:
combined_df = combined_df.merge(data_points[key], left_index=True, right_index=True)

# Print the resulting combined DataFrame containing all the keys (external_ids) and values with datapoints
combined_df

df_charts = pd.DataFrame()

# Final Dataframe for storing the charts (column wise)
df_charts['Chart03_LP_Crude API_Meter'] = (141.5/combined_df['ts-YT-LP-vol_sprod-SPG'] - 131.5)

df_charts['Chart12_LP_KERO SWUP'] = combined_df['ts-YT-LP-swpc-HK1']
df_charts['Chart13_LP_DSL SWUP'] = combined_df['ts-YT-LP-swpc-DS1']
df_charts['Chart14_LP_MVGO SWUP'] = combined_df['ts-YT-LP-swpc-SV1']
df_charts['Chart15_LP_HVGO SWUP'] = combined_df['ts-YT-LP-swpc-XV1']

df_charts['Chart18_LP_FG MFOEB'] = (combined_df['ts-YT-LP-derivedyld-VBALFG1'] * combined_df['ts-YT-LP-MBFeed-Total_Feed'])/1000
df_charts['Chart19_LP_C3C4 MFOEB'] = (combined_df['ts-YT-LP-derivedyld-VBALLP1'] * combined_df['ts-YT-LP-MBFeed-Total_Feed'])/1000
df_charts['Chart20_LP_NAPH MBBLD'] = (combined_df['ts-YT-LP-derivedyld-VBALFN1'] * combined_df['ts-YT-LP-MBFeed-Total_Feed'])/1000
df_charts['Chart21_LP_KERO MBBLD'] = (combined_df['ts-YT-LP-derivedyld-VBAL1'] * combined_df['ts-YT-LP-MBFeed-Total_Feed'])/1000


so finally, I can save this df_charts as a xls and user can download from CDF. This worked for me and ?I can see the results. 

Only thing is that it takes a while to run this snippet (like 11 minutes)

 

I'll pass the feedback along to the product team. 

Reply