Changesets e706dc3 and cf0db1e introduce a new way to make LCA calculations in Brightway2. Previously, a user pressed the calculate button, and an LCA calculation was made and formatted into a web page. There is nothing wrong with this, but we can do better.
Separating presentation and content
One key concept in both the planning of Brightway2 and computer science in general is the separation of concerns. Calculating LCA results is a very different thing from formatting these results into appealing text and graphics. Now, when an LCA calculation is requested, an LCA report is generated by a separate module in Brightway2-analyzer, and the raw data is saved to a JSON file on the hard drive. When using the web interface, the user is redirected to a new URL, and the LCA report is generated from saved data.
This separation of presentation (the display of the result tables and graphs) from the content (the underlying data) is a very good thing for a number of reasons.
- It allows results to be uploaded and formatted in different ways for different audiences.
- It makes it easier for people to contribute, because the results calculator and display code are independent of each other.
- It allows LCA results to computed asynchronously, meaning that other operations can be performed while an LCA is in progress, that LCA calculations can be queued, and that LCA calculations can be thought of as a web service instead of part of a specific web UI.
- It makes writing tests for correct behaviour easier, ensuring that results are more correct over time.
This is a big step towards making Brightway2 a platform for LCA calculations.
Report data can now be uploaded to http://reports.brightwaylca.org, or a different server under your control. By defult, report uploading is turned off, but it can be configured in Brightway2's settings. The report server is a completely separate program, and has no dependencies on Brightway2. This program is, of course, open source, and the source code is up on https://bitbucket.org/cmutel/brightway2-web-reports.
Installation of the report server
Open a terminal window (command shell in Windows), and type the following:
pip install bw2webreports
Configuration of the report server
The web server is a very simple Flask server. It has one mandatory parmeter: the data directory where you want to store the uploaded report data. It is run like this:
Where <data-dir> is the absolute path to whatever directory you want to use. The user starting the report server must have read and write access to this directory. In addition, you can specify the following optional parameters:
- --port=<port-number>: Specify the port number (default is 8000)
- --local: Only allow local connections (if you want to limit the report server to only listen to localhost).
Note that, by default, the report server accepts outside connections.
How to upgrade
You can upgrade to the latest version of all Brightway2 packages by opening a terminal window (command shell in Windows), and type the following:
pip install --upgrade --no-deps bw2calc bw2analyzer bw2ui