extreme_wind_speed.py 1.6 KB

123456789101112131415161718192021222324252627282930
  1. from abstract_api import AbstractApi
  2. from apis.operate_mysql import OperateMysql
  3. import datetime
  4. class Extreme_wind_speed(AbstractApi):
  5. """返回极大风速(一定时间范围内的最大风速)"""
  6. def operation(self, request):
  7. operate_mysql = OperateMysql()
  8. wind_direction = request['basic_datas'][0] # 表示风向,如c1
  9. wind_speed = request['basic_datas'][1] # 表示风速,如c2
  10. res_wind_speed = operate_mysql.return_result(request, wind_speed.replace('c', ''))
  11. begin_time = res_wind_speed['begin_time']
  12. end_time = res_wind_speed['end_time']
  13. # 返回给定时间内的最大风速、最大风速对应的时间 [{'c2': 3.0, 'times': datetime.datetime(2021, 5, 4, 16, 25, 31)}]
  14. sql1 = "SELECT %s, times FROM %s WHERE times >= \'%s\' and times < \'%s\' ORDER BY %s desc limit 1;" % (wind_speed, res_wind_speed['table_name'], begin_time, end_time, wind_speed)
  15. res1 = operate_mysql.execute_sql(sql1)
  16. if len(res1) != 0:
  17. speed = res1[0][wind_speed]
  18. times = res1[0]['times']
  19. res_wind_direction = operate_mysql.return_result(request, wind_direction.replace('c', ''))
  20. sql3 = "SELECT %s FROM %s WHERE times = \'%s\';" % (wind_direction, res_wind_direction['table_name'], times)
  21. res3 = operate_mysql.execute_sql(sql3)[0][wind_direction]
  22. dict_res = {request['keys'][0]: res3, request['keys'][1]: speed, request['keys'][2]: times.strftime('%Y-%m-%d %H:%M:%S')}
  23. return dict_res
  24. else:
  25. return None