Skip to content

Commit

Permalink
Remove old CFTable code, clean up imports
Browse files Browse the repository at this point in the history
  • Loading branch information
dgdekoning committed Aug 19, 2019
1 parent 208d172 commit e099e05
Showing 1 changed file with 3 additions and 45 deletions.
48 changes: 3 additions & 45 deletions activity_browser/app/ui/tables/impact_categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
import numbers

import brightway2 as bw
import pandas as pd
from pandas import DataFrame
from PyQt5 import QtWidgets

from activity_browser.app.signals import signals

from .table import ABTableWidget, ABTableItem
from .views import ABDataFrameView, dataframe_sync


Expand Down Expand Up @@ -61,7 +60,7 @@ def sync(self, query=None):
"method": method_obj[1],
}
data.append(row)
self.dataframe = pd.DataFrame(data, columns=self.HEADERS)
self.dataframe = DataFrame(data, columns=self.HEADERS)

def _resize(self):
self.setColumnHidden(3, True)
Expand Down Expand Up @@ -103,51 +102,10 @@ def sync(self, method: tuple) -> None:
}
row.update({"Amount": amount, "Uncertain": uncertain, "key": key})
data.append(row)
self.dataframe = pd.DataFrame(data, columns=self.HEADERS)
self.dataframe = DataFrame(data, columns=self.HEADERS)

def _resize(self):
self.setColumnHidden(5, True)
self.setSizePolicy(QtWidgets.QSizePolicy(
QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Maximum
))


class CFTable(ABTableWidget):
COLUMNS = {
0: "name",
1: "amount",
2: "unit",
3: "uncertain",
}
HEADERS = ["Name", "Category", "Amount", "Unit", "Uncertain"]

def __init__(self):
super(CFTable, self).__init__()
self.setVisible(False)
self.setColumnCount(len(self.HEADERS))
self.setSizePolicy(QtWidgets.QSizePolicy(
QtWidgets.QSizePolicy.Preferred,
QtWidgets.QSizePolicy.Maximum)
)


@ABTableWidget.decorated_sync
def sync(self, method):
self.setHorizontalHeaderLabels(self.HEADERS)
method = bw.Method(method)
data = method.load()
self.setRowCount(len(data))
for row, obj in enumerate(data):
key, amount = obj[:2]
flow = bw.get_activity(key)
if isinstance(amount, numbers.Number):
uncertain = "False"
else:
uncertain = "True"
amount = amount['amount']
self.setItem(row, 0, ABTableItem(flow['name'], key=key))
self.setItem(row, 1, ABTableItem(str(flow['categories']), key=key))
self.setItem(row, 1, ABTableItem(str(flow['categories']), key=key))
self.setItem(row, 2, ABTableItem("{:.6g}".format(amount), key=key))
self.setItem(row, 3, ABTableItem(flow.get('unit', 'Unknown'), key=key))
self.setItem(row, 4, ABTableItem(str(uncertain), key=key))

0 comments on commit e099e05

Please sign in to comment.