Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
print("*************************************************************")
print("* SQL data 15 min")
print("*************************************************************")
# push extracted and filtered data to temporary database
for key, value in processed_data.items():
# abbreviate data table
m = m_raw_data[key]
if key == "SE_ZIMIRICEA":
length = len(value)
mean = statistics.mean(value)
deviation = statistics.stdev(value)
dataset = (float(m.meta['start']), float(m.meta['end']), length, mean, deviation)
sql.add_data(conn, "SE_ZIMIRICEA_IDLE", dataset)
elif key == "IMIR_HK_ICE_SEC_VOLT4":
length = len(value)
mean = statistics.mean(value)
deviation = statistics.stdev(value)
dataset = (float(m.meta['start']), float(m.meta['end']), length, mean, deviation)
sql.add_data(conn, "IMIR_HK_ICE_SEC_VOLT4_IDLE", dataset)
else:
length = len(value)
mean = statistics.mean(value)
deviation = statistics.stdev(value)
dataset = (float(m.meta['start']), float(m.meta['end']), length, mean, deviation)
sql.add_data(conn, key, dataset)
# abbreviate data table
m = m_raw_data[key]
if key == "SE_ZIMIRICEA":
length = len(value)
mean = statistics.mean(value)
deviation = statistics.stdev(value)
dataset = (float(m.meta['start']), float(m.meta['end']), length, mean, deviation)
sql.add_data(conn, "SE_ZIMIRICEA_IDLE", dataset)
elif key == "IMIR_HK_ICE_SEC_VOLT4":
length = len(value)
mean = statistics.mean(value)
deviation = statistics.stdev(value)
dataset = (float(m.meta['start']), float(m.meta['end']), length, mean, deviation)
sql.add_data(conn, "IMIR_HK_ICE_SEC_VOLT4_IDLE", dataset)
else:
length = len(value)
mean = statistics.mean(value)
deviation = statistics.stdev(value)
dataset = (float(m.meta['start']), float(m.meta['end']), length, mean, deviation)
sql.add_data(conn, key, dataset)
if key == "SE_ZIMIRICEA":
key = "SE_ZIMIRICEA_IDLE"
if key == "IMIR_HK_ICE_SEC_VOLT4":
key = "IMIR_HK_ICE_SEC_VOLT4_IDLE"
length = len(value)
mean = statistics.mean(value)
deviation = statistics.stdev(value)
dataset = (float(m.meta['start']), float(m.meta['end']), length, mean, deviation)
sql.add_data(conn, key, dataset)
except:
if 'variance requires at least two data points' == str(sys.exc_info()[1]):
dataset = (float(m.meta['start']), float(m.meta['end']), float(1), value[0], float(0))
sql.add_data(conn, key, dataset)
else:
log.log('Error: ' + str(sys.exc_info()[1]), 'Error')
dataset = (float(m.meta['start']), float(m.meta['end']), length, mean, deviation)
sql.add_data(conn, "SE_ZIMIRICEA_IDLE", dataset)
elif key == "IMIR_HK_ICE_SEC_VOLT4":
length = len(value)
mean = statistics.mean(value)
deviation = statistics.stdev(value)
dataset = (float(m.meta['start']), float(m.meta['end']), length, mean, deviation)
sql.add_data(conn, "IMIR_HK_ICE_SEC_VOLT4_IDLE", dataset)
else:
length = len(value)
mean = statistics.mean(value)
deviation = statistics.stdev(value)
dataset = (float(m.meta['start']), float(m.meta['end']), length, mean, deviation)
sql.add_data(conn, key, dataset)
try:
# get data
data, meta, info = edb.query_single_mnemonic(mnemonic_name, start_time, end_time, token=mast_token)
data['time_iso'] = Time(data['MJD'], format='mjd').iso
del data['theTime']
# data.show_in_browser(jsviewer=True)
value = data['euvalue']
# process querried data
length = len(value)
mean = statistics.mean(value)
deviation = statistics.stdev(value)
dataset = (float(start_time.decimalyear), float(end_time.decimalyear), length, mean, deviation)
sql.add_data(conn, mnemonic_name, dataset)
# set text and color
status = 'Succes'
color = '\033[0m' # color black (standard)
except:
# set text and color
status = 'Failure'
color = '\33[31m' # color red
print_string = 'dt_corn_job: ' + DateTime.now().isoformat() + '\t' + status + '\t' + mnemonic_name
sys.stdout = oldstdout # enable output
print_string = color + print_string + '\033[0m'
# sys.stdout.flush()
# sys.stdout.write("\r%s" %print_string)
print(print_string)
#abbreviate data table
m = m_raw_data.mnemonic(key)
if key == "SE_ZIMIRICEA":
length = len(value)
mean = statistics.mean(value)
deviation = statistics.stdev(value)
dataset = (float(m.meta['start']), float(m.meta['end']), length, mean, deviation)
sql.add_data(conn, "SE_ZIMIRICEA_IDLE", dataset)
elif key == "IMIR_HK_ICE_SEC_VOLT4":
length = len(value)
mean = statistics.mean(value)
deviation = statistics.stdev(value)
dataset = (float(m.meta['start']), float(m.meta['end']), length, mean, deviation)
sql.add_data(conn, "IMIR_HK_ICE_SEC_VOLT4_IDLE", dataset)
else:
length = len(value)
mean = statistics.mean(value)
deviation = statistics.stdev(value)
dataset = (float(m.meta['start']), float(m.meta['end']), length, mean, deviation)
sql.add_data(conn, key, dataset)