• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LCA-ActivityBrowser / activity-browser / 10319203045

09 Aug 2024 12:27PM UTC coverage: 54.132% (-0.3%) from 54.397%
10319203045

push

github

web-flow
Merge pull request #1336 from mrvisscher/its_the_final_logger

Logging changes

136 of 164 new or added lines in 50 files covered. (82.93%)

68 existing lines in 2 files now uncovered.

8280 of 15296 relevant lines covered (54.13%)

0.54 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

45.83
/activity_browser/bwutils/superstructure/utils.py
1
# -*- coding: utf-8 -*-
2
import time
1✔
3
from logging import getLogger
1✔
4

5
import pandas as pd
1✔
6

7
from activity_browser.mod import bw2data as bd
1✔
8

9
log = getLogger(__name__)
1✔
10

11
# Different kinds of indexes, to allow for quick selection of data from
12
# the Superstructure DataFrame.
13
# TODO review if this can be made a list instead of pd.Index
14
SUPERSTRUCTURE = pd.Index(
1✔
15
    [
16
        "from activity name",
17
        "from reference product",
18
        "from location",
19
        "from categories",
20
        "from database",
21
        "from key",
22
        "to activity name",
23
        "to reference product",
24
        "to location",
25
        "to categories",
26
        "to database",
27
        "to key",
28
        "flow type",
29
    ]
30
)
31

32

33
def edit_superstructure_for_string(
1✔
34
    superstructure=SUPERSTRUCTURE, sep="<br>", fhighlight=""
35
):
36
    """
37
    Produces a string format for the essential columns for the scenario difference files with html
38
    style formatting. Allows for different defined structures.
39

40
    Parameters
41
    ----------
42
    superstructure: the list of superstructure column headers (by default set to the SUPERSTRUCTURE index,
43
    this needs to have a defined __str__ operator
44
    sep: a short string that defines the separator for the column headers, by default this is the html line
45
    break <br>
46
    fhighlight: this is provided as a means to highlight the fields, by default this is empty (SHOULD NOT BE
47
    SET TO None), but could be set to "[]", where the first and last elements enclose the field
48

49
    Returns
50
    -------
51
    A formatted strign with the required file fields
52
    """
53
    text_list = ""
×
54
    for field in superstructure:
×
55
        text_list += (
×
56
            f"{fhighlight[0]}{field}{fhighlight[-1]}{sep}"
57
            if fhighlight
58
            else f"{field}{sep}"
59
        )
60
    return text_list
×
61

62

63
def guess_flow_type(row: pd.Series) -> str:
1✔
64
    """Given a series of input- and output keys, make a guess on the flow type."""
65
    if row.iat[0][0] == bd.config.biosphere:
×
66
        return "biosphere"
×
67
    elif row.iat[0] == row.iat[1]:
×
68
        return "production"
×
69
    else:
70
        return "technosphere"
×
71

72

73
def _time_it_(func):
1✔
74
    # TODO rename to non_protected name
75
    """
76
    For use as a wrapper to time the execution of functions using the python time library
77
    """
78

79
    def wrapper(*args):
1✔
80
        now = time.time()
×
81
        result = func(*args)
×
NEW
82
        log.info(f"{func} -- {time.time() - now}")
×
83
        return result
×
84

85
    return wrapper
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc