Skip to content

Commit 343c03e

Browse files
Merge pull request #53 from RiwsPy/dev
chore: apply ruff on project except algo.py
2 parents e616e6a + e347acb commit 343c03e

File tree

11 files changed

+96
-79
lines changed

11 files changed

+96
-79
lines changed

app/config.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
21
# CUSTOMIZE IF NEEDED
3-
APP= "app/"
4-
# APP= "app/" OR ""
2+
APP = "app/"
3+
# APP= "app/" OR ""
54

65
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
76
# AUTO

app/main.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
from taipy.gui import State, Gui, navigate, get_state_id
2-
from app import config as cfg
1+
import pandas as pd
2+
from taipy.gui import Gui, State, navigate # ,get_state_id
33

4-
from app.pages.company.company import company_md, on_init as on_init_company
4+
from app import config as cfg
5+
from app.pages.company.company import company_md
6+
from app.pages.company.company import on_init as on_init_company
57
from app.pages.contact.contact import contact_md
68
from app.pages.download.download import download_md
7-
from app.pages.home.home import home_md, on_init as on_init_home
9+
from app.pages.home.home import home_md
10+
from app.pages.home.home import on_init as on_init_home
811
from app.pages.keystories.keystories import keystories_md
912
from app.pages.methodology.methodology import methodology_md
1013
from app.pages.root import root
1114

12-
import pandas as pd
13-
1415
# Global variables
1516
# APP
1617
APP_TITLE = "Taxplorer"
@@ -19,28 +20,31 @@
1920
MAX_YEAR_OF_REPORTS = 2021
2021
PATH_TO_DATA = f"{cfg.DATA}/data_final_dataviz.csv"
2122

22-
data:pd.DataFrame = None
23+
data: pd.DataFrame = None
24+
2325

2426
def on_init(state: State):
2527
# print('MAIN ON_INIT...')
2628
# print(f'MAIN STATE {get_state_id(state)}')
27-
29+
2830
# Init data
2931
init_data(state)
3032
# Call company on_init
3133
on_init_company(state)
3234
# Call company on_init
33-
on_init_home(state)
34-
35-
# print('MAIN ON_INIT...END')
36-
37-
# Performance optimization
35+
on_init_home(state)
36+
37+
# print('MAIN ON_INIT...END')
38+
39+
40+
# Performance optimization
3841
def init_data(state: State):
39-
df = pd.read_csv(f"{PATH_TO_DATA}", sep=",", low_memory=False, encoding='utf-8')
42+
df = pd.read_csv(f"{PATH_TO_DATA}", sep=",", low_memory=False, encoding="utf-8")
4043
# Filter dataset with the maximum year to take in account
4144
df = df.loc[df["year"] <= MAX_YEAR_OF_REPORTS].reset_index()
42-
state.data = df
43-
45+
state.data = df
46+
47+
4448
# Add pages
4549
pages = {
4650
"/": root,
@@ -49,9 +53,10 @@ def init_data(state: State):
4953
"Company": company_md,
5054
"Methodology": methodology_md,
5155
"Contact": contact_md,
52-
"Download": download_md
56+
"Download": download_md,
5357
}
5458

59+
5560
# Functions used to navigate between pages
5661
def goto_home(state):
5762
navigate(state, "Home")
@@ -78,18 +83,15 @@ def goto_download(state):
7883

7984

8085
# Initialise Gui with pages and style sheet
81-
gui_multi_pages = Gui(
82-
pages=pages,
83-
css_file="css/style.css"
84-
)
86+
gui_multi_pages = Gui(pages=pages, css_file="css/style.css")
8587

8688
# Customize the Stylekit
8789
stylekit = {
8890
"color_primary": "#021978",
8991
"color_secondary": "#C0FFE",
9092
"color_paper_light": "#FFFFFF",
9193
"color_background_light": "#FFFFFF",
92-
"font_family": "Manrope"
94+
"font_family": "Manrope",
9395
}
9496

9597

@@ -105,7 +107,7 @@ def goto_download(state):
105107
watermark="LOCAL DEVELOPMENT",
106108
)
107109
else:
108-
## PRODUCTION
110+
## PRODUCTION
109111
# Start the app used by uwsgi server
110112
web_app = gui_multi_pages.run(
111113
dark_mode=False,
@@ -116,9 +118,7 @@ def goto_download(state):
116118
debug=False,
117119
# Remove watermark "Taipy inside"
118120
watermark="",
119-
# IMPORTANT: Set the async_mode to gevent_uwsgi to use uwsgi
121+
# IMPORTANT: Set the async_mode to gevent_uwsgi to use uwsgi
120122
# See https://python-socketio.readthedocs.io/en/latest/server.html#uwsgi
121-
async_mode='gevent_uwsgi'
123+
async_mode="gevent_uwsgi",
122124
)
123-
124-

app/page.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import inspect
21
from taipy.gui import Markdown
32
from app import config as cfg
43

4+
55
class Page:
6-
def __init__(self, id:str):
7-
self.id= id
8-
6+
def __init__(self, id: str):
7+
self.id = id
8+
99
def markdown(self) -> Markdown:
1010
# caller = inspect.currentframe().f_back
1111
# print("PAGED Called from module", caller.f_globals['__name__'])
1212
# print(f"{cfg.PAGES_PATH}/{self.id}/{self.id}.md")
13-
return Markdown(f"{cfg.PAGES_PATH}/{self.id}/{self.id}.md")
13+
return Markdown(f"{cfg.PAGES_PATH}/{self.id}/{self.id}.md")

app/pages/_header/_header.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
from taipy.gui import navigate
2-
from app import config as cfg
2+
3+
from app import config as cfg
34
from app.page import Page
45

5-
page_id="_header"
6+
page_id = "_header"
7+
68

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

12+
1013
# Path to image
1114
taxplorer_logo_path = f"{cfg.IMAGES}/taxplorer-logo.svg"
1215

@@ -17,9 +20,10 @@ def to_text(val):
1720
("/Company", "Company"),
1821
("/Methodology", "Methodology"),
1922
("/Contact", "Contact"),
20-
("/Download", "Data")
23+
("/Download", "Data"),
2124
]
2225

26+
2327
def goto_d4g_website(state):
2428
navigate(state, "https://dataforgood.fr/", tab="_blank")
2529

app/pages/company/company.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import numpy as np
44
import pandas as pd
5-
from taipy.gui import Markdown, State, get_state_id
5+
from taipy.gui import Markdown, State # , get_state_id
66

77
from app import algo
88
from app import config as cfg

app/pages/contact/contact.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from taipy.gui import Markdown
2+
23
from app import config as cfg
34

45
# Generate page from Markdown file

app/pages/download/download.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from taipy.gui import Markdown
2+
23
from app import config as cfg
34

45
# Initialise default name for file to download

app/pages/home/home.py

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,78 @@
1-
from taipy.gui import State, Markdown
1+
from taipy.gui import Markdown, State # , get_state_id
22

3-
from app import config as cfg
43
from app import algo
5-
from app.page import Page
4+
from app import config as cfg
65
from app.viz import Viz
6+
77
# from app.data.data import data
88

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

13+
1314
# Initialize state (Taipy callback function)
1415
# Called by main.py/on_init
1516
def on_init(state: State):
1617
# print('HOME ON INIT...')
1718
# print(f'HOME STATE ID {get_state_id(state)}')
1819
with state as s:
1920
update_viz(s)
20-
# print('HOME ON INIT...END')
21+
# print('HOME ON INIT...END')
22+
2123

2224
# Viz store map[viz_id,viz_dict]
2325
# Important for taipy bindings
2426
# Use Viz.init on each page with set of viz_id
25-
viz:dict[str,dict] = Viz.init(
27+
viz: dict[str, dict] = Viz.init(
2628
(
2729
"general_number_of_tracked_reports",
2830
"general_number_of_tracked_reports_over_time",
2931
"general_number_of_tracked_mnc",
30-
"general_number_of_tracked_mnc_available",
32+
"general_number_of_tracked_mnc_available",
3133
)
32-
)
34+
)
35+
3336

3437
def update_viz(state: State):
35-
id ="general_number_of_tracked_reports"
36-
state.viz[id] = Viz(id=id,
37-
state=state,
38-
data=algo.number_of_tracked_reports(state.data),
39-
title="Reports tracked",
40-
sub_title=""
41-
).to_state()
42-
43-
id ="general_number_of_tracked_reports_over_time"
38+
id = "general_number_of_tracked_reports"
39+
state.viz[id] = Viz(
40+
id=id,
41+
state=state,
42+
data=algo.number_of_tracked_reports(state.data),
43+
title="Reports tracked",
44+
sub_title="",
45+
).to_state()
46+
47+
id = "general_number_of_tracked_reports_over_time"
4448
# TODO PERF : all in once
4549
# algo_data, algo_fig = algo.display_number_of_tracked_reports_over_time(state.data)
46-
state.viz[id] = Viz(id=id,
47-
state=state,
48-
data=algo.number_of_tracked_reports_over_time(state.data),
49-
fig=algo.display_number_of_tracked_reports_over_time(state.data),
50-
title="Number of reports over time"
51-
).to_state()
52-
53-
id ="general_number_of_tracked_mnc"
54-
state.viz[id] = Viz(id=id,
55-
state=state,
56-
data=algo.number_of_tracked_mnc(state.data),
57-
title="Multinationals",
58-
sub_title="with 1+ report tracked"
59-
).to_state()
60-
61-
id ="general_number_of_tracked_mnc_available"
62-
state.viz[id] = Viz(id=id,
63-
state=state,
64-
data=algo.compute_number_of_tracked_mnc_available(state.data),
65-
fig=algo.display_number_of_tracked_mnc_available(state.data),
66-
title="Multinationals available",
67-
sub_title="with 1+ report tracked"
68-
).to_state()
50+
state.viz[id] = Viz(
51+
id=id,
52+
state=state,
53+
data=algo.number_of_tracked_reports_over_time(state.data),
54+
fig=algo.display_number_of_tracked_reports_over_time(state.data),
55+
title="Number of reports over time",
56+
).to_state()
57+
58+
id = "general_number_of_tracked_mnc"
59+
state.viz[id] = Viz(
60+
id=id,
61+
state=state,
62+
data=algo.number_of_tracked_mnc(state.data),
63+
title="Multinationals",
64+
sub_title="with 1+ report tracked",
65+
).to_state()
66+
67+
id = "general_number_of_tracked_mnc_available"
68+
state.viz[id] = Viz(
69+
id=id,
70+
state=state,
71+
data=algo.compute_number_of_tracked_mnc_available(state.data),
72+
fig=algo.display_number_of_tracked_mnc_available(state.data),
73+
title="Multinationals available",
74+
sub_title="with 1+ report tracked",
75+
).to_state()
6976

7077

7178
# Generate page from Markdown file

app/pages/keystories/keystories.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from taipy.gui import Markdown
2+
23
from app import config as cfg
34

45
# Path to images

app/pages/methodology/methodology.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from taipy.gui import Markdown
2+
23
from app import config as cfg
34

45
# Path to equation image

app/pages/root.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from taipy.gui import Markdown, navigate
2+
23
from app import config as cfg
34

5+
46
def to_text(val):
57
return "{:,}".format(int(val)).replace(",", " ")
68

@@ -16,9 +18,10 @@ def to_text(val):
1618
("/Company", "Company"),
1719
("/Methodology", "Methodology"),
1820
("/Contact", "Contact"),
19-
("/Download", "Data")
21+
("/Download", "Data"),
2022
]
2123

24+
2225
def goto_d4g_website(state):
2326
navigate(state, "https://dataforgood.fr/", tab="_blank")
2427

0 commit comments

Comments
 (0)