0

sorry to asking questions like this I am new to flask and html not able to figure out error where I am getting. building small application where it calculates the cycle count of the time series curves when curve profile lower end value <13 and peak end of the curve >20 my script calculates the count how many time the curve goes up above >20 and billow 13 values this is i did for static data if user input the data below 4 and above 15 it has to show the count value so far i used this script for count calculation

import numpy as np
from flask import Flask, render_template, request
app = Flask(__name__)
x = np.array([0, 7, 18, 24, 26, 27, 26, 25, 26, 16, 20, 16, 23, 33, 27, 27,
22, 26, 27, 26, 25, 24, 25, 26, 23, 25, 26, 24, 23, 12, 22, 11, 15, 24, 11,
12, 11, 27, 19, 25, 26, 21, 23, 26, 13, 9, 22, 18, 23, 26, 26, 25, 10, 22,
27, 25, 19, 10, 15, 20, 21, 13, 16, 16, 15, 19, 17, 20, 24, 26, 20, 23, 23,
25, 19, 15, 16, 27, 26, 27, 28, 24, 23, 24, 27, 28, 30, 31, 30, 9, 0, 11,
16, 25, 25, 22, 25, 25, 11, 15, 24, 24, 24, 17, 0, 23, 21, 0, 24, 26, 24,
26, 26, 26, 24, 25, 24, 24, 22, 22, 22, 23, 24, 26,23])
@app.route('/')
def main():
    return render_template('index.html',count_result=get_count(x))
@app.route('/send', methods=['POST'])

def get_count(id_count):
        first_input1=request.form["Input1"]
        first_input2 = request.form["Input2"]
        unit=int(first_input1)
        unit=int(first_input2)
        sub_lists = np.split(x1, np.where(np.diff(x1) < 0)[0] + 1)
        id_count = 0
        id_list = []
        for unit in sub_lists:
          if min(unit) <= 13 and max(unit) > 20 and len(set(unit)) > 1:
            id_count += 1
            id_list.append(unit)
        return render_template(
            'index.html',
            unit=unit,
            count_result=get_count(x1))
        return id_count
        return render_template("index.html", get_count(x1))
print("Number of counts: ", get_count(x))
if __name__=="__main__":
    app.run(debug=False, port=1223)

the values min(unit) and max(unit) in this script are static if user changes the values by inputs the values from UI the count has to get i have so much data like this for counting cycles how to approach this

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Calculator</title>
</head>
<body>
 <h1> Acceleration Calculator</h1>
 <form method="POST">
        <input type="text" name="Input1" id="Input1">
        <input type="text" name="Input2" id="Input2">
        <input type="submit" value="Submit"/>

   <br />
   <br />
     <p>the acceleration count lower end bilow 0 to 13 and upper end limits in between above 18 and bilow 26 is.....{{count_result}}  </p>
  </form>
</body>
</html>
davidism
  • 121,510
  • 29
  • 395
  • 339
  • Just so you now. You are overwritting the value of the variable unit when you do this the second assignment `unit=int(first_input2)`. Also, please be more specific at the end of the question. Dou you neec acces to count_result in which html? – pyjavo Dec 22 '22 at 22:47
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Dec 22 '22 at 22:49
  • Two more things: 1. Both functions are rendering `index.html` and that's kind of confusing. Maybe you need a redirect at the enf of one of them. 2. The get_count()` function doesn't have `count_result=get_count(x)` (You are expecting `count_result` in the HTML, right?) – pyjavo Dec 22 '22 at 22:52
  • @pyjavo yes iam expecting that one only if user changer the min(unit) and max(unit) values via html page –  Dec 23 '22 at 01:39

0 Answers0