Financial Preparedness Program with Mermaid Visualisation

Financial Preparedness Program with Mermaid Visualisation

Was trying to create a financial preparedness program with mermaid visuals using Python. After few iteration am able to create a fine grained program using python.

Problem statement :

Get input from spreadsheet on financial goals and check my Financial Preparedness (any logics can be used, here simplified) and create a mermaid chart. We are using google sheet where financial goals are set and publishing it.

Here we go..!

  1. Create google sheet with goals/data and Publish it. Sample here
  2. Get the data from csv in to Python List listexcel
  3. Write mermaid syntax as variable Merstory and replace placeholders with data from the above list. and join Merstory and Merstory1, which is the final generated mermaid code (t1)
  4. create a function which uses mermaid image renderer from base64 of t1, which render Mermaid chart.
  5. As per defined logic our financial preparedness score will be printed in text.

## The code for generating  Financial Preparedness. 

import base64
from IPython.display import Image, display
import matplotlib.pyplot as plt
import re
import csv
import requests

#Export as list from Excel
##Publish to Web as csv
##https://docs.google.com/spreadsheets/d/e/2PACX-1vQIaRbgAen22hHQ3ScWZKieaRGE0C53yVrqu80TsaP8IBeIv6YZav0ZmGztjuMdrgdKo0_3r5E8TjJD/pub?output=csv


listexcel=[]
url="https://docs.google.com/spreadsheets/d/e/2PACX-1vQIaRbgAen22hHQ3ScWZKieaRGE0C53yVrqu80TsaP8IBeIv6YZav0ZmGztjuMdrgdKo0_3r5E8TjJD/pub?output=csv"

response = requests.get(url)

reader = csv.reader(response.content.decode('utf-8').splitlines())
for row in reader:
    listexcel.append(row)

response.close()


MerStory = """
    section {no}) {Name}
    {target} :active, e1, 2025-{prio}-01, 30d
    {acheived}:done, a1, 2025-{prio}-01, {ach}d
  """
prep1=0
prep2=0
temp_variable = ""
for i in range(len(listexcel)):
  #for j in range(len(listexcel[i])):
  if (i >0):
      ach= int(listexcel[i][2]) / int(listexcel[i][1]) * 30
      temp_variable= temp_variable+re.sub(r"{Name}", str(listexcel[i][0]), MerStory)
      temp_variable= re.sub(r"{no}", str(i), temp_variable)
      temp_variable= re.sub(r"{target}", str(listexcel[i][1]), temp_variable)
      temp_variable= re.sub(r"{acheived}", str(listexcel[i][2]), temp_variable)
      temp_variable= re.sub(r"{prio}", str(listexcel[i][3]), temp_variable)
      temp_variable= re.sub(r"{ach}", str(ach), temp_variable)
      prep1 += int(listexcel[i][1])
      prep2 += int(listexcel[i][2])
      
MerStory1="""
    gantt
    title Planned Expense VS Current Fin Position For 2025
    dateFormat  YYYY-MM-DD
    axisFormat %B-%Y
    tickInterval 1month
    """
t1= MerStory1 + temp_variable
def mm(graph):
  graphbytes = graph.encode("ascii")
  base64_bytes = base64.b64encode(graphbytes)
  base64_string = base64_bytes.decode("ascii")
  display(Image(url="https://mermaid.ink/img/" + base64_string))

mm(t1)
print("You are",(prep2/prep1)*100, "% Financially Prepared")        

Output

Captured from Result of above code


Refer my Github Repo below

https://github.com/shkgiri/Learnings/blob/main/MermaidChart.ipynb

要查看或添加评论,请登录

Shankar Murali的更多文章

  • Slow or Fast - Its a Choice

    Slow or Fast - Its a Choice

    Life is a series of choices, each leading to the next, shaping the path we take. I wasn't always a book lover.

  • Create you first ML Model

    Create you first ML Model

    The feeling of creating our own first Machine learning model is Awesome - like any creation we do for the first time…

    2 条评论
  • The Personal Mastery Framework

    The Personal Mastery Framework

    (A framework for Healthy, Happy and Contented Life) Below is my Novel work, simplified for general Audience. During my…

    1 条评论
  • Vande Mukunda Hare..!

    Vande Mukunda Hare..!

    It is Krishna's Birthday, he is now 97 yrs old. He woke up at 5 am and did Yoga, Pooja and other rituals which he was…

  • What exactly is Services and Programs in Windows?

    What exactly is Services and Programs in Windows?

    This is a common question in minds of any Security Practitioners. This article will throw some light on execution of…

  • Ordinary Man with Extra Ordinary Mind

    Ordinary Man with Extra Ordinary Mind

    Once upon a time, i was walking to my new office in Bangalore. Suddenly a stranger came and ask me “where is the…

  • The Short Fable about Economy and Business

    The Short Fable about Economy and Business

    Long before Government of Richland Printed new 100 r notes and distributed to economy (citizens). We will take a sample…

    1 条评论
  • The Story of Bob and Sally - The Power of Data

    The Story of Bob and Sally - The Power of Data

    A Fictional Story Sally is working in a Search Engine company. She was assigned to experiment "behavior changing"…

  • Python Basics

    Python Basics

    Credit - MIT Open Courseware - https://ocw.mit.

  • Uniting Threat Vulnerability and Risk

    Uniting Threat Vulnerability and Risk

    I have an unclear vision for a long time on “how i can combine Risk, Vulnerability and Threat data available and use it…

社区洞察

其他会员也浏览了