wissel.net

Usability - Productivity - Business - The web - Singapore & Twins

By Date: June 2013

Air Quality Measurements


Singapore is facing a severe haze crisis. Besides the subjective " this is bad", I got curious how the official air quality gets reported. Singapore's National Environment Agency uses the US devised Pollution Standard Index, but reports that onlt only as 24h, but also 3 h average for different places in the republic. Besides that they report the 2.5? particle (PM2.5) count that isn't part of the PSI ( PM stands for particulate matter).
So far it feels like the information is genuine. Nevertheless knowing how an abstract number is formed is the first step to independent verification. With a little digging NEA provides the detailed instructions how the value is computed. The substances measured are: Sulphur dioxide (?g/m?). Particles with 10? or more size (?g/m?), Carbon Monoxide (mg/m?), Ozone (?g/m?) and Nitrogene dioxide (?g/m?) which NEA publishes separately including a haze map:
Regional Haze Map
Source: NEA
A quick check on Google reveals, that air quality measurement is quite a popular application both with Arduino as well as the Raspberry PI (there are more). It seems the Arduino has an edge when it comes to coupling the sensors, while the Raspberry PI shines in aggregation and web accessibility. Probably a combination of both would be a winner. Something like the Pinoccio meshed with a Raspberry Pi powered CouchDB for aggregation.
The real challenge however are the sensors (and their calibration later on). The PSI measurements are in weight per volume, while most of the data sheets for the sensors I found state sensitivity in particles per million (PPM) or particles per billion (PPB). Luckily LennTech provides an online calculator to transcribe the values for us:
Substance range (weight/volume) Parts per million Parts per billion
Sulphur dioxide 80-2620 ?g/m? 0.0284 - 0.9289 28.4 - 928.9
Carbon monoxide 5-57.5 mg/m? 4.05 -46.6 4050 - 46600
Ozone 118-1180 ?g/m? 0.0558 - 0.558 55.8 - 558
Nitrogen dioxide 1130 - 3750 ?g/m? 0.558 - 1.85 558 - 1850
The PM concentration can't be converted from weight/volume into ppm using a static formula, since particles can be anything with different weight. It needs to be measured.
So the hunt for suitable sensors starts. SO2 seems to be the biggest item on the list. I've looked so far at the following providers: I would be grateful for more hints of suppliers. Once the sensors have been settled, further planning will commence. stay tuned!

Posted by on 23 June 2013 | Comments (1) | categories: After hours Singapore

Managed Beans, XPages and Testability


I like my Java to be well managed, properly prepared and of top quality.
Unless you are living under an XRock, you know that managed beans are (one of) the talk of the town in the XPages community.
While managed beans are simple beans that have been given a name and a scope, they need some thought when you want to test your applications.
Refering from one bean to another or to a session and the current database is made easy using com.ibm.xsp.extlib.util.ExtLibUtil. However I like to test my code outside the XPages environment, where such a call (or any call to a JSF resolver) will fail. So I came up with a helper class to make the beans testable. Let's start with a typical managed bean setup:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config>
<managed-bean>
<managed-bean-name>huey </managed-bean-name>
<managed-bean-class>com.ibm.disney.toons.ducks.Huey </managed-bean-class>
<managed-bean-scope>application </managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>dewey </managed-bean-name>
<managed-bean-class>com.ibm.disney.toons.ducks.Dewey </managed-bean-class>
<managed-bean-scope>session </managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>louie </managed-bean-name>
<managed-bean-class>com.ibm.disney.toons.ducks.Louie </managed-bean-class>
<managed-bean-scope>view </managed-bean-scope>
</managed-bean>
<!--AUTOGEN-START-BUILDER: Automatically generated by IBM Domino Designer. Do not modify.-->
<!--AUTOGEN-END-BUILDER: End of automatically generated section-->
</faces-config>
To access those beans from plain Java as well as the session and current database I use a helper class. It doesn't matter if you use thee helper from the command line or in an XPages, the results will be the same. What is important: you can't store the oobjects when you use them in the XPage since they are either not thread save (session, database) or would loose their scope association (the rest). If you want to make the setBeans (see below) method more robust, you could call javax.faces.context.FacesContext.getCurrentInstance(). If anything else but null is coming back, you are in the XPages thread and should not set the objects to anything but null (or add that to your getter?)
The enum.INSTANCE is a Singleton and asures that I always get the same object back. This allows me to write a test class (or actually use JUnit tests) like this:
package com.ibm.disney.toons.ducks ;

import lotus.domino.Database ;
import lotus.domino.NotesException ;
import lotus.domino.NotesFactory ;
import lotus.domino.NotesThread ;
import lotus.domino.Session ;

public class LocalTest {
public static void main ( String [ ] args ) throws NotesException {
System. out. println ( "Starting local test" ) ;
NotesThread. sinitThread ( ) ;
Session s = NotesFactory. createSession ( ) ;
Database db = s. getDatabase ( "", "Customers\\swg\\ctpsi-ap.nsf" ) ;
String [ ] roles = [ "[Scout]", "[Naseweis]", "[Neffe]" ] ;
Huey huey = (Huey ) DuckFactory. makeDuck ( "Huey" ) ;
Dewey dewey = (Dewey ) DuckFactory. makeDuck ( "Dewey" ) ;
Louie louie = (Louie ) DuckFactory. makeDuck ( "Louie" ) ;
DuckFetcher. INSTANCE. setBeans (s, db, huey, dewey, louie, roles ) ;
// Ducks do what ducks have to do
DuckAdeventure d = new DuckAdventure ( ) ;
d. getStarted ( ) ;
d. chaseBadguys ( ) ;
d. findSolution ( ) ;
d. shutDown ( ) ;
// Game over
DuckFetcher. INSTANCE. setBeans ( null, null, null, null, null ) ;
db. recycle ( ) ;
NotesThread. stermThread ( ) ;
System. out. println ( "Done!" ) ;
}
}
The test class is easily run from Eclipse or the debug perspecitve in Domino Designer and you can step through with the debugger. Other than the local http preview the code runs with the current userid's permissions, so you don't need to mess with the ACL. The whole class is about a hundred lines and pretty easy to understand:

Read more

Posted by on 20 June 2013 | Comments (1) | categories: XPages