Skip to content

Instantly share code, notes, and snippets.

package dbcalc;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import org.openlca.core.database.Derby;
import org.openlca.core.database.NativeSql;
import org.openlca.core.model.Actor;
import org.openlca.core.model.Category;
@msrocka
msrocka / full_db_calculation.java
Created January 27, 2021 19:21
An example of how you can calculate all processes of an openLCA database in a single step
package dbcalc;
import static java.lang.System.out;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import org.openlca.core.DataDir;
import org.openlca.core.database.IDatabase;
import org.openlca.core.database.ImpactCategoryDao;
@msrocka
msrocka / random_dqis.java
Created January 23, 2021 11:05
Generates random data quality values for an openLCA database.
package dqi;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Supplier;
import org.openlca.core.database.NativeSql;
import org.openlca.core.database.derby.DerbyDatabase;
public class Main {
from org.openlca.core.results import FullResult, Sankey
# load the product system with the given ID
system = db.get(
ProductSystem,
'f91f539b-2686-4224-893b-5d0993b06c39')
# calculate the result of that system
result = FullResult.of(db, system)
mass = db.forName(FlowProperty, 'Mass')
e = db.insert(Flow.elementary('e', mass))
pp = db.insert(Flow.product('p1', mass))
p = Process.of('p1', pp)
p.output(e, 1)
db.insert(p)
for i in range(2, 11):
qq = db.insert(Flow.product('p%i' % i, mass))
@msrocka
msrocka / write_openlca_parameters_to_csv.py
Created August 20, 2020 06:31
A script that writes the parameters of an openLCA database to a CSV file
# This script can be executed in the openLCA Python editor.
# An activated databases is required. Also, you need to
# change the path to the CSV file below.
#
# This script should work with openLCA 1.10.x. In openLCA 2.0
# LCIA parameters are bound to impact categories and not to
# LCIA methods.
import csv
@msrocka
msrocka / pandoc.css
Created December 18, 2018 16:59 — forked from killercup/pandoc.css
Add this to your Pandoc HTML documents using `--css pandoc.css` to make them look more awesome. (Tested with Markdown and LaTeX.)
/*
* I add this to html files generated with pandoc.
*/
html {
font-size: 100%;
overflow-y: scroll;
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
}
@msrocka
msrocka / openlca_lci_process_name_fix.py
Created September 14, 2018 08:27
This script fixes wrong name suffixes of LCI result processes in openLCA
# This script fixes wrong name suffixes of LCI result processes in openLCA: in
# some databases, the name of such processes ends with `, U` but should end
# with `, S` to indicate that this is an LCI result/system process. This script
# can be executed directly in openLCA: Window > Developer tools > Python. After
# the script finished, you need to close and reopen the database to see the
# updated names in the navigation.
def main():
global db, log
@msrocka
msrocka / SplitLines.go
Created June 13, 2018 08:28
SplitLines takes the given text and splits it into multiple lines by trying to applying the maxRunes parameter as a margin.
import (
"bytes"
"strings"
"unicode/utf8"
)
// SplitLines takes the given text and splits it into multiple lines by trying
// to applying the maxRunes parameter as a margin.
func SplitLines(text string, maxRunes int) []string {
var lines []string
@msrocka
msrocka / ilcdpatch.go
Last active May 25, 2018 15:09
ilcdpatch is a command line program that replaces files in an ILCD package with the files from a patch package.
// This is a command line program that replaces files in an ILCD package with
// the files from a patch package. It takes the files `raw.zip` and `patch.zip`
// as input and creates a package `out.zip` where the data sets from the
// `raw.zip` package that are also in the `patch.zip` package are replaced by
// the version in the `patch.zip` package.
package main
import (
"fmt"