Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
NeqModPlus
de.hft-stuttgart.cityunits
Commits
46d5fd1f
Commit
46d5fd1f
authored
3 years ago
by
Kai-Holger Brassel
Browse files
Options
Download
Email Patches
Plain Diff
Get carbon emission untis right
parent
390a76ad
Pipeline
#4357
passed with stage
in 3 minutes and 9 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+3
-3
README.md
de.hftstuttgart.cityunits.model/src/de/hftstuttgart/cityunits/model/UrbanSimulationUnits.java
+9
-7
...de/hftstuttgart/cityunits/model/UrbanSimulationUnits.java
de.hftstuttgart.cityunits.tests/src/de/hftstuttgart/cityunits/tests/QuantityTest.java
+6
-4
...sts/src/de/hftstuttgart/cityunits/tests/QuantityTest.java
with
18 additions
and
14 deletions
+18
-14
README.md
+
3
-
3
View file @
46d5fd1f
...
...
@@ -79,9 +79,9 @@ Some units of special interest for urban simulation introduced with this plug-in
| W/m² | [M]/[T]³ Intensity
| ppm | one
| dB | one
| g
CO₂eq | [M] CarbonEmission
| kg
CO₂eq | [M] CarbonEmission
| t
CO₂eq
| [M] CarbonEmission
| gCO₂eq
| [M] CarbonEmission
| kgCO₂eq
| [M] CarbonEmission
| t
on
CO₂eq | [M] CarbonEmission
| € | [$]
| $ | [$]
...
...
This diff is collapsed.
Click to expand it.
de.hftstuttgart.cityunits.model/src/de/hftstuttgart/cityunits/model/UrbanSimulationUnits.java
+
9
-
7
View file @
46d5fd1f
...
...
@@ -33,9 +33,10 @@ public class UrbanSimulationUnits extends AbstractSystemOfUnits {
}
public
static
final
Unit
<
Mass
>
TON
=
addUnit
(
Units
.
KILOGRAM
.
multiply
(
1000
));
public
static
final
Unit
<
CarbonEmission
>
GRAM_CO2_EQUIVALENT
=
Units
.
GRAM
.
asType
(
CarbonEmission
.
class
);
public
static
final
Unit
<
CarbonEmission
>
KILOGRAM_CO2_EQUIVALENT
=
Units
.
KILOGRAM
.
asType
(
CarbonEmission
.
class
);
public
static
final
Unit
<
CarbonEmission
>
TON_CO2_EQUIVALENT
=
TON
.
asType
(
CarbonEmission
.
class
);
public
static
final
Unit
<
CarbonEmission
>
KILOGRAM_CO2_EQUIVALENT
=
addUnit
(
AlternateUnit
.
of
(
Units
.
KILOGRAM
,
"kgCO₂eq"
).
asType
(
CarbonEmission
.
class
));
public
static
final
Unit
<
CarbonEmission
>
GRAM_CO2_EQUIVALENT
=
addUnit
(
KILOGRAM_CO2_EQUIVALENT
.
divide
(
1000
));
public
static
final
Unit
<
CarbonEmission
>
TON_CO2_EQUIVALENT
=
addUnit
(
KILOGRAM_CO2_EQUIVALENT
.
multiply
(
1000
));
public
static
final
Unit
<
Dimensionless
>
PARTS_PER_MILLION
=
addUnit
(
new
TransformedUnit
<>(
AbstractUnit
.
ONE
,
MultiplyConverter
.
ofRational
(
BigInteger
.
ONE
,
BigInteger
.
valueOf
(
1000000
))));
...
...
@@ -45,16 +46,17 @@ public class UrbanSimulationUnits extends AbstractSystemOfUnits {
new
AlternateUnit
<
Intensity
>(
Units
.
WATT
.
divide
(
Units
.
SQUARE_METRE
),
"W/m²"
));
// To model costs I added monetary units quick and dirty as SI base units.
// According to JavaDoc of AbstractUnit,
monetary units should rather be
implemented in an extra type hierarchy
// below ComparableUnit.
// According to JavaDoc of AbstractUnit, monetary units should rather be
//
implemented in an extra type hierarchy
below ComparableUnit.
public
final
static
Dimension
MONEY_DIMENSION
=
UnitDimension
.
parse
(
'M'
);
public
final
static
Unit
<
Euro
>
EURO
=
new
BaseUnit
<
Euro
>(
"€"
,
MONEY_DIMENSION
);
public
final
static
Unit
<
Dollar
>
DOLLAR
=
new
BaseUnit
<
Dollar
>(
"$"
,
MONEY_DIMENSION
);
static
{
SimpleUnitFormat
.
getInstance
().
label
(
TON
,
"t"
);
SimpleUnitFormat
.
getInstance
().
label
(
KILOGRAM_CO2_EQUIVALENT
,
"kg CO₂eq"
);
SimpleUnitFormat
.
getInstance
().
label
(
TON_CO2_EQUIVALENT
,
"t CO₂eq"
);
SimpleUnitFormat
.
getInstance
().
label
(
KILOGRAM_CO2_EQUIVALENT
,
"kgCO₂eq"
);
SimpleUnitFormat
.
getInstance
().
label
(
GRAM_CO2_EQUIVALENT
,
"gCO₂eq"
);
SimpleUnitFormat
.
getInstance
().
label
(
TON_CO2_EQUIVALENT
,
"tonCO₂eq"
);
SimpleUnitFormat
.
getInstance
().
label
(
DECIBEL
,
"dB"
);
SimpleUnitFormat
.
getInstance
().
label
(
PARTS_PER_MILLION
,
"ppm"
);
SimpleUnitFormat
.
getInstance
().
label
(
EURO
,
"€"
);
...
...
This diff is collapsed.
Click to expand it.
de.hftstuttgart.cityunits.tests/src/de/hftstuttgart/cityunits/tests/QuantityTest.java
+
6
-
4
View file @
46d5fd1f
...
...
@@ -18,6 +18,7 @@ import tech.units.indriya.quantity.Quantities;
import
tech.units.indriya.unit.Units
;
// Quantities.getQuantity("1.50 €"); does not compile in Maven without cast to String ???
// mvn install won't run this tests, since tycho (?) handles tests as integration tests, thus, mvn verify is required
class
QuantityTest
{
@BeforeAll
static
void
init
()
{
...
...
@@ -67,12 +68,13 @@ class QuantityTest {
}
@Test
void
testCO2eq
()
{
Quantity
<
CarbonEmission
>
q
=
Quantities
.
getQuantity
((
String
)
"5200.7 kg CO₂eq"
).
asType
(
CarbonEmission
.
class
);
void
testCO2eq
()
{
Quantity
<
CarbonEmission
>
q
=
Quantities
.
getQuantity
((
String
)
"5200.7 kgCO₂eq"
).
asType
(
CarbonEmission
.
class
);
System
.
out
.
println
(
q
);
assertEquals
(
"[M]"
,
q
.
getUnit
().
getDimension
().
toString
(),
"Wrong dimension!"
);
assertTrue
(
q
.
isEquivalentTo
(
Quantities
.
getQuantity
((
String
)
"5.2007 t
CO₂eq"
).
asType
(
CarbonEmission
.
class
)),
assertTrue
(
q
.
isEquivalentTo
(
Quantities
.
getQuantity
((
String
)
"5.2007 t
on
CO₂eq"
).
asType
(
CarbonEmission
.
class
)),
"Wrong conversion from kg of CO₂eq to ton of CO₂eq!"
);
assertTrue
(
q
.
isEquivalentTo
(
Quantities
.
getQuantity
((
String
)
"5200700 g
CO₂eq"
).
asType
(
CarbonEmission
.
class
)),
assertTrue
(
q
.
isEquivalentTo
(
Quantities
.
getQuantity
((
String
)
"5200700 gCO₂eq"
).
asType
(
CarbonEmission
.
class
)),
"Wrong conversion from kg of CO₂eq to gram of CO₂eq!"
);
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets