Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PLUM
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Land Use Lab
PLUM
Commits
f9529136
Commit
f9529136
authored
5 years ago
by
R0slyn
Browse files
Options
Downloads
Patches
Plain Diff
Files missed out of last commit for demand system rebasing.
parent
8c6215bf
No related branches found
No related tags found
No related merge requests found
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
data/calories_per_t.csv
+1219
-0
1219 additions, 0 deletions
data/calories_per_t.csv
src/ac/ed/lurg/demand/CalorieManager.java
+80
-0
80 additions, 0 deletions
src/ac/ed/lurg/demand/CalorieManager.java
with
1299 additions
and
0 deletions
data/calories_per_t.csv
0 → 100644
+
1219
−
0
View file @
f9529136
This diff is collapsed.
Click to expand it.
src/ac/ed/lurg/demand/CalorieManager.java
0 → 100644
+
80
−
0
View file @
f9529136
package
ac.ed.lurg.demand
;
import
java.io.BufferedReader
;
import
java.io.FileReader
;
import
java.util.HashMap
;
import
java.util.Map
;
import
ac.ed.lurg.ModelConfig
;
import
ac.ed.lurg.country.CountryManager
;
import
ac.ed.lurg.country.SingleCountry
;
import
ac.ed.lurg.types.CommodityType
;
import
ac.ed.lurg.utils.LogWriter
;
public
class
CalorieManager
{
private
static
final
int
COUNTRY_COL
=
0
;
private
static
final
int
COMMODITY_COL
=
1
;
private
static
final
int
CALORIE_PER_G_COL
=
2
;
private
Map
<
SingleCountry
,
Map
<
CommodityType
,
Double
>>
calorieMap
=
new
HashMap
<
SingleCountry
,
Map
<
CommodityType
,
Double
>>();
public
CalorieManager
()
{
super
();
read
();
}
public
void
read
()
{
String
filename
=
ModelConfig
.
CALORIE_PER_T_FILE
;
try
{
BufferedReader
fitReader
=
new
BufferedReader
(
new
FileReader
(
filename
));
String
line
,
countryName
,
commodityName
;
double
kcalPerT
;
fitReader
.
readLine
();
// read header
while
((
line
=
fitReader
.
readLine
())
!=
null
)
{
String
[]
tokens
=
line
.
split
(
","
);
if
(
tokens
.
length
<
3
)
LogWriter
.
printlnError
(
"Too few columns in "
+
filename
+
", "
+
line
);
countryName
=
tokens
[
COUNTRY_COL
];
commodityName
=
tokens
[
COMMODITY_COL
];
kcalPerT
=
Double
.
parseDouble
(
tokens
[
CALORIE_PER_G_COL
]);
SingleCountry
country
=
CountryManager
.
getForName
(
countryName
);
if
(
country
==
null
)
LogWriter
.
printlnError
(
"Null country for"
+
countryName
);
else
{
CommodityType
commodity
=
CommodityType
.
getForFaoName
(
commodityName
);
Map
<
CommodityType
,
Double
>
commodityMap
=
calorieMap
.
get
(
country
);
if
(
commodityMap
==
null
)
{
commodityMap
=
new
HashMap
<
CommodityType
,
Double
>();
calorieMap
.
put
(
country
,
commodityMap
);
}
commodityMap
.
put
(
commodity
,
kcalPerT
);
}
}
fitReader
.
close
();
}
catch
(
Exception
e
)
{
LogWriter
.
printlnError
(
"Failed in reading country specific calorie per t values"
);
LogWriter
.
print
(
e
);
}
LogWriter
.
println
(
"Processed "
+
filename
+
", create "
+
calorieMap
.
size
()
+
" calorie per t values"
);
}
public
Map
<
CommodityType
,
Double
>
get
(
SingleCountry
country
)
{
Map
<
CommodityType
,
Double
>
commodityMap
=
calorieMap
.
get
(
country
);
if
(
commodityMap
==
null
)
{
LogWriter
.
printlnError
(
"CalorieManager: can't calorie get values for "
+
country
);
return
null
;
}
return
commodityMap
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment