Showing code samples for drill-down choice:
household sweepings.
Start over
Ruby
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# Install the AMEEconnect Ruby SDK with 'gem install amee'
# See https://github.com/AMEE/amee-ruby
require 'rubygems'
require 'amee'
# Server connection details
SERVER = "stage.amee.com"
USERNAME = "your_api_key"
PASSWORD = "your_api_key"
# The path and drill to identify the correct calculation
CATEGORY = "/home/waste"
DRILL = "type=household+sweepings"
# Create a connection to the server
amee = AMEE::Connection.new(SERVER, USERNAME, PASSWORD)
# Create a new profile
profile = AMEE::Profile::Profile.create(amee)
# Get the UID of the data item
uid = AMEE::Data::DrillDown.get(amee, "/data#{CATEGORY}/drill?#{DRILL}").data_item_uid
# Prepare the values for the calculation
# The following values MAY be provided for this usage
optional_values = {
:massPerTime => 'SOME_VALUE',
:savingType => 'SOME_VALUE'
}
# Store profile item and perform calculation
item = AMEE::Profile::Item.create_without_category(amee,
"/profiles/#{profile.uid}#{CATEGORY}",
uid,
optional_values
)
# Print results
puts 'Result:'
item.amounts.each do |amt|
puts "#{amt[:type]}: #{amt[:value]} #{amt[:unit]}#{'/'+amt[:per_unit] if amt[:per_unit].present?}"
end |
PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
<?php
// Install the AMEEconnect PHP SDK with 'pear install pearhub/Services_AMEE'
// See https://github.com/AMEE/amee-lib-php
// Include required files
require_once 'Services/AMEE/DataItem.php';
require_once 'Services/AMEE/Profile.php';
require_once 'Services/AMEE/ProfileItem.php';
// Server connection details
define('AMEE_API_URL', 'stage.amee.com');
define('AMEE_API_PROJECT_KEY', 'your_api_key');
define('AMEE_API_PROJECT_PASSWORD', 'your_api_password');
// The path and drill to identify the correct calculation
$sProfileCategory = "home/waste";
$aProfileCategory = array(
"type" => "household sweepings"
);
try {
// Create a new profile
$oProfile = new Services_AMEE_Profile();
// Get the data item
$oDataItem = new Services_AMEE_DataItem($sProfileCategory, $aProfileCategory);
// Prepare the values for the calculation
// The following values MAY be provided for this usage
$aOptionalProfileItemValues = array(
'massPerTime' => 'SOME_VALUE',
'savingType' => 'SOME_VALUE'
);
// Store profile item and perform calculation
$oProfileItem = new Services_AMEE_ProfileItem(array(
$oProfile,
$oDataItem,
$aOptionalProfileItemValues
));
// Display the result
$aInfo = $oProfileItem->getInfo();
echo "Result:\n";
echo "CO2 ({$aInfo['unit']}/{$aInfo['perUnit']}): {$aInfo['amount']}\n";
} catch (Exception $oException) {
// An error occured
echo "Error: " . $oException->getMessage() . "\n";
}
?> |
Java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
// First, get the AMEEconnect Java SDK and add to your CLASSPATH
// See https://github.com/AMEE/amee-lib-java
import java.util.List;
import java.util.ArrayList;
import com.amee.client.AmeeException;
import com.amee.client.service.*;
import com.amee.client.model.base.*;
import com.amee.client.model.profile.*;
import com.amee.client.model.data.*;
import com.amee.client.util.Choice;
public class CreateProfileItem {
public static void main(String[] args) throws AmeeException {
// Set up connection to the server
AmeeContext.getInstance().setUsername("your_api_key");
AmeeContext.getInstance().setPassword("your_api_password");
AmeeContext.getInstance().setBaseUrl("http://stage.amee.com");
AmeeObjectFactory objectFactory = AmeeObjectFactory.getInstance();
// The path and drill to identify the correct calculation
String profileCategory = "home/waste";
AmeeDrillDown drillDown = objectFactory.getDrillDown("home/waste/drill");
drillDown.addSelection("type","household sweepings");
// Create a new profile
AmeeProfile profile = objectFactory.getProfile();
// Get the UID of the data item
drillDown.fetch();
String dataItemUID = drillDown.getDataItem().getUid();
// Set options for new item
List<Choice> values = new ArrayList<Choice>();
// The following values MAY be provided for this usage
values.add(new Choice("massPerTime", SOME_VALUE));
values.add(new Choice("savingType", SOME_VALUE));
// Store profile item and perform calculation
AmeeProfileCategory cat = objectFactory.getProfileCategory(profile, profileCategory);
AmeeProfileItem item = cat.addProfileItem(dataItemUID, values);
// Print results
System.out.println("Result:");
System.out.format("CO2 (kg/year): %s\n", item.getAmount());
}
}
|
cURL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# These commands assume a bash shell and that
# you have curl and xpath available.
# Create profile and get UID
curl 'https://stage.amee.com/profiles' \
-X POST \
-d 'profile=true' \
-H 'Accept: application/xml' \
-u your_api_key:your_api_password \
| xpath '//Profile/@uid'
# Get data item UID
curl 'https://stage.amee.com/data/home/waste/drill?type=household+sweepings' \
-H 'Accept: application/xml' \
-u your_api_key:your_api_password \
| xpath '//Choices/Choice/Name/text()'
# Perform calculation
curl 'https://stage.amee.com/profiles/PROFILE_UID/home/waste' \
-X POST \
-d 'dataItemUid=DATA_ITEM_UID&representation=full&' \
-H 'Accept: application/xml' \
-u username:password \
| xpath '//Amounts/Amount' |