Skip to content

Commit 91afaca

Browse files
committed
Fixed logging formatting
1 parent 4aa4ed7 commit 91afaca

16 files changed

Lines changed: 40 additions & 56 deletions

File tree

activity_browser/bwutils/calculations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def do_LCA_calculations(data: dict):
5151
QApplication.restoreOverrideCursor()
5252
raise CriticalCalculationError
5353
else:
54-
log.error("Calculation type must be: simple or scenario. Given:", cs_name)
54+
log.error(f"Calculation type must be: simple or scenario. Given: {cs_name}")
5555
raise ValueError
5656

5757
mlca.calculate()

activity_browser/bwutils/commontasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def cleanup_deleted_bw_projects() -> None:
9696
NOTE: This cannot be done from within the AB.
9797
"""
9898
n_dir = bd.projects.purge_deleted_directories()
99-
log.info("Deleted {} unused project directories!".format(n_dir))
99+
log.info(f"Deleted {n_dir} unused project directories!")
100100

101101

102102
# Database

activity_browser/bwutils/metadata.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,13 @@ def add_metadata(self, db_names_list: list) -> None:
7777
dfs = list()
7878
dfs.append(self.dataframe)
7979
log.debug(
80-
"Current shape and databases in the MetaDataStore:",
81-
self.dataframe.shape,
82-
self.databases,
80+
f"Current shape and databases in the MetaDataStore: {self.dataframe.shape} {self.databases}"
8381
)
8482
for db_name in new:
8583
if db_name not in bd.databases:
8684
raise ValueError("This database does not exist:", db_name)
8785

88-
log.debug("Adding:", db_name)
86+
log.debug(f"Adding: {db_name}")
8987
self.databases.add(db_name)
9088

9189
# make a temporary DataFrame and index it by ('database', 'code') (like all brightway activities)
@@ -130,7 +128,7 @@ def update_metadata(self, key: tuple) -> None:
130128
) # if this does not work, it has been deleted (see except:).
131129
except (UnknownObject, ActivityDataset.DoesNotExist):
132130
# Situation 1: activity has been deleted (metadata needs to be deleted)
133-
log.debug("Deleting activity from metadata:", key)
131+
log.debug(f"Deleting activity from metadata: {key}")
134132
self.dataframe.drop(key, inplace=True, errors="ignore")
135133
# print('Dimensions of the Metadata:', self.dataframe.shape)
136134
return
@@ -143,7 +141,7 @@ def update_metadata(self, key: tuple) -> None:
143141
if (
144142
key in self.dataframe.index
145143
): # Situation 2: activity has been modified (metadata needs to be updated)
146-
log.debug("Updating activity in metadata: ", act, key)
144+
log.debug(f"Updating activity in metadata: {key}")
147145
for col in self.dataframe.columns:
148146
if col in self.CLASSIFICATION_SYSTEMS:
149147
# update classification data
@@ -156,7 +154,7 @@ def update_metadata(self, key: tuple) -> None:
156154
self.dataframe.at[key, 'key'] = act.key
157155

158156
else: # Situation 3: Activity has been added to database (metadata needs to be generated)
159-
log.debug('Adding activity to metadata:', act, key)
157+
log.debug(f'Adding activity to metadata: {key}')
160158
df_new = pd.DataFrame([act.as_dict()], index=pd.MultiIndex.from_tuples([act.key]))
161159
df_new['key'] = [act.key]
162160
if act.get('classifications', False): # add classification data if present

activity_browser/bwutils/montecarlo.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,8 @@ def calculate(self, iterations=10, seed: int = None, **kwargs):
245245
self.results[iteration, row, col] = self.lca.score
246246

247247
log.info(
248-
"Monte Carlo LCA: finished {} iterations for {} reference flows and {} methods in {} seconds.".format(
249-
iterations,
250-
len(self.func_units),
251-
len(self.methods),
252-
np.round(time() - start, 2),
253-
)
248+
f"Monte Carlo LCA: finished {iterations} iterations for {len(self.func_units)} reference flows and "
249+
f"{len(self.methods)} methods in {np.round(time() - start, 2)} seconds."
254250
)
255251

256252
@property
@@ -272,10 +268,10 @@ def get_results_by(self, act_key=None, method=None):
272268

273269
if act_key:
274270
act_index = self.activity_index.get(act_key)
275-
log.info("Activity key provided:", act_key, act_index)
271+
log.info(f"Activity key provided: {act_key} {act_index}")
276272
if method:
277273
method_index = self.method_index.get(method)
278-
log.info("Method provided", method, method_index)
274+
log.info(f"Method provided: {method} {method_index}")
279275

280276
if not act_key and not method:
281277
return self.results
@@ -284,7 +280,6 @@ def get_results_by(self, act_key=None, method=None):
284280
elif method and not act_key:
285281
return np.squeeze(self.results[:, :, method_index])
286282
elif method and act_key:
287-
log.info(act_index, method_index)
288283
return np.squeeze(self.results[:, act_index, method_index])
289284

290285
def get_results_dataframe(self, act_key=None, method=None, labelled=True):
@@ -335,7 +330,7 @@ def get_labels(
335330
def perform_MonteCarlo_LCA(project="default", cs_name=None, iterations=10):
336331
"""Performs Monte Carlo LCA based on a calculation setup and returns the
337332
Monte Carlo LCA object."""
338-
log.info("-- Monte Carlo LCA --\n Project:", project, "CS:", cs_name)
333+
log.info(f"-- Monte Carlo LCA --\n Project: {project} CS: {cs_name}")
339334
bd.projects.set_current(project)
340335

341336
# perform Monte Carlo simulation

activity_browser/bwutils/sensitivity_analysis.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def get_lca(fu, method):
3636
lca = bc.LCA(fu, method=method)
3737
lca.lci()
3838
lca.lcia()
39-
log.info("Non-stochastic LCA score:", lca.score)
39+
log.info(f"Non-stochastic LCA score: {lca.score}")
4040

4141
# add reverse dictionaries
4242
lca.activity_dict_rev, lca.product_dict_rev, lca.biosphere_dict_rev = (
@@ -230,7 +230,7 @@ def get_parameters_DF(mc):
230230
if bool(mc.parameter_data): # returns False if dict is empty
231231
dfp = pd.DataFrame(mc.parameter_data).T
232232
dfp["GSA name"] = "P: " + dfp["name"]
233-
log.info("PARAMETERS:", len(dfp))
233+
log.info(f"PARAMETERS: {len(dfp)}")
234234
return dfp
235235
else:
236236
log.info("PARAMETERS: None included.")
@@ -334,14 +334,8 @@ def perform_GSA(
334334
return None
335335

336336
log.info(
337-
"-- GSA --\n Project:",
338-
bd.projects.current,
339-
"CS:",
340-
self.mc.cs_name,
341-
"Activity:",
342-
self.activity,
343-
"Method:",
344-
self.method,
337+
f"-- GSA --\n Project: {bd.projects.current} CS: {self.mc.cs_name} "
338+
f"Activity: {self.activity} Method: {self.method}",
345339
)
346340

347341
# get non-stochastic LCA object with reverse dictionaries

activity_browser/bwutils/superstructure/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def _time_it_(func):
7979
def wrapper(*args):
8080
now = time.time()
8181
result = func(*args)
82-
log.info(f"{func} -- " + str(time.time() - now))
82+
log.info(f"{func} -- {time.time() - now}")
8383
return result
8484

8585
return wrapper

activity_browser/layouts/panels/panel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def show_tab(self, tab_name):
6161
"""Makes existing tab visible."""
6262
if tab_name in self.tabs:
6363
tab = self.tabs[tab_name]
64-
log.info("+showing tab:", tab_name)
64+
log.info(f"+showing tab: {tab_name}")
6565
tab.setVisible(True)
6666
self.addTab(tab, tab_name)
6767
self.select_tab(tab)
@@ -72,7 +72,7 @@ def get_tab_name(self, obj):
7272
if len(tab_names) == 1:
7373
return tab_names[0]
7474
else:
75-
log.warning("found", len(tab_names), "occurences of this object.")
75+
log.warning(f"found {len(tab_names)} occurrences of this object.")
7676

7777
def get_tab_name_from_index(self, index):
7878
"""Return the name of a tab based on its index."""

activity_browser/layouts/panels/right.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def show_tab(self, tab_name):
5252
"""
5353
if tab_name in self.tabs:
5454
tab = self.tabs[tab_name]
55-
log.info("+showing tab:", tab_name)
55+
log.info(f"+showing tab: {tab_name}")
5656
tab.setVisible(True)
5757
self.insertTab(self.tab_order[tab_name], tab, tab_name)
5858
self.select_tab(tab)

activity_browser/layouts/tabs/LCA_results_tabs.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,12 +1326,12 @@ def calculate_mc_lca(self):
13261326
iterations = int(self.iterations.text())
13271327
seed = None
13281328
if self.seed.text():
1329-
log.info("SEED: ", self.seed.text())
1329+
log.info(f"SEED: {self.seed.text()}")
13301330
try:
13311331
seed = int(self.seed.text())
13321332
except ValueError as e:
13331333
log.error(
1334-
"Seed value must be an integer number or left empty.", error=e
1334+
"Seed value must be an integer number or left empty.", exc_info=e
13351335
)
13361336
QMessageBox.warning(
13371337
self,
@@ -1356,7 +1356,7 @@ def calculate_mc_lca(self):
13561356
InvalidParamsError
13571357
) as e: # This can occur if uncertainty data is missing or otherwise broken
13581358
# print(e)
1359-
log.error(error=e)
1359+
log.error(e)
13601360
QMessageBox.warning(
13611361
self, "Could not perform Monte Carlo simulation", str(e)
13621362
)
@@ -1630,7 +1630,7 @@ def calculate_gsa(self):
16301630
)
16311631
# self.update_mc()
16321632
except Exception as e: # Catch any error...
1633-
log.error(error=e)
1633+
log.error(e)
16341634
message = str(e)
16351635
message_addition = ""
16361636
if message == "singular matrix":
@@ -1709,7 +1709,7 @@ def set_mc(self, mc, iterations=20):
17091709
self.iterations = iterations
17101710

17111711
def run(self):
1712-
log.info("Starting new Worker Thread. Iterations:", self.iterations)
1712+
log.info(f"Starting new Worker Thread. Iterations: {self.iterations}")
17131713
self.mc.calculate(iterations=self.iterations)
17141714
# res = bw.GraphTraversal().calculate(self.demand, self.method, self.cutoff, self.max_calc)
17151715
log.info("in thread {}".format(QtCore.QThread.currentThread()))

activity_browser/ui/tables/models/activity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def create_row(self, exchange) -> dict:
7474
return row
7575
except DoesNotExist as e:
7676
# The input activity does not exist. remove the exchange.
77-
log.warning(f"Broken exchange: {e}, removing.")
77+
log.warning(f"Broken exchange: {exchange}, removing.")
7878
actions.ExchangeDelete.run([exchange])
7979

8080
def get_exchange(self, proxy: QModelIndex) -> ExchangeProxyBase:

0 commit comments

Comments
 (0)