text: from datetime import timedelta
  
  import matplotlib.dates as mdates
  import matplotlib.pyplot as plt
  import pandas as pd
  from measurement.models import Tick
  
  
  
  def get_last_15min_info_df(input_df):
      tmp_interval = timedelta(minutes=5)
      tmp_df = input_df[input_df.created_at > input_df.created_at.iloc[-1] - tmp_interval]
      tmp_df.index = tmp_df.created_at
      tmp_df = tmp_df.resample(rule="s").mean()
      return tmp_df.interpolate(method="linear")
  
  
  def get_last_10hour_info_df(input_df):
      tmp_interval = timedelta(hours=10)
      tmp_df = input_df[input_df.created_at > input_df.created_at.iloc[-1] - tmp_interval]
      tmp_df.index = tmp_df.created_at
      tmp_df = tmp_df.resample(rule="s").mean()
      return tmp_df.interpolate(method="linear")
  
  
  def get_last_1week_info_df(input_df):
      tmp_interval = timedelta(weeks=1)
      tmp_df = input_df[input_df.created_at > input_df.created_at.iloc[-1] - tmp_interval]
      tmp_df.index = tmp_df.created_at
      tmp_df = tmp_df.resample(rule="s").mean()
      return tmp_df.interpolate(method="linear")
  
  
  def draw_temperature_plot(input_df, input_ax):
      tmp_avg = input_df.temperature_inside.mean()
      input_ax.set_ylim(tmp_avg // 1 - 6, tmp_avg // 1 + 6)
      input_ax.set_ylabel('[°C]')
      input_ax.plot(input_df.index, input_df.temperature_inside, input_df.index, input_df.temperature_outside)
  
  
  def draw_pressure_plot(input_df, input_ax):
      tmp_avg = input_df.pressure_inside.mean()
      input_ax.set_ylim(tmp_avg // 1 - 5, tmp_avg // 1 + 5)
      input_ax.set_ylabel('[hPa]')
      input_ax.plot(input_df.index, 1006.7/1006.3 * input_df.pressure_inside, input_df.index, input_df.pressure_outside)
  
  
  def draw_humidity_plot(input_df, input_ax):
      tmp_avg = input_df.humidity_inside.mean()
      input_ax.set_ylim(tmp_avg // 1 - 10, tmp_avg // 1 + 10)
      input_ax.set_ylabel('[%]')
      input_ax.plot(input_df.index, 47/49.5 * input_df.humidity_inside, input_df.index, input_df.humidity_outside)
  
  
  def draw_plot_for_temperature(input_df, tmp_15min_df, tmp_10hour_df, tmp_1week_df):
      fig3 = plt.figure(constrained_layout=True, figsize=(16, 8))
      gs = fig3.add_gridspec(3, 3)
      f3_ax1 = fig3.add_subplot(gs[0, :])
      draw_temperature_plot(tmp_15min_df, f3_ax1)
      f3_ax1.set_title('Temperature for last 5 minutes')
      f3_ax1.xaxis.set_major_locator(mdates.MinuteLocator(interval=2))
      f3_ax1.xaxis.set_major_formatter(mdates.DateFormatter('%H:%M'))
  
      f3_ax2 = fig3.add_subplot(gs[1, :])
      draw_temperature_plot(tmp_10hour_df, f3_ax2)
      f3_ax2.set_title('Temperature for last 10 hours')
      f3_ax2.xaxis.set_major_locator(mdates.HourLocator(interval=2))
      f3_ax2.xaxis.set_major_formatter(mdates.DateFormatter('%m-%d-%H'))
  
      # f3_ax3 = fig3.add_subplot(gs[2, :])
      # f3_ax3.set_title('Temperature for last 1 week')
      # f3_ax3.xaxis.set_major_locator(mdates.DayLocator(interval=2))
      # f3_ax3.xaxis.set_major_formatter(mdates.DateFormatter('%m-%d'))
      # draw_temperature_plot(tmp_1week_df, f3_ax3)
  
      fig3.savefig("/run/media/hoosiki/WareHouse2/hoosiki/JUPYTER/gitrepository/Django/iot2/iot2/static/images/temperature.png")
  
  
  def draw_plot_for_pressure(input_df, tmp_15min_df, tmp_10hour_df, tmp_1week_df):
      fig3 = plt.figure(constrained_layout=True, figsize=(16, 8))
      gs = fig3.add_gridspec(3, 3)
      f3_ax1 = fig3.add_subplot(gs[0, :])
      draw_pressure_plot(tmp_15min_df, f3_ax1)
      f3_ax1.set_title('Pressure for last 5 minutes')
      f3_ax1.xaxis.set_major_locator(mdates.MinuteLocator(interval=2))
      f3_ax1.xaxis.set_major_formatter(mdates.DateFormatter('%H:%M'))
  
      tmp_10hour_df = get_last_10hour_info_df(input_df)
      f3_ax2 = fig3.add_subplot(gs[1, :])
      draw_pressure_plot(tmp_10hour_df, f3_ax2)
      f3_ax2.set_title('Pressure for last 10 hours')
      f3_ax2.xaxis.set_major_locator(mdates.HourLocator(interval=2))
      f3_ax2.xaxis.set_major_formatter(mdates.DateFormatter('%m-%d-%H'))
  
      # f3_ax3 = fig3.add_subplot(gs[2, :])
      # f3_ax3.set_title('Pressure for last 1 week')
      # f3_ax3.xaxis.set_major_locator(mdates.DayLocator(interval=2))
      # f3_ax3.xaxis.set_major_formatter(mdates.DateFormatter('%m-%d'))
      # draw_pressure_plot(tmp_1week_df, f3_ax3)
  
      fig3.savefig("/run/media/hoosiki/WareHouse2/hoosiki/JUPYTER/gitrepository/Django/iot2/iot2/static/images/pressure.png")
  
  
  def draw_plot_for_humidity(input_df, tmp_15min_df, tmp_10hour_df, tmp_1week_df):
      fig3 = plt.figure(constrained_layout=True, figsize=(16, 8))
      gs = fig3.add_gridspec(3, 3)
      f3_ax1 = fig3.add_subplot(gs[0, :])
      draw_humidity_plot(tmp_15min_df, f3_ax1)
      f3_ax1.set_title('Humidity for last 5 minutes')
      f3_ax1.xaxis.set_major_locator(mdates.MinuteLocator(interval=2))
      f3_ax1.xaxis.set_major_formatter(mdates.DateFormatter('%H:%M'))
  
      f3_ax2 = fig3.add_subplot(gs[1, :])
      f3_ax2.set_title('Humidity for last 10 hours')
      f3_ax2.xaxis.set_major_locator(mdates.HourLocator(interval=2))
      f3_ax2.xaxis.set_major_formatter(mdates.DateFormatter('%m-%d-%H'))
      draw_humidity_plot(tmp_10hour_df, f3_ax2)
  
      # f3_ax3 = fig3.add_subplot(gs[2, :])
      # f3_ax3.set_title('Humidity for last 1 week')
      # f3_ax3.xaxis.set_major_locator(mdates.DayLocator(interval=2))
      # f3_ax3.xaxis.set_major_formatter(mdates.DateFormatter('%m-%d'))
      # draw_humidity_plot(tmp_1week_df, f3_ax3)
  
      fig3.savefig("/run/media/hoosiki/WareHouse2/hoosiki/JUPYTER/gitrepository/Django/iot2/iot2/static/images/humidity.png")
  
  