def get(self, area): area = int(area) radar_time = amayadori.get_radar_time() nowcast_time = amayadori.get_nowcast_time() links = [] for areainfo in areamanager.areas: if areainfo.code == area: links.append("<b>" + areainfo.name + "</b>") else: links.append('<a href="/image/' + str(areainfo.code) + '.html">' + areainfo.name + "</a>") values = { "area": ("%03i" % area), "radar_time": radar_time.strftime("%Y%m%d%H%M"), "nowcast_time": nowcast_time.strftime("%Y%m%d%H%M"), "link": "[ " + " | ".join(links) + " ]", } path = os.path.join(os.path.dirname(__file__), "views/image.html") html = template.render(path, values) self.response.out.write(html)
def get(self, lat, lng): lnglat = (float(lng), float(lat)) area = areamanager.get_nearest_area(lnglat) if area == None: self.error_message("範囲外です。") return xy = area.lnglat_to_xy(lnglat) current_time = amayadori.get_current_time() radar_time = amayadori.get_radar_time(current_time) nowcast_time = amayadori.get_nowcast_time(current_time) time_table = amayadori.get_time_table(radar_time, nowcast_time) # 雨量解析を投機的に実行 trackers = [] for (image_time, image_ordinal), present_time in time_table: tracker = taskmanager.add_rainfall_task(area.code, image_time, image_ordinal, xy) trackers.append(tracker) # すべての投機的タスクの実行が完了するか、4秒経過するまで待つ for i in range(20): rest = len([0 for tracker in trackers if not tracker.is_completed()]) if rest == 0: break time.sleep(0.2) records = [] for (image_time, image_ordinal), present_time in time_table: rainfall = amayadori.get_rainfall(area.code, image_time, image_ordinal, xy) if rainfall[0] == rainfall[1]: rainfall_str = str(rainfall[0]) else: rainfall_str = str(rainfall[0]) + "~" + str(rainfall[1]) records.append({ "type": ("現在値" if image_ordinal == 0 else "予測値"), "time": present_time.strftime("%H時%M分"), "delta": timeutil.timedelta_to_word(present_time - current_time), "rainfall": rainfall_str, "image_time": image_time.strftime("%Y%m%d%H%M"), "image_ordinal": ("%02i" % image_ordinal), }) # http://amayadori-opt.appspot.com/ のためのGoogle Maps API Key mapkey = "ABQIAAAA-ys93Qu6HH7Py3ElrvrGIxQGMNRpk4DlDb3SBK780CawkJsqbhR6Q77-5by3FYPdmP6wscv2utyMUQ" values = { "area" : str(area.code), "lat" : str(lnglat[1]), "lng" : str(lnglat[0]), "x" : str(xy[0]), "y" : str(xy[1]), "mapkey" : mapkey, "current_time_ja": current_time.strftime("%H時%M分"), "radar_time" : radar_time.strftime("%Y%m%d%H%M"), "radar_time_ja" : radar_time.strftime("%Y-%m-%d %H:%M"), "nowcast_time" : nowcast_time.strftime("%Y%m%d%H%M"), "nowcast_time_ja": nowcast_time.strftime("%Y-%m-%d %H:%M"), "records" : records, } path = os.path.join(os.path.dirname(__file__), "views/view.html") html = template.render(path, values) self.response.out.write(html)