-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Peva Blanchard
committed
Jan 26, 2024
1 parent
6fece28
commit d74dc4e
Showing
11 changed files
with
158 additions
and
97 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
tutorials/02-language-features/05-datasources/00-datasources.lca
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
A datasource is assumed to provide a sequence of records. | ||
For now, only the local CSV file source is supported. | ||
*/ | ||
|
||
datasource inventory { | ||
/* | ||
The location is relative to the path chosen when invoking the cli. | ||
*/ | ||
location = "data/inventory.csv" | ||
|
||
/* | ||
The schema is defined using default values. Note that the unit of | ||
the default value will be the one chosen for the entire column. | ||
*/ | ||
schema { | ||
quantity = 1 p | ||
ram_size = 16 GB | ||
storage_size = 1 TB | ||
amortization_period = 5 year | ||
power = 400 W | ||
ram_allocation = 75 percent | ||
storage_allocation = 25 percent | ||
|
||
// embodied impact | ||
GWP = 0 kg_CO2_Eq | ||
WU = 0 m3 | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
tutorials/02-language-features/05-datasources/01-lookup.lca
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
Lookup primitive | ||
*/ | ||
|
||
process my_lookup { | ||
products { | ||
1 p material | ||
} | ||
variables { | ||
/* | ||
The lookup primitive fetches exactly one record matching | ||
the given condition. Here, the chosen row is the one whose | ||
value in the column 'id' equals the value "small". | ||
|
||
If no record or more than one record is found, an error | ||
is thrown. | ||
*/ | ||
row = lookup inventory match id = "small" | ||
|
||
/* | ||
Individual entries of the record are accessed using | ||
the dot syntax. Their dimensions is specified by | ||
the data source schema. | ||
*/ | ||
|
||
quantity = row.quantity | ||
GWP = row.GWP | ||
} | ||
|
||
impacts { | ||
quantity * GWP GWP | ||
} | ||
} | ||
|
||
test my_lookup { | ||
given { | ||
1 p material from my_lookup | ||
} | ||
assert { | ||
GWP between 38 p * 2800 kg_CO2_Eq and 38 p * 2900 kg_CO2_Eq | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
process datacenter { | ||
params { | ||
id = "dc-zone-01" | ||
} | ||
variables { | ||
dc = lookup datacenters match id = id | ||
total = dc.reserved_power * dc.amortization_period | ||
} | ||
products { | ||
total energy | ||
} | ||
inputs { | ||
// include electricity from the relevant geographic zone | ||
total electricity from electricity_mix(geo = dc.geo) | ||
|
||
// include all components belonging to the given datacenter | ||
for_each row from datacenter_components match datacenter_id = dc .id { | ||
|
||
// pass the component parameters | ||
1 p component from datacenter_component(dc_component = row) | ||
} | ||
} | ||
} | ||
|
||
process datacenter_component { | ||
params { | ||
dc_component from datacenter_components | ||
} | ||
products { | ||
1 p component | ||
} | ||
impacts { | ||
dc_component.GWP GWP | ||
} | ||
} | ||
|
||
process electricity_mix { | ||
params { | ||
geo = "GLO" | ||
} | ||
variables { | ||
mix = lookup electricity_mixes match geo = geo | ||
} | ||
products { | ||
1 kWh electricity | ||
} | ||
impacts { | ||
mix.GWP GWP | ||
} | ||
} | ||
|
||
test datacenter { | ||
given { | ||
1 kWh energy from datacenter(id = "dc-zone-01") | ||
} | ||
assert { | ||
GWP between 70 g_CO2_Eq and 75 g_CO2_Eq | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters