From e4e2ba5a94c02d1bb15c1d4aaf21430198fdf63a Mon Sep 17 00:00:00 2001 From: amilashanaka <dsa.amilashanaka@gmail.com> Date: Tue, 3 Jan 2023 02:30:52 +0000 Subject: [PATCH] add new endpoints --- api/run.py | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/api/run.py b/api/run.py index 1de2626..8e1ba81 100644 --- a/api/run.py +++ b/api/run.py @@ -9,6 +9,7 @@ from app import app import pandas as pd import datetime as dt import numpy as np +import json from sqlalchemy import create_engine @@ -23,6 +24,9 @@ from flask import flash, request from datetime import datetime, timedelta import matplotlib.pyplot as plt +import matplotlib.dates as mdates +import seaborn as sns +sns.set_theme(style="darkgrid") #================================================= @@ -199,6 +203,72 @@ setup() # end points declaration +@app.route("/plot_order-demands",methods=['GET']) +def plot_order_demands_total(): + global raw_data_set + sns.lineplot(x='Date', y='Order_Demand',hue='Warehouse', data=raw_data_set) + plt.figure(figsize=(20, 7)) + plt.xticks(rotation=15) + plt.gcf().autofmt_xdate() + + plt.legend() + plt.show() + + return "Order demand" + + +@app.route("/plot_order_demand_total",methods=['GET']) +def plot_order_demands(): + global data_set + import matplotlib.pyplot as plt + from matplotlib.ticker import (MultipleLocator, FormatStrFormatter, + AutoMinorLocator) + import matplotlib.dates as mdates + + dtFmt = mdates.DateFormatter('%Y-%b') # define the formatting + + sns.lineplot(x='Date', y='Order_Demand', data=data_set) + plt.figure(figsize=(20, 7)) + plt.gca().xaxis.set_major_formatter(dtFmt) + # show every 12th tick on x axes + plt.gca().xaxis.set_major_locator(mdates.MonthLocator(interval=1)) + plt.xticks(rotation=90, fontweight='light', fontsize='x-small',) + plt.legend() + plt.show() + + return "Order demand" + + +@app.route("/products",methods=['GET']) + +def products(): + global raw_data_set + result_array =raw_data_set['Product_code'].unique() + return result_array.tolist() + +@app.route("/date_range",methods=['GET']) + +def date_range(): + + result_array =data_set['Date'].unique() + return result_array.tolist() + + +@app.route("/warehouse",methods=['GET']) + +def warehouse(): + global raw_data_set + warehouse_array =raw_data_set['Warehouse'].unique() + return warehouse_array.tolist() + + +@app.route("/row_data",methods=['GET']) +def row_data(): + global raw_data_set + return raw_data_set.to_json(orient='records') + + + @app.route("/validation",methods=['GET']) def validation(): @@ -207,7 +277,7 @@ def validation(): return result.to_json(orient='records') @app.route("/forecast_to_date",methods=["POST"]) -def forecast(): +def forecast_to_date(): global data_set global scaler global index_data_set @@ -255,7 +325,7 @@ def forecast_to_range(): new_date=datetime.strptime(date, "%Y-%m-%d").date() new_date=new_date - timedelta(days=(feature_length-1)) new_date=new_date.strftime("%Y-%m-%d") - + result=predict_given_date(index_data_set,new_date, feature_length) df=pd.DataFrame() # df=pd.DataFrame(data=result,columns=["Prediction"]) -- GitLab