Commit b63fb3ef authored by Sergio Bruni's avatar Sergio Bruni

commmit

parent a885020c
......@@ -635,10 +635,15 @@ class DaemonGPS(daemon.Daemon):
return False
os.chmod(self.dest_file_full_name, 0o644)
date = "%s-%s-%s" %(self.macros['__CCYY__'], self.macros['__MM__'], self.macros['__DD__'])
header_data = self.extractRinexData()
self.DBaddRinex(self.conf_reti["key"], self.macros['__STATION_CODE_LOWER_CASE__'], date, header_data)
#date = "%s-%s-%s" %(self.macros['__CCYY__'], self.macros['__MM__'], self.macros['__DD__'])
#header_data = self.extractRinexData()
#self.DBaddRinex(self.conf_reti["key"], self.macros['__STATION_CODE_LOWER_CASE__'], date, header_data)
my_date = date(int(self.macros['__CCYY__']),
int(self.macros['__MM__']),
int(self.macros['__DD__']))
self.DBIndexRinex(self.conf_reti["key"], self.macros['__STATION_CODE_LOWER_CASE__'], my_date)
return True
def makeSymbolicLink(self, stazione):
......@@ -853,7 +858,7 @@ class DaemonGPS(daemon.Daemon):
except Exception as e:
self.logger.error("error: %s" % str(e))
def DBaddRinex(self, network_name, station_code, my_date, header_data):
def DBaddRinex_DEPRECATED(self, network_name, station_code, my_date, header_data):
try:
if self.conf_global["database"]["active"].upper() != "TRUE":
return
......@@ -887,6 +892,88 @@ class DaemonGPS(daemon.Daemon):
self.logger.error("error: %s [%s]" % (str(e), msg))
# New method based on anubis
def DBIndexRinex(self, network_name, station_code, my_date):
if self.conf_global["database"]["active"].upper() != "TRUE":
return
runqc = os.path.join(self.conf_global["RunQC_folder"], 'RunQC.pl')
anubis_xml_dir = os.path.join(self.tmpdirname, 'anubis_log')
my_args = [runqc,
'--time_lim', '99',
'BRD/%Y',
'-verb', '1',
'-mask_rxo', self.dest_file_full_name,
'--save_dir', anubis_xml_dir
]
result = subprocess.run(my_args,
stdout=subprocess.PIPE,
cwd = self.conf_global["RunQC_folder"])
doy = str(my_date.timetuple().tm_yday).zfill(3)
year = str(my_date.year)
anubis_output_xml_file_name = "{}{}{}0.xml".format(station_code, year, doy)
anubis_output_xml_file_full_name = os.path.join(anubis_xml_dir, anubis_output_xml_file_name)
try:
with open(anubis_output_xml_file_full_name, 'r') as myfile:
anubis_xml = myfile.read()
except FileNotFoundError as e:
self.logger.error("[{}] Anubis did not create xml output file" \
.format(self.dest_file_full_name))
put_data = {}
put_data["network_name"] = network_name
put_data["station_code"] = station_code
put_data["day"] = "{:%Y-%m-%d}".format(my_date)
put_data["bad"] = True
head = {'Content-type': 'application/json'}
url = self.conf_global["rest_services_url"] + "/rinex"
try:
ret = requests.put(url,
data = json.dumps(put_data),
headers = head)
except Exception as e:
self.logger.error("[%s] error: %s" \
.format(__name__, str(e)))
else:
self.logger.info("Status [%s] text: [%s]" % (ret.status_code, ret.text.replace('\n', '')))
return
post_data = {}
post_data["network_name"] = network_name
post_data["station_code"] = station_code
post_data["day"] = "{:%Y-%m-%d}".format(my_date)
post_data["anubis_xml"] = anubis_xml
payload_json = json.dumps(post_data).encode('utf8')
head = {'Content-type': 'application/json'}
url = self.conf_global["rest_services_url"] + "/gps/data/qcfile"
try:
res = requests.post(url, data=payload_json, headers=head)
except Exception as e:
self.logger.error("error: %s" % str(e))
return
self.logger.info("Status [%s] text: [%s]" % (res.status_code, res.text.replace('\n', '')))
if res.status_code == 200:
self.logger.info("Already indexed file {} has been updated" \
.format(self.dest_file_full_name))
elif res.status_code == 201:
self.logger.info("new file {} has been indexed" \
.format(self.dest_file_full_name))
else:
self.logger.error("Error returned on indexing file {}. Status code: {}" \
.format(self.dest_file_full_name, res.status_code))
return
def DBRefreshCache(self):
# la disabilito per il momento ...
......@@ -1053,7 +1140,7 @@ class DaemonGPS(daemon.Daemon):
except:
self.error = "error on sub %s extracting from zip file %s : %s" % ("extractFileFromZipArchive", zip_archive_full_name, str(sys.exc_info()))
def extractRinexData(self):
def extractRinexData_DEPRECATED(self):
put_data = {}
put_data["bad"] = False
#tmp = self.tmpdirname.encode('ascii', 'replace')
......@@ -1652,13 +1739,24 @@ class DaemonGPSaragea(DaemonGPS):
return self.downloader.list_remote_stations()
def manageStation(self):
date = "%s/%s/%s" % (self.macros['__DD__'], self.macros['__MM__'], self.macros['__CCYY__'])
if not self.downloader.get_file(self.dest_file_name, self.dest_dir_name, date, self.macros['__STATION_CODE_UPPER_CASE__']):
date_str = "%s/%s/%s" % (self.macros['__DD__'], self.macros['__MM__'], self.macros['__CCYY__'])
if not self.downloader.get_file(self.dest_file_name, self.dest_dir_name, date_str, self.macros['__STATION_CODE_UPPER_CASE__']):
return False
header_data = self.extractRinexData()
my_date = "%s-%s-%s" %(self.macros['__CCYY__'], self.macros['__MM__'], self.macros['__DD__'])
self.DBaddRinex(self.conf_reti["key"], self.macros['__STATION_CODE_LOWER_CASE__'], my_date, header_data)
#header_data = self.extractRinexData()
#my_date = "%s-%s-%s" %(self.macros['__CCYY__'], self.macros['__MM__'], self.macros['__DD__'])
#self.DBaddRinex(self.conf_reti["key"], self.macros['__STATION_CODE_LOWER_CASE__'], my_date, header_data)
# a = int(self.macros['__CCYY__'])
# m = int(self.macros['__MM__'])
# g = int(self.macros['__DD__'])
my_date = date(int(self.macros['__CCYY__']),
int(self.macros['__MM__']),
int(self.macros['__DD__']))
# my_date = date(a,m,g)
self.DBIndexRinex(self.conf_reti["key"], self.macros['__STATION_CODE_LOWER_CASE__'], my_date)
return True
class DaemonGPSumbria(DaemonGPS):
......@@ -1961,9 +2059,9 @@ class DaemonGPSmetrica__DEPRECATED(DaemonGPS):
my_date = date(int(self.macros['__CCYY__']), 1, 1) + timedelta(int(self.macros['__DOY__']) - 1)
string_date = "{:%Y-%m-%d}".format(my_date)
header_data = self.extractRinexData()
self.DBaddRinex(self.conf_reti["key"], self.macros['__STATION_CODE_LOWER_CASE__'], string_date, header_data )
#header_data = self.extractRinexData()
#self.DBaddRinex(self.conf_reti["key"], self.macros['__STATION_CODE_LOWER_CASE__'], string_date, header_data )
self.DBIndexRinex(self.conf_reti["key"], self.macros['__STATION_CODE_LOWER_CASE__'], my_date)
self.logger.warning("end process %s" % (self.conf_rete["name"]))
......@@ -2319,13 +2417,17 @@ class DaemonGPSgalnet(DaemonGPS):
os.chmod(self.dest_file_full_name, 0o644)
date = "%s-%s-%s" %(self.macros['__CCYY__'], self.macros['__MM__'], self.macros['__DD__'])
self.logger.info('New file %s has been created' % (self.dest_file_full_name))
header_data = self.extractRinexData()
self.DBaddRinex(self.conf_reti["key"], self.macros['__STATION_CODE_LOWER_CASE__'], date, header_data)
self.logger.info('New file %s has been created' % (self.dest_file_full_name))
#date = "%s-%s-%s" %(self.macros['__CCYY__'], self.macros['__MM__'], self.macros['__DD__'])
#header_data = self.extractRinexData()
#self.DBaddRinex(self.conf_reti["key"], self.macros['__STATION_CODE_LOWER_CASE__'], date, header_data)
my_date = date(int(self.macros['__CCYY__']),
int(self.macros['__MM__']),
int(self.macros['__DD__']))
self.DBIndexRinex(self.conf_reti["key"], self.macros['__STATION_CODE_LOWER_CASE__'], my_date)
def list_remote_stations(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment