Posts

Proper Asynchronous Loops in Javascript

I see this in PRs and catch myself doing it a lot, so putting this out here for my own reference. Loops in Javascript will not wait for await s before moving on to the next item or moving out of the loop entirely.  The easiest way I've found to get around this is to collect the promises from each iteration into an array via _.map , and then await Promise.all to make sure each iteration has completed before moving on. const  _ = require( 'underscore' ); function  sleep(ms) { return   new  Promise(resolve  =>  setTimeout(resolve, ms)); } async   function  wrong() {   _.forEach([ 1 , 2 , 3 ],  async   function  (i) {  await  sleep( 1000 ); console.log(i);});   console.log( 'done' ); };  wrong(); async   function  right() {    await  Promise.all(_.map([ 1 , 2 , 3 ],  async   function  (i) {  await  s...

Working with Esper: Problems and Solutions

Esper is an open-source Complex Event Processing solution for Java (or use NEsper for .NET). The code seems fairly straight forward, and there are plenty of examples included with the package. However, there is very little documentation available for troubleshooting problems. Over the last few days I have been attempting to set up a fairly simple example: read data from a CSV file and look for specific patterns (signaling an event). After spending hours debugging errors, I decided to put my findings all down in one place.  Exception in thread "main" com.espertech.esper.client.EPException: myInputFile.csv not found Put the file at the same level as the packages (under src/ or src/main/java in Maven) and then refresh the package explorer in Eclipse Exception in thread "main" com.espertech.esper.client.EPException: Encountered unexpected character " I removed quotation marks around my data in the csv file. I can't reproduce the problem now, it is wo...

Enhancing An Existing Project

In my last post , I did a technical review of an open source project to analyze how well it met the Three Prime Directives of Open Source Software. This week I have put that analysis to the test by actually enhancing the project. My group had created a system with the same functionality, but of course we approached the problems in very different ways than the group that created this code. Having written a similar system made some aspects of adding the enhancements easier because I knew what to expect, but it also made some parts more difficult because I made assumptions based on our previous project that weren't always true with this new project. Working with my group went really well this time, partially because it was a smaller job but also because we were familiar with each other's working and communication style. My group added three new functions to the command-line interface. The first is named "set-baseline" and takes a location and a date as arguments. Fo...

Technical Review

This week I will do a technical review of the hale-aloha-cli-jz software system made by some classmates. The project is a command line interface that displays various energy and power usage data for a group of buildings. For those of you who read last week's blog, you'll notice that it has the same functionality as the system my group created. If you haven't been keeping up, do not fear: I will do a recap of all of the technologies used in the project. First, the purpose and function of the software system. This project creates an interface to the WattDepot service. WattDepot can collect and store power and energy data from any electrical meter. In this case, we are using data from the meters within the Hale Aloha residential towers at the University of Hawaii-Manoa. Data from each meter can be aggregated into virtual sources, so data can be reported for an entire tower at once even though many meters are used to collect the data. Four commands are built into hale-aloha...

Issue-Driven Project Management

The projects I've written about so far have been done individually, by me alone. For small projects this is certainly less complex and usually faster, but not exactly a realistic software engineering method. Serious systems are almost always created in groups, with developers coming and going throughout the life of the project. Group projects mean having meetings, planning ahead, and sometimes compromising strongly held beliefs on the best solution to a problem. When approached incorrectly, they can cause endless frustration. So the goal of this post is to reveal what worked and what didn't in my latest experience with a group project. First I'll explain the project. My three-person team created a command line interface for WattDepot (the energy data system that I introduced in my last post). Four built-in commands produce current power usage, daily energy usage, energy usage since a particular date, and energy usage rankings for the four Hale Aloha residential towers on ...

WattDepot Katas

Image
Last week's post about energy in Hawaii was a precursor to today's task. I had briefly mentioned WattDepot , which is a web service that can collect and store energy and power data from smart meters. That data can then be analyzed and displayed for purposes of research, experimentation, and awareness. I've completed six katas using a WattDepot API. Kata 1: SourceListing Implement a class called SourceListing, whose main() method accepts one argument (the URL of the WattDepot server) and which writes out the URL argument and a list of all sources defined on that server and their descriptions, sorted in alphabetical order by source name.  Use the System.out.format method to provide a nicely formatted list.  This kata was very simple (and therefore a good place to start). It took about ten minutes to get used to the API and generate the correct output. It only required one API call to the server to get the list of sources, and then a loop through the list of sources to pri...

Energy in Hawaii

"Going Green" and using renewable energy are popular topics these days. Construction projects around the world are vying for LEED Certification, and solar panels and wind farms are becoming more commonplace. These efforts may be more important in Hawaii than in many other places.  Energy on Oahu is up to three times more expensive than on the mainland, and other islands can be even more expensive. This is mainly because of the isolation of our islands. All energy produced on the mainland is connected through a super grid, where very large and efficient plants can provide power for a big area. Energy can be bought and sold between regions of the grid. Obviously Hawaii is not connected to this grid - each of the islands must maintain their own grid which is much smaller and therefore not as efficient. Energy must be created on the same island it is needed on. The majority of the energy in our state comes from oil, which is the most expensive source. Only 1% of the mainland...