def save_to_mongo(_results, _saved, model_update_time): done = True for key in _results.keys(): result_pair = _results[key] if result_pair[1].return_value is None: done = False continue else: if _saved[key] == False: _saved[key] = True to_save = (result_pair[0], result_pair[1].return_value, result_pair[2]) region = to_save[0] for single_hour_prediction in zip(to_save[1], to_save[2]): p = Prediction() p.setRegion(region) p.setModelUpdateTime(model_update_time) p.setPredictedValues( float(single_hour_prediction[0][1]), math.sqrt(float(single_hour_prediction[0][2]))) p.setTime(str(single_hour_prediction[1])) p_json = p.toJSON() save_interface = PredictionInterface() save_interface.saveDocument(p_json) return done
def getNearestPrediction(self): pi = PredictionInterface() pi.setDB('citybeat_production') if self.data_source == 'instagram': pi.setCollection('online_prediction_instagram') else: pi.setCreatedTime('online_prediction_twitter') self.region.display() return pi.getNearestPrediction(self.region, str(self.cur_time))
def getNearestPrediction(self): pi = PredictionInterface() pi.setDB('citybeat') pi.setCollection('online_prediction') print 'set collection as ', self.prediction_collection print 'search for ' self.region.display() print str(self.cur_time) return pi.getNearestPrediction(self.region, str(self.cur_time))
def save_to_mongo(_results, _saved, model_update_time): done = True for key in _results.keys(): result_pair = _results[key] if result_pair[1].return_value is None: done = False continue else: if _saved[key] == False: _saved[key] = True to_save = (result_pair[0], result_pair[1].return_value, result_pair[2]) region = to_save[0] for single_hour_prediction in zip(to_save[1], to_save[2]): p = Prediction() p.setRegion(region) p.setModelUpdateTime(model_update_time) p.setPredictedValues( float(single_hour_prediction[0][1]), math.sqrt(float(single_hour_prediction[0][2]))) p.setTime( str(single_hour_prediction[1]) ) p_json = p.toJSON() save_interface = PredictionInterface() save_interface.saveDocument( p_json ) return done
def getNearestPrediction(self): pi = PredictionInterface() pi.setDB('citybeat') pi.setCollection('online_prediction') print 'set collection as ',self.prediction_collection print 'search for ' self.region.display() print str(self.cur_time) return pi.getNearestPrediction(self.region, str(self.cur_time))
from utility.prediction_interface import PredictionInterface if __name__ == "__main__": pi = PredictionInterface() pi.setDB('citybeat') pi.setCollection('online_prediction') region = { "min_lat": 40.79133132, "max_lng": -73.93005052, "min_lng": -73.9380568, "max_lat": 40.7966366 } condition = ({ 'region.min_lat': region['min_lat'], 'region.min_lng': region['min_lng'], 'region.max_lat': region['max_lat'], 'region.max_lng': region['max_lng'] }) prediction = pi.getNearestPrediction(region, '1361801869') #1361772000 print prediction
def getNearestPrediction(self): pi = PredictionInterface() pi.setDB('citybeat') pi.setCollection(self.prediction_collection) return pi.getNearestPrediction(self.region, str(self.cur_time))
def save_to_mongo(_results, _saved, model_update_time, data_source): done = True for key in _results.keys(): result_pair = _results[key] if result_pair[1].return_value is None: done = False logging.warn("Haven't finish yet for key %s, continue..." % key) continue else: if _saved[key] == False: _saved[key] = True to_save = (result_pair[0], result_pair[1].return_value, result_pair[2]) region = to_save[0] for single_hour_prediction in zip(to_save[1], to_save[2]): p = Prediction() p.setRegion(region) p.setModelUpdateTime(model_update_time) p.setPredictedValues( float(single_hour_prediction[0][1]), math.sqrt(float(single_hour_prediction[0][2])) ) p.setTime(str(single_hour_prediction[1])) p_json = p.toDict() if data_source == "twitter": save_interface = PredictionInterface() save_interface.setDB(TwitterConfig.prediction_db) save_interface.setCollection(TwitterConfig.prediction_collection) save_interface.saveDocument(p_json) elif data_source == "instagram": save_interface = PredictionInterface() save_interface.setDB(InstagramConfig.prediction_db) save_interface.setCollection(InstagramConfig.prediction_collection) save_interface.saveDocument(p_json) return done
def getNearestPrediction(self): pi = PredictionInterface() pi.setDB("citybeat") pi.setCollection(self.prediction_collection) return pi.getNearestPrediction(self.region, str(self.cur_time))
from utility.prediction_interface import PredictionInterface if __name__=="__main__": pi = PredictionInterface() pi.setDB('citybeat') pi.setCollection('online_prediction') region ={ "min_lat" : 40.79133132, "max_lng" : -73.93005052, "min_lng" : -73.9380568, "max_lat" : 40.7966366 } condition = ({'region.min_lat':region['min_lat'], 'region.min_lng':region['min_lng'], 'region.max_lat':region['max_lat'], 'region.max_lng':region['max_lng']}) prediction = pi.getNearestPrediction(region, '1361801869') #1361772000 print prediction