简体   繁体   中英

converting ddmmyy into week number

I have my ML model which takes input as week number and predicts output using flask framework. I have considered starting date from 04-01-2016 as week number 1 and so on till 23-12-2019 (week number is 208). I want my user in HTML page to select date via datepicker, and that selected ddmmyy should be converted to equivalent week number. If I try to use datetime library it will show week number between 1-52. But I've considered 53,54,55.... after 52. 数据文件

How can I implement this? and where to insert this conversion and call in flask framework.

当前框架直接将周数作为输入 I'm unable to find a logic.

import numpy as np
from flask import Flask, request, jsonify, render_template
import pickle

app = Flask(__name__)
model = pickle.load(open('mech.pkl', 'rb'))

@app.route('/')
def home():
   return render_template('mech.html')

@app.route('/predict',methods=['POST'])
def predict():
   int_features = [int(x) for x in request.form.values()]
   final_features = [np.array(int_features)]
   prediction = model.predict(final_features)

output = round(prediction[0], 2)

return render_template('mech.html', prediction_text='Water prediction should be {} litres'.format(output))


if __name__ == "__main__":
    app.run(debug=True)

js uses milliseconds when it calculates dates. Start with your base date. convert to an actual date and then subtract that from each of your dates in question. divide as needed and you'll get the week you're looking for. Also note that new Date() takes a string in mdy format so your dmy format first needs to be converted. if you are using jquery datepicker I believe you'll get a string already in the correct mdy format. This logic would be added to your predict route. But remember you are now dealing with a string. example follows:

 function dmy_mdy(base){ base = base.split('-') return base[1] + '-' + base[0] + '-' + base[2] } var baseDate = new Date(dmy_mdy('04-01-2016')) var newDate = new Date(dmy_mdy("28-11-2016")) var dateDiff = newDate - baseDate var week =Math.ceil( dateDiff / (60*60*24*1000*7)) + 1 console.log(week )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM