title: Analysing graph from matplotlib
body: <p>I'm currently making a device where it uses MyoWare Muscle Sensor to collect data , send it to the mysql database , and using matplotlib to display the graph. As this device is for sports purposes ( in my case weight lifting ) , i want to be able to determine the number of repetitions the user does. Does anyone know or can show me how can i achieve it ?</p>
  
  <p><a href="https://i.stack.imgur.com/Rdj50.png" rel="nofollow noreferrer">Here is my graphs with 4 reps</a></p>
  
  <p>My python code</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>conn = pymysql.connect(host="localhost", user="root", passwd="123456", db="XXX")
  cur = conn.cursor()
  query = """
  SELECT CONVERT(data,SIGNED INTEGER),time FROM sensordata
  """
  cur.execute(query)
  data = cur.fetchall()
  cur.close
  
  cur =conn.cursor()
  query1 = """
  SELECT CONVERT(data1,SIGNED INTEGER),time1 FROM sensordata2
  """
  cur.execute(query1)
  data1= cur.fetchall()
  cur.close
  conn.close()
  
  data,time= zip(*data)
  data1,time1= zip(*data1)
  
  data_moving_average = []
  for initial_element_index in range(len(data)): 
      data_moving_average.append(sum(data[initial_element_index:initial_element_index+20])/5.)
  data_moving_average1 = []
  for initial_element_index in range(len(data1)):
      data_moving_average1.append(sum(data1[initial_element_index:initial_element_index+20])/5.)
  
  plt.plot(time,data_moving_average)
  plt.plot(time1,data_moving_average1)</code></pre>
  </div>
  </div>
  
  What is inside my database
  <div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>+-----+------+---------------------+----------------------------+
  | id  | data | time                | analyzetime                |
  +-----+------+---------------------+----------------------------+
  |   1 | 1    | 2017-06-22 08:23:09 | 2017-06-22 08:23:09.846534 |
  |   2 | 0    | 2017-06-22 08:23:10 | 2017-06-22 08:23:10.048035 |
  |   3 | 0    | 2017-06-22 08:23:10 | 2017-06-22 08:23:10.333497 |
  |   4 | 0    | 2017-06-22 08:23:10 | 2017-06-22 08:23:10.656422 |
  |   5 | 0    | 2017-06-22 08:23:10 | 2017-06-22 08:23:10.865791 |
  |   6 | 0    | 2017-06-22 08:23:10 | 2017-06-22 08:23:10.954816 |
  |   7 | 0    | 2017-06-22 08:23:11 | 2017-06-22 08:23:11.147128 |
  |   8 | 0    | 2017-06-22 08:23:11 | 2017-06-22 08:23:11.402207 |
  |   9 | 0    | 2017-06-22 08:23:11 | 2017-06-22 08:23:11.613567 |
  |  10 | 0    | 2017-06-22 08:23:11 | 2017-06-22 08:23:11.867029 |</code></pre>
  </div>
  </div>
  </p>