def send(): ip_addr = request.remote_addr if request.method == "POST": return redirect(url_for("home")) data = json.load(open('data.json')) jtopy = json.dumps(data) dict_json = json.loads(jtopy) print(jsonify(dict_json)) x = dict_json['x'] y = dict_json['y'] found_user = users.query.filter_by(ip=ip_addr).first() state = found_user.state county = found_user.county file = corona.get_file(raw_data) x = [] y = [] corona.get_data(x, y, file, state, county) return render_template("graph.html", state=state, county=county, json_data=dict_json, x=x, y=y)
def sms_reply(): """Respond to incoming calls with a simple text message.""" # Fetch the message msg_text = request.form.get('Body') phone_no = request.form.get('From') if(bool(phone_no)==False): msg = MessagingResponse() resp = msg.message("Hello this is a bot which gives you covid-19 statistics just enter a country name and it " "will provide with current statistics ") return str(resp) else: # Create reply data = get_data(msg_text) msg = MessagingResponse() resp = msg.message(data) return str(msg)
def home(): ''''global selected if not selected: file = corona.get_file(raw_data) states = corona.get_states(file) keys = [] values = [] corona.create_dict(keys, values, file, raw_data) return render_template("index.html", states=states, len=len(states), len2=len(keys), keys=keys, values=values, seleceted=selected) else:''' global selected if request.method == "POST": state = request.form['state'] county = request.form['county'] if state == 'default' or county == 'county': state = 'California' county = 'San Francisco' file = corona.get_file(raw_data) x = [] y = [] dump_data(state, county, file, x, y, 'data.json') corona.get_data(x, y, file, state, county) ip_addr = request.remote_addr found_user = users.query.filter_by(ip=ip_addr).first() if found_user: found_user.state = state found_user.county = county db.session.commit() else: user = users(ip_addr, state, county) db.session.add(user) db.session.commit() file = corona.get_file(raw_data) states = corona.get_states(file) keys = [] values = [] corona.create_dict(keys, values, file, raw_data) print(selected) return render_template("index.html", states=states, len=len(states), len2=len(keys), keys=keys, values=values, selected='True') else: ip_addr = request.remote_addr file = corona.get_file(raw_data) states = corona.get_states(file) keys = [] values = [] corona.create_dict(keys, values, file, raw_data) file = corona.get_file(raw_data) x = [] y = [] data = json.load(open('data.json')) jtopy = json.dumps(data) dict_json = json.loads(jtopy) state = dict_json['state'] county = dict_json['county'] found_user = users.query.filter_by(ip=ip_addr).first() if found_user: found_user.state = state found_user.county = county db.session.commit() else: user = users(ip_addr, state, county) db.session.add(user) db.session.commit() dump_data(state, county, file, x, y, 'data.json') file = corona.get_file(raw_data) return render_template("index.html", states=states, len=len(states), len2=len(keys), keys=keys, values=values, selected=selected)
def dump_data(state, county, file, x, y, json_file): corona.get_data(x, y, file, state, county) data = {'x': x, 'y': y, 'state': state, 'county': county} with open(json_file, 'w') as outfile: json.dump(data, outfile, indent=4)
def main(): country = get_params() if not country: data = corona.get_data(True, True) COUNTRY = None else: c = r'\b' + re.escape(str(country).lower()) + r'\b' data = corona.get_data(True, False, c) if not data: print(u.error(), 'INVALID COUNTRY') quit() COUNTRY = 'US' if country == 'Us' else country # Get everything for plot & print xarr, yarr = build_func_data(data, COUNTRY) a, k_e, b, L, k_l, x0 = get_functions(xarr, yarr) B = 0 # b-value in exp function if COUNTRY is None: dates = list(data.keys()) else: dates = list(data[COUNTRY].keys()) # Print functions and data print_functions(a, k_e, B, L, k_l, x0) print_forecast(L, k_l, x0, a, k_e, B, dates, yarr, ndays) # Print last expected date and estimated number of confirmed cases based on logistic function start = datetime.strptime(dates[0], "%y-%m-%d").date() print_last_day(L, k_l, x0, start) # Plot graph try: # Generate dates for x-axis x_values = [ start + timedelta(days=x) for x in range(len(dates) + ndays) ] # Generate y-values end = len(x_values) x = numpy.linspace(0, end, num=end) y_values_e = exponential(x, *[a, k_e, B]) y_values_l = logistic(x, *[L, k_l, x0]) # Set size plt.rcParams['figure.figsize'] = [16, 9] plt.rc('font', size=10) # Format x-axis & y-axis fig, ax = plt.subplots() fig.autofmt_xdate() formatter = mdate.DateFormatter('%y-%m-%d') ax.xaxis.set_major_formatter(formatter) ax.get_xaxis().set_major_locator(mdate.DayLocator(interval=7)) ax.yaxis.set_major_formatter(ticker.StrMethodFormatter('{x:,.0f}')) plt.scatter(x_values[:len(xarr)], yarr, zorder=3, marker='o', s=40, alpha=0.75, edgecolors="dimgrey", color="lightgrey", label="Real") plt.plot(x_values, y_values_e, marker='.', markersize=4, linewidth=1, color='firebrick', label="Exponential") plt.plot(x_values, y_values_l, marker='.', markersize=4, linewidth=1, color='green', label="Logistic") plt.text(x_values[-ndays], yarr[-1], '{:,.0f}'.format(yarr[-1]), color="dimgrey") plt.grid() plt.legend() plt.show() except Exception as e: print(e.args)