Skip to content

Commit

Permalink
chore: apply ruff on project except algo.py
Browse files Browse the repository at this point in the history
  • Loading branch information
RiwsPy committed Jun 13, 2024
1 parent e616e6a commit e347acb
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 79 deletions.
5 changes: 2 additions & 3 deletions app/config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

# CUSTOMIZE IF NEEDED
APP= "app/"
# APP= "app/" OR ""
APP = "app/"
# APP= "app/" OR ""

# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# AUTO
Expand Down
54 changes: 27 additions & 27 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
from taipy.gui import State, Gui, navigate, get_state_id
from app import config as cfg
import pandas as pd
from taipy.gui import Gui, State, navigate # ,get_state_id

from app.pages.company.company import company_md, on_init as on_init_company
from app import config as cfg
from app.pages.company.company import company_md
from app.pages.company.company import on_init as on_init_company
from app.pages.contact.contact import contact_md
from app.pages.download.download import download_md
from app.pages.home.home import home_md, on_init as on_init_home
from app.pages.home.home import home_md
from app.pages.home.home import on_init as on_init_home
from app.pages.keystories.keystories import keystories_md
from app.pages.methodology.methodology import methodology_md
from app.pages.root import root

import pandas as pd

# Global variables
# APP
APP_TITLE = "Taxplorer"
Expand All @@ -19,28 +20,31 @@
MAX_YEAR_OF_REPORTS = 2021
PATH_TO_DATA = f"{cfg.DATA}/data_final_dataviz.csv"

data:pd.DataFrame = None
data: pd.DataFrame = None


def on_init(state: State):
# print('MAIN ON_INIT...')
# print(f'MAIN STATE {get_state_id(state)}')

# Init data
init_data(state)
# Call company on_init
on_init_company(state)
# Call company on_init
on_init_home(state)

# print('MAIN ON_INIT...END')

# Performance optimization
on_init_home(state)

# print('MAIN ON_INIT...END')


# Performance optimization
def init_data(state: State):
df = pd.read_csv(f"{PATH_TO_DATA}", sep=",", low_memory=False, encoding='utf-8')
df = pd.read_csv(f"{PATH_TO_DATA}", sep=",", low_memory=False, encoding="utf-8")
# Filter dataset with the maximum year to take in account
df = df.loc[df["year"] <= MAX_YEAR_OF_REPORTS].reset_index()
state.data = df

state.data = df


# Add pages
pages = {
"/": root,
Expand All @@ -49,9 +53,10 @@ def init_data(state: State):
"Company": company_md,
"Methodology": methodology_md,
"Contact": contact_md,
"Download": download_md
"Download": download_md,
}


# Functions used to navigate between pages
def goto_home(state):
navigate(state, "Home")
Expand All @@ -78,18 +83,15 @@ def goto_download(state):


# Initialise Gui with pages and style sheet
gui_multi_pages = Gui(
pages=pages,
css_file="css/style.css"
)
gui_multi_pages = Gui(pages=pages, css_file="css/style.css")

# Customize the Stylekit
stylekit = {
"color_primary": "#021978",
"color_secondary": "#C0FFE",
"color_paper_light": "#FFFFFF",
"color_background_light": "#FFFFFF",
"font_family": "Manrope"
"font_family": "Manrope",
}


Expand All @@ -105,7 +107,7 @@ def goto_download(state):
watermark="LOCAL DEVELOPMENT",
)
else:
## PRODUCTION
## PRODUCTION
# Start the app used by uwsgi server
web_app = gui_multi_pages.run(
dark_mode=False,
Expand All @@ -116,9 +118,7 @@ def goto_download(state):
debug=False,
# Remove watermark "Taipy inside"
watermark="",
# IMPORTANT: Set the async_mode to gevent_uwsgi to use uwsgi
# IMPORTANT: Set the async_mode to gevent_uwsgi to use uwsgi
# See https://python-socketio.readthedocs.io/en/latest/server.html#uwsgi
async_mode='gevent_uwsgi'
async_mode="gevent_uwsgi",
)


10 changes: 5 additions & 5 deletions app/page.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import inspect
from taipy.gui import Markdown
from app import config as cfg


class Page:
def __init__(self, id:str):
self.id= id
def __init__(self, id: str):
self.id = id

def markdown(self) -> Markdown:
# caller = inspect.currentframe().f_back
# print("PAGED Called from module", caller.f_globals['__name__'])
# print(f"{cfg.PAGES_PATH}/{self.id}/{self.id}.md")
return Markdown(f"{cfg.PAGES_PATH}/{self.id}/{self.id}.md")
return Markdown(f"{cfg.PAGES_PATH}/{self.id}/{self.id}.md")
10 changes: 7 additions & 3 deletions app/pages/_header/_header.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
from taipy.gui import navigate
from app import config as cfg

from app import config as cfg
from app.page import Page

page_id="_header"
page_id = "_header"


def to_text(val):
return "{:,}".format(int(val)).replace(",", " ")


# Path to image
taxplorer_logo_path = f"{cfg.IMAGES}/taxplorer-logo.svg"

Expand All @@ -17,9 +20,10 @@ def to_text(val):
("/Company", "Company"),
("/Methodology", "Methodology"),
("/Contact", "Contact"),
("/Download", "Data")
("/Download", "Data"),
]


def goto_d4g_website(state):
navigate(state, "https://dataforgood.fr/", tab="_blank")

Expand Down
2 changes: 1 addition & 1 deletion app/pages/company/company.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import numpy as np
import pandas as pd
from taipy.gui import Markdown, State, get_state_id
from taipy.gui import Markdown, State # , get_state_id

from app import algo
from app import config as cfg
Expand Down
1 change: 1 addition & 0 deletions app/pages/contact/contact.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from taipy.gui import Markdown

from app import config as cfg

# Generate page from Markdown file
Expand Down
1 change: 1 addition & 0 deletions app/pages/download/download.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from taipy.gui import Markdown

from app import config as cfg

# Initialise default name for file to download
Expand Down
85 changes: 46 additions & 39 deletions app/pages/home/home.py
Original file line number Diff line number Diff line change
@@ -1,71 +1,78 @@
from taipy.gui import State, Markdown
from taipy.gui import Markdown, State # , get_state_id

from app import config as cfg
from app import algo
from app.page import Page
from app import config as cfg
from app.viz import Viz

# from app.data.data import data

# Path to images
world_map_path = f"{cfg.IMAGES}/world_map.png"
download_icon_path = f"{cfg.IMAGES}/Vector.svg"


# Initialize state (Taipy callback function)
# Called by main.py/on_init
def on_init(state: State):
# print('HOME ON INIT...')
# print(f'HOME STATE ID {get_state_id(state)}')
with state as s:
update_viz(s)
# print('HOME ON INIT...END')
# print('HOME ON INIT...END')


# Viz store map[viz_id,viz_dict]
# Important for taipy bindings
# Use Viz.init on each page with set of viz_id
viz:dict[str,dict] = Viz.init(
viz: dict[str, dict] = Viz.init(
(
"general_number_of_tracked_reports",
"general_number_of_tracked_reports_over_time",
"general_number_of_tracked_mnc",
"general_number_of_tracked_mnc_available",
"general_number_of_tracked_mnc_available",
)
)
)


def update_viz(state: State):
id ="general_number_of_tracked_reports"
state.viz[id] = Viz(id=id,
state=state,
data=algo.number_of_tracked_reports(state.data),
title="Reports tracked",
sub_title=""
).to_state()

id ="general_number_of_tracked_reports_over_time"
id = "general_number_of_tracked_reports"
state.viz[id] = Viz(
id=id,
state=state,
data=algo.number_of_tracked_reports(state.data),
title="Reports tracked",
sub_title="",
).to_state()

id = "general_number_of_tracked_reports_over_time"
# TODO PERF : all in once
# algo_data, algo_fig = algo.display_number_of_tracked_reports_over_time(state.data)
state.viz[id] = Viz(id=id,
state=state,
data=algo.number_of_tracked_reports_over_time(state.data),
fig=algo.display_number_of_tracked_reports_over_time(state.data),
title="Number of reports over time"
).to_state()

id ="general_number_of_tracked_mnc"
state.viz[id] = Viz(id=id,
state=state,
data=algo.number_of_tracked_mnc(state.data),
title="Multinationals",
sub_title="with 1+ report tracked"
).to_state()

id ="general_number_of_tracked_mnc_available"
state.viz[id] = Viz(id=id,
state=state,
data=algo.compute_number_of_tracked_mnc_available(state.data),
fig=algo.display_number_of_tracked_mnc_available(state.data),
title="Multinationals available",
sub_title="with 1+ report tracked"
).to_state()
state.viz[id] = Viz(
id=id,
state=state,
data=algo.number_of_tracked_reports_over_time(state.data),
fig=algo.display_number_of_tracked_reports_over_time(state.data),
title="Number of reports over time",
).to_state()

id = "general_number_of_tracked_mnc"
state.viz[id] = Viz(
id=id,
state=state,
data=algo.number_of_tracked_mnc(state.data),
title="Multinationals",
sub_title="with 1+ report tracked",
).to_state()

id = "general_number_of_tracked_mnc_available"
state.viz[id] = Viz(
id=id,
state=state,
data=algo.compute_number_of_tracked_mnc_available(state.data),
fig=algo.display_number_of_tracked_mnc_available(state.data),
title="Multinationals available",
sub_title="with 1+ report tracked",
).to_state()


# Generate page from Markdown file
Expand Down
1 change: 1 addition & 0 deletions app/pages/keystories/keystories.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from taipy.gui import Markdown

from app import config as cfg

# Path to images
Expand Down
1 change: 1 addition & 0 deletions app/pages/methodology/methodology.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from taipy.gui import Markdown

from app import config as cfg

# Path to equation image
Expand Down
5 changes: 4 additions & 1 deletion app/pages/root.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from taipy.gui import Markdown, navigate

from app import config as cfg


def to_text(val):
return "{:,}".format(int(val)).replace(",", " ")

Expand All @@ -16,9 +18,10 @@ def to_text(val):
("/Company", "Company"),
("/Methodology", "Methodology"),
("/Contact", "Contact"),
("/Download", "Data")
("/Download", "Data"),
]


def goto_d4g_website(state):
navigate(state, "https://dataforgood.fr/", tab="_blank")

Expand Down

0 comments on commit e347acb

Please sign in to comment.