fetching weather data

classic Classic list List threaded Threaded
6 messages Options
GL
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

fetching weather data

GL
Hi PowerTAC developers,

To save you time let me first go straight to the point.

Question:
How can I fetch weather data (e.g. call getTemperature()) from the sample broker class?

Detailed query:
I have made a copy sample-broker. So far I have managed to make it work and trade along the default broker. After making easy modifications to the improveTarrifs() method of PortfolioManagerService class. I realized that having info of past weather conditions can be useful. So I have tried using the code in powertac-tools/logtool-examples/src/main.../WeatherStats.java without success.
What I'm tryng to accomplish is to retrieve the current or past weather conditions, such as temperature, from the sample-broker classes like PortfolioManagerService. I appreciate if you could shed some light on how to approach this. Please find below what I tried:

//somehwere inside improveTarrifs()
WeatherStats wr = new WeatherStats();
double temperature = wr.getTemperature();
system.out.println("Temperature="+temperature);

This didn't work. I imported the logtools.commons.* into the  PortfolioManagerService class but still no success.

Concluding remarks:
I appreciate your time and I find PowerTAC a brilliant idea.

Thanks.

Genaro

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: fetching weather data

grampajohn
Administrator
Hello, Genaro -
GL wrote
Question:
How can I fetch weather data (e.g. call getTemperature()) from the sample broker class?

Detailed query:
I have made a copy sample-broker. So far I have managed to make it work and trade along the default broker. After making easy modifications to the improveTarrifs() method of PortfolioManagerService class. I realized that having info of past weather conditions can be useful. So I have tried using the code in powertac-tools/logtool-examples/src/main.../WeatherStats.java without success.
What I'm tryng to accomplish is to retrieve the current or past weather conditions, such as temperature, from the sample-broker classes like PortfolioManagerService. I appreciate if you could shed some light on how to approach this. Please find below what I tried:
This is a very good question. Weather reports and forecasts are sent to the broker, and they are currently handled by the MarketManagerService. But it doesn't do anything with them, it just drops them on the floor.

It might make sense to put them into the WeatherReportRepo and the WeatherForecastRepo respectively. You would have to autowire them, like the TimeslotRepo is currently autowired (near the top). Once you have references to these repos, each has an add() method that takes a WeatherReport or WeatherForecast respectively. The WeatherReportRepo will then return the currentWeatherReport() or the list of allWeatherReports().  The WeatherForecastRepo works pretty much the same way. You might be better off just keeping track of them yourself if you want to implement more sophisticated queries.

Does this make sense?

John
GL
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: fetching weather data

GL
Hi John,

Thanks a million for the advises. They helped, although I took a different path but I am still getting the current temperature. Would you please tell me if what I did is the right thing.

Initial Attempt

I Autowired in the PortfolioManagerService class like this:

@Autowired
private WeatherReportRepo weatherReportRepo;

then inside the activate() method I inserted this:

if(weatherReportRepo.count()>0)
{
  double tempe = weatherReportRepo.currentWeatherReport().getTemperature();
  System.out.println("Im in activate and temp is="+ tempe);
}

For some reason weatherReportRepo.count() never increased. Thus, I was not getting temperature readings.

Final working Attempt

In the MarketManagerService class I updated/inserted:

private double temperature=0.0;

public synchronized void handleMessage (WeatherReport report)
{
  temperature=report.getTemperature();
}
 
public double temp ()
{
  return temperature;
}

Then in the interface MarketManager, I added, below getMeanMarketPrice ();, this:
public double temp();

Finally, in the PortfolioManagerService class

double mytemp = marketManager.temp();
System.out.println("temp="+ mytemp);

I compiled and tested the broker and I got what I was expecting.

Question
Would you give me your impressions of why the initial attempt didn't work. I think my doubt is who is in charge of adding weather reports into the Repo? My guess would be the server but I am quite confused at the moment.

Thanks again for your patient and help.

Genaro
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: fetching weather data

grampajohn
Administrator
Hello again, Genaro
GL wrote
...
Would you give me your impressions of why the initial attempt didn't work. I think my doubt is who is in charge of adding weather reports into the Repo? My guess would be the server but I am quite confused at the moment.
The server does indeed add weather reports to its own repo, but that's a different repo instance than the one you autowired into your broker. It's at the other end of the wire, in a different process. It's just a Java class, not a shared database.

What you are missing is that you need to add the incoming weather reports to your local repo, in the handleMessage() method.

Does this help?

John
GL
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: fetching weather data

GL
Hi John,

I think now I understand what you said. So this is what I did:

    In MarketManagerService class

    import org.powertac.common.repo.WeatherReportRepo;

    @Autowired
    private WeatherReportRepo wrRepo;

    public synchronized void handleMessage (WeatherReport report)
    {
          wrRepo.add(report);
    }

Such that in PortfolioManagerService class I added:

    @Autowired
    private WeatherReportRepo weatherReportRepo;

    double tempe = weatherReportRepo.currentWeatherReport().getTemperature();

I'm getting temperature and the other weather variables as well.

If this is not what you meant please let me know.

You might be guessing why I'm so confused; I use C by and large. This is my first time with Java and seems to be a more puzzling language.

Regards,
Genaro

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: fetching weather data

grampajohn
Administrator
I'm glad you got it working. I've worked extensively in C and at least 15 other languages over the last 40 years. The most productive language I've worked in was Lisp, but in my experience Java is far more productive than C or C++ for this type of programming. By productive, I mean the amount of working code an experienced developer can implement in a given amount of time (and the Java advantage grows significantly if you want your code to run on multiple platforms).

If you look around in the Power TAC code, you will see extensive use of the vast array of libraries available for the Java platform, such as Spring, Apache MQ, AspectJ, XStream, Joda Time, Mockito, log4j, several of the Apache Commons libraries, and of course Apache Maven which is what allows us to distribute the server as a simple pom.xml file with a README and some configuration. We also make heavy use of Java annotations and reflection to push dependency resolution off to runtime, simplifying code considerably. You have already seen some of that, in the form of the handleMessage() methods in the sample-broker services. Note that there is no explicit registration of these methods as you might expect from an implementation of the Observer pattern. Handler registration happens in broker-core, specifically in PowerTacBroker.registerMessageHandlers(), called during broker initialization. Annotations also standardize module configuration and generation of the state logs across modules; for example, if you look at WeatherReport, you will see the @Domain annotation in front of the class declaration. The result of that annotation is that an entry is made in the state log whenever a new instance of WeatherReport is created, either by calling its constructor or by having one created as a result of an incoming weather-report message.

Have fun building your broker. I hope it does well in the competition.

John
Loading...