Quickstart =================== Let’s simulate a use case where we take a june edition report Gummy Bear Price Report June 2023 and we want to convert it to July report automatically. Step 1: We authenticate using our PW and Password ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. code:: ipython3 # Import necessary libraries import pandas as pd import numpy as np from richviewsdk import RichViewSession, ParagraphBlock with open('pws.txt') as f: email, password = f.read().split(',') session = RichViewSession.authenticate_with_password(email, password) session .. parsed-literal:: Step 2: Let’s retrieve all the RichView reports in our account ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The reports are represented with their ID and title in our console. .. code:: ipython3 reports = session.get_reports() reports .. parsed-literal:: [RichViewReport(id=de270fac-2e8d-4107-b369-dc068290b2d7, title=RichView Tutorial), RichViewReport(id=dbed2de0-9cf1-4c16-a6bf-a25eb0021f57, title=Sample Report - Demise of SVB), RichViewReport(id=5de821c5-4ff0-4374-9725-2f78728031fc, title=GummiesJune23)] Step 3: Let’s choose the report named GummiesJune23 of the reports and retrieve it ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. code:: ipython3 old_report = next(report for report in reports if report.title == 'GummiesJune23') old_report .. parsed-literal:: RichViewReport(id=5de821c5-4ff0-4374-9725-2f78728031fc, title=GummiesJune23) Step 4: Let’s duplicate the report and renames it GummiesJuly23 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ We see it’s directly with the new title .. code:: ipython3 report = old_report.duplicate() report = report.set_title('GummiesJuly23') report .. parsed-literal:: RichViewReport(id=ada1e699-519a-4bfa-aae6-b6e51020fce5, title=GummiesJuly23) Step 5: Let’s see how the report is built ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Each block type has its own unique index allowing for fast updates and preventing report corruption. We can quickly query them based on their text or content. .. code:: ipython3 report.get_blocks() .. parsed-literal:: [ImageBlock(id=BLI6RSGmTp, caption=), HeaderBlock(id=BacaW7lbzt, text=Gummy Bear...), ParagraphBlock(id=ayIQwbGZFq, text=Our analys...), EmbedBlock(id=6_fkJcT4h5, service=youtube), ParagraphBlock(id=rO30-mrKUT, text=Gummy Bear...), ParagraphBlock(id=cBAJQMsa0M, text=Here's a c...), TableBlock(id=1pMboyLLGd), ParagraphBlock(id=tK_WIGzNKl, text=We appreci...), ChartBlock(id=TT0Fw_xjqq, title=Gummy Bear Price Index)] Step 6: Let’s query the report for all the charts ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Charts are what makes RichView special - we provide few unique functions for ChartBlocks. .. code:: ipython3 charts = report.get_charts() charts .. parsed-literal:: [ChartBlock(id=TT0Fw_xjqq, title=Gummy Bear Price Index)] Step 7: Let’s now get the chart we want to update by it’s ID ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. code:: ipython3 chart_id = [chart.block_id for chart in charts if chart.title == 'Gummy Bear Price Index'][0] chart = report.get_chart(chart_id) chart .. parsed-literal:: ChartBlock(id=TT0Fw_xjqq, title=Gummy Bear Price Index) Step 8: Let’s retrieve the data of the chart to see how it’s structured ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. code:: ipython3 old_data = chart.get_data().round(2) old_data .. raw:: html
Gummy Bear Price Index | Line
Category
2021-06-01 6.11
2021-06-02 6.08
2021-06-03 6.15
2021-06-04 6.33
2021-06-05 6.29
... ...
2023-06-25 4.50
2023-06-26 4.74
2023-06-27 4.78
2023-06-28 4.79
2023-06-29 4.70

759 rows × 1 columns

Step 9: Let’s generate a fresh of data for the chart ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Some Simulated prices of delicious Gummy Bears! .. code:: ipython3 # Setting a seed for reproducibility np.random.seed(42) # Define parameters start_date = pd.to_datetime('2023-06-29') end_date = pd.to_datetime('2023-07-31') n_days = (end_date - start_date).days start_price = old_data.iloc[-1, 0] drift = 0.0001 # Slight upward trend volatility = 0.02 # Some randomness seasonality_amplitude = 0.10 # Amplitude of seasonal component # Generate dates dates = pd.date_range(start=start_date, periods=n_days) # Generate random walk component random_walk = np.random.normal(drift, volatility, n_days).cumsum() # Generate seasonal component seasonality = seasonality_amplitude * np.sin((dates.dayofyear / 365) * 2 * np.pi) # Combine components to generate prices prices = start_price * np.exp(random_walk + seasonality) # Create DataFrame new_data = pd.DataFrame(data={'Category': dates, 'Gummy Bear Price Index | Line': prices}) new_data.set_index('Category', inplace=True) new_data.index = new_data.index.strftime('%Y-%m-%d') new_data .. raw:: html
Gummy Bear Price Index | Line
Category
2023-06-29 4.767867
2023-06-30 4.747002
2023-07-01 4.801104
2023-07-02 4.941580
2023-07-03 4.910525
2023-07-04 4.879671
2023-07-05 5.028104
2023-07-06 5.097623
2023-07-07 5.041834
2023-07-08 5.088631
2023-07-09 5.033580
2023-07-10 4.978914
2023-07-11 4.995065
2023-07-12 4.799870
2023-07-13 4.629736
2023-07-14 4.570713
2023-07-15 4.471993
2023-07-16 4.493120
2023-07-17 4.405363
2023-07-18 4.276009
2023-07-19 4.396395
2023-07-20 4.369855
2023-07-21 4.369070
2023-07-22 4.239880
2023-07-23 4.187639
2023-07-24 4.190651
2023-07-25 4.089195
2023-07-26 4.113957
2023-07-27 4.058885
2023-07-28 4.029420
2023-07-29 3.975496
2023-07-30 4.119657
Step 10: Let’s update the data of the chart and changes the chart type ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Any block can be directly updated only with set\_\* functoins. I do not need to keep track what was the ID of the report where the chart was - everything is neatly linked together. If I want to keep the old object for safety purposes, I can, by default, all set\_\* functions return a fresh object synced with the server, I can store the old one to be able to revert to it .. code:: ipython3 all_data = pd.concat([old_data, new_data]) all_data = all_data.rename( columns={'Gummy Bear Price Index | Line': 'Gummy Bear Price Index | Area'}) #Lets change chart type chart = chart.set_data(all_data.round(2)) Step 11: Let’s update the title of the chart ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. code:: ipython3 chart = chart.set_title('Gummy Bear Price Index July Update') Step 12: Let’s add a paragraph of the text ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Then we use either the UI or the Python SDK to tweak and update the remaining blocks. .. code:: ipython3 paragraph = ParagraphBlock(report.report_id, 'I can add some autogenerated maybe?', session) report.add_block(paragraph) .. parsed-literal:: ParagraphBlock(id=79xb69PMpu, text=I can add ...)