replaced TRUE/FALSE with 1/0 in SQL statements in myems-cleaning service

pull/136/MERGE
13621160019@163.com 2022-03-24 14:13:48 +08:00
parent bf78978032
commit 10ff46bae1
1 changed files with 7 additions and 7 deletions

View File

@ -33,8 +33,8 @@ def process(logger):
# Note: # Note:
# the default value of unchecked values' is_bad property is NULL # the default value of unchecked values' is_bad property is NULL
# if a value is checked and the result is bad then is_bad would be set to TRUE # if a value is checked and the result is bad then is_bad would be set to 1
# else if a value is checked and the result is good then is_bad would be set to FALSE # else if a value is checked and the result is good then is_bad would be set to 0
################################################################################################################ ################################################################################################################
# Step 1: get the time slot to clean. # Step 1: get the time slot to clean.
@ -212,7 +212,7 @@ def process(logger):
try: try:
query = (" SELECT id, point_id, actual_value " query = (" SELECT id, point_id, actual_value "
" FROM tbl_energy_value " " FROM tbl_energy_value "
" WHERE utc_date_time >= %s AND utc_date_time <= %s AND is_bad IS NOT TRUE ") " WHERE utc_date_time >= %s AND utc_date_time <= %s AND (is_bad = 0 OR is_bad IS NULL) ")
cursor_historical.execute(query, (min_datetime, max_datetime,)) cursor_historical.execute(query, (min_datetime, max_datetime,))
rows_energy_values = cursor_historical.fetchall() rows_energy_values = cursor_historical.fetchall()
except Exception as e: except Exception as e:
@ -239,7 +239,7 @@ def process(logger):
if len(bad_list) > 0: if len(bad_list) > 0:
try: try:
update = (" UPDATE tbl_energy_value " update = (" UPDATE tbl_energy_value "
" SET is_bad = TRUE " " SET is_bad = 1 "
" WHERE id IN (" + ', '.join(map(str, bad_list)) + ")") " WHERE id IN (" + ', '.join(map(str, bad_list)) + ")")
cursor_historical.execute(update, ) cursor_historical.execute(update, )
cnx_historical.commit() cnx_historical.commit()
@ -393,7 +393,7 @@ def process(logger):
try: try:
query = (" SELECT point_id, id, utc_date_time, actual_value " query = (" SELECT point_id, id, utc_date_time, actual_value "
" FROM tbl_energy_value " " FROM tbl_energy_value "
" WHERE utc_date_time >= %s AND utc_date_time <= %s AND is_bad IS NOT TRUE " " WHERE utc_date_time >= %s AND utc_date_time <= %s AND (is_bad = 0 OR is_bad IS NULL) "
" ORDER BY point_id, utc_date_time ") " ORDER BY point_id, utc_date_time ")
cursor_historical.execute(query, (min_datetime, max_datetime,)) cursor_historical.execute(query, (min_datetime, max_datetime,))
rows_energy_values = cursor_historical.fetchall() rows_energy_values = cursor_historical.fetchall()
@ -463,7 +463,7 @@ def process(logger):
if len(bad_list) > 0: if len(bad_list) > 0:
try: try:
update = (" UPDATE tbl_energy_value " update = (" UPDATE tbl_energy_value "
" SET is_bad = TRUE " " SET is_bad = 1 "
" WHERE id IN (" + ', '.join(map(str, bad_list)) + ")") " WHERE id IN (" + ', '.join(map(str, bad_list)) + ")")
cursor_historical.execute(update, ) cursor_historical.execute(update, )
cnx_historical.commit() cnx_historical.commit()
@ -557,7 +557,7 @@ def process(logger):
################################################################################################################ ################################################################################################################
try: try:
update = (" UPDATE tbl_energy_value " update = (" UPDATE tbl_energy_value "
" SET is_bad = FALSE " " SET is_bad = 0 "
" WHERE utc_date_time >= %s AND utc_date_time < %s AND is_bad IS NULL ") " WHERE utc_date_time >= %s AND utc_date_time < %s AND is_bad IS NULL ")
# NOTE: use '<' instead of '<=' in WHERE statement because there may be some new inserted values # NOTE: use '<' instead of '<=' in WHERE statement because there may be some new inserted values
cursor_historical.execute(update, (min_datetime, max_datetime,)) cursor_historical.execute(update, (min_datetime, max_datetime,))