PokemonGoers / PredictPokemon-2

In this project we will apply machine learning to establish the TLN (Time, Location and Name - that is where pokemons will appear, at what date and time, and which Pokemon will it be) prediction in Pokemon Go.
Apache License 2.0
9 stars 3 forks source link

Add weather related features #6

Closed bensLine closed 8 years ago

bensLine commented 8 years ago

Add weather related features to the existing data. Possible features used in a tutorial:

goldbergtatyana commented 8 years ago

@Aurel-Roci @bensLine @marwage @MatthiasBaur & @semioniy, please get in touch with the members of group A https://github.com/PokemonGoers/PokeData to see which of these features they already have in their database.

And guys, we should really get the basics of ML covered. For that WE NEED an ARFF file created from our dummy data ASAP. We will use it to get to know the general steps of ML method development. Once we are familiar with these steps applying them to real data will really be fun.

Can we have the arff file today (Thursday)?

MatthiasBaur commented 8 years ago

Good morning, we meet this morning and assign more tasks. I am sure the .arff file will be ready later today.

bensLine commented 8 years ago

we contacted group A, you can follow the discussion here: https://github.com/PokemonGoers/PokeData/issues/71

semioniy commented 8 years ago

Will return: Timezone: String/ nominal, example: "Australia/Sydney" Weather: String/ nominal, example: "Partly Rain" WeatherShort: String/ nominal, example: "Rain" Temperature: numeric, example: 16.5 Humidity: numeric, example: 0.88 Speed of wind: numeric, example: 12.82 Wind bearing: numeric, example: 357 Pressure: numeric example: 995.57 @bensLine need your help with how to pass all this to "main class"

semioniy commented 8 years ago

Dear @goldbergtatyana, @juanmirocks, @sacdallago and @gyachdav,

I'm stuck with this feature for already three days and need your help. Please, ckeck the WeatherFeatures branch. I made it so that you have to run getApiDataTest.js, which avoids TEAM A api call as well as call of other features. Output gues to arff/getApiDataTest.arff, and the feature itself - weather_features.js. Shortly, the script gets pokeEntry object (described in readme) and array of keys. The script should give back json file with key: value pairs (key from keys array). It seems that while calling forecast.io API the script keeps on running without getting the respond, and I can't find a way to make it wait for the respond. Later than it should, but anyway the script gets the answer from API, which is put to the console.

Please, check the script for mistakes and correct/ hint me, if you can. Thanx in advance.

P.S. the commit is 9b5e6230c44e7ef8ce145ce47097f7829a552008

gyachdav commented 8 years ago

@semioniy this is a classic case where you want to use promises to make sure that all your AJAX calls have completed and then and only then call the method that makes use of all the data you collected. Remember that you are using AJAX calls which are async by nature and you will have to account for that using promises. I recommend you read a bit about JavaScript promises before proceeding and let us know if you have specific questions on how to make them work.

semioniy commented 8 years ago

@gyachdav I have a question about how to make it work. I awaited this to work, but it doesn't. var promise = new Promise (function(resolve, reject) { Forecast.getAtTime(pokeEntry.latitude, pokeEntry.longitude, timestamp, function (err, res, data) {.....}) if (resolve) { console.log("Resolved") }} But if (resolve) { console.log("Resolved") gets called before the asynchronous function Forecast.getAtTime() is ready. I expected that it'll wait untill response, but it just checks if there was an error or not. How can I make it wait?

gyachdav commented 8 years ago

@semioniy please take a closer read of how promises work

https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise

For instance I see you did not set up a callback in a then method that will handle the returned value of your asynch call.

I strongly suggest you read through some tutorials and play with a few exampled before you try to apply those to your code. It will make the whole mechanism behind the promises much clearer for you.

Hint: The promise prototype already takes care of waiting for async processes to resolve/reject and retrieve returned values once these are made available. You only need to learn how to properly take advantage of this facility.

semioniy commented 8 years ago

@gyachdav I just didn't want to paste here all the code. I have the ".then" var date = new Date(pokeEntry.appearedLocalTime) var timestamp = Math.round(date.getTime() / 1000) var promise = new Promise ( function(resolve, reject) { Forecast.getAtTime(pokeEntry.latitude, pokeEntry.longitude, timestamp, function (err, res, data) {//calling API for forecast if (err) throw err; else if (data) { //console.log(data) console.log("API Called") temp = [data.timezone, data.currently.summary, data.currently.precipType, ((data.currently.temperature - 32) / 1.8).toFixed(1), data.currently.humidity, data.currently.windSpeed, data.currently.windBearing, data.currently.pressure]; console.log("temp: " + temp) resolve(temp) } }); if (resolve) { console.log("Resolved") } else { console.log("Rejected") } }); promise.then( function(val){ respond[pokeEntry["_id"]] = val console.log("respond inside API call: " + respond[pokeEntry["_id"]]) returnResponse(keys, pokeEntry) } ); everything inside the then() gets skipped. But, as I understood from Howto`s, it shouldn't.

semioniy commented 8 years ago

@sacdallago maybe you can help?

semioniy commented 8 years ago

ok, I'll just make it with xmlhttprequest.

gyachdav commented 8 years ago

@semionly Pastebin would be nicer :smile:

You're on the right track though. If then was skipped it means something is not quite right with your code or and you'll need to debug. btw did you notice that you throw an err in your callback that never gets caught?

We unfortunately are not here to debug your code. That's part of the tough love we show. I strongly recommend that as a first step you simplify your code and just setup a promise, fire an API call, check that it is being resolved and then print out the response within your then method.

semioniy commented 8 years ago

@gyachdav xmlhttprequest worked, so it doesn't matter anymore. But there remains one thing to think about: forecast.io lets one have 1000 free requests/day. And I don't know, what happens when I exceed the limit yet.

sacdallago commented 8 years ago

@samitsv I use promises via Q in a slightly different way:

  1. Create a deferred promise and return it
  2. React on events of promise

About the limits: they probably just ban you for the rest of the day. Do you know if this has to do with IP or cookies?

semioniy commented 8 years ago

@sacdallago I have API key to access them. I wrote key switcher, so if they respond on my usual request somehow unusual, I just switch to the next key. (3 keys so far)

semioniy commented 8 years ago

all clear, weather features work