According to the utility electrical meter, this morning the house is at 4496 kwh.
***
Looking back at my own LJ posts, the earliest one with the new meter on the house was 2010-01-20, where I posted it read 159kwh (http://mrflash818.livejournal.com/83167.html)
2010-10-01 - 2010-01-20 = X days (2010-10-06 according to quick and dirty spreadsheet math, X should be 254, which means the average also should be 17kwh/day.
>> 2010-10-17 EDIT, after using BigDecimal and spending hours, as documented below, getting Debian Lenny Stable to be able to actually compile Java using Eclipse and Sun's/Oracle's JDK I have indeed computed 254 is the right answer [...falling to floor... THUD] ) <<
4496kwh - 159kwh = 4337 kwh
4337 kwh / X days = kwh average use per day during that time period.
***
To determine X, I'll use java. Fired up eclipse v3.2 in Debian lenny stable, ...and received error messages! oh no!
"robert@pip:~$ eclipse
searching for compatible vm...
testing /usr/lib/jvm/java-6-openjdk...not found
testing /usr/lib/jvm/java-gcj...found
/usr/lib/jvm/java-gcj/bin/java: symbol lookup error: /home/robert/.eclipse/org.eclipse.platfo
rm_3.2.0/configuration/org.eclipse.osgi/b
undles/149/1/.cp/libswt-mozilla-gtk-3236.s
o: undefined symbol: _ZN4nsID5ParseEPKc"
Okay, then did a quick google search on the phrase "libswt-mozilla-gtk-3236.so: undefined symbol"
Which led me to http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=511713
"install
xulrunner-dev
and eclipse 3.2.2-6.1 should start under lenny."
So I then did robert@pip:~$ sudo aptitude install xulrunner-dev
Now eclipse v3.2 fires up fine in my Debian Lenny stable workstation.
***
When trying to run or debug my java program in eclipse v3.2.2-6.1
"Exception in thread "main" java.lang.NoClassDefFoundError:
at gnu.java.lang.MainThread.run(libgcj.so.9
0)
Caused by: java.lang.ClassNotFoundException: not found in gnu.gcj.runtime.SystemClassLoader{urls=[f
ile:/home/robert/projects/java/daysBetwe
enDates/DateArithmetic/], parent=gnu.gcj.runtime.ExtensionClassLoa
der{urls=[], parent=null}}
at java.net.URLClassLoader.findClass(libgcj.s
o.90)
at gnu.gcj.runtime.SystemClassLoader.findCl
ass(libgcj.so.90)
at java.lang.ClassLoader.loadClass(libgcj.s
o.90)
at java.lang.ClassLoader.loadClass(libgcj.s
o.90)
at gnu.java.lang.MainThread.run(libgcj.so.9
0)"
Searching on google again:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=275656
Okay, so seems I need to get the Java JDK, fine:
http://wiki.debian.org/Java
robert@pip:~$ sudo aptitude install default-jre
robert@pip:~$ java --version
java version "1.5.0"
gij (GNU libgcj) version 4.3.2
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Shutdown and restarted Eclipse, rebuilt, and tried again... still failed.
***
Installing the default-jre did not work, so now will go install the actual Java from Sun/Oracle that is still via Debian packages:
http://wiki.debian.org/Java/Sun
robert@pip:~$ sudo aptitude install sun-java6-jdk
Couldn't find any package whose name or description matched "sun-java6-jdk" (grr!)
***
Adjusting aptitude sources list to include searches in non-free
added a line to
/etc/apt/sources.list
robert@pip:/etc/apt$ sudo view sources.list
edited the existing lines to append 'non-free' at the end:
deb http://ftp.debian.org/debian/ lenny main non-free
deb-src http://ftp.debian.org/debian/ lenny main non-free
next did
robert@pip:~$ sudo aptitude update
...so aptitude now also has the list of packages available in non-free
and finally
robert@pip:~$ sudo aptitude install sun-java6-jre
robert@pip:~$ sudo aptitude install sun-java6-jdk
Sun's java installed into: robert@pip:/usr/lib/jvm/java-6-sun-1.6.0.2
0$
robert@pip:/usr/lib/jvm/java-6-sun/bin$ ./javac -version
javac 1.6.0_20
***
2010-10-17
Now just need to tell eclipse where the sun java goodies are.
Project-->Properties-->Java Build Path--> set the "Standard VM" to be set to /usr/lib/jvm/java-6-sun-1.6.0.20
***
Now back to the original goal, use java to calculate the number of days between 2010-10-01 and 2010-01-20:
First I just used long and double, but was not happy with the final result's rounding error after just 4 division operations, so switched to BigDecimal.
***
Here is the source code:
DatesBetweenTwoDates.java
----------------------------------------
----
package org.rxl.DateArithmetic;
import java.lang.String;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Calendar;
import java.util.Date;
import java.util.StringTokenizer;
public class DaysBetweenTwoDates {
/**
* Takes a String in the form of yyyy-mm-dd Returns Date set to yyyy-mm-dd
* with time of 00:00:00
*
* @param dateString
* @return Date
*/
static Date parseDateString(String dateString) {
int year = 0;
int month = 0;
int dayOfMonth = 0;
String item = null;
Date result = null;
StringTokenizer st = new StringTokenizer(dateString, "-");
item = st.nextToken();
year = Integer.parseInt(item);
item = st.nextToken();
month = Integer.parseInt(item);
item = st.nextToken();
dayOfMonth = Integer.parseInt(item);
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, year);
// January is MONTH value of 0
cal.set(Calendar.MONTH, month-1);
cal.set(Calendar.DAY_OF_MONTH, dayOfMonth);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
result = cal.getTime();
return result;
}
public static String printDate(Date date) {
String result = "";
Calendar cal = Calendar.getInstance();
cal.setTime(date);
result += cal.get(Calendar.YEAR);
result += "-";
result += cal.get(Calendar.MONTH) + 1;
result += "-";
result += cal.get(Calendar.DAY_OF_MONTH);
return result;
}
public static void usage() {
}
/**
* @param args
*/
public static void main(String[] args) {
if (args.length != 2) {
usage();
System.exit(0);
}
Date date1 = null;
Date date2 = null;
date1 = parseDateString(args[0]);
date2 = parseDateString(args[1]);
long lminDate = Math.min(date1.getTime(), date2.getTime());
long lmaxDate = Math.max(date1.getTime(), date2.getTime());
long lresult = lmaxDate - lminDate;
System.out.println("The difference between " + printDate(date1) + " and " + printDate(date2) + " is: ");
System.out.println("milliseconds: " + lresult);
//double dresult = lresult;
int SCALE = 1;
BigDecimal bdResult = new BigDecimal(lresult);
//dresult = dresult / (double) 1000.0;
bdResult = bdResult.divide(new BigDecimal(1000),SCALE,RoundingMode.HALF
_UP);
System.out.println("seconds: " + bdResult);
//dresult = dresult / (double) 60.0;
bdResult = bdResult.divide(new BigDecimal(60),SCALE,RoundingMode.HALF_U
P);
System.out.println("minutes: " + bdResult);
//dresult = dresult / (double) 60.0;
bdResult = bdResult.divide(new BigDecimal(60),SCALE,RoundingMode.HALF_U
P);
System.out.println("hours: " + bdResult);
//dresult = dresult / (double) 24.0;
bdResult = bdResult.divide(new BigDecimal(24),SCALE,RoundingMode.HALF_U
P);
System.out.println("days: " + bdResult);
}
}
***
Here is the result:
The difference between 2010-10-1 and 2010-1-20 is:
milliseconds: 21942000000
seconds: 21942000.0
minutes: 365700.0
hours: 6095.0
days: 254.0
***
Tags: debian, eclipse, electricity, java, kwh, lenny, non-free, stable, utility
Current Mood:
mellow